05.31.07
Reproducing the entire Pitch Class Set catalog with Python
Allen Forte’s classic work, The Structure of Atonal Music, featured a catalog of all the possible prime forms for pitch class sets. That is, even though one can write [0,4,7], [2,6,9], or even [2,5,9], these are all essentially the same set.
In “prime form”, these sets are all the same — [0,3,7]. You can use this prime form to regenerate any of the previous sets I’ve mentioned through operations such as transposition, inversion, or both. I’ll demonstrate this below using the Python module I wrote, pcset.py. From interactive mode:
>>> from pcset import PitchClassSet as Pcs >>> a, b, c = Pcs([0,4,7]), Pcs([2,6,9]), Pcs([2,5,9]) >>> a.prime(), b.prime(), c.prime() (None, None, None) >>> a.toList(), b.toList(), c.toList() ([0, 3, 7], [0, 3, 7], [0, 3, 7])
As you can see, all reduce to the same prime form. Now let’s get them back from the prime form, [0,3,7]:
>>> p = Pcs([0,3,7]) >>> p.TnI(7) >>> p.toList() [7, 4, 0] >>> p.sort() >>> p.toList() [0, 4, 7]
Set “a” can be regenerated from inversion, then transposition by 7. Of course the order is reversed, which we can solve with sort(). Set “b” is similar:
>>> p = Pcs([0,3,7]) >>> p.TnI(9) >>> p.toList() [9, 6, 2] >>> p.sort() >>> p.toList() [2, 6, 9]
And set “c” is actually easier than the first two, a mere transposition by 2:
>>> p = Pcs([0,3,7]) >>> p.transpose(2) >>> p.toList() [2, 5, 9]
It’s been around 34 years since this book was published. There’s a lot of information about musical set theory on the Web. Oddly, though, the common thread I’ve found is that people complain about the above relation, which seems simple and obvious. Specifically, they complain that the “major chords” and “minor chords” both fall into the same pitch class. If you’ll notice, [0,4,7] is a C major chord, while [2,5,9] is a D minor chord:
>>> a, b, c = Pcs([0,4,7]), Pcs([2,6,9]), Pcs([2,5,9])
>>> a.toString(), b.toString(flats=False), c.toString()
('C E G', 'D F# A', 'D F A')
However, this makes perfect sense to me — not only for the reasons in Forte’s book, but also from practical experience in working with these chords. Major and minor chords have a similar feel. They are not the same, but they are at least first cousins. Certainly they don’t sound like [0,1,6]!
Look at the interval patterns in a major or minor chord — always a perfect fifth, a major third, and a minor third. The difference is in the stacking.
>>> a.ivec(), b.ivec(), c.ivec() ([0, 0, 1, 1, 1, 0], [0, 0, 1, 1, 1, 0], [0, 0, 1, 1, 1, 0])
And the other odd thing about prime forms is that it greatly simplifies thinking about pitch class sets. Consider this: with 12 notes, and a yes/no option for each note, that corresponds to 2^12, or 4096 possible permutations.
However, many of these permutations correspond to the same prime forms. Surprisingly, all 4096 permutations collapse to merely 224 prime forms.
Forte put a lot of work into writing his table. It must have taken quite some time.
However, I’ve just written a Python program that does it in 4.5 seconds
Now, this doesn’t go into the elaborate classification scheme or Z properties or any of that. This program simply finds the 224 distinct prime forms and sorts them by cardinality. For example, there’s only one empty set prime form; there’s also only one single element prime form, [0], because you can generate any other single note through transposition.
Below, I’ve given the output of the program. If you want to try and run it yourself, you need the other two modules, pcset.py and pcops.py. Just copy and paste the programs into the appropriately named file, save to the same directory as setcatalog.py, and you’re ready to go. The complete listing for setcatalog.py is given after the output.