Algorithmic Beatles

Markov music matrix

When Eric Morecambe mangled Grieg’s Piano Concerto on a TV special in 1971, he insisted he was “playing all the right notes, but not necessarily in the right order”. That’s a valid point, because there aren’t that many different notes on a piano and the only thing that distinguishes one tune from another is the order in which you play them.

To a mathematician or computer programmer the situation is crying out for quantitative analysis. The diagram above shows the “transition matrix” for one specific Beatles tune (using the MIDI standard where middle C is C5). It’s clear there’s a lot of order here. One thing that jumps out is that there’s only one “black” note, G#5, and it’s always followed by A5. In fact A5 is a very popular note, cropping up after no fewer than 8 different pitches. On the other hand, G#5 itself is very rare, only ever coming after D6, and then only 6% of the time.

As well as analysing the original tune, this allows us to write a new tune of our own using the same transition matrix. The result (as the aforementioned mathematicians and computer programmers will recognize) is a first-order Markov chain. Producing an algorithm of this type from scratch would be rather tedious (as indeed the initial analysis would be), but fortunately there’s some free software called OpenMusic which includes built-in Markov functions that make the process much simpler.

Of course, there’s more to a tune than the pitch of the notes – there’s the duration of a note too. But that can be analysed and reproduced by exactly the same method. I experimented with an algorithmic composition of my own, based on the Beatles song analysed above. As a first step, I used the OpenMusic Markov functions to generate a series of tune-fragments for both the “right hand” and “left hand” of the piano. Then, to give the composition some structure, I arranged the fragments in a rough approximation to classical sonata form.

I won’t say what the original song was, because I want to see if anyone can guess it. As a hint, I’ve inserted a brief quotation from the original at the mid-point of the piece. Here it is on YouTube:

The joy of (musical) sets

Music set-theory

I mentioned musical set theory in a previous post, and now that I understand it better I’m getting very enthusiastic about it. It’s a really powerful technique for analysing and composing music. The mathematical connection may give the impression that it “dehumanizes” music by imposing mechanistic constraints and artificial rules – but the exact opposite is true. It’s traditional music theory that forces arbitrary rules and constraints on you – set theory liberates you from them. It’s a framework for organizing your own creativity – with no rules whatsoever.

I’ll explain how it works in a moment, but first a few words about my sources. The bible of the subject is Allen Forte’s The Structure of Atonal Music, which is divided into two roughly equal parts. The first is packed with useful stuff, although the second part was much too advanced for me. But Forte’s book is really about musical analysis, and what I was interested in was composition. On that front, I found a great little book by Stanley Funicelli called Basic Atonal Counterpoint (which is a CreateSpace book, but very professionally done). I also found a lot of practical tips on Frans Absil’s YouTube channel – he also produced the Pitch-Class Set Graphical Toolkit you can see on my iPad in the photograph above.

Musical set theory starts from a few basic observations:

  • The notes of the chromatic scale can be represented by integer “pitch-classes”: C = 0, C# = 1, D = 2 etc. After B = 11 you get back to C = 0, so additions and subtractions have to be done with mod-12 arithmetic.
  • Intervals between pitch-classes are much more important than absolute pitches. So C major [0, 4, 7] and E flat major [3, 7, 10] are just different transpositions of the same set (it’s called 3-11).
  • Inverting an interval (i.e. subtracting it from 12) doesn’t change its basic nature. So interval 7 (perfect fifth) can be grouped with 5 (perfect fourth), interval 8 (minor sixth) with 4 (major third) etc. This leaves us with just six “interval classes”: 1, 2, 3, 4, 5, 6.
  • The characteristic sound of a set is mainly determined by its interval vector. For example, the major chord 3-11 = [0, 4, 7] has an interval vector 001110 (one minor third, one major third, one perfect fifth and nothing else).

Traditional Western music depends heavily on set 7-35 [0, 2, 4, 5, 7, 9, 11] – the white notes on a piano, aka the major or minor scale (remember you can transpose these notes up by any integer between 1 and 11 to get all the other major and minor scales). Within that 7-element set, there are a number of strongly favoured subsets – most notably the aforementioned 3-11 (the major triad and its inversion, the minor triad).

The purpose of set theory should be obvious now. It gives you access to dozens of other sets, all with their own unique sound. You might think “but they’re going to sound terrible”, and in some cases they do. Set theory helps you to avoid the terrible-sounding ones! But there are some great-sounding sets that simply don’t exist in traditional music theory, such as 4z-29 = [0, 1, 3, 7], with an eyecatching interval vector of 111111.

To teach myself how the system works, I wrote a short “symphony” using the above ideas. It’s my first ever musical composition, and the result sounds a lot more interesting than if I’d struggled with all that traditional stuff about sharps and flats, majors and minors, dominants and subdominants etc. That wouldn’t have told me how to get close to the kind of spooky, spacey, quirky music I wanted to write.

Here is a link to the YouTube video:

Symmetry in Music

Symmetric and asymmetric music chordsI recently came across the idea of applying set theory to musical analysis (which apparently has been around for some time, although I’d never heard of it before). For most people, who have a stronger intuitive grasp of music than mathematics, this must seem a pointless exercise, but for anyone like me who’s the other way around it’s really very illuminating.

Take symmetry, for example. In most areas of the arts and sciences, symmetry is seen as a good thing – but in music, that’s not the case. All the most popular chords are asymmetric in terms of interval content. You can see that in the left-hand image above, which shows the three notes of the C major chord on the chromatic circle. They’re separated by intervals of 3, 4, and 5 semitones.

In contrast, an augmented C chord, shown on the right, is perfectly symmetric, with all three intervals equal to 4 semitones. The problem (as far as musicians are concerned) is that it’s not very firmly tied to C major. It could equally well be A flat or E major. In the same way, the four-note symmetric chord C – E♭ – F♯ – A can be interpreted in four different ways: as Cdim7, E♭dim7, F♯dim7 or Adim7.

There’s even a completely symmetric two-note interval, in the form of the tritone, consisting of two notes 6 semitones apart (or 3 whole tones, which is how it gets its name). That’s exactly half an octave, for example from C to F sharp. But it’s also the distance from F sharp to C, so you really don’t know which key you’re in. That’s why composers spent centuries trying to avoid it. They called it diabolus in musica, or “the devil in music”.

Being a symmetry-loving scientist rather than a musician, I decided to try writing something that consisted only of symmetric chords. It’s a sort of canon, in the key of everything.

Here’s a link to a YouTube video, with added graphics depicting the various chords on the chromatic circle. Hopefully you’ll enjoy the graphics even if you don’t like the music!

Telescopic Tourist video

I’ve just belatedly produced a promotional video for my book The Telescopic Tourist’s Guide to the Moon, which came out last summer. Here it is:

The background “music” (actually just a sequence of spacey sounding chords) is my own composition!

Needless to say, The Telescopic Tourist’s Guide to the Moon is available from all good bookshops, as well as online retailers such as Amazon.com and Amazon UK.

Dirac on Einstein

I was going through some old audio cassettes I recorded from the radio when I was a student, and came across a really interesting little snippet. It’s the physicist Paul Dirac reminiscing about Einstein on a BBC programme, though I’m afraid I’ve no idea which one. The note I made at the time says “recorded in March 1979″ – when Dirac would have been 76 (he lived to 82).

Although the quote is very short, it’s really fascinating – and a Google search didn’t turn up any other references to it. So I made a little YouTube video of it, which hopefully the following link will take you to:

Here is my transcript of what Dirac has to say about Einstein:

He wasn’t merely trying to construct theories to agree with observation. So many people do that; Einstein worked quite differently. He tried to imagine “If I were God, would I have made the world like this?” – and according to the answer to that question, he would decide on whether he liked a particular theory or not.

And I can’t resist adding a couple of Amazon links for my own book about Einstein:

Einstein book covers