CITE THIS NOTEBOOK: A geometric exploration of music by Cael Harris. Wolfram Community NOV 7 2022.
In this exposition, I would like to explore some of the major ideas from Western music theory through a geometric lens, augmented with modules involving sound and visual interaction created using the Wolfram Language.

Melody

The Chromatic Scale and Dihedral Group Action

The usual starting point for Western music theory is the chromatic scale, which is the following discrete set of twelve “notes” or “pitches,” denoted by the conventional alphabetical labeling, with “sharp” notes between every “natural” note, except in between E and F and B and C.
In[]:=
chrom={"C","C#","D","D#","E","F","F#","G","G#","A","A#","B"};
The chromatic scale can be viewed as an equivalence class over the integers, via an interval of size twelve. This is what gives the scale its “wrap around” character in the sense that, as one traverses the integers and suddenly goes beyond twelve half steps, we get back to where we started.
Now, the question becomes, given our notes, what is music? Suffice to say, people have been creating music for a long time without any real completely objective and analytical response to this question, and there may be no true such thing given that it necessarily involves a subjective and artistic component, however, in this exposition I would like to explore the idea that constructing a mathematical model for what music is gives rise to a kind of structured arena within which aesthetic qualities may be discerned more effectively, that when understood at an intuitive level, serves to facilitate the creative process of subjective and artistic musical composition even more. I should also mention that this kind of analysis has been done before, from a variety of academic perspectives, however, in my opinion, the usual kind of group theoretic analysis has been remiss of a certain aesthetic dimension that is important in analyzing music, and so I attempt here to incorporate both the sonic qualities and the geometric interpretation of music as a mathematical entity. Therefore, we will now postulate that music is a kind of dynamics happening in this moduli space of the integers that I mentioned above . That is to say, we should think of music conceptually as being represented by a set of motions happening on our chromatic scale set, Z12 . I .e ., consider the cyclic group on twelve elements, or, in other words, (Z12, +), the set equipped with addition mod twelve, which has Cayley graph as follows .
In[]:=
CayleyGraph[CyclicGroup[12]]
Out[]=
What motions can we imagine performing in this space? In this model, essentially all we can do is walk around successively from adjacent note to adjacent note, wrapping back around via modular translation whenever we reach the end. Music theorists call this group action “transposition,” not “translation” as a mathematician might call it, and since we are discussing music, we will adopt their terminology. This gets us fairly far in our efforts to model musical space, it has most of the essential ingredients we want present in our model. However, it turns out that there is actually another kind of operation that it makes sense to talk about in musical space. Again, another confusion in cross-disciplinary terminology, this is the music theoretical notion of “inversion,” to which a mathematician would refer to as “reflection.” Thus, the complete group dynamics of musical space is not given by the cyclic group, but rather, the dihedral group of twelve elements, or, in other words, the group of symmetries of the 12-gon.
In[]:=
Graph3D[CayleyGraph[DihedralGroup[12]]]
Out[]=
For those unfamiliar with the idea of a dihedral group,it basically has two different “classes” of operations. One is the usual rotation of an n-gon in the plane, which corresponds to this musical transposition action, and the other is reflection of the polygon along the axis of its diagonals, which corresponds to musical inversion. Notice that the structure of this group’s Cayley graph can be visualized as having two copies of cyclic graphs that are sort of “glued” to each other node-wise via this involutive reflection operation that goes back and forth between the pair of nodes being glued. Equipped with our set of notes Z12 and the group D12 acting on it, we are now in a position to say that we have a complete representation of what is known as “atonal music theory” in Western tradition. This particular method of viewing music mathematically is to be contrasted with the alternative apparatus of “neo-Riemannian” music theory, which we will see more of towards the end of this article. Of course, the exposition so far has relied on mathematical description and visual intuition, both very important tools, however I mean to highlight an aspect here that is usually missing from expositional sources on this subject, namely, the actual sonic quality of music itself. Music appeals to a wholly separate sense organ, the sense of sound. In order to truly appreciate the ideas explicated here in their relationship to music, and thus uncover why certain musical patterns are aesthetically pleasing to the human ear, we should attempt to actually hear the mathematical transformations taking place. Therefore, I created this interactive module that illustrates the geometric intuition associated with the sounds we are trying to represent (see the Appendix at the end of the article for fully interactive modules and functions definitions).
In[]:=
Graph[CyclicEdges[chrom],VertexLabels->Automatic]
Out[]=
Initially, there are a lot of interesting things to notice with this construction. Firstly, one should remark that, once the entire cycle has been completely traversed, the pitch returns to its initial sound, i.e. it goes back down instead of playing the equivalent note one octave higher. It might be interesting to investigate constructing the same thing as above except that one somehow keeps track of some kind of “winding number,” indicating the octave level of the pitch as well as its position in the pitch equivalence class (pitch class). Such as it is, however, there is already enough rich structure to go into. Starting with single notes, via the attached module, examine both the tonal quality and the dynamical character of different transpose steps as transformations happening in the space. Here is an interesting question. Contrast traversing the cycle at steps which are divisors of twelve, as opposed to those that are not. What do you notice?The next thing you might do is look at the dynamics of multiple notes at once, for instance, if you know a little bit of music theory, a good starting point would be the usual triadic chords. See how these fit inside the larger chromatic scale structure, and see which ones are related by inversion. More on chords later, when we get into developing a full fledged dynamics of harmony.

Substructures of the Chromatic Scale

One of the next reasonable things we might examine is the substructure of the chromatic scale. For instance, in music theory it is traditional to define the usual heptatonic scales, that is, the scales composed of seven notes, and thus yielding a heptagonal group theoretic structure. In fact, these are the scales that are used most often in conventional Western classical composition. A natural question arises, why seven? You could answer this by simply saying that a scale based on seven notes is large enough to have interesting structure of its own, and this would be correct, however, by framing this idea mathematically, there is still more to the story to uncover. The choice is, of course arbitrary, but it is a clever one, and it has to do with a particularly central feature of music theory, called the circle of fifths. First, it is important to notice that Z7 is not actually a subgroup of Z12, as seven is not a divisor of twelve. What this means then, geometrically speaking, is that when one moves along or transposes inside of Z7, eventually, what will happen is that one will be transposed outside of the group, or algebraically, Z7 is not closed under addition modulo 12 as it sits inside of Z12. Go back to the chromatic scale, set the transpose step to five, and select all of the natural notes, (the C major scale). Now, as the entire scale gets stepped by five along the graph, you should notice something interesting. The result is that every note stays the same, except for one each time, which gets moved to a sharp. The ultimate consequence of all this, then, is that all of the heptatonic scales are related to each other, one can walk from one to the other inside of the chromatic scale, and they can be transformed into each other (think key changes) in a way that the actual subgroups of Z12 can’t, because those satisfy this insular, algebraic closure property. Thus, we find that this structure is one in which each note acts as a representative for a particular scale, another desirable property. Essentially, this property allows us to represent the relationship between all of the heptatonic scales as a mirror of the chromatic scale, where each note of the chromatic scale now stands for its representative heptatonic scale (in more formal mathematical language, we can treat the set of cosets as a partition or set of equivalence classes over the chromatic scale i.e. a quotient space that is isomorphic to the original chromatic scale). Actually, each chromatic note gets two scales, as all of the heptatonic scales are actually partitioned into two disjoint classes related by inversion, which, in traditional music theory terminology, are called major and minor. Here are the major and minor heptatonic scales over the note “C,” as an example.
In[]:=
{Graph[CyclicEdges[Major["C"]],VertexLabels->Automatic],Graph[CyclicEdges[Minor["C"]],VertexLabels->Automatic]}
Out[]=

,


Harmony

References

https://jazz-library.com/articles/tonnetz/​
A Geometry of Music: Harmony and Counterpoint in the Extended Common Practice; Dmtri Tymoczko
A First Course in Abstract Algebra; John B. Fraleigh