Recursive Melody

Extra Credit Assignment


Find the values of these recursive functions to produce a three-part number-one pop hit. Embelish with percussion if desired.

Each value of n is a different eighth-note. There are four measures, so compute the values of base(n), tenor(n) and alto(n) for the first 32 values of n (0 through 31). These four measures repeat forever. It is a really annoying melody that will be stuck in your head for twelve days.

You can write a program to produce the right values, or you can do it by hand. Below are recursively defined math functions (not C code).

First, the base and tenor part numbers represent half steps, where 0 is middle C. Therefore, -3 is A and 5 is F. 3 is E flat.


foundation(0) = 0
foundation(n) = 5 + foundation(n-1)
m(n) = foundation(RoundDownToInteger(n/8))

base(n) = (( m(n) + 6 ) % 12) - 6

c(0) = 0
c(n) = 2 + c(n - 1)

t(n) = c(n) % 6
tenor(n) = if RoundDownToInteger(n/8) is even, t(n % 8) + base(n)
           else base(n)

Second, the alto part numbers are not half steps, but rather are positions along a major scale, relative to the value of the base(n) note. This is a major scale starting at the basenote and going up -- the base note is the tonic of the scale, like the key you are in changes according to the base note. By the way, the base note is either 0 or 1 -- I think it is 1 but I forget -- try it both ways to see which sounds better.

q(0,i,j,x) = x
q(n,i,j,x) = if (j==0), q(n-1, i+1, i+1, (-1)x)
             else q(n-1,i,j-1,x)
arrow(n) = q(n,0,0,-1)

a(0) = 2
a(n) = a(n - 1) + arrow(n - 1)
alto(n) = if RoundDownToInteger(n/8) is odd, a(n % 8)
          else 5


Show your work. You get one point for producing the sequence of notes, or you can get two points for performing (voice, whistle, or playing a tape of) the correct tune in class on the day it is due.

Good luck, may the Force be with you, and don't forget to wear ear plugs.


email: evs at cs dot columbia dot edu