Archive for February, 2008

February 5th, 2008

Every now and then I like to play a video game or two and one I discovered recently is Secret Mayro Chronicles, an open source (ie free) game based on Nintendo’s classic Super Mario World. It has received some very positive reviews so I thought I would give it a try. A quick look through synaptic showed me that the game is included in the standard Ubuntu Linux (windows version repositories under the packages ‘smc’ and ‘smc-data’ so I installed them and went to play.

The first thing I noticed was that the game was not included in Gnome’s ‘games’ menu which is not uncommon in the world of Linux games. No problem – just open a terminal and run the command


and you will be up and running…normally. Unfortunately it seems that the supporting libraries for the game were not packaged correctly so when you try and run the game you will get the following error

CEGUI::Exception: DynamicModule::DynamicModule – Failed to load module: ‘’ cannot open shared object file: No such file or directory
CEGUI Exception occurred : DynamicModule::DynamicModule – Failed to load module ‘’: cannot open shared obj

which looks a little scary. This can be fixed by running the following commands in a terminal just once.

cd /usr/lib
sudo ln -s
sudo ln -s
sudo ln -s

All this does is set up a few symbolic links so that the game can find the files it needs. The game still won’t appear in the menu but it will run just fine from the terminal.

The version in the standard Ubuntu repositories is a little out of date but I have been playing it for the last half an hour or so and its great fun. You could go over to the games official website to get the latest version if you wish but I am happy to wait for it to be upgraded in the repositories.

If you have any children then I imagine that they would love this game and you really can’t beat it at the price. There is a windows version available too from the official site but I haven’t tried it so have no idea how it compares to the Linux version.

February 4th, 2008

A new version of SpaceTime, the fantastic commercial pocket PC mathematics application has been released. Changes include the addition of two new plot types – vector plots and 3D lists – and improvements to the symbolic integration engine. Click here for the full list of changes.

February 4th, 2008

A new version of SAGE Math was released a couple of days ago. This includes an important security patch so if you are a SAGE Math user then it is highly recommended that you upgrade. The full changelog can be found here.

February 1st, 2008

In a recent post over at 360 the author was discussing how Joe Turner (a prof of musical composition) has formed a musical composition based on the expansion of Pi in base 12 and it sounds pretty good considering the fact that it is based on a random sequence. This was picked up by another blog I discovered recently (thanks to the carnival of mathematics) where the author asked if anyone else would mind producing similar compositions based on other mathematical constants.

On the train journey home from work I thought that I might be able to get Mathematica to produce simplified versions of these sort of compositions without too much effort. So I fired up my copy of Mathematica, plugged in some headphones (I was fairly sure that my fellow commuters would not appreciate the music of Pi as much as I) and set to work. Although I knew that Mathematica had sound capabilities I had never used them before so the help browser (as usual) was indispensable.

I am going to present the rest of this post as a tutorial, with Mathematica commands in bold followed by the output in normal tyle. This is my first attempt at a tutorial in a blog post so feedback would be welcomed.

From the help browser I discovered that you can represent a note in Mathematica using SoundNote. Middle C is represented by SoundNote[0], one semi-tone above middle C is SoundNote[1] , a whole tone above Middle C is SoundNote[2] and so on. You can also use negative numbers so that SoundNote[-1] is one semi-tone below middle C for example.

So far so good but I don’t want to just represent the notes symbolically – I want to actually play them. The way to do this is by wrapping a SoundNote expression with Sound[]. So to play a middle C just evaluate


A little interface appears that looks like the graphic above and when you click the play button (represented by a triangle) you will hear a piano sample at middle C that lasts for one second.

So far so good – I have a way of playing any integer I choose but I need to be able to play a list of notes if I am going to convert Pi to music. For those of you who don’t know much about Mathematica all you need to do to create a list of ANYTHING is separate them by commas and wrap the whole thing in curly braces {} so a list the integers 1 to 5 looks like this


A list of strings looks like this


Finally, a list of three SoundNotes looks like this:

{SoundNote[3], SoundNote[1], SoundNote[4]}

Wrap this list with Sound[] to play the three notes in sequence:

Sound[{SoundNote[3], SoundNote[1], SoundNote[4]}]

So all I need now is to get the digits of Pi (or any other number I might choose) into a list of SoundNotes. If all I wanted was the decimal expansion of Pi to any number of digits I choose then I could use the N command:



Since the original article asks for Pi in base twelve I could use BaseForm[number,base] to display Pi in base 12 as follows:



This is all well and good but what I actually want is a list of the digits of Pi in base 12 and so I am going to use the RealDigits command which has the syntax RealDigits[number,base,number_of_digits]. This returns a list of the digits of your number according to your specified base and number of digits. So to get a list of the first 20 digits of Pi in base 12 I do

RealDigits[Pi, 12, 20]

{{3, 1, 8, 4, 8, 0, 9, 4, 9, 3, 11, 9, 1, 8, 6, 6, 4, 5, 7, 3}, 1}

Now this result is not just a simple list but is list of lists instead. The first element is a list of the digits of Pi in base 12 and the second element is the number of digits to the left of the decimal point. I only want the first element of this list of lists – namely the list of digits of Pi. To extract elements from lists in Mathematica you use double square brackets [[ ]] so to get the 3rd element of the list {1,4,9,16,25} you would type



So to get that first list from the result of RealDigits[Pi, 12, 20] we do

RealDigits[Pi, 12, 20][[1]]

{3, 1, 8, 4, 8, 0, 9, 4, 9, 3, 11, 9, 1, 8, 6, 6, 4, 5, 7, 3}

So far so good but we are not done yet – somehow I need to wrap each integer in this list with SoundNote[]. One way to do this is by using Map[]. For example I can wrap each element of the list {3,1,4} with SoundNote by doing


{SoundNote[3], SoundNote[1], SoundNote[4]}

Applying this knowledge to the code we have built up so far allows us to write the following

RealDigits[Pi, 12, 20][[1]]

{SoundNote[3], SoundNote[1], SoundNote[8], SoundNote[4], SoundNote[8],SoundNote[0], SoundNote[9], SoundNote[4], SoundNote[9],SoundNote[3], SoundNote[11], SoundNote[9], SoundNote[1],SoundNote[8], SoundNote[6], SoundNote[6], SoundNote[4], SoundNote[5],SoundNote[7], SoundNote[3]}

I have started to format my Mathematica commands a bit to make them more readable by using multiple lines. This is not necessary but I find that if I don’t do this then I soon start to loose track of all those square brackets and get into a horrible mess. All that I have to do now is wrap this result with Sound[] and my job is done.

RealDigits[Pi, 12, 20][[1]]

By modifying this group of commands you can ‘play’ any expression you like to as many decimal places as you like but there is still work to be done. For example we are stuck with only using a piano and every note has a one second duration which is far from ideal but this post is getting a bit long so I will explain how to change these in a future post if anyone is interested.

By the time my train journey was over I had produced a little ‘applet’ in Mathematica using the principles described here along with the Manipulate function. It could play Pi in any number base using any one of a range of instruments with variable note speed. I fully intended on refining it a bit and submitting it to the Wolfram Demonstrations project but when I got home and regained internet access I discovered that I had been beaten to it by someone called Hector Zenil. Hector has written a very nice demonstration called Math Songs which does exactly what I had been trying to achieve and a whole lot more. Not only can you listen to Pi but you can also listen to e, Euler’s Gamma constant, the golden ratio, the Catalan constant and a few more I haven’t even heard of.

Oh well…you can’t win them all and Hector has done a fantastic job (better than I would have done to be honest). The best thing is that you don’t even need Mathematica to play with his creation. The free (but rather large) MathPlayer will do the job nicely for you.

So, have fun with Hector’s little demonstration and I hope the mini-tutorial here was useful to someone. As always feel free to leave comments.

Comments Off on Music From Mathematical Constants