How great would it be if you were able to perfectly characterize melodies in mathematical terms? You could populate an abstract "melodyspace" with your own melodies and find similar or totally different ones.

Lets reduce the complexity right away and consider only pitch and note length. These two quantities offer plenty possibilities to characterize melodies. Later we could expand our analysis by considering meter, dynamics in general, harmonic context (scale) and probably many more aspects.

I think it is sufficient to consider only a relative pitch and note length. You could shift a whole melody by some semitones and it would still be the same.

__What is a note in our system?__

We consider only two aspects. This results in a 2-tuple, e.g. $\left( \mathrm{A4}, \frac{1}{4} \right)$, of some pitch value, here A4 (see scientific notation), and a length, 1/4th.

But this is an absolute measure. We could look a little to the side and shift the focus to the gap

**between**the notes - lets talk in terms of intervals! The pitch is represented as some stepsize, e.g. $+5$ for a perfect fourth (see interval), and could be limited to meaningful values. No stepsize should lead to a lower note than C0 or a higher note than G9 (highest possible MIDI note). Interestingly this restricts the ability to transpose the melody. The melody C0 G9 C0 G9 can't be shifted at all - in contrast to something like C4 E4 C4 E4.

It would be also a good idea to normalize the note length to a whole note and limit it to values between $\frac{1}{32}$ and $1$.

Finally this would lead to a 2-tuple of the form $\left( \pm n, \frac{1}{m} \right)$, with $n,m \in \mathbb{N}$ and some arbitrary meaningful restrictions for $n$ and $m$.

__What is a melody in our system?__

A melody would be just a sequence of notes. Something like

$$\left(\mathrm{A4}, \frac{1}{2} \right),\left( +5, \frac{1}{2} \right), \left( +5, \frac{1}{2} \right), \left( -7, 1 \right) $$

Which corresponds to the sequence A4, D5, G5, C5, if you start with a note A4.

To underline the generic nature it could be a good idea to define a special tuple for the first note. Something like $\left( n', \frac{1}{m} \right)$, with $n' \in \left[ n_{\mathrm{lowest}}, n_{\mathrm{highest}}\right]$ and $m$ as above. $\left[ n_{\mathrm{lowest}}, n_{\mathrm{highest}}\right]$ is the interval of possible starting notes, which has to be computed according to the limit of C0 as the lowest and G9 as the highest note.

__Creating the melodyspace:__

What quantities can we think of to characterize such a melody?

There are quantities which do not rely on the order of the involved intervals. These are for example a mean-interval + the according variance, the amount of dissonant/consonant intervals, the length of the melody, the mean note-length + according variance, etc.

Other quantities could be dependent on the order. I don't know if this is important later, but it surely is interesting!

And what the heck is this melodyspace I am talking of?

If you consider every of the above quantities as an (independent) direction in a multidimensional space, then a melody is characterized by a vector in this space.

For example you could imagine that we want to characterize a melody only by its total length and its tendency to be "rising" or "falling". (0 would mean something like 100% falling, e.g. the melody C9 C8 C7 C6, and 1 would mean something like 100% rising, like A6 A7 A8 A9)

In this case the melodyspace would only be a two dimensional graph with the length on the x-axis and the tendency on the y-axis.

Both example melodies, C9 C8 C7 C6 and A6 A7 A8 A9, would have a $x$ value of $4$, but the former would be at $y = 0$ and the later would be at $y = 1$

I have no clue at all if this leads to something useful, but I surely will implement this model in some programming language and look where it leads to.