Imagine that you want to write a melody that can be combined by itself at a certain transpositional level and/or at a certain time delay: what is generally known as a canon. Even with the restriction that each non-embellishing harmonic intervals is a consonance -- a third, fifth, sixth, or octave -- the composition of such a canon is easy, and can be done in countless ways. Here's the beginning of a familiar one.
Now, imagine that you want to write a more versatile melody that can be combined with itself in different ways; in particular, using different pitch transpositions and/or different time delays. J.S. Bach has written melodies like this. The chart below shows all of the different combinations he uses in the first fugue from the first book of his Well-Tempered Clavier, all transposed to the fugue's key of C major and stripped of accidentals. The labels in angle brackets indicate the transposition of the later voice (e.g. +5 is up a fifth) and how much later the later voice is.
As versatile as this melody is, it still does not allow for certain canonic time intervals. For example, it is impossible to write a canon -- or stretto, as it is called in a fugue -- with Bach's melody using an eighth-note time delay and produce only diatonic consonances for the non-embellishing harmonic intervals, regardless of what note upon which you begin.
What melody could be consonantly combined with itself at any transpositional level or at any time delay? Such a melody may sound difficult to make, but, if one does not mind a highly patterned melody, it is quite simple. For example, as suggested by the notation below, this could be accomplished by a melody that continuously ascends by step in even durations (the left half below) or by a melody that alternates back and forth between two different intervals (the right half below). Think of each half of the music below not as one eight-voice music composition, but as seven two-voice compositions, each using the bottom line as the bottom voice. Notice how each of the seven members of the C-major scale start one of the seven delayed lines.
In this context, the following eight-note melody is quite special. It has no recurring intervallic patterns—never does one interval or a series of intervals immediately repeat—with the exception of the repetition of the entire melody. And yet it can be combined consonantly with another version of itself at any time delay or at any transpositional level. Only around .05% of all eight-note melodies (ignoring octave differences for individual notes) have all of these properties, and every such melody is a transposition, inversion, and/or rotation -- that is, starting at another part of the repeating loop -- of the melody below.
If one adds to the melody above a dotted rhythm, binds into one duration immediately repeated notes, and rotates it so that its first note starts on beat 2 of the common-time meter, then the result is rather similar to the music for the words "It's the hard-knock life for us" from "It's the Hard-Knock Life" from Annie. It has the same triadic arpeggiation as "It's the hard knock life" and the same rhythmic syncopation as "life for us." The example below demonstrates time intervals from one to seven eighth notes and pitch transpositions from unison through seventh; as before, notice how each of the seven places within the diatonic scale start one of the seven delayed lines. The clef is not fixed, but should be the same for any two voices in canon: this allows for certain scale modifications to keep melodic and harmonic fourths and fifths perfect.