I have recently watched a talk by Gabriel Gonzalez about folds, which caught my attention because of my interest in both recursion schemes and optics. A Fold is an interesting abstraction. It encapsulates the idea of focusing on a monoidal contents of some data structure. Let me explain.

Suppose you have a data structure that contains, among other things, a bunch of values from some monoid. You might want to summarize the data by traversing the structure and accumulating the monoidal values in an accumulator. You may, for instance, concatenate strings, or add integers. Because we are dealing with a monoid, which is associative, we could even parallelize the accumulation.

In practice, however, data structures are rarely filled with monoidal values or, if they are, it’s not clear which monoid to use (e.g., in case of numbers, additive or multiplicative?). Usually monoidal values have to be extracted from the container. We need a way to convert the contents of the container to monoidal values, perform the accumulation, and then convert the result to some output type. This could be done, for instance by fist applying fmap, and then traversing the result to accumulate monoidal values. For performance reasons, we might prefer the two actions to be done in a single pass.

Here’s a data structure that combines two functions, one converting a to some monoidal value m and the other converting the final result to b. The traversal itself should not depend on what monoid is being used so, in Haskell, we use an existential type.

data Fold a b = forall m. Monoid m => Fold (a -> m) (m -> b)


The data constructor of Fold is polymorphic in m, so it can be instantiated for any monoid, but the client of Fold will have no idea what that monoid was. (In actual implementation, the client is secretly passed a table of functions: one to retrieve the unit of the monoid, and another to perform the mappend.)

The simplest container to traverse is a list and, indeed, we can use a Fold to fold a list. Here’s the less efficient, but easy to understand implementation

fold :: Fold a b -> [a] -> b
fold (Fold s g) = g . mconcat . fmap s


See Gabriel’s blog post for a more efficient implementation.

A Fold is a functor

instance Functor (Fold a) where
fmap f (Fold scatter gather) = Fold scatter (f . gather)


In fact it’s a Monoidal functor (in category theory, it’s called a lax monoidal functor)

class Monoidal f where
init :: f ()
combine :: f a -> f b -> f (a, b)


You can visualize a monoidal functor as a container with two additional properties: you can initialize it with a unit, and you can coalesce a pair of containers into a container of pairs.

instance Monoidal (Fold a) where
-- Fold a ()
init = Fold bang id
-- Fold a b -> Fold a c -> Fold a (b, c)
combine (Fold s g) (Fold s' g') = Fold (tuple s s') (bimap g g')


where we used the following helper functions

bang :: a -> ()
bang _ = ()

tuple :: (c -> a) -> (c -> b) -> (c -> (a, b))
tuple f g = \c -> (f c, g c)


This property can be used to easily aggregate Folds.

In Haskell, a monoidal functor is equivalent to the more common applicative functor.

A list is the simplest example of a recursive data structure. The immediate question is, can we use Fold with other recursive data structures? The generalization of folding for recursively-defined data structures is called a catamorphism. What we need is a monoidal catamorphism.

# Algebras and catamorphisms

Here’s a very short recap of simple recursion schemes (for more, see my blog). An algebra for a functor f with the carrier a is defined as

type Algebra f a = f a -> a


Think of the functor f as defining a node in a recursive data structure (often, this functor is defined as a sum type, so we have more than one type of node). An algebra extracts the contents of this node and summarizes it. The type a is called the carrier of the algebra.

A fixed point of a functor is the carrier of its initial algebra

newtype Fix f = Fix { unFix :: f (Fix f) }


Think of it as a node that contains other nodes, which contain nodes, and so on, recursively.

A catamorphism generalizes a fold

cata :: Functor f => Algebra f a -> Fix f -> a
cata alg = alg . fmap (cata alg) . unFix


It’s a recursively defined function. It’s first applied using fmap to all the children of the node. Then the node is evaluated using the algebra.

# Monoidal algebras

We would like to use a Fold to fold an arbitrary recursive data structure. We are interested in data structures that store values of type a which can be converted to monoidal values. Such structures are generated by functors of two arguments (bifunctors).

class Bifunctor f where
bimap :: (a -> a') -> (b -> b') -> f a b -> f a' b'


In our case, the first argument will be the payload and the second, the placeholder for recursion and the carrier for the algebra.

We start by defining a monoidal algebra for such a functor by assuming that it has a monoidal payload, and that the child nodes have already been evaluated to a monoidal value

type MAlgebra f = forall m. Monoid m => f m m -> m


A monoidal algebra is polymorphic in the monoid m reflecting the requirement that the evaluation should only be allowed to use monoidal unit and monoidal multiplication.

A bifunctor is automatically a functor in its second argument

instance Bifunctor f => Functor (f a) where
fmap g = bimap id g


We can apply the fixed point to this functor to define a recursive data structure Fix (f a).

We can then use Fold to convert the payload of this data structure to monoidal values, and then apply a catamorphism to fold it

cat :: Bifunctor f => MAlgebra f -> Fold a b -> Fix (f a) -> b
cat malg (Fold s g) = g . cata alg
where
alg = malg . bimap s id


Here’s this process in more detail. This is the monoidal catamorphism that we are defining:

We first apply cat, recursively, to all the children. This replaces the children with monoidal values. We also convert the payload of the node to the same monoid using the first component of Fold. We can then use the monoidal algebra to combine the payload with the results of folding the children.

Finally, we convert the result to the target type.

We have factorized the original problem in three orthogonal directions: the monoidal algebra, the Fold, and the traversal of the particular recursive data structure.

# Example

Here’s a simple example. We define a bifunctor that generates a binary tree with arbitrary payload a stored at the leaves

data TreeF a r = Leaf a | Node r r


It is indeed a bifunctor

instance Bifunctor TreeF where
bimap f g (Leaf a) = Leaf (f a)
bimap f g (Node r r') = Node (g r) (g r')


The recursive tree is generated as its fixed point

type Tree a = Fix (TreeF a)


Here’s an example of a tree

We define two smart constructors to simplify the construction of trees

leaf :: a -> Tree a
leaf a = Fix (Leaf a)

node :: Tree a -> Tree a -> Tree a
node t t' = Fix (Node t t')


We can define a monoidal algebra for this functor. Notice that it only uses monoidal operations (we don’t even need the monoidal unit here, since values are stored in the leaves). It will therefore work for any monoid

myAlg :: MAlgebra TreeF
myAlg (Leaf m) = m
myAlg (Node m m') = m <> m'


Separately, we define a Fold whose internal monoid is Sum Int. It converts Double values to this monoid using floor, and converts the result to a String using show

myFold :: Fold Double String
myFold = Fold floor' show'
where
floor' :: Double -> Sum Int
floor' = Sum . floor
show' :: Sum Int -> String
show' = show . getSum


This Fold has no knowledge of the data structure we’ll be traversing. It’s only interested in its payload.

Here’s a small tree containing three Doubles

myTree :: Tree Double
myTree = node (node (leaf 2.3) (leaf 10.3)) (leaf 1.1)


We can monoidally fold this tree and display the resulting String

Notice that we can use the same monoidal catamorphism with any monoidal algebra and any Fold.

The following pragmas were used in this program

{-# language ExistentialQuantification #-}
{-# language RankNTypes #-}
{-# language FlexibleInstances #-}
{-# language IncoherentInstances #-}


# Relation to Optics

A Fold can be seen as a form of optic. It takes a source type, extracts a monoidal value from it, and maps a monoidal value to the target type; all the while keeping the monoid existential. Existential types are represented in category theory as coends—here we are dealing with a coend over the category of monoids $\mathbf{Mon}(\mathbf{C})$ in some monoidal category $\mathbf C$. There is an obvious forgetful functor $U$ that forgets the monoidal structure and produces an object of $\mathbf C$. Here’s the categorical formula that corresponds to Fold

$\int^{m \in Mon(C)} C(s, U m)\times C(U m, t)$

This coend is taken over a profunctor in the category of monoids

$P n m = C(s, U m) \times C(U n, t)$

The coend is defined as a disjoint union of sets $P m m$ in which we identify some of the elements. Given a monoid homomorphism $f \colon m \to n$, and a pair of morphisms

$u \colon s \to U m$

$v \colon U n \to t$

we identify the pairs

$((U f) \circ u, v) \sim (u, v \circ (U f))$

This is exactly what we need to make our monoidal catamorphism work. This condition ensures that the following two scenarios are equivalent:

• Use the function $u$ to extract monoidal values, transform these values to another monoid using $f$, do the folding in the second monoid, and translate the result using $v$
• Use the function $u$ to extract monoidal values, do the folding in the first monoid, use $f$ to transform the result to the second monoid, and translate the result using $v$

Since the monoidal catamorphism only uses monoidal operations and $f$ is a monoid homomorphism, this condition is automatically satisfied.

Previously we discussed ninth chords, which are the first in a series of extension chords. Extensions are the notes that go beyond the first octave. Since we build chords by stacking thirds on top of each other, the next logical step, after the ninth chord, is the eleventh and the thirteenth chords. And that’s it: there is no fifteenth chord, because the fifteenth would be the same as the root (albeit two octaves higher).

This strange musical arithmetic is best understood if we translate all intervals into their semitone equivalents in equal temperament. Since we started by constructing the E major chord, let’s work with the E major scale, which consists of the following notes:

|E |  |F#|  |G#|A  |  |B |  |C#|  |D#|E |

Let’s chart the chord tones taking E as the root.

We see the clash of several naming conventions. Letter names have their origin is the major diatonic scale, as implemented by the white keys on the piano starting from C.

|C |  |D |  |E |F |  |G |  |A |  |B |C |

They go in alphabetical order, wrapping around after G. On the guitar we don’t have white and black keys, so this convention seems rather arbitrary.

The names of intervals (here, marked by digits, with occasional accidental symbols) are also based on the diatonic scale. They essentially count the number of letters from the root (including the root). So the distance from E to B is 5, because you count E, F, G, A, B — five letters. For a mathematician this convention makes little sense, but it is what it is.

After 12 semitones, we wrap around, as far as note names are concerned. With intervals the situation is a bit more nuanced. The ninth can be, conceptually, identified with the second; the eleventh with the fourth; and the thirteenth with the sixth. But how we name the intervals depends on their harmonic function. For instance, the same note, C#, is called the sixth in the E6 chord, and the thirteenth in E13. The difference is that E13 also contains the (dominant) seventh and the ninth.

A full thirteenth chord contains seven notes (root, third, fifth, seventh, ninth, eleventh, and thirteenth), so it cannot possibly be voiced on a six-string guitar. We usually drop the eleventh (as you can see above). The ninth and the fifth can be omitted as well. The root is very important, since it defines the chord, but when you’re playing in a band, it can be taken over by the bass instrument. The third is important because it distinguishes between major and minor modes (but then again, you have power chords that skip the third). The seventh is somewhat important in defining the dominant role of the chord.

Notice that a thirteenth chord can be seen as two separate chords on top of each other. E13 can be decomposed into E7 with F#m on top (try to spot these two shapes in this grip). Seen this way, the major/minor clash is another argument to either drop the eleventh (which serves as the minor third of F#m) or sharp it.

Alternatively, one could decompose E13 into E with DΔ7 on top. The latter shape is also easily recognized in this grip.

I decided against listing eleventh chords because they are awkward to voice on the guitar and because they are rarely used. Thirteenth chords are more frequent, especially in jazz. You’ve seen E13, here’s G13:

It skips the 11th and the 5th; and the 9th at the top is optional.

## The Role of Harmonics

It might be worth explaining why omitting the fifth in G13 doesn’t change the character of the chord. The reason is that, when you play the root note, you are also producing harmonics. One of the strongest harmonics is the fifth, more precisely, the fifth over the octave. So, even if you don’t voice it, you can hear it. In fact, a lot of the quality of a given chord voicing depends on the way the harmonics interact with each other, especially in the bass. When you strum the E chord on the guitar, you get a strong root sound E, and the B on the next thickest string amplifies its harmonic fifth. Compare this with the G shape, which also starts with the root, but the next string voices the third, B, which sounds okay, but not great, so some people mute it.

Inverted chords, even though they contain the same notes (up to octave equivalence) may sound dissonant, depending on the context (in particular, voice leading in the bass). This is why we don’t usually play the lowest string in C and A shapes, or the two lowest strings in the D shape.

In the C shape, the third in the bass clashes with the root and is usually muted. That’s because the strongest harmonic of E is B, which makes C/E sound like CΔ7.

On the other hand, when you play the CΔ7 chord, the E in the bass sounds great, for exactly the same reason.

You can also play C with the fifth in the bass, as C/G, and it sounds good, probably because the harmonic D of G gives it the ninth flavor. This harmonic is an octave and a fifth above G, so it corresponds to the D that would be voiced on the third fret of the B string.

The same reasoning doesn’t quite work for the A shape. Firstly, because all four lower strings in A/E voice the very strong power chord (two of them open strings) drowning out the following third. Also the fifth above E is the B that’s just two semitones below the third C# voiced on the B string. (Theoretically, C/G has a third doubled on the thinest string but that doesn’t seem to clash as badly with the D harmonic of G. Again, the ear beats theory!)

Next: Altered chords.

We have already discussed several kinds of seventh chords. But if you can extend the chord by adding a third above it, why not top it with yet another third? This way we arrive at the ninth chord. But a ninth is one whole step above the octave. So far we’ve been identifying notes that cross the octave with their counterparts that are 12 semitones lower. A mathematician would say that we are doing arithmetic modulo 12. But this is just a useful fiction. A lot of things in music theory can be motivated using modular arithmetic, but ultimately, we have to admit that if something doesn’t sound right, it’s not right.

A ninth is 14 semitones above the root (if you don’t flat or sharp it), so it should be identified with the second, which is 2 semitones up from the root. That puts it smack in the middle between the root and the third: a pretty jarring dissonance. We’ve seen a second used in a chord before, but it was playing the role of a suspended third. In a ninth chord, you keep the third, and move the second to the next octave, where it becomes a ninth and cannot do as much damage. Instead it provides color and tension, making things more interesting.

To construct E9, we start with E7. It has the root duplicated on the thinnest string, so it’s easy to raise it by two semitones to produce the ninth.

There are many variations of the ninth chord. There is a minor version, with the third lowered; the seventh can be raised to a major seventh; and the ninth itself can be flatted or sharped. We won’t cover all these.

Following the same pattern, C9 can be constructed from C7 by raising the root by two semitones.

We get a highly movable shape, especially if we put the fifth on the thinnest string. In particular, it can be moved one fret towards the nut to produce B9–a slight modification of the B7 grip we’ve seen before.

If you look carefully at this shape, you might recognize parts of Gm in it (the three thinnest strings). This is no coincidence. The fifth, the seventh, and the ninth of any ninth chord form a minor triad.

Here is the E9 grip obtained by transposing C9 down the fretboard. It’s used a lot in funk:

The same chord with a sharped ninth is called the Hendrix chord, after Jimi Hendrix who popularized it:

The E9 shape is not only movable, but it’s also easy to mutate. This is the minor version:

and this is the major seventh version:

Such chords are quite common in Bossa Nova.

A9 is obtained by raising the root of A7 by two semitones:

Can you spot the Dm shape raised by two frets?

Similarly, G9 is constructed from G7, and it conceals a Dm as part of it.

Next: Extension chords.

Previously we talked about dominant seventh chords, which are constructed by adding a minor seventh to a chord. Adding a major seventh instead is a very “jazzy” thing. With it, you can jazz up any chord, not just the dominant.

A major seventh is one semitone below the octave, so it forms a highly dissonant minor second (a single semitone) against it. This adds a lot of tension but, unlike the dominant seven, major dominant seventh doesn’t have an obvious resolution, so it provides an element of excitement and unpredictability.

Major-seventh chords are usually voiced in such a way as to put distance between the seventh and the root. But you can try this slightly unusual grip, in which there is a semitone interval between the two highest strings (although the third of the triad is missing, so it’s a variation of a power chord).

The notation for major-seventh chords varies–in jazz, the major seventh is often marked with a triangle, as in $\Delta 7$. It’s also common to see Maj in front of 7.

You may think of major-seventh chords as constructed either by lowering the root by a semitone, or raising the seventh of the corresponding dominant seventh chord.

Here’s the E major-seventh grip, together with its less common minor version:

When transposing these chords down the fretboard, we often skip the fifth in the bass as well as the root on the highest string. We either mute these strings or finger-pick the remaining four strings. Here’s the G major-seventh chord constructed this way:

You might be wondering at the resemblance of this grip to A minor. This is no coincidence–the major-seventh chord contains a minor triad. Check this out: there is a minor third between 3 and 5, and a major third between 5 and $\Delta 7$. In fact, every four-note chord contains two triads (the dominant seventh chord contained a diminished triad built inside a tritone, and the minor major-seventh chord contains an augmented triad).

Here are, similarly constructed, major-seventh versions of A chords. They are also easy to transpose down the fretboard. (Can you spot a flatted Dm shape in the first one?)

And these are the D chords:

C major-seventh is an odd one (that’s because there is an open string between the minor seventh and the root), but it’s very easy to grip:

If you squint hard enough, you can see the elements of E minor in it.

Here’s the open-string version of G major-seventh:

Squint again, and you can see the elements of B minor.

Previously, we discussed chord construction by mutating the third (we’ll come back to the topic of mutating the fifth later). Another important mutation is adding more notes to a chord. Traditionally, the most common addition is that of the seventh. There are two versions of the seventh: minor, consisting of 10 semitones; and major, 11 semitones. We’ll start with the minor mutation, because it plays a very important role in functional harmony.

Classical music was built around the idea of tension and resolution, and the perfect expression of it was the authentic cadence, a two chord progression from the dominant chord to the tonic. The dominant is the fifth above the tonic so, for instance, E dominates A. You could build a whole song with just these two chords, and you’d probably end it on the cadence from E to A (the word cadence is derived from cadere, which means to fall).

To add more tension to a dominant chord, it is customary to extend it with a minor seventh. This creates a very dissonant interval between it and the third of the chord. The major third is 4 semitones above the root, the minor seventh is 10 semitones from the root, and 10 – 4 = 6. Six semitones is a diminished fifth, or the cursed tritone. The resolution of the tension created by this dissonance is very satisfying to our ears. A chord with a minor seventh is called the dominant seventh chord.

Let’s go back to the basic E shape and see how we can add a seventh to it.

We have two possibilities: we can either raise one of the fifth, or we can lower one of the roots. Luckily, both are duplicated, so we are not losing any triad tones.

Raising the fifth by three semitones (7 + 3 = 10) produces this grip:

Notice how smoothly it resolves down to the A chord by small movements of notes in opposite directions.

Here’s the alternative grip of E7, obtained by lowering the root (or the octave: 12 – 2 = 10) by two semitones:

This is a two-finger shape, and it’s easily transposed to any position on the fretboard. Alternatively, if you’re willing to skip the repeated fifth and the duplicated root, you may use this “jazzy” movable shape– here to voice a G7 at the third fret:

We can also add the minor seventh to minor chords to obtain minor seventh chords (sometimes called minor minor seventh chords). These are not as dissonant as their major counterparts (no tritone).

Again, we have two options, one of them easily movable across the fretboard

You can also mute the fifth in the second grip and obtain this strange chord:

This grip is often used in jazz, transposed across the fretboard, with either the top E string muted, or with both bass strings muted.

The story for the dominant seventh versions of the A chord is very similar:

And these are its two minor versions:

The D chords have only one dominant seven version each, obtained by lowering the root (octave):

And here’s the G7 chord in its usual shape, together with the truncated version which, incidentally, could be identified with the A7 chord shifted by two frets in the “wrong” direction:

We’ve seen the minor version of G seventh, Gm7, earlier.

There is only one version of C7:

Interestingly, it’s variation (the one with the fifth on the E string) can be shifted by one fret towards the nut to produce the B7 chord:

This new shape can, in turn, undergo further mutations, giving rise to other interesting extended chords.

As I said, dominant seventh chords have a strong tendency to resolve to their tonic chords, so it pays to learn at least part of the so called circle of fifths. Each chord in this list dominates the one to its right: B, E, A, D, G, C, F (followed by the sharped/flatted chords, to make the full circle of 12). The neighbor to the right of a given chord is called its subdominant. For instance E7 is the dominant of A, whose subdominant is D. The whole 12 bar blues can be played with any three consecutive chords picked from the circle of fifths.

Next time: major seventh chords.

So far we’ve been discussing chord transformations that didn’t change the chord’s function. We’ve been essentially dealing with just one major chord and its transpositions. You can think of a major chord as a rigid shape rotating through the circle of pitches: a four-semitone step topped with a three-semitone step, combining to seven semitones of the perfect fifth. We’ll keep the fifth for the time being, because it’s such a nice consonance, but we’ll be mutating the third.

The first such transformation is to lower the third by one semitone to obtain a minor triad. For some reason, we perceive minor chords as sad or melancholy, sometimes a bit whiny.

They are not very common in pop or rock music, but they are popular in folk and jazz (especially with added sevenths, which makes them edgy).

The first three shapes we’ve seen so far are perfect for this transformation: they have a single third, and it sits under a finger. Lifting or shifting this finger is easy. That changes the major third to a minor third, which we will notate as 3♭, since you can think of it as a flatted third. In jazz, flatting is often represented by a minus sign, so you might see Em notated as E-, and so on.

Here are the three basic minor shapes constructed this way:

When playing Dm, we usually mute the two lowest strings. I also listed the inversion Dm/F, as it’s sometimes used in chord progressions (e.g., a walking bass).

The C shape has the third voiced on an open string, and it’s doubled, so it’s humanly impossible to lower it. G shape is also tricky, although with the “folk” G you could cheat and mute the third, which results in a power chord. A power cord can be substituted, in a pinch, for either a major or a minor chord.

Normally, though, you produce all other minor chords by transposing (barring) either Em or Am.

It’s possible to move the third one more semitone step down or up. This results in suspended chords. Twice lowered third becomes a second, so that chord is called the suspended second. A raised third becomes a fourth, so that chord is called the suspended fourth. They are often used as embellishments, or in progression, with a regular major or minor chord in between (George Harrison’s Something or John Lennon’s Happy Xmas (War Is Over) use this riff extensively).

Suspended fourth works with the E shape as well

But suspended second in E is not very practical, since you have to use the adjacent string at the fourth fret, and you end up with the fifth in triplicate (of course, you can mute one).

Interestingly enough, the second can be reinterpreted as the ninth, an octave over. So, instead of using a suspended second, you may replace it with a better sounding add-nine chord. This one keeps the major third, but adds a ninth:

I’ll let you figure out suspensions for the C and G shapes.

Next: Dominant seventh chords.

Previously, we’ve seen how to transform the shapes of major chords by transposing them down the fretboard and across the fretboard. All these transformations can be composed. A mathematician would say that they form a group. Strictly speaking, one should introduce the identity transformation, which is just holding the same shape in place, and the inverse transformation. The latter is always possible, because the fretboard is cyclic: it repeats itself after the twelfth fret. So subtracting two frets is the same as adding ten frets.

Obviously, we can combine sideways shifts with vertical shifts and, for instance, produce the C chord by shifting down the A shape.

Even though all our shapes require only three fingers, the barred versions become progressively harder to grip as they require wider stretching of fingers. So the most common barred chords are either built from the E and A shapes, or use fewer than six strings (either by muting, or by finger picking).

And then there are some hybrid grips that merge multiple shapes. That’s because there is one more type of transformation, which I call “crawling,” where you move to a different triad note on the same string. We’ve already seen examples of creating variations of the G chord and the C chord by replacing the third by the fifth or vice versa. The third and the fifth are only separated by three frets, so they are often within easy reach. You have to be careful with replacing the third, though, if it wasn’t duplicated in the first place. For instance, here’s a version of the D chord that misses the third:

Such chords that only contain the root and the fifth are called power chords and are used a lot in heavy metal.

It’s also possible to replace the fifth by the root, as in this grip:

This is an interesting case of a hybrid grip. It started off as the A shape, but you may also see the beginnings of the G shape transposed down three frets, especially if you mute the two bass strings. The A shape has the ability to crawl down to a G shape.

Similarly, the D shape can crawl down to C shape (see the D triangle at the top?):

These two shapes (with the bass strings left out) can be easily transposed and are pretty useful in practice.

In fact, all chord shapes can be unified in one diagram, if you mark all triad tones across the fretboard. Here’s such a chart for the E chord. You can recognize, in order, the E shape, followed by the D shape, followed (and partially overlapped) by the C shape, which transitions into the A shape, which morphs into G, and finally goes back to E. You can use this diagram to play the same E chord in five different positions (after which it repeats itself).

You can, of course, produce such a chart starting from any of the five shapes, just by cycling it. Or you can cut this diagram out and glue it into a ring.

If you’re an astronomer, you might recognize some common constellations in this chart, like the Orion, or Draco, but that’s just pure coincidence.

Next time we’ll talk about minor chords.

Previously, we talked about transforming the basic E chord shape by transposing it up the fretboard. You may be aware that there are other chord shapes, sometimes grouped into the so called CAGED system. I’ll show you how to derive this system “scientifically.” Scientists arrive at new theories by looking at patterns. Sometimes a pattern doesn’t fit exactly, but it makes sense to temporarily ignore the discrepancy, forge ahead with incorrect assumptions, and then introduce subtle corrections to fix them. I know, this is not what they teach you in school, but that’s how it’s done in real life.

Let’s make some simplifying assumptions about guitar tuning. The first is that the top string can be identified with the bottom string: they are both E strings. Strictly speaking, this is not true: they are two octaves apart, and sometimes you can finger them differently, but we are playing scientists who ignore such distinctions. So we’ll consider the bottom E string a duplicate of the top E string. Second assumption is more outrageous: strings are tuned in fourths. Well, this is true in 80% of the cases. The 20% exception is the interval of a major third between the G string and the B string. We’ll just ignore it for the moment. With these assumptions in place, we can think of the strings forming a circle: we glue together the two E strings, and we get a circle of five strings a fourth apart.

In this imaginary world, we can now shift any chord shape sideways, around the circle, without changing its function. Granted, it will shift all the pitches up by a fourth, so shifting the E chord to the right would result in the A chord, another shift would produce the D chord, and so on. Lets try it!

We’ll start with the E chord and shift it to the right.

We get this:

Hurray! Within experimental error, it worked! Granted, this is the A minor chord, not the A major that we were expecting, but still, considering that our assumptions were partially wrong, that’s close enough.

The question is, how can we modify our theory to produce the A major chord? Our problem has its source in the anomaly between the G string and the B string. When we shift a finger between the two, keeping it on the same fret, we are not moving the pitch up by a fourth, we’re moving it by a third. If all shifts were by a fourth, relative intervals wouldn’t change, and we would just transpose a major chord into another major chord.

But not all is lost. It just means that we have to introduce a correction to our theory. In order to preserve relative intervals, when shifting from the G string to the B string, we have to move the finger one fret up the fretboard (or down, in the diagram). It works:

This is indeed the A major chord.

Of course, theory aside, the chord has to also sound right. This one is okay, except that the fifth of the triad is in the bass, which makes it an inverted chord. In guitar notation inversions are often written as slash chords; here it would be A/E, because of the E in the bass. Inverted chords don’t always work in a chord progressions so, in practice, people try to mute the low E and emphasize the root A.

To test our theory further, let’s apply the right shift to A. The fourth above A is D and, indeed we get the D major. Notice the adjustment when moving between the G and the B strings.

Again, the bass part is a little tricky. Here, I just duplicated the high E string grip on the lower E string, which resulted in another inversion D/F#. In practice, people usually mute both the E and the A strings and emphasize the root D.

Another shift to the right and we get the G chord (again, correcting the move from the G string to the B string and mirroring the E string):

This particular variant is often used in folk music. The more popular variant gets rid of the fifth on the B string, since the open B is the third of the triad.

This change leads to the duplication of the third, so people often mute the third in the bass.

Another shift, and we get the C major. Here, the move from the open G string is corrected by pressing the B string at the first fret. All according to our theory.

The third in the bass doesn’t sound good, so it’s usually muted. Another inversion, with the fifth in the bass, sounds better in many contexts, so here’s C/G:

Here’s another variant with, the fifth on the highest E string

We’ll see this variant modified by extension notes (the sevenths and the ninths).

We have just covered all the shapes in the CAGED system (the letters stand for the five major chords). And, indeed, we went full circle, because the next shift produces the F chord (the open G string turns into first fret press on the B string).

This makes perfect sense. If it weren’t for the anomaly, the fifth shift should bring us back to the same shape. But every time a black dot crosses the anomaly, it drops down so, after a full circle, the whole shape drops down one fret. Therefore five shifts to the right equal one shift down. We have just proven a theorem.

Notice that in the first three iterations a triangle shape is formed by three fingers. This shape consists of the fifth, the root, and the third of the triad. This information will come in handy when we discuss chord modifications. To the left of the triangle, we have the root, and to the right, another fifth (except in the D chord, where it’s pushed off the edge). In the G chord, we start seeing part of this triangle peeking on the left (the root and the third), shifted down because of the anomaly. In C/G the triangle is fully reconstituted, albeit one fret down. If you can spot these shapes, you’ll have no problem remembering where to find the third (and, for instance, lower it to make a minor chord) or where to insert the seventh.

This theory can be also visualized by arranging the strings in a radial pattern, the frets forming a spiral. Here’s the diagram for the E chord:

If you rotate the dots counterclockwise, you’ll get the A chord, and so on. The anomaly adjustment happens automatically, because the B string is offset by one step. Also, if no dot moves into the B string, a new dot at the first fret is produced.

Next time, combining the transformations.

We have our first guitar chord, E major:

We can apply a simple transformation to it to generate all of the major chords (there are twelve of them). The transformation is called transposition, and it simply moves all the notes up the fretboard by the same distance. We can easily move the three fingers that form the shape of E, but there are also three open strings. They have to be shifted as well. This is where barring with your index finger comes handy. Your finger creates a new nut (that’s what the upper end of the fretboard is called).

Below is the A major chord created by shifting E five semitones, or five frets, down the fretboard. The intervals don’t change, but the root changes from E to A, and all the notes get renamed accordingly.

This is how you grip it.

Technically, barring a chord, is not easy for beginners. You have to develop enough strength and precision in your left hand. But conceptually, it’s very simple. Shifting the whole shape doesn’t change relative intervals, so a major chord remains a major chord. If you don’t have perfect pitch, and somebody shifted a chord, you might not be able to tell. It’s all relative.

That’s why it reminds me of special relativity. You are looking at the same chord from a different frame of reference. All laws of physics (relative intervals) are the same. There is even an analog of relativistic shortening of distances (Lorenz contraction): the distances between frets get shorter as you move down the fretboard. If the frets continued all the way to the bridge, the distances between them would shrink to zero, and there would be infinitely many of them. Reaching the bridge is like reaching the speed of light in special relativity.

It’s very useful to know the names of frets on the E string, because each of them can become the root of a shifted chord. They are, starting from the zeroth fret, or the nut:

E, F, F#, G, G#, A, A#, B, C, C#, D, D#, E.

The twelveth fret is E again, one octave higher, and then the pattern repeats itself. As you can see, there is some regularity in the naming of notes, but then there are the odd cases. Every note can be sharped (the # sign) but you don’t see E# there because it’s the same as F. Also, B# is identified with C.

G major is barred on the third fret (three semitones from E):

and so on.

Later we’ll see that almost all chords with un-sharped names have alternative grips that don’t require barring. The odd one is F, which is really hard to play for beginners:

There is an alternative fingering that requires pressing two thinnest strings with the index finger and either not playing the thickest E string (muting it), or pressing it with a thumb wrapped around the stock:

Just for fun, here’s the F# major chord in which all the notes are sharped.

Perhaps surprisingly, transposition on the piano is much harder, because of the white key / black key irregularities.

Next time we’ll talk about the transformation that generates the CAGED system.

Music teaches us a lot about reality. It shows enough regularity to suggest a simple mathematical model, but also enough irregularity to frustrate our attempts at formalizing it. In this series of essays, I’ll try to describe some of this frustration mixed with fascination. I’m going to talk about the guitar; both because I know more about it and because it’s even more quirky than the piano.

The guitar is a versatile instrument. You can play individual notes of a melody, you can play chords, and you can play the bass line, sometimes all at the same time. All this with just six strings. These six strings are tuned is such a way as to maximize the number of chords that can be played on it. You play chords by making shapes with your left hand (or the right hand if, like Jimi Hendrix, you’re left-handed). It’s a very interesting optimization problem that involves equal parts of music theory and human anatomy.

Here are some anatomical constraints: we have five fingers in the string-pressing hand. The thumb is mostly used for grip, although you can sometimes use it to play bass notes on the thickest string by reaching around the neck. That leaves us with four fingers to control six strings. If we want to strum all six strings, we have two options: we can let two or more strings ring free, or use one of the fingers (usually the index finger) to bar multiple strings and use the remaining three fingers to create the chord shape. So the basic chord shape is a three-finger grip. If we can form a chord with three fingers, we can move it up the fretboard using the index finger for barring. As with all musical instruments, the available shapes are limited by anatomy: we can only stretch our fingers so much.

Now for some music theory. The basic chords are triads built from three notes: the root, the third, and the fifth (relative to the root). The intervals between these notes determine the type of the chord. A major triad is build from a major third and a minor third (the sum of these thirds is a perfect fifth–yes, in music 3 + 3 = 5). The C major triad, for instance, consists of three notes: C, E, and G. The distance from C to E is a major third, and the distance from E to G is a minor third. The distance from C to G is a perfect fifth.

Naively, we might think that the guitar should be tuned in thirds, say, the lowest string C, then E, and then G. But what then? What about the three remaining strings? We could repeat C, E, and G, an octave higher. That would be okay if we only wanted to play major triads. But there are also minor triads, with a minor third followed by a major third. C minor triad is C, E♭ (E flat), and G. So maybe we could use that for the tuning? It would allow us to play C minor with no fingers, and C major by pressing two strings with two fingers. Unfortunately, there are many other types of chords that would be very hard to play in that tuning, so this idea is scrapped.

Observe, though, that with six strings, it’s unavoidable that some notes of the triad would have to be doubled (modulo shifting by an octave or two). This introduces more intervals between notes: for instance, the distance from G to the C in the next octave is a fourth. So within a duplicated triad we have the intervals of a major third, minor third, the perfect fifth (their sum), a fourth (from G to C), as well as two sixths (from E to C and from G to E), a few octaves, and so on.

So here’s a new idea: If we tune the strings in fourths, we can easily, without stretching our fingers too much, produce thirds, fourths, and fifths. That’s because we can shorten an interval by pressing the lower sting, or lengthen it by pressing the higher string.

Let’s see how this works. The lowest string on the guitar is E, so that’s where we’ll start. A fourth about it is A, so that’s the next thickest string. Let’s see what intervals we can make using those two.

By pressing the E string at the first fret, we can produce a major third, F to A.

By pressing it at the second fret, we can produce a minor third, F# to A.

By releasing the E string and pressing the A string at the second fret, we can produce a perfect fifth, from E to B.

And, of course, by releasing both strings, we get a perfect fourth, from E to A. That’s a lot of handy intervals within easy reach.

Let’s use this idea to build the simplest guitar chord, E major, which contains E, G#, and B. In principle, the order of these notes and the octaves they are in doesn’t matter, but some combinations sound better than others. We’ll start with the open E string for the root. To start with, let’s assume the tuning in fourths, so the second string is A, the third D, and the fourth G.

We can can press the A string at the second fret to produce the fifth of the triad, B. (We are skipping G# for now, because it’s not easily reachable.)

The next triad note within reach is another E, an octave higher. We can play it by pressing the D string at the second fret.

Now we can finally add the third, G#, by pressing the next string, G, at the first fret.

We now have the root (doubled), the fifth, and the third of the triad.

There are two more strings to go, and we have already used three fingers to press three strings. If we continued tuning strings in fourths, the next string would be C. That’s not part of our triad, and we can’t easily stretch our pinky to reach the next E. So we begrudgingly give up on our rule of fourths, and instead tune the next string a semitone lower than we promised, to a B. B happens to be in our triad, so we’re fine. And a fourth about B is again E, so that works too.

Here are the notes we used in this grip, together with intervals between them.

Notice that the root E is repeated three times, in different octaves. The fifth of the triad, B, appears twice, and the third, G#, only once. As we’ll see later, this arrangement gives us a lot of flexibility when transforming this grip.

The leap of a fifth in the bass, from E to B, is actually very pleasant to the ear — skipping the G# there is advantageous.

Here’s the same grip annotated with root-relative intervals. 1 is the root (E), 3 is the third (G#), and 5 is the fifth (B). It’s very important to remember which is which, in order to understand how to transform this shape to produce other interesting chords.

Not surprisingly, this is called the E shape in the popular CAGED system.

We’ve used only three fingers, which is great, because we’ll be able to use the index finger as a bar to move this triad up the fretboard, if we wish so.

In the process, we have arrived at the standard guitar tuning E, A, D, G, B, E. It is basically in fourth, except for the major third from G to B. This one exception introduces a lot of complexity into chord building on the guitar.

By now, you might have noticed some irregularities in music notation. They have accumulated over the centuries of development. We now use the so called equal temperament system in which the basic interval is a semitone, corresponding to one fret on the guitar. Standard musical intervals can be expressed in semitones, with the additional convenience that they satisfy standard arithmetic. For instance, a minor third is 3 semitones, a major third is 4 semitones, their sum is 7 semitones, corresponding to a perfect fifth. A perfect fourth is 5 semitones, which is an octave (12 semitones) minus the perfect fifth (7 semitones).

We could have motivated our tuning by postulating the distance of two octaves (24 semitones) between the lowest and the highest string. If we divide two octaves between six string (5 intervals), we get 4.8, which is almost the perfect fourth (5 semitones), but not quite. That’s why we introduced the “leap interval” of a major third between the G and the B strings.

Next, I’ll show you how all common chords and the majority of jazz chords can be derived from this single shape by applying various transformations (or, as mathematicians call them, morphisms).

## Acknowledgment

I used the excellent free web program chordpic to generate my string diagrams.