An important and practical aspect of mathematics is that it can be used
to describe (technically model ) arbitrary processes,
making it possible to analyse and understand them in a formal,
Use the tools below to compose a tune, or alternatively
let the computer compose it for you, and see how
a simple mathematical model of composition allows us to generate
But it also allows us to study mathematically the
diversity of tunes that can result, and, in the light of discussions
about plagiarism, copyright and originality in popular music,
we can consider questions like "How many different songs can there be?"
This application is discussed in detail in my associated blog entry:
How many tunes?
Exploring how mathematics can be used to describe and create music
This activity involves mathematically representing music and the
process of composition by modelling it as a three step process
— build a rhythm, add a melody, then harmonise.
Follow the below to work through these three steps
to compose a tune, or alternatively
let the computer compose it for you.
You might be surprised at what comes out.
Step 1: Make the rhythm
The first step is to choose the timing of your song, and
the rhythm of your melody.
There are two choices for the timing: #4 (i.e. three beats in a bar), or
$4 (four beats in a bar).
The song will be two bars in total, and each
note duration is counted in half beats.
This means you need to fill the 12 or 16 counts in the two bars by
choosing from the note durations:
1 for a half beat (a quaver) — e
2 for a whole beat (a crotchet) — q
3 for one and a half beats (a dotted crotchet) — q.
4 for two whole beats (a minim) — h
Notes joined by a tie have their durations combined, so,
for example, the note q-q lasts for 2 whole beats. Ties are
used when the timing means a note crosses a barline or an
important internal beat.
Specify your chosen rhythm by entering a string of digits from 1 to 4
in the text box below (just like the example values shown),
finishing when you have the required total sum.
Alternatively, you can ask the computer
to compose a rhythm for you by hitting the Random
Step 2: Make the melody
For the melody, you can use any of the notes from A below middle C to E an octave above
by typing the corresponding letter as follows:
Once again, hitting Random will cause the computer to
randomly assign notes to the given rhythm. The melody will always finish on middle C,
and any randomly generated melody will start on middle C as well.
Step 3: Make the harmony
To complete the composition, enter a harmony based on the three major chords:
C = [C,E,G],
F = [F,A,C], and G = [G,B,D],
and their relative minors:
Am = [A,C,E],
Dm = [D,F,A], and Em = [E,G,B].
Two chords are used to harmonise each bar, applied on the 1st and 3rd beats
respectively, and hitting Random
will cause the computer to match a chord to the associated notes of the melody.
Because frequently more than one chord will match, there are several possible
harmonies that the computer will randomly choose between. However, it will
avoid clear disharmonies.
If a fifth chord is not specified, the computer will add a final C chord,
except when the starting chord is Am, in which case it may
end on either a C or an Am.
Perform the finished product
Finally, choose an instrument for the melody, and both an instrument and
playing style for the harmony, then listen to your music by hitting the
hitting Play button.
Save and print your favourites.
About the activity
We describe very large numbers as astronomical
by analogy with the enormous distances of interstellar space.
But these values are only enormous in physical terms. Mathematically,
they are tiny compared to the values that arise in many counting
problems — that is problems connected to the way things can be
selected and arranged (see the permutations and combinations link in
the Related… links section, and
my blog entry at Puzzles with 4 numbers, and the amazing power of powers).
The variation available in music is such a problem, because it
is about arrangements of notes and rhythms to form musical pieces.
The simple approach to composition contained in this activity illustrates
both the mathematical underpinnings of music and its notation, but also
the incredible number of different tunes that are possible.
This is discussed in more detail in my associated blog entry
How many tunes?
Sound generation is using the MIDI.js library,
and the music notation is rendered by the abcjs