I have been experimenting with an algorithmic/mathematical approach to combine two melodies into a single, new melody and want to ask if there are other approaches to this problem.

Example combination of two known melodies

The code can be found here, and the method is described here

Edit: I could interpolate two simple melodies to generate this piece: audio, score

  • In the other post you are asking an awkward question: "My mathematical question is, if there is a musically better way to combine these melody-matrices". That's really confusing, and actually pointless in my opinion. What you're asking in "musical terms" seems mostly about aesthetics and: 1. that's clearly not something relateable in mathematical functions; 2. aesthetics is a very broad and highly subjective aspect, and in most cases simple algorithms (no matter how the involved math is complex) are not able to be involved in such aspects (machine learning is usually a preferred path). Apr 25, 2021 at 19:23
  • @musicamante: you are wrong with that. see: en.wikipedia.org/wiki/Twelfth_root_of_two The perceived aesthetics is because of "simple" rational numbers which are captured by the formula described in the other post. Apr 25, 2021 at 19:33
  • And where's the relation to music aesthetics in that? I'm not talking about the relation between intervals, that's a completely different subject. Apr 25, 2021 at 19:38
  • Difficult to describe. It is based on measuring simple rational numbers and converting them to vectors. Then doing matrix singular value decomposition. Apr 25, 2021 at 19:44
  • 1
    Have you compared it to the algorithm "give both melodies to a musician and ask him/her to improvise based on them" ?
    – Emil
    Apr 26, 2021 at 5:59

1 Answer 1


I suggest looking into two things:

In "traditional", common practice music there is something called compound melody which is a single melodic line, but because the pitches get grouped into high/low regions, or through other devices, the single line seems to be a counterpoint of two separate lines. In some ways this is just a "trick." If you take two basic lines in counterpoint - for example, something in simple quarter notes - all you need to do is displace the notes of each line with quarter rests so the notes alternate back and forth between the two. It's a way to get a melodic instrument like a flute to sound like it's playing harmony.

In modern serial music you can have a series of pitches - a melody - and the series, sometimes called a row, can be permuted in various ways including breaking it up into smaller segments or recombining with itself in various counterpoints. This style is usually atonal. It's more math-ish treating all permutations are about equally viable.

Either of these could be described as some kind of multiple lines combined into, or derived from, a single line.

Oh, there's one other, really it technically fits into the serial stuff, but historically it's part of counterpoint and canon technique. The cancrizan, or crab canon. It's one melody played in counterpoint to itself played in retrograde, backwards. Since it's a separate term, I thought I should mention it.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.