# How many melodies are there?

Clearly if we assume only 12 chromatic notes to the scale, not all of which sound good next to each other, a melody of length $N$ chooses from less than $12^N$ potential melodies. Allowing melodies to start at one of let's say 24 pitches (= a 2-octave vocal range $\oplus$ chromatic scale) and then only use relatively nearby diatonic notes, the number of possibilities might be something like $24 \cdot 7 \cdot 5 \cdot 3 \cdot 3 \cdot 3 \cdot \ldots$ as roughly a lower bound.

It's also possible to figure out how many $k$-tuplets ($k$=3 being a triad) of length $N$ can be played, although this is not how I think of "melodies". (I can't think of a Paul McCartney song that splits into $k=2$ at any point as a crucial part of the "melody" — that seems to be the separate issue of harmony.)

But what if we think of "melody" as sound waves? What if we want to add in the possibility that instrumentation or rhythm is what really makes a melody distinct?

The number of waveforms of a fixed length (say 10 seconds) has to have an infinite basis, because we could use any $\mathbb{R} \ni$ frequency of a sine wave.

We could make that slightly more finite by saying that

1. the human ear can only distinguish a subset of $\mathbb{Q}$ frequencies
2. energy is limited so very high frequencies are disallowed
3. The ear can't hear very low or very high frequencies either so they don't count as melodies.

That's a start on an upper bound for tune $\oplus$ rhythm $\oplus$ instrumentation.

But let's forget instrumentation and define a melody of length $N$ to consist of a string of notes from a chromatic basis, played for a certain length of time—drawn from {♩, ♪, ♩., 𝅘𝅥𝅯, 𝄽, 𝄿, 𝅗𝅥}. This is again a little too easy—just the multiplication rule—so let's add one more thing to make it interesting. Let's say that to cover variations in "attack" and "release" each of the time options can be expanded or contracted by $\pm \varepsilon$. For example $.99♩$ might be distinct from $1.01♩$, the first being a "sharper" or "more staccato" quarter note ♩ and the second being a "lazier" quarter note ♩.

If you allow for slight variations in rhythm, how many more melodies does that make?

Part of the puzzle for me here is that we're combining a finite basis $\{ \tt{do, re, mi, fa, sol, la, ti, do} \}$ with an infinite basis (like $[.9, 1.1] \subset \mathbb{R}$). What's a reasonable way to assign measure to something like that?

-