Scales and modes

The same algorithm made a Cuban rhythm

Ask Bjorklund's algorithm for seven onsets in twelve steps and it returns 101101011010, which read as pitch classes is the natural minor scale. That function has been producing the tresillo and the cinquillo here from the beginning, and nobody has said that the scale field's central object comes out of it unchanged.

Assumes: Seven of the twelve, chosen unevenly

The site’s rhythm field opens with an algorithm: ask for five strikes over eight beats spaced as evenly as possible and it produces the cinquillo; ask for three over eight and it produces the tresillo. Nobody told it about Cuba.

The function that does that is in this repository and has been since the first phase. Hand it seven and twelve.

It returns 101101011010.

Read the ones as pitch classes rather than as onsets and they are 0, 2, 3, 5, 7, 8, 10 — the natural minor scale, exactly, with no adjustment.

One construction, a scale on one side and a rhythm on the other. Both rings are the same computation: k things placed as evenly as possible in n positions. On the left it is 7 notes in 12 semitones, which is the major scale; on the right 5 strikes in 8 steps, which is the cinquillo. The filled positions come from the J-function and the open marks from Bjorklund's algorithm, and they are the same set of positions turned by 9 and 6.
Fig. 1 The two objects side by side, both computed rather than tabulated. On the left, seven notes placed as evenly as possible in twelve semitones, which is the major scale; on the right, five strikes placed as evenly as possible in eight steps, which is the cinquillo. The filled marks come from Clough and Douthett’s J-function and the rings around them from Bjorklund’s algorithm, and they are the same positions rotated.

Two names for one construction

The pitch-theory literature calls it maximal evenness and writes it as a formula. The kth element of the maximally even set of k things in n positions is the floor of (ni + m)/k, where m is an offset. It appears in the American music-theory literature of the early 1990s as a way of characterising the diatonic set, the pentatonic set and the octatonic set at once.

The rhythm literature calls it a Euclidean rhythm and computes it with Bjorklund’s algorithm, which was published in 1978 for spacing the timing pulses of a neutron accelerator and reached music theory in 2005. It works by repeatedly pairing groups, which is the structure of Euclid’s algorithm for a greatest common divisor, and it is why the rhythms are called Euclidean.

They are the same construction. One is stated as a formula and one as a procedure; both place k things in n slots so that no two adjacent gaps differ by more than one, and for every pair of numbers they produce the same set up to rotation.

The site’s own two implementations were written for different fields, two phases apart, from two different sources, and neither file mentions the other. Running one of them on the other’s arguments is all it takes to see it, and nothing had.

Where the rotation comes from, and what it is

The two do not produce identical output, and the difference is exactly one turn of the ring.

Bjorklund’s answer for seven in twelve begins on an onset and produces the natural minor; the J-function at offset five produces the major scale. Every offset from zero to six produces a different rotation:

offset set name
0 0 1 3 5 6 8 10 Locrian
1 0 1 3 5 7 8 10 Phrygian
2 0 2 3 5 7 8 10 Aeolian
3 0 2 3 5 7 9 10 Dorian
4 0 2 4 5 7 9 10 Mixolydian
5 0 2 4 5 7 9 11 Ionian
6 0 2 4 6 7 9 11 Lydian

The offset is the mode. That is not an analogy; the parameter that decides which rotation of the even set is produced is the same parameter that decides which degree is called home, and the site’s own essay on modes is about exactly that reassignment.

The identity, checked on every pair rather than on the figure’s

The claim that the two constructions coincide is a theorem elsewhere and, as the caveats below record, was checked here only for the pairs the figures draw. Checking it is a loop: run both functions for every k and n with n up to thirty-two, and ask whether the two sets agree under some rotation.

They agree on all 496 pairs, with no exceptions. And the maximally even set is unique up to rotation on all 496 as well — the k offsets never produce two genuinely different shapes, only rotations of one.

How many offsets there are, which turns out to be the mode count

The second of those is worth pushing on, because the offsets do not always produce k different rotations and the number they do produce is exact.

Running every offset for every pair and counting the distinct sets: the answer is k divided by the greatest common divisor of k and n, on all 496 pairs. When k and n are coprime every offset gives a different rotation; when they share a factor, offsets collapse together, and when k divides n every offset gives the same set.

That quotient is not a new quantity. It is the mode count, and it is the one the modes ladder derives from a set’s transposition symmetry — a set has as many modes as it has notes divided by the order of its own symmetry. For a maximally even set the symmetry order is gcd(k, n), which means the mode count of every such set is decided by nothing but the two numbers it was asked for:

notes in twelve gcd modes
4 4 1 the diminished seventh
5 1 5 the pentatonic scale
6 6 1 the whole-tone scale
7 1 7 the diatonic set
8 4 2 the octatonic collection

That table is the modes ladder’s own, arrived at from the other side and without ever testing a set for symmetry. Its census walks every subset of the twelve and asks which transpositions return it; this reaches the same five rows by dividing two numbers, because a maximally even set’s symmetry is forced by the arithmetic that constructs it.

So “the offset is the mode” is exact and has a count attached. The seven diatonic modes exist because seven and twelve are coprime — and that is the same coprimality that makes the diatonic set generable by a fifth, which is the theorem the deepness rung quotes. Three properties of the scale that arrive in three different chapters of the literature all turn on gcd(7, 12) = 1.

It also says where the rhythmic reading loses its parameter. E(4,8) is four strikes evenly spaced in eight, gcd is four, and every offset gives the same pattern — there is no downbeat to choose, because the pattern is its own rotation. A rhythm that is perfectly even has nowhere to put a beginning, which is the same fact as a whole-tone scale having nowhere to put a tonic.

The rhythmic version has the same parameter and it decides where the downbeat is. A rhythm drawn as a cycle turns out to be shared across continents, differing only in where somebody decided to start counting — which is the same sentence with “mode” replaced by “starting point”, and it was written two phases before this one without either essay noticing.

One construction, a scale on one side and a rhythm on the other. Both rings are the same computation: k things placed as evenly as possible in n positions. On the left it is 5 notes in 12 semitones, which is the pentatonic scale; on the right 3 strikes in 8 steps, which is the tresillo. The filled positions come from the J-function and the open marks from Bjorklund's algorithm, and they are the same set of positions turned by 4 and 2.
Fig. 2 The other famous pair, on the same construction. Five in twelve is the pentatonic scale and three in eight is the tresillo, and both come out of the same two implementations agreeing. The rotation between the J-function’s answer and Bjorklund’s is four positions on the left and two on the right, which is the only thing that ever differs between them.

Why evenness produces two step sizes

The connection to the property this ladder’s third rung is about is immediate and worth spelling out, because it explains why the same construction keeps producing usable objects.

Placing k things as evenly as possible in n positions, where k does not divide n, cannot give equal gaps. The best available is gaps that take only two values, differing by one, distributed as regularly as they can be. Twelve over seven is 1.71, so the gaps are 2 and 1 — five twos and two ones. Eight over five is 1.6, so the gaps are 2 and 1 — three twos and two ones.

Two sizes of step is not an additional property of these objects; it is what maximal evenness means when the division is not exact. So every Euclidean rhythm has two note lengths and every maximally even scale has two step sizes, by construction, and the same argument covers both.

Six rhythms, all from the same construction. Euclidean rhythms generated by Bjorklund's algorithm, which spreads a number of onsets as evenly as a number of steps allows. The patterns were not transcribed from recordings; they are what the algorithm produces, and the names beside them are where each one is already in use.
Fig. 3 Five members of the family with the last two read as pitch rather than as time. The two scales sit in this table without any adjustment: they are what the algorithm returns for those arguments, and their step patterns — 3 2 3 2 2 and 2 1 2 2 1 2 2 — have exactly two values each, like every other row.

The place the two fields already met and nobody noticed

The identity is not the only thing the two implementations share, and the second overlap is more surprising than the first because it is about an error.

The site’s own euclidean docstring records that the naive accumulator produces a rotation of the right answer, and that the rotation matters: E(3,8) has to come out as the tresillo and E(5,8) as the cinquillo, starting on the downbeat, or the essays are describing something else. That was written as a warning about rhythm.

It is the same warning about scales. The J-function’s offset and Bjorklund’s starting point are the same free parameter, and getting it wrong in the pitch reading does not produce a wrong scale — it produces a mode, which is a perfectly good object that is not the one asked for. A silent rotation in one field is an error and in the other is a different named thing, and both come from the same line of code.

One construction, drawn twice as pitch. Both rings are the same computation: k things placed as evenly as possible in n positions. On the left it is 7 notes in 12 semitones, which is the major scale; on the right 5 notes in 12 semitones, which is the pentatonic. The filled positions come from the J-function and the open marks from Bjorklund's algorithm, and they are the same set of positions turned by 9 and 4.
Fig. 4 Both rings read as pitch, which is where the rotation warning turns out to be about scales. The filled positions come from the J-function and the open marks from Bjorklund’s algorithm, and on each ring they are the same set of positions turned — by nine on the left and four on the right. In the rhythm reading that turn is a bug: E(3,8) has to come out as the tresillo starting on the downbeat or the essay is describing something else. In the pitch reading the identical turn produces a mode, which is a perfectly good object that is not the one asked for. One free parameter, one line, an error in one field and a named thing in the other.

Where the analogy stops

An identity between two constructions is not an identity between two subjects, and three differences are worth stating because they are what stops this being a claim that rhythm and pitch are the same thing.

The ring is not the same ring. A pitch ring’s twelve positions are related by frequency ratios and its 2:1 is a genuine equivalence — an octave fuses because every partial coincides. A rhythm ring’s positions are related by counting and its wrap-around is a repeat, not an equivalence. The two rings have the same topology and completely different content.

A rhythmic gap has no analogue of a semitone’s roughness. In pitch, the two step sizes are 100 and 200 cents, which are perceptually and acoustically different quantities; in time they are one and two steps of a pulse, which differ only in duration. So the consequences of the two-size property are unrelated in the two fields even though the property is one.

And a scale is a resource while a rhythm is a piece of material. A scale is the set from which notes are chosen; a rhythm is the thing itself. Nothing in the construction distinguishes them, which is why it applies to both, and everything about how they are used does.

One construction, a scale on one side and a rhythm on the other. Both rings are the same computation: k things placed as evenly as possible in n positions. On the left it is 7 strikes in 12 steps, which is a bell pattern; on the right 7 notes in 12 semitones, which is the natural minor. The filled positions come from the J-function and the open marks from Bjorklund's algorithm, and they are the same set of positions turned by 10 and 10.
Fig. 5 The same two numbers, drawn twice, once in each reading — and the two pictures are identical in every particular. Seven in twelve is an ordinary bell pattern on the left and the natural minor scale on the right, and no property of either drawing says which field it belongs to. What differs is entirely outside the figure: the left ring’s wrap-around is a repeat and the right ring’s is an octave, which fuses because every partial coincides; the left ring’s two gap sizes are one and two pulses and the right ring’s are a semitone and a tone, which are perceptually unrelated quantities. The two rings have the same topology and completely different content.
How many sizes each interval comes in. Each generic interval of the diatonic scale and of seven consecutive semitones, with the specific sizes it takes as the starting degree moves round. The first gives exactly two sizes for every one of them; the second gives 2, 2, 2, 2, 2, 2. Of the 462 seven-note selections from the twelve that contain the tonic, 14 have two sizes for every generic interval — 3.0% of them, and they are the rotations of just 2 step patterns: 1·1·1·1·1·1·6 and 1·2·2·1·2·2·2.
Fig. 6 Why two step sizes is the useful consequence. Each generic interval — every second, every third, every fourth — comes in exactly two specific sizes in the diatonic set, so one word does for two distances and a musician can say “a third” without qualifying it. A run of seven semitones also has two step sizes and is not maximally even, so it manages the property by a different route and is useless for anything else.

What the two fields do with the leftover

The construction leaves a remainder — n modulo k — and what each field does with it is where they finally diverge.

Twelve over seven leaves five, so the diatonic set has five large steps and two small ones. Eight over five leaves three, so the cinquillo has three long gaps and two short ones. In both cases the remainder decides how many of each size there are, and the algorithm decides where they go.

In pitch, the two small steps are the semitones, and where they fall is the whole of what distinguishes the modes from each other — the character of a mode comes from which degree the semitones sit next to. In rhythm, the two short gaps are the syncopations, and where they fall is what makes a pattern a tresillo rather than a march.

So both fields treat the minority step as the marked element, and both derive their internal variety from where it lands. That is a genuine structural parallel and it is the deepest one available, because it is about how the objects are used rather than about how they are built.

And the amount of variety available is the gcd result again, read as a count of arrangements. If k and n share a factor, the minority steps are distributed symmetrically and several starting points give the same arrangement, so there are fewer distinct patterns to choose between; if they are coprime there are k, one for every note. A field’s expressive room is the coprimality of the two numbers it started from — seven modes in twelve, five in the pentatonic, three in the tresillo, and exactly one in the whole-tone scale and the even four-in-eight.

One construction, a scale on one side and a rhythm on the other. Both rings are the same computation: k things placed as evenly as possible in n positions. On the left it is 4 strikes in 8 steps, which is a factor in common; on the right 5 notes in 12 semitones, which is coprime. The filled positions come from the J-function and the open marks from Bjorklund's algorithm, and they are the same set of positions turned by 0 and 4.
Fig. 7 Where the expressive room comes from, which is the greatest common divisor read as a count. Four in eight share a factor of four, so the minority steps are distributed symmetrically and turning the ring by two gives back the same arrangement — one distinct pattern, and no modes. Five in twelve are coprime, so every one of the five starting points gives a different arrangement. That is the same result in both fields: seven modes in twelve, five in the pentatonic, three in the tresillo, and exactly one in the whole-tone scale and in an even four-in-eight. A field’s variety is the coprimality of the two numbers it started from.

Whose music, and when

The rhythms in the table are named practices: the tresillo and cinquillo of Cuban music, the Turkish aksak, West African bell patterns. Bjorklund’s algorithm produces them and did not know about any of them, which is the rhythm essay’s finding and is not restated here.

The scales are the European diatonic and pentatonic collections, and the claim that they are maximally even is a claim of the twentieth-century American theory literature rather than of any practice. Nobody in the fifteenth century derived a scale by placing seven things evenly.

What the identity is evidence for is narrower than it looks. It does not show that scales and rhythms have a common origin, or that one was derived from the other, or that a listener perceives them alike. It shows that both are solutions to the same combinatorial problem — put k things in n slots without clumping — and that a problem with a unique answer will be arrived at repeatedly by people who have never met.

That is the honest reading and it is still a strong one, because the alternative explanations for either object are much more specific. The diatonic set is usually derived from a chain of fifths and the tresillo from a West African timeline, and neither derivation predicts the other object at all.

What promoting one function would have hidden

There is a temptation, on finding two implementations of one construction in a repository, to delete one of them.

It would be wrong here, and the reason is worth recording because it is a judgement this site has made in the other direction before. euclidean returns a boolean array indexed by step, because a rhythm is a pattern of struck and unstruck positions and the unstruck ones are as much part of it as the struck. maximallyEven returns a sorted list of positions, because a scale is a set and its complement is not an object anybody names.

Those are different return types for a reason that belongs to the subject rather than to the code, and merging them would mean one field constantly converting. A shared construction is not always a shared function. The usual version of that warning is about names: two functions called the same thing that turn out to compute different quantities. This is the opposite case — two functions with different names that compute the same quantity — and it has the same resolution, which is to read the bodies and keep whichever difference the subject actually needs.

What the two do share is a claim, and the claim is now tested rather than assumed: the figure computes both and prints the rotation between them, so a change to either that broke the identity would show up as a caption saying the sets do not match.

Where the model stops

The two implementations agree and that is a fact about this repository. The claim that Bjorklund’s algorithm and the J-function coincide in general is a theorem in the literature; what is checked here is that the site’s two functions produce the same sets, up to rotation, for every k and n with n up to thirty-two — 496 pairs, no exceptions — rather than only for the pairs the figures use, which is what this note previously recorded. The figure also prints the rotation it found, so a pair where they diverged would say so rather than being silently drawn as agreeing.

Maximal evenness picks a unique shape at every size and not a useful one. The set is unique up to rotation for all 496 pairs checked, so the ambiguity is never about which shape; it is about what the shape is good for. Where k divides n the answer is the perfectly even set — six in twelve is the whole-tone scale, four in twelve is the diminished seventh — and those are symmetrical objects with quite different properties, including being useless for locating a modulation and, by the gcd result above, having one mode rather than k. Evenness alone is not enough, which is the next rung’s subject, and the gcd is the number that says in advance which sizes will disappoint.

And the construction says nothing about tuning. It places seven positions out of twelve and is silent about where the twelve are. Every question this site’s tuning field is about — where the comma goes, what a fifth is worth — is invisible to it, because it counts rather than measures.

What the picture cannot show

It cannot show which rotation was chosen and why. The offset is a free parameter and the figure prints its value; what decides it in practice is a downbeat in one field and a tonic in the other, and both are supplied by a listener rather than by the construction.

And it cannot show the pulse. A rhythm ring assumes an underlying grid of equal steps, and a great deal of what makes a groove is the deviation from that grid. The construction is exact about which slots and silent about when the slots actually occur.

Where the ladder goes next

The diatonic set now has three properties — two sizes of every step, distinct interval counts, and maximal evenness — and each is shared with some other set. The last rung asks how many shapes in the whole twelve-note universe have all of them at once, and scans every subset of every size to find out.

Part 5 of 9

One essay in the series on the diatonic set. The essays either side of this one:

What links here

Essays that reach for this one mid-argument — the half of a link its own author cannot write down, the 8 sharing most with it of 10.

The objects named here

The third way in, after the field and the series: the things themselves, and every essay that touches each one.

Bjorklund's algorithmCycleDiatonic scaleEuclidean rhythmInterval patternMaximal evennessRotation