How many melodies are there in the universe?

After writing "Is music written or discovered?" I started thinking a little bit harder about how one might go about searching for new musical discoveries. specifically, short little melodies.

So I started wondering how many melodies of a given length are out there. Clearly it is a finite number. So I have set out to try to count them, or at least put an upper bound on their number.

First we have to limit things in some way, we can't allow infinitely long melodies. So, I'll arbitrarily draw the line at 32 notes, or rather, 1 measure's worth of 1/32 notes.

There are 12 notes total (in the Western scale, which for some very good reasons which I can't actually recall, has been shown to be the "best" scale, overall. There are other scales, but they all suffer from more problems than the 12 note scale does. The math seems to end up favoring the 12 note scale.) I will also ignore intervals larger than 1 octave, just because.

Further, each note may transition to the next note in a number of ways, "normally" (separately plucked and fretted), by sliding, by hammer-on by pull-off. I will allow for the possibility of sliding from a note to itself which enables 1/16th notes, 1/8th notes, (and even 3/8th notes).

So what does that leave?

Choose 1 note from 12, 32 times, and choose one of four methods of transitioning to the next note, 31 times.

Damn that's a big number.

1232 x 431:

% bc -l
4^31 * 12^32
157637523953697211105908171958186454333476434685722624

Wow!

I can probably divide that number by twelve because it would count each riff played in each key, and I would really only want to count each riff in one key. (Yeah, that helps).

12^31 * 4^31
13136460329474767592159014329848871194456369557143552

Hmm, I still don't feel like I've accomplished anything. What is stil missing is a way to toss out even some proportion of the riffs as being "non-musical", I know there are plenty of non-musical riffs counted in there, but I have no idea how to toss them out.

Hmm, lets say I only allow two methods of transitioning between notes. After all, riffs that differ only by using a pull-off or a hammer-on vs. an ordinary plucking style aren't really all that different, it's more a matter of how well the riff is performed than a matter of it being a different riff altogether. I still have to allow for sliding though, to allow for the possibility of different time values for the notes and still have everything add up to just one measure.

So that would be:

12^31 * 2^31
6117141027690268863066571918245810640257024

A little better, but still a freakin' huge number, and I'm still counting too many duplicate riffs that differ only by "sliding" vs. normal plucking.

So thinking about it a little differently, for the first note, there, are 12 choices. For the remaining 31 notes, you really have 13 choices, you can just allow the previous note to continue uninterupted, or you can start new note, from a choice of 12. And once again, I can divide by 12 to limit each riff to one key.

So that gives us:

12 * 13^31 / 12
34059943367449284484947168626829637

One problem I still see, most music has whole notes, half notes, quarter notes, eighth notes, sixteenth notes, and 32nd notes, which I have allowed for, but I have also allowed for 3/8th notes, 7/8th notes, etc... Well those would typically be written as a quarter note note tied to an eighth note, or a half note tied to a quarter note tied to an eighth note respectively, so I suppose I have to allow them.

But, suppose we limit things so that notes can only be 32nds, 16ths, 8ths, 4ths, halves, or whole notes, that is, no "3/8th" notes, no triplets, or other weird Chopin-esque stuff. (Chopin would do weird things like have the left hand play 17 notes in one measure while the right hand had to play 13 in the same amount of time, 17 against 13. What a bastard.)

Anyway, what would that kind of convenient blindness leave?

I imagined a measure, which you chop up in a number of pieces (at most 32 pieces) and as you cut it up, you could make as many as 31 cuts, or as few as zero, and each cut would have to slice one of the remaining pieces exactly in half. Being rather bad at combinatorics and discrete math I wrote a little brute force C program:

#include < stdio.h>

struct measure
{
        int length;
        struct measure *left, *right;
};

long
ways_to_cut(struct measure *m, int cuts)
{

        long ways_cut = 0;
        long left_cut;
        long right_cut;
        struct measure m1, m2;

        int i;

        if (m->length <= cuts) return(0L);
        if (cuts == 0) return(1L);
        if (cuts == 1) return 1L;

        m1.length = (m->length >> 1);
        m2.length = (m->length >> 1);
        m->left = &m1;
        m->right = &m2;

        cuts--;

        for (i=0;i<=cuts;i++)
        {
                left_cut = ways_to_cut(m->left, i);
                right_cut = ways_to_cut(m->right, cuts-i);
                ways_cut += left_cut * right_cut;
        }

        return(ways_cut);
}

int main(int argc, char **argv)
{ 
        long wtc;
        struct measure m;
        int i;
        long total=0L;

        m.left = NULL;
        m.right = NULL;
        m.length = 32;

        for (i=0;i < 32;i++)
        {
                wtc = ways_to_cut(&m, i);
                total += wtc;
                printf("ways to make %d cuts = %ld\n", i, wtc);
        }

        printf("Total ways to cut: %ld\n", total);
}

And the output:

ways to make 0 cuts = 1
ways to make 1 cuts = 1
ways to make 2 cuts = 2
ways to make 3 cuts = 5
ways to make 4 cuts = 14
ways to make 5 cuts = 42
ways to make 6 cuts = 100
ways to make 7 cuts = 221
ways to make 8 cuts = 470
ways to make 9 cuts = 958
ways to make 10 cuts = 1860
ways to make 11 cuts = 3434
ways to make 12 cuts = 6036
ways to make 13 cuts = 10068
ways to make 14 cuts = 15864
ways to make 15 cuts = 23461
ways to make 16 cuts = 32398
ways to make 17 cuts = 41658
ways to make 18 cuts = 49700
ways to make 19 cuts = 54746
ways to make 20 cuts = 55308
ways to make 21 cuts = 50788
ways to make 22 cuts = 41944
ways to make 23 cuts = 30782
ways to make 24 cuts = 19788
ways to make 25 cuts = 10948
ways to make 26 cuts = 5096
ways to make 27 cuts = 1932
ways to make 28 cuts = 568
ways to make 29 cuts = 120
ways to make 30 cuts = 16
ways to make 31 cuts = 1
Total ways to cut: 458330

Pipe that through a short filter:
./cuts | awk '/ways to make/ { printf("%d * 12 ^ (%d+1)\n", $7, $4 );}' | bc -l

which yields a very pretty sequence:

12
144
3456
103680
3483648
125411328
3583180800
95025954816
2425096765440
59316834926592
1381995569479680
30617888939311104
645810987668078592
12926491101077962752
244416990259238141952
4337569597936449355776
71878562636176677666816
1109074817815117490552832
15878155968719959464345600
209883024546529473038647296
2544451171947419448687722496
28038096359484820776730755072
277867979924918797194422648832
2447071950614776964115597361152
18877003349528376284550493372416
125327733578312106466500182802432
700040332826172993664543220563968
3184798876813578234913416410038272
11235812186522437499570313794420736
28485157655972376759474034971770880
45576252249555802815158455954833408
34182189187166852111368841966125056

the sum of which is some kind of answer:
./cuts | awk '/ways to make/ { printf("%d * 12 ^ (%d+1)\n", $7, $4 );}' |\ bc -l | ( awk 'BEGIN { printf("0 ");} { printf(" + %s ", $0); }' ;\ echo ) | bc -l
123511210975209861511554928715787036

Ok, so if you listened to one measure per second, how long could you go without repeating a measure?

% bc -l
123511210975209861511554928715787036/3600/24/365
3916514807686766283344588049

That's 3916514807686766283344588049 YEARS folks!

Jebus help me!

So there you have it. Boy was this node a waste of time or what? But it does demonstrate how cool awk and bc are.

I wish not to disturb your mind further ( :) ), ferrouslepidoptera, but there is more than meets the eye to the question how many melodies are there in the universe?. There are many, many more than one would expect.

For example, music is not limited to the diatonic system of the West. Oh, no, that would be far too easy. Arabic music has quarter tones, and some of their tones are off pitch to our western ears. Indian music... don't get me started. Chinese music is easy, and adds little to the list - it traditionally has five notes (which, I believe, mirror their five elements), which (I hope) use tones that us westerners adopted.

Oh, yeah, Western music has at least five different tunings, including but not limited to: Pure Major, Pure Minor, Pythagorean, Unequal Temperament and Equal Temperament.

Blues has blue notes, avant-garde music has cents (one hundredth of one whole tone, although the brain can only differentiate differences of only about a sixteenth of a note without difficulty), and the equation in the previous writeup does not address grace notes, mordents, trills, turns, and pitch bends, dynamics, tempo, timbre, modulation, nor almost any other fragment of music theory.

Music also has different segments to it, which can have an already-made melody in it without the song being called "plagarized". One can also have short snippets of melody, called riffs, which are not necessarily characeristic of a song, artist, nor style of music. Even music played in a different style of music can sound completely different, not to mention remixes.

Making an equation among these lines is nigh impossible, as even forgetting just one characteristic can throw off the equation by billions. I am confident to say that there are enough melodies in the world for my liking, perhaps infinite.


I realize that alternate tunings will not differentiate music much, but it can bring out character in songs and changes harmony in subtle ways.

I've stumbled upon this node many many times in my search of interesting takes on music synthesis and the like and finally I'm writing the solution thats occured to me. ferrouslepidoptera's node, while very interesting and insightful, made many generalizations, which were mostly noted throughout their node. First off, i'd like to give props to them for tackling such a large problem reasonably. Now exit all reasonability and enter this node.

These generalizations are:

1.) Melodies are no longer than 32 1/32 notes
2.) Notes are always multiples of 1/32
3.) Timbre does not change musical melody
4.) Differing volumes do not change musical melody
5.) There is no pitch sliding/modulation/just intonation/etc

With this said, I propose a much simpler solution. A PCM audio file of 44100 hz and 16 bits can (watch me make a generalization here) reproduce any sound audible to the human ear. This means that if we take a 16-bit number (0 to 65535) 44,100 times a second, we can reproduce any 'melody' for that second, matching any timbre, amplitude, chording, just intonation, etc. So if we make a generalization that no melody lasts more than a second, we find that there are only:
(65535^44100 - 65535) different sounds that can be reproduced in 1 second. (minus 65535, because there are that many combinations where every number is the same, producing silence). Using some trivial mathematics, the result is:
2.96958 *(10^215,529).
And keep in mind, that result is only mono. Stereo would be the square of that number. Note: We could probably divide this number by 16 (2^4) as our ear could probably not perceive the difference in speaker position of 16/65535 or 1/4095 of the speaker's maximum aplitude.

Now, as for the musical qualities of the afformentioned 'melodies'? Who am I to dictate what arbitrary set of 16-bit integers speaks directly to the soul of an individual? Some combination of each of those seconds creates your favorite song, your most hated song, and yes, even that overuse of power chords and distortion you created in your basement. To me, this is really interesting. No matter what you say, or how you say it, or how you play your instrument, or what it sounds like when you blink or click your mouse, for one second it is simply 1 of the possible 2.96958 *(10^215,529) seconds of sound.

Well, there you have it folks. Nothing more to see here. Move along. As for me? I'm back to hex editing .wav files and rewriting Beethovens's 5th using Csound.

A fine attempt, but let us not forget that you've left out at least two possibilities:

 1) Use of rests/durations: Rests and durations are important in melody making, otherwise, you'll end up sounding like some weird electronic music or a Steve Reich piece. This significantly increases the number of melodies you can get, each note can be held out from anywhere from the 32 or so quavers you define your melody to last, and that is a combinatorial problem my brain is too tired to figure out right now exactly. I think it's something along the lines of (32 * 13) permute 32: This you get from pretending all your possible notes were hand-painted balls in a big vat, which makes ((12notes + space)* 32max), and then you select 32 of these and include the permutations. I think I'm right. Anyway, it's a larger number.

2) Melodies don't always stay within an octave: Think, let's say, OK, a slighty obscure example - Prokofiev's piano sonata no. 6, 3rd movement. The arpegiated a-minor melody comes in, mucks around a bit, does it's thing, and then all of a sudden the tail end of the melody gets carried upwards in ribbons and ends up getting placed in the same spot an octave higher. Sure, while the release date of the next recording of the Prokofiev sonata no. 6 does not exactly have Justin Timberlake crossing out squares in his calendar, that doesn't mean this happens rarely. For instance, you know that bit in a pop song, where everything goes higher? Think Mariah Carey's "Can't live", or most Celine Dion songs. It's a modulation upwards, I think by a perfect fifth in most cases. I don't think you couldn't call that entire stretch a melody, and I think the lowest and highest notes in that set will probably poke outside the 1 octave range.

 

Melody is a hard thing to define, even definitions that seem academic come up in real music, see brain-liquefying modern music compositions. In my estimation, for all practical purposes there are probably an infinite number of melodies. A friend said that there are more chess games possible than atoms in the universe, and I have another friend that made music out of chess games. Monophonic mostly, I think. Ergo, there are at least as many 'melodies' as there are atoms in the universe.

I have pondered this for more than 30 years.

According to military communication research (sorry, I don't recall specifics), the theoretical maximum amount of information that the human brain can absorb per second is only approximately the equivalent of 45 bits per second. 10800 bits per 4 minutes of listening to the radio or watching TV. I don't know if they know which bits are sufficient to reproduce that experience but I agree that I probably can't send a review report by telegram about a 4 minute video. A good typist can exceed that rate by reflex even without understanding the dictation.

An analog telephone line carries only a frequency range of 3000 cycles per second. It can use QAM to transmit 56000 bits per second, but phase modulation is involved and human hearing is not very much aware of the phase aspect of sound.

An analog telephone line or AM radio station is capable of transmitting a mechanical television show, while the old NTSC broadcasts required as much bandwidth as 4 times all of the AM radio stations combined. (600 radio stations could fit in one TV channel).

30 years ago I began using a primitive extremely lossy binary representation of sound, by which voice and music could be processed experimentally with arithmetic within the limit of 64000 bytes of RAM, able to store one minute of sound at a time in the simplest case, and whole songs by using tricks.

First I made sounds by counting or pseudo random means, 3 years before using this technique for recording. Its purpose was to build a synthesizer, which I knew nothing about, and thought that it was a music generating automatic machine. In my format, counting sounds musical, and pseudo random sounds like the hiss of the s and sh sounds. It may be important that my format is so lossy that it doesn't preserve frequencies, phase, nor amplitude aspects of sound and thus its recognizability and intelligibility are unexplained and generally only useful for fast experimental calculation and exploration of "thumbnail" quality music.

Octave and musical note frequencies can be expressed in Base 12 Log2, from 0.0 for a low A to 11.11 for a high G#. Log2 explains how binary counting generates octaves but not the notes.

I now occasionally use 4 megabytes to represent experimental binary numeric sound, but usually never even come close to exceeding 64K bytes. Most of my experiments do not exceed a screenful of significant data to generate musical sound.

4 megabytes can hold over 256^4,000,000 numbers from all 00 to
all FF in hexadecimal. Assuming 8-bit PCM, there are constraints that bring the number of possible songs down, such as the average byte value must be hex 80. The same song will be heard if all bits are flipped between 0 and 1, so that makes half as many possible songs. The same song will be heard if the bytes are shifted and the player is looping and therefore the total number of songs must be divided by 4000000. The lowest bit is meaningless, so the number must be halved. Removing all bits except the highest bit still plays recognizable sound, so the number of songs must be divided by 128.
So the number of possible songs must be around...
2^4000000 / 2 due to bit flipping / 4000000 due to shift equivalence = 2 ^ 500,000 possibilities left.
Now what if everyone in the world recorded the same song using a device that records in my format? Out of 6,000,000,000 people, no two people will create an identical file.
There are less than ((2^500,000)-(2^33)) possible songs.
This should be an exponent but it is not. The reason is that all of the songs can be represented by a single bit in that much memory. We know the constant third dimension is the same number.

Now consider that this number represents every possible song sung by every possible singer in every possible language and backed by every possible instrument and every possible parody version and every possible non musical speech or combination of sounds ...plus noise, and I forgot to try to calculate how many are physically impossible sounds that should be excluded.

I recently wrote a short song which has never been sung and programmed my unique synthesizer to create it so that it sounds like that old song that I thought was spontaneously generated by a synthesizer 30 years ago. It is called Viray's Inspiration, and it fits in 32000 bytes and plays for approximately 30 seconds. The voice sounds the same, but the lyrics are different. The music sounds similar but the melody is different. That shall be for replacing all the OLD good-feeling songs that we can't get copyright licenses for with NEW ones that sound similar but are ORIGINAL and may even sound like Elvis singing Michael Jackson's hits with new lyrics and old instruments.

I have partially squeezed (not copied) the Doctor Who intro, including Video into 64K, the audio will be like the original Derbyshire version, and the video of the vortex will be Parametrically synthesized, like Farbrausch's 2000 64KB demoscene thriller called FR-08. I think that was about 15 minutes of music and video in 64K.
65536/15?/60=getting quite close to 45 bits per second, perhaps?

Hmmm. My guess is any 4-minute song can fit in 64K, so there are less than 2^65536 songs.
But if we can only hear the equivalent of 45 bits per second then
there are only 45x60x4=2^10800 songs. With or without video.
Go Farbrausch!

Here’s a much simpler way to arrive at the same number as ferrouslepidoptera:

  • There are a1 = 12 melodies of length 1, where each melody is a single note of length 1.
  • There are a2n = 12 + an2 melodies of length 2n, where each melody is either a single note of length 2n, or the concatenation of two melodies of length n.
  • Therefore, there are a32 = 12 + (12 + (12 + (12 + (12 + 122)2)2)2)2 = 123,511,210,975,209,861,511,554,928,715,787,036 melodies of length 32.

Log in or register to write something here or to contact authors.