← All projects

Coprime pairs and musical intervals

A pair of whole numbers (x, y) is coprime when gcd(x, y) = 1, that is, when x/y is already in lowest terms. On a grid the coprime pairs form rays out of the corner. As knots, they are the Turk's heads that tie with one strand. On a number line from 1 to 2, they are the intervals inside one octave. On an oscilloscope, they are the Lissajous figures. Standing at the corner, they are the trees you can see.

Whose ideas these are. The author came up with the connections on this page independently: the coprime grid and its rays, the number line with heights 1/(p² + q²) and its match to the musical intervals, Turk's head knots, turning Lissajous figures, the view from the orchard, and the ratio π² : 6 (at the age of 14). Some had been found before by others, and the page names them where known (Euclid's orchard, Thomae's function, Pólya, Tenney, Euler, Ptolemy, Helmholtz) for history and comparison. The last section, Further connections, is different: none of it is the author's.

Explore the grid

x runs left to right, y top to bottom, starting at (1, 1). A square is light when x and y are coprime and dark when they share a factor. Pick a square to see its pair, the ray it lies on, the Turk's head knot with x leads and y bights, and the Lissajous figure x : y.

(5, 3)
gcd
1
lowest terms
5/3
ray
step 5 across, 3 down
Turk's head: one strand
Arrow keys move the selection; drag or tap to pick.
Turk's head, 5 leads × 3 bights, seen from the end of the drum
Lissajous 5:3, seen from the side of the drum

The Lissajous figure is x = sin(a·t + δ), y = sin(b·t) with a and b the pair. It is drawn as a wire on a turning drum: the part of the wire on the far side is faint. Turning the drum is the same as letting δ drift, which is what an oscilloscope shows when two tones are a little out of tune.

One idea, five views

Everything on this page is one question asked several ways: is the ratio a : b in lowest terms?

Coprime a : ba : b with a common factor dWhat makes it simple
Grida light square, the first point of its raya dark square, point d of the ray a/d : b/dnear the corner
Musican interval, frequencies in the ratio a : bthe same interval as a/d : b/dsmall a and b: more shared overtones, more consonant
Turk's heada leads, b bights, one strandd separate strands, each an a/d × b/d patternfew leads and bights
Lissajousone closed curve, touching each side a times and the top b timesthe a/d : b/d curve traced d timesfew lobes, a steady figure
Orcharda tree you can see from (0, 0)hidden behind the tree at (a/d, b/d)near you, so tall in view

The grid and its rays

100 by 100 coprime grid: white where coprime, black otherwise, with 29 coloured rays fanning out from the top-left corner
100 × 100 pairs. The 29 rays with both steps at most 7 and the smaller at most 4 are drawn solid, coloured by angle; the red one is the diagonal. The same grid at one pixel per pair, the size of a 4K screen.

Take any step p across and q down with gcd(p, q) = 1. The points (2p, 2q), (3p, 3q), (4p, 4q)… have gcd 2, 3, 4…, so every one of them is dark: each coprime step makes a dark ray out of the corner (0, 0). The first point, (p, q) itself, is light. The 1:1 ray is the diagonal. Lines drawn from (1, 1) instead of (0, 0) come out light: (1 + 2k, 1 + k), for example, always has gcd 1.

Turk's head knots

A Turk's head knot is described by its leads, the number of times the strand passes round, and its bights, the scallops at each edge. A Turk's head with L leads and B bights ties with a single strand exactly when gcd(L, B) = 1. Otherwise it falls apart into gcd(L, B) separate loops.

So the light squares of the grid are the Turk's heads that work, read as x leads and y bights. The dark rays are the ones that don't: the point k·(p, q) on a ray makes k separate strands, each tracing the (p, q) pattern turned a little. The explorer above draws each strand in its own colour.

The knotwork sound-hole generators use exactly this rule: the single-strand generator takes any leads × bights and refuses a pair that isn't coprime.

6/π²

About 61% of the squares are light. As the grid grows, the share tends to 6/π² ≈ 60.79%: the probability that two random whole numbers are coprime. It is 1/ζ(2), where ζ(2) = 1 + 1/4 + 1/9 + 1/16 + … = π²/6. In the 3840 × 2160 grid the share is 60.80%.

The same figure sets the number line's count. Of all the fractions p/q from 1 to 2 with q up to Q, the share in lowest terms tends to 6/π²: 1103 of 1890 (58%) at Q = 60, 304,193 of 501,500 (60.7%) at Q = 1000. So the number line has about 3Q²/π² lines.

The author found this ratio, π² : 6, independently at the age of 14.

The number line

Every coprime fraction between 1 and 2 as a vertical line of height 1 over p squared plus q squared, on a log scale, with the musical intervals named and coloured
Every coprime p/q from 1 to 2 with denominator up to 60, height 1/(p² + q²) on a log scale. The just-intonation intervals are named and coloured by class.

Why p² + q². The author chose this height because √(p² + q²) is the distance from the pair's square on the grid to the origin, (0, 0). The height is 1 over that distance squared, so pairs near the corner stand tall and far ones short. That choice is what makes the number line the same picture as the view from the orchard, below.

The pattern repeats at every scale: each tall line stands in a gap with smaller arches either side. The gaps are real, since no fraction with a small denominator lies close to a simple one like 3/2, but their width here comes from stopping at denominator 60.

Standing in the orchard

Panorama from the origin of thin trees on every coprime pair, tallest at 45 degrees, and below it the stretch between the trees at (1,2) and (1,2) with the musical intervals coloured
Top: the view from (0, 0) with a thin tree, one unit tall, on every coprime pair out to distance 300, eye on the ground. Bottom: the stretch between the trees at (1, 1) and (1, 2), where the ratio y/x runs 1 to 2 left to right, just as the number line does.

Stand at (0, 0) and put a thin tree on every coprime pair. This is Euclid's orchard. No tree hides another, since each coprime point is the first on its ray, and the trees left out are exactly the ones that would have been hidden. A full orchard, with a tree on every point, looks just the same from here.

The orchard is the number line seen in perspective:

Does the height order the intervals by consonance?

Very nearly. Sorted by p² + q², the intervals come out unison, octave, fifth, fourth, major sixth, major third, minor third, minor sixth: the order Helmholtz gave for the consonances in On the Sensations of Tone (1863). Dissonances follow, the minor second near the end and the tritone last. The two ratios with a 7 in them, 7:4 and 7:5, come in above the minor sixth; Western 12-tone music has no 7-based ratios, so the usual lists leave them out.

Simple ratios sound smooth because two notes in the ratio p:q share overtones: their waveforms line up every p cycles of one and q cycles of the other. Smaller numbers mean more shared overtones and less beating.

Four rules for how simple p:q is. Each cell is the score and, in brackets, the rank; equal scores share a rank.

IntervalRatiop²+q²p+q (Pythagorean)p·q (Tenney)Euler gradus
unison1:12 (1)2 (1)1 (1)1 (1)
octave2:15 (2)3 (2)2 (2)2 (2)
perfect 5th3:213 (3)5 (3)6 (3)4 (3)
perfect 4th4:325 (4)7 (4)12 (4)5 (4)
major 6th5:334 (5)8 (5)15 (5)7 (5)
major 3rd5:441 (6)9 (6)20 (6)7 (5)
minor 3rd6:561 (7)11 (7)30 (8)8 (6)
harmonic 7th7:465 (8)11 (7)28 (7)9 (7)
septimal tritone7:574 (9)12 (8)35 (9)11 (9)
minor 6th8:589 (10)13 (9)40 (10)8 (6)
minor 7th9:5106 (11)14 (10)45 (11)9 (7)
major 2nd9:8145 (12)17 (11)72 (12)8 (6)
major 7th15:8289 (13)23 (12)120 (13)10 (8)
minor 7th16:9337 (14)25 (13)144 (14)9 (7)
minor 2nd16:15481 (15)31 (14)240 (15)11 (9)
tritone45:323049 (16)77 (15)1440 (16)14 (10)

The Greeks didn't rank all these intervals. The Pythagoreans counted only the octave, fifth and fourth and their octave compounds as consonant: ratios that are multiple (n:1) or superparticular ((n+1):n) and built from 1, 2, 3 and 4. Ptolemy broke with them over the octave plus a fourth (8:3), which he heard as consonant though it is neither. Thirds and sixths were counted as consonances only from the Middle Ages on.

Two limits. These are just-intonation ratios, and equal temperament only comes close: a piano's major third is 400 cents, 5:4 is 386. And how consonant an interval sounds also depends on register, timbre and context, which no formula sees.

Further connections (not the author's)

The author did not come up with anything in this section. These six connections were suggested by Claude, the AI assistant that helped build this page, and are standard results found by others.

Farey sequences and Ford circles

List every fraction in lowest terms with denominator up to n, in order: that is the Farey sequence. Two neighbours a/b and c/d in it always satisfy bc − ad = 1. On a circle drawn at each fraction p/q, resting on the number line with diameter 1/q², no two circles overlap, and two circles touch exactly when their fractions are Farey neighbours (Lester Ford, 1938). It is the number line's heights and gaps drawn as circles: next to p/q, no fraction with denominator up to n comes closer than 1/(qn).

Ford circles on every fraction from 1 to 2 with denominator up to 24. The big circles on 1 and 2 are cut off at the top.

The Stern–Brocot tree

Start with 1/1 and 2/1 and keep putting the mediant (a + c)/(b + d) between each pair of neighbours. Each round adds:

RoundNew fractions between 1 and 2
13/2
24/3   5/3
35/4   7/5   8/5   7/4
46/5   9/7   11/8   10/7   11/7   13/8   12/7   9/5

The fifth comes first, then the fourth and major sixth, then the major third, minor sixth and the two 7-based ratios: close to the consonance order, though the minor third, 6/5, waits until round 4. The full tree, from 0/1 and 1/0, makes every coprime pair exactly once, and its neighbours are always Ford circles that touch (Moritz Stern, 1858; Achille Brocot, 1861, a clockmaker choosing gear ratios).

Star polygons

Put n points on a circle and join every k-th one. If gcd(n, k) = 1 you draw one star without lifting the pen; otherwise it falls into gcd(n, k) separate polygons. It is the Turk's head rule with the over and under taken away: 5 points stepping 2 is the pentagram in one stroke, 6 stepping 2 is two triangles.

Left to right: 5 points stepping 2, 7 stepping 3, 6 stepping 2, 9 stepping 3. Each separate stroke has its own colour.

Mode locking

Two oscillators that nudge each other, such as pendulum clocks on one beam (Christiaan Huygens noticed his in 1665), organ pipes side by side, or a heart's pacemaker cells, tend to lock into a simple ratio of their speeds and stay there. Each ratio p:q holds over a band of detuning, an Arnold tongue, and the bands are widest for the smallest numbers: 1:1, then 1:2 and 2:1, then 2:3 and 3:2. Plot the locked ratio against the detuning and you get the devil's staircase, a step at every fraction with the biggest steps at the simplest ones: the number line's heights again, made by physics.

Orbital resonances

Moons and planets that tug on each other often end up with orbital periods in a simple ratio. Io, Europa and Ganymede go round Jupiter in times in the ratio 1 : 2 : 4; Neptune goes round the Sun three times for every two of Pluto's. A simple ratio can also clear a space: the Kirkwood gaps in the asteroid belt sit where an asteroid would go round 3, 5/2, 7/3 or 2 times for each orbit of Jupiter, and the Cassini division in Saturn's rings is where a ring particle would orbit twice for each orbit of the moon Mimas. Gaps beside the simple fractions, as on the number line. Johannes Kepler went further in Harmonices Mundi (1619) and heard the planets' speeds as musical intervals.

Polyrhythms and Euclidean rhythms

A polyrhythm plays a beats against b in the same span, 3 against 2 or 4 against 3: the interval ratios played as time instead of pitch. Coprime a and b meet only at the start of each cycle of a × b pulses; 4 against 2 is just 2 against 1 played twice, as with the Lissajous figures.

Spreading k beats as evenly as possible over n pulses is Euclid's gcd algorithm in disguise (Erik Bjorklund used it for timing in a particle accelerator), and Godfried Toussaint showed in 2005 that it makes many traditional rhythms. Three beats over eight is the Cuban tresillo, x..x..x.; five over eight is the cinquillo, x.xx.xx..

More to look at

Also suggested by Claude and not the author's, left as links: