← Back to Hailstone Harmonics

How it works

The music of 3n + 1

Hailstone Harmonics turns the Collatz conjecture into sound with almost no artistic license. The rule only ever multiplies by 3 and divides by 2, and those are exactly the two numbers harmony is built from. This page walks through the mathematics behind every choice in the app, and why the results sound composed rather than random.

The rule

One rule, two moves

Pick a whole number. If it’s even, halve it. If it’s odd, triple it and add one. Repeat.

T(n) = n / 2when n is even T(n) = 3n + 1when n is odd

Start at 27 and the sequence wanders for a long time: 27 → 82 → 41 → 124 → 62 → 31 → 94 → 47 → … It climbs to 9,232 at step 77 and finally reaches 1 at step 111. Numbers like these are called hailstone numbers, because they rise and fall like hail tossed around inside a thundercloud before it drops to the ground.

The Collatz conjecture, posed by Lothar Collatz in 1937, says every starting number eventually reaches 1. Once there, the rule loops forever: 1 → 4 → 2 → 1. Nobody has proved it. Computers have checked every starting number up to 271 (about 2.36 × 1021), and in 2019 Terence Tao showed that almost all starting numbers eventually fall to “almost bounded” values, the strongest result so far. Paul Erdős put it bluntly: “Mathematics may not be ready for such problems.”

Why 2 and 3

Pitch is a logarithm

A musical pitch is a vibration frequency, and our ears hear ratios, not differences. Going from 110 to 220 Hz sounds like the same jump as 440 to 880 Hz, an octave, because both double the frequency. So musicians measure intervals by the logarithm of the ratio, in cents:

interval = 1200 · log2(f2 / f1) cents

An octave is 1,200 cents and a piano semitone is 100. Now apply the two Collatz moves to a frequency:

Those two moves are the entire toolkit of Pythagorean tuning, the 2,500-year-old system that builds every interval from factors of 2 and 3. A Collatz sequence is Pythagorean music with a single grain of sand in it: the +1.

Two ways to listen

Contour and Harmonic series

The app has two ways of turning numbers into notes. Both put 1 on the tonic, the home note you pick under “Tonic.”

Contour, the default

Pitch follows the height of the chart. The app takes log2n (how many doublings n sits above 1), scales it so the sequence’s peak fits the range you chose, and rounds to the nearest note of the scale:

note = round(d · log2n) scale steps above the tonic d = min(Rm / log2 peak, 0.3 m), with R the range in octaves and m the notes per octave in the scale

For 27 in a three-octave major pentatonic, d ≈ 1.14. Every halving steps down about one note of the scale, and every leap climbs about 1.8 notes, because a leap is log2 3 ≈ 1.585 doublings. The tune traces the chart, and its final five notes, 16 → 8 → 4 → 2 → 1, come out as C, G, E, D, C: a walk down to the tonic.

Harmonic series

Every note an instrument plays is secretly a chord. A string vibrating at a frequency f also vibrates at 2f, 3f, 4f and so on: its harmonics. In Harmonic series mode the number n sounds as the nth harmonic of the tonic, at n times its frequency, folded down by whole octaves into the range you chose. With C as the tonic, the first sixteen are:

1C
2C
3G+2¢
4C
5E−14¢
6G+2¢
7B♭−31¢
8C
9D+4¢
10E−14¢
11F♯−49¢
12G+2¢
13A♭+41¢
14B♭−31¢
15B−12¢
16C

Here the arithmetic becomes the music exactly. Every power of 2 is the tonic, halving is a literal octave, 3 is a perfect fifth, and 27 = 3 × 3 × 3 is the Pythagorean major sixth, A at 905.9¢. Set Scale to “Unquantized” and you hear the exact ratios, including microtones a piano can’t play.

The pitch clock

  • Halving keeps the note name, so it steps straight in along its spoke, one ring (one octave) per step.
  • 3n + 1 swings 7/12 of the way around (a perfect fifth) and about 1.6 rings out.
  • 16 → 8 → 4 → 2 → 1 runs down the tonic’s spoke to the center.
Angle is the note name and distance from the center is the octave (log2n rings out). Because every leap turns by nearly the same angle, the amber chords pile up into a star: the circle of fifths, drawn by arithmetic.
The +1

The grain of sand

If the rule were “triple” instead of “triple and add one,” every leap would be a pure twelfth, and the melody would never come down: an odd number times 3 is still odd, so it would climb by twelfths forever. The +1 makes every leap land on an even number, so at least one fall always follows. It also bends each leap slightly sharp:

bend = 1200 · log23n + 13n ≈ 577 / n cents

The bend is huge for small numbers and vanishes for large ones:

nPure ×33n + 1BendWhat it does
13 (G)4 (C)498¢Bends a fifth into the tonic: the only known loop, 1 → 4 → 2 → 1
515 (B)16 (C)112¢A semitone: the leading tone becomes the tonic
27818221¢About a fifth of a semitone
3411,0231,0241.7¢Below what most ears can detect in a melody
9,99929,99729,9980.06¢Effectively pure

You can hear the bend as beating. Two tones that are almost the same pitch wobble in loudness at the difference of their frequencies. Play the 81st and 82nd harmonics together (folded into the same octave) and they wobble about four times a second: that wobble is the +1. At 243 against 244 it slows to twice a second.

Endings

Every melody resolves

In musical terms, the Collatz conjecture says every melody ends on the tonic.

A counterexample would be a tune that never comes home, either climbing forever or falling into some other loop. And the ending is more fixed than you might expect. 8 can only be reached from 16, 4 only from 8 (apart from the loop), and 2 only from 4, so every sequence that starts above 8 finishes 16 → 8 → 4 → 2 → 1. In Harmonic series mode that’s the tonic in five octaves; in Contour it’s a walk down the scale to the tonic.

Just before that run comes the last odd number m, and 3m + 1 has to be a power of 2. That only works for even powers, so m must be one of 5, 21, 85, 341, 1,365, … For every starting number up to a million:

The last odd number before the final run of powers of 2, for the 999,999 starting numbers from 2 to 1,000,000. Intervals are the Harmonic series pitch of each number above the tonic.

Now listen to what that means. 5 is the fifth harmonic, the major third E. Tripling it would give 15, the leading tone B, the note that pulls hardest toward the tonic, and the +1 lifts it to 16, the tonic itself. So 94% of Collatz melodies end with a leading tone resolving up to the tonic, except the leading tone never sounds. It’s the note 3n would have hit. The other endings, through 85 and 341, sit just under a perfect fourth (491¢ and 496¢) and leap home: the plagal “Amen” cadence at the end of a hymn.

Even the rhythm broadens at the cadence. The final bass note is held for 5 sixteenths when the ending comes through 5, 9 through 85 and 11 through 341, where most bass notes last 2 or 3. That’s the way a composer slows the harmony at an ending, except here the arithmetic does it.

The bass

The Syracuse skeleton

The bass plays only the odd numbers, each held until the next one arrives. On their own, the odd numbers form the Syracuse sequence, the Collatz map with the halvings skipped:

S(n) = (3n + 1) / 2k where 2k is the largest power of 2 that divides 3n + 1

27’s bass line runs 27, 41, 31, 47, 71, 107, 161, 121, 91, …: the melody plays every step, and the bass plays the skeleton.

The rhythm

A bass note lasts 1 + k sixteenths: one for the leap and one for each halving after it. Exactly half of all odd numbers have k = 1, a quarter have k = 2, an eighth k = 3, and so on, because 3n + 1 cycles evenly through the remainders. So bass notes are usually 2 sixteenths long, often 3, occasionally much longer, and 3 on average. None of that syncopation is programmed; the arithmetic writes it.

2 sixteenths3 sixteenths
Every bass note of 27, in order, left to right and line by line. Width is how long the note is held. Each block shows the odd number and its pitch in Harmonic series mode.

The harmony

In Harmonic series mode, each Syracuse step multiplies by 3 + 1/n and divides by a power of 2. Ignoring octaves, that’s a perfect fifth up plus the +1 bend, so the bass walks the circle of fifths: A, E, B, F♯… for 27. Each fifth runs a little wide, 21¢ at first and about 5¢ once the numbers pass 100, so the walk drifts sharp; by the fourth note, F♯ has slid two-thirds of the way to G.

Meanwhile the melody spends each bass note on 3n + 1 and its halvings, which all keep the same note name. So it sits a fifth above the bass, and every bass note carries a power chord.

Rhythm and drift

Why the melody comes down

The Beat layer puts a kick on every leap. Two odd numbers never arrive back to back, because 3n + 1 is always even, so the kicks land 2, 3, 4… sixteenths apart with the same odds as the bass notes. Against a clap that lands every 8 sixteenths no matter what, that uneven spacing is syncopation. In the coda it locks into a pattern: around the loop 4 → 2 → 1, the leap from 1 comes every third sixteenth, so the kick and bass settle into three against four, lining up with the beat only once every three beats.

The same odds explain why sequences tend to fall. Call one leap plus the halvings after it a round. A leap multiplies by about 3 and each halving by 1/2, with two halvings on average, so a typical round multiplies n by 3/4.

As an interval, 3/4 is a perfect fourth down. Each updraft and fall leaves the melody, on average, a fourth lower.

That’s the hailstone again: tossed up, but mostly falling. The same estimate predicts a sequence about 10.4 · ln n steps long; for starting numbers up to a million the actual average is 131.4 steps, against 133.6 predicted. It’s a heuristic, not a proof: nothing obvious stops a special number from having unlucky rounds forever. 27 is an unusually long flight, 111 steps where the estimate says 34.

Choirs and canons

The Collatz tree, sung

Every number has exactly one next number, so two paths can meet but never split again. Traced backward from 1, the paths branch out into the Collatz tree, which contains every whole number if the conjecture is true. Enter several numbers in the app and it plays their paths as a choir.

Converge

Line the voices up so they all land on 1 at the same moment. Then every number has a fixed seat in time, its count of steps to 1, so two voices sound the same number at the same moment exactly when their paths have joined, and from then on they sing in unison. The choir is the tree heard from the branches to the trunk, and every voice sings the final 16, 8, 4, 2, 1 together.

15, 7 and 12, aligned to land together. Columns count steps to 1. 7 joins 15 at 40 and 12 joins them at 10 (outlined). Shaded cells are shared; after each meeting the voices never differ again.

Canon

Line up the starts instead. If m turns up d steps into n’s sequence, then n’s voice repeats m’s melody exactly d sixteenths late: a canon at the unison, like a round. 47, 31, 41 and 27 all lie on one branch. 47 leads, and 31 picks up its tune 2 sixteenths behind, 41 five behind and 27 seven behind.

The canon preset, aligned at the start. Tinted cells are 47’s melody; each voice reaches it 0, 2, 5 or 7 steps in, and then repeats it note for note.

Hear them in the app: the five-voice choir and the canon. Or type your own list, like 15, 7, 12.

Fifths never close

Why tuning theory cares

Here the music and the mathematics turn out to be the same problem. Suppose some sequence looped back to where it started without ever reaching 1, making b leaps and a halvings on the way round. Multiplying all the steps around the loop has to give exactly 1, which works out to

2a3b = (1 + 13n1) (1 + 13n2) ⋯ (1 + 13nb) one factor for each odd number ni in the loop

In musical terms: a octaves have to come out slightly wider than b twelfths, and the +1 bends have to make up the difference exactly.

That mismatch is the oldest problem in tuning. No power of 3 equals a power of 2, so a stack of fifths never lands exactly on an octave. Twelve fifths overshoot seven octaves by the Pythagorean comma, 23.46¢. The best near misses come from the continued fraction of log2 3 = [1; 1, 1, 2, 2, 3, 1, 5, 2, 23, …], and they’re famous in music:

Near missTuning it suggestsMismatch
35 ≈ 285 equal notes per octave, close to a pentatonic scale90.2¢
312 ≈ 21912 notes per octave: the piano23.5¢
341 ≈ 26541 notes per octave19.8¢
353 ≈ 28453 notes per octave, nearly perfect fifths3.6¢
3306 ≈ 2485306 notes per octave1.8¢
3665 ≈ 21054665 notes per octave0.08¢

A second Collatz loop would need an extraordinarily good near miss of this kind. Every number below 271 is known to reach 1, so every number in such a loop would be enormous, and every +1 bend in it almost nothing. Using exactly this continued fraction, Shalom Eliahou proved in 1993 that any other loop would need at least 17,087,915 steps, based on the computer checks of the time, and the bound has grown as the checks have.

The reason a piano has twelve keys per octave and the reason there are no short Collatz loops are the same number: log₂ 3.

The rest

The rest of the machine

Tempo
One step is a sixteenth note. At the default 112 BPM that’s about 7.5 steps a second, so 27 takes 15 seconds.
Drone
The tonic’s first harmonics, in the ratios 1, 3/2 and 2 (tonic, a pure fifth, octave), slowly filtered. It sits two octaves below the melody’s tonic on the music box, 8-bit and theremin, and one octave below on the other instruments.
Coda
The rule doesn’t stop at 1; it loops 1 → 4 → 2 → 1. So the piece doesn’t stop either: on the very next sixteenth it carries on around the loop for about six seconds, holding full volume for one turn and then fading out.
Stereo
In a solo, low notes sit to the left and high notes to the right, as if you were sitting at a piano. In a choir each voice gets its own place, and merged voices sit at the average of theirs, so the sound collapses toward the center as the choir converges.
Big numbers
The arithmetic is exact, up to 21200. 264 − 1 is sixty-four 1s in binary; each leap-and-fall multiplies it by 3/2 and uses up one of those 1s, so its first 128 steps alternate strictly up, down, up, down: a staircase before the chaos.
Instruments
All synthesized live in the browser: additive partials for the music box and marimba, FM for the electric piano, Karplus–Strong for the plucked string, formant filters for the choir, and a gliding oscillator for the theremin.
Sources

Further reading

Figures on this page are computed live from the same code the app uses. The ending statistics and average lengths were computed for every starting number up to 1,000,000.