Buddhabrot plots

As an exercise in programming Fortran 90, I wrote something to generate Buddhabrot pictures. Buddhabrot plots are related to the Mandelbrot set. Instead of just trying to display the Mandelbrot set itself, you track the “path” of the sequence

 z_{n+1} = z_n^2 + c

for various complex numbers  c , which are not in the Mandelbrot set. Wikipedia explains this process better:

The Buddhabrot is rendered by first creating a 2-dimensionalarray of counters, each counter corresponding to a final pixel of the image and initialized to zero. Then, a random sampling of c points are iterated through the Mandelbrot function. For points which do escape within a chosen maximum number of iterations, and therefore are not in the Mandelbrot set, their values are sent through the Mandelbrot function again and this time its path is plotted into the array. After a large number of c values have been iterated, grayscale shades are then chosen based on the values recorded in the array. The result is a density plot highlighting regions where z values spend the most time on their way to infinity. This could also be thought of as a probability distribution where the bright regions correspond to regions of high probability (of trajectories passing through the region) and the dark regions correspond to regions of low probability.

How to generate the Mandelbrot set

Really – don’t read this. Just look it up on Wikipedia or something.

Basically you start with some complex number c. The first value  z_0 is always set to zero. Using the formula above you calculate z_1 and from this z_2, z_3 and so on. Note that this sequence of complex numbers depends on the “starting value” c.

For some values of c the absolutes of z_n grow larger and larger. The points “escapes”. If this happens c does not belong to the Mandelbrot set. However if the sequence of numbers doesn’t escape after infinite steps, the number c does belong to the Mandelbrot set.

On a computer you can’t do infinite steps. One way to work around this is to check after every step if the absolute of the next number z_{n+1} exceeds some threshold value. If – after a certain maximum number of steps – the absolutes are still smaller than the threshold value, we can say that the point c is an element of the Mandelbrot set, at least with high probability. The larger you choose the threshold value and the maximum number of steps, the better the approximation to the Mandelbrot set.

To get those colorful images of the Mandelbrot set, you create a grid of starting points for c for every pixel on the image and send them all through the sequence. Some of them will exceed the threshold value after a few iterations, others will take longer. Then we assign every pixel a colour based on how many iterations it took to exceed. If the points don’t escape at all for a certain maximum number of steps, they are considered part of the Mandelbrot set and get a different colour (black in the example above). Here is a nice gif, which shows how you get a better and more detailed approximation of the set by increasing the maximum number of iterations.

More interesting: Plotting Buddhabrot pictures

Now we know how to find out if a point belongs to the Mandelbrot set (at least approximatively). To plot a Buddhabrot we take some starting number c and let it run through the Mandelbrot sequence. If it is not part of the set, we send it through the sequence again. Now we record the path the numbers z_n take, as they wander through the complex plane. To record this path we set up a two-dimensional array, where each entry represents a point in the complex plane. At first every value of this array is set to zero. This array will give us our Buddhabrot image and we call this the “counter array”.

As the sequence wanders through the complex plane we record the path using the counter array. For each point (element) of the sequence, we add +1 to the respective entry in the counter array. Now take a lot (a LOT!) of different starting points and let them wander through the complex plane. In the end we can plot the array.

The picture you get depends on the maximum number of iterations you’ve chosen for the plot. Here are some examples:

A Buddhabrot using 20 iterations

A Buddhabrot using 40 iterations

A Buddhabrot using 2,000 iterations

These black and white plots were generated using gnuplot, but that it’s not important which software you choose (maybe code it yourself?). Just plot an image based on the counter array. Bright pixels correspond to high counts.

Needs moar colours!

We can make colourful plots using the Nebulabrot technique: Take three different (read: different maximum number of iterations) Buddhabrot plots and use them as red, green and blue channels of a picture. Using this technique I got this cool image:

A coloured Buddhabrot

To be honest I tweaked the colours a little bit, but the principle still applies: Exploit the fact that you can get very different Buddhabrot plots for various iteration numbers and mix these images to get pretty pictures.

Watching the Buddhabrot grow

I also created an animation that shows how the Buddhabrot “grows”. Each successive image is a Buddabrot plot with a higher maximum number of iterations than the previous image. Note the noise: This is because of the random sampling.

For each individual image I took a sample of 10,000,000 points.

Fortran 90 code

You can read the code of the program here: http://pasteit.com/17432

The program needs a function called ran2(seed) to generate random numbers in the interval (0,1). I used this one http://pasteit.com/17459 (I didn’t write it and I don’t know how it works).

This f90 program consists basically of four subroutines:

The subroutine createNewCounterArray(filename, fn_len) creates a new counter array (standard size is 1000×1000) and saves it to a file. filename is a String (Note: This is an array of characters. Fortran 90 does not come with a String object. That’s also the reason for the integer argument fn_len. You can’t read the length of an array, so you have to tell the subroutine how long the file name should be. If you want the file name to be ‘buddha.txt’ set the fn_len to 10.)  You need to run this for a new plot.

loadCounterArray(filename, fn_len, out_c_array) loads the file created by the createNewCounterArray and writes it to the array out_c_array, which should be a 1000 by 1000 integer array.

saveCounterArray(filename, fn_len, in_c_array) saves a counter array to a file. in_c_array is a 1000 by 1000 integer array.

These three subroutines are used to save a plot and load it later. Buddhabrot plots take a lot of time, so I wanted to be able to save the progress somehow.

computePoints(max_points, max_iterations, counterArray) samples a certain number of points (max_points) and sends them through the Mandelbrot sequence using max_iterations. The progress is saved to the counterArray. Note: The threshold value for the sequence is hardcoded to 10. The rectangle in the complex plane from which the random points are chosen is also hardcoded.

Using these 4 subroutines I was able to create the plots above. The program itself creates the individual plots for the animated Buddhabrot using gnuplot. You can write Buddhabrot stuff using any language, but Fortran is cool because it’s fast and supports complex numbers. There is no need to write a complex number class first!

Posted in Mathematics, Programming | Leave a comment

The deepest hole ever drilled

Kola Superdeep Borehole, the deepest hole ever drilled.


View Larger Map

The Kola Superdeep Borehole (Russian: Кольская сверхглубокая скважина) is the result of a scientific drilling project of the Soviet Union on the Kola Peninsula. The project attempted to drill as deep as possible into the Earth’s crust.

A number of boreholes were drilled by branching from a central hole. The deepest, SG-3, reached 12,262 metres (40,230 ft) in 1989, and is the deepest hole ever drilled, and the deepest artificial point on earth.

Wouldn’t it be awesome to just drill a deep hole into the earth and use geothermal power plants for virtually endless energy?

Posted in Yeah, Science!! | Leave a comment

Penrose’s graphical notation II

I have been reading Roger Penrose’s book “Road to Reality“, which has been amazing so far. In the chapter about manifolds and tensors Penrose presents his graphical notation for tensor calculus. At first I didn’t understand what you can really do with this new notation and thought it was just a (more or less useless) tool to visualize certain structures or equations. Surely, I was wrong: Turns out there are more (a lot more) diagrammatic approaches in mathematics (such as trace diagrams). For instance some guy wrote a book on group theory that uses a graphical notation similiar to the one Penrose uses. Of course adopting a new notation only makes sense if you can use it to speed up derivations or gain some new insight.

In this post I want to summarize some basics things I’ve learned about this graphical notation.

First, let’s see how to write down a vector v^a using diagrams: For the “name” of the vector (in this case it’s v) we take some two-dimensional shape like a square or a circle. Next we want to say that this is a vector with an upper index, so we draw a line from the shape upwards. The results looks like this:

Diagrammatic representation of a vector

To draw a covector we use a shape and a line that is pointing down.

Diagrammatic representation of a covector

More complicated tensors just have more indices, right? So we just draw more lines to get a tensor of an arbitrary type.

A tensor of type (2,3)

Every unconnected line represents a “free” index.

Now that we know how to write down the most simple stuff we want to know how to do operations on them. For index contraction we just connect the lines. For instance the scalar product of two vectors v^a w_a looks like this:

The scalar product in graphical notation

Connecting lines reduces the numbers of unconnected lines (duh..) and therefore reduces the type of the tensors, just like index contraction.

If we want to add or subtract tensors of the same type we just use the plus and minus symbols.

We can also symmetrize or antisymmetrize index sets using straight or squiggly lines:

Antisymmetrization of a (0,2)-tensor

 

Symmetrization of a (0,2)-tensor

Using the tensor contraction we can draw a few examples:

A few examples of tensor contraction

The identity map or Kronecker delta \delta^a_b can be written down in a very natural way. It is just a straight line. Inserting this straight line in our examples above doesn’t change anything, which is precisely what the identity map is supposed to do.

The Kronecker-Delta

Now on to more fun stuff: To get the dual element of a vector we use the metric tensor g_{ab} like this v_a = g_{ab} v^b. By this we turn an upper index into a lower index. In the graphical notation we do the same: Just turn the line that is turning upwards into one that is turning downwards by “bending” it downward:

"Pulling" indices using the metric tensor

Using this picture we can identify the metric tensor: It is the bent line connecting two downward pointing lines. Conversely the metric tensor with two upper indices g^{ab} is  a bent line in the other direction.

Diagrammatic representation of the metric tensor

In abstract index notation the equation

g_{ab} g^{bc} = \delta_a^b

must hold for the metric tensor. In the graphical notation we “see” this immediately. First, connect the two bent lines that represent the metric tensor. Now let us straight out this line:

Identity for the metric tensor

If you remember, we defined the straight line to be the identity map.  This is a way of “proving” the equation stated above. Neat, isn’t it?

Seeing this example made me understand that this kind of way writing things down isn’t just a waste of time. You can actually derive stuff with it and quickly too!

How do we write down the trace of a tensor? Here’s how:

Trace of a tensor

In particular we can consider the trace of the metric tensor:

Trace of the metric tensor

The result is just the number of dimensions n.

These things are really just the basics. Right now I am trying to find more examples of proofs that get way more easier using graphical representations for tensors and if I do, I will post them here. The most important thing about is not just finding neat pictures for things, but also using them in a natural and intuitive way to actually derive and prove stuff!

Posted in Mathematics, Physics | Leave a comment

Upward Mobility June 2011 Drum & Bass Mix

Dat opening track. Thanks to Scrambled|RK for this awesome mix!

Listening to this mix made me look up some stuff on youtube how to do various effects in electronic music. This tutorial looks pretty good:

Now I have to get my hands on Reason. Never tried it, I’m only using Ableton and Fruity Loops.

Posted in Music | Leave a comment

Pink Floyd

You have to listen to 4 minutes of ambient to get to the first guitar part, but it’s really worth the wait. That guitar riff is phenomenal.

Very eerie and it sticks in my mind.

I might continue this post to add more songs.

Posted in Music | Leave a comment

Penrose’s graphical notation

This stuff looks hilarious, just look at these equations:

http://en.wikipedia.org/wiki/Penrose_graphical_notation#Covariant_derivative

The German wiki article has even more examples. For instance the bianchi identity:

what the fuck

what the fuck am I looking at?

 \nabla_{[a}R_{bc]d}^{\quad e}=0

Posted in Mathematics, Physics | Leave a comment

LaTeX works too!

 R_{ab} - \frac{1}{2}g_{ab}R=8 \pi T_{ab}

If you don’t know, these are the Einstein field equations, without the cosmological constant.

Posted in Uncategorized | Leave a comment

physics.stackexchange.com

http://physics.stackexchange.com/

This is a really great site with interesting questions and usually professionals answering them.  By contrast the questions in /r/physics are often/sometimes answered by people, who don’t really know what they are talking about and I think it is tiring searching through the comments to get a partially right answer.

Posted in Physics | Leave a comment

How energy in general relativity is not conserved

A very simple question actually: If light is red-shifted, as the universe expands, where does the energy go? Physical intuition tells me that energy should be conserved, right?

As mind-boggling as it is, the answer is no, energy is not conserved in general relativity.

If the Hamiltonian has time translation invariance (or if there exists a time-like killing vector field), we say that energy is conserved. This follows from Noethers theorem.

However, even if we consider the most simple cosmological models in general relativity, namely the FLRW-models, there exists no time-translation invariance, as the universe is expanding. There are no time-like killing vectors, only time-like conformal killing vectors. Therefore energy is not conserved globally.

I know the math behind that stuff, but I still can’t wrap my mind around this. These links helped understand the problem better:

http://motls.blogspot.com/2010/08/why-and-how-energy-is-not-conserved-in.html

http://physics.stackexchange.com/questions/296/is-energy-really-conserved

Posted in Physics | Leave a comment