Skip to content

The Rhythm of Numbers · Drag the tree

Drag a number, and watch its continued fraction change

Every number has a continued fraction: a whole number, then a smaller one after it, then a smaller one after that. Here you can take hold of a number and move it. The terms, the way down the Stern–Brocot tree and the best fractions all follow your finger.

The instrument

One number, four pictures

Jump to
The number
Continued fraction (tap a term to lock it)
The way down the tree

Best fractions (convergents)

Its rhythm.

How the point moves. The point never sits on just any decimal. As you drag, it lands on the simplest fraction within reach: the one with the smallest bottom number inside the little stretch of line under your finger. Zoomed out, that is a fraction like 3/1 or 7/2. Zoom in and finer fractions come within reach, like 22/7, then 333/106, then 355/113. Finding the simplest fraction between two numbers is the same as walking down the Stern–Brocot tree until you first land between them, so the tree above the line is the map the point is using.

You can also drag along the tree itself: the point jumps from node to node, so it only ever visits fractions that are in the picture.

The path

Run lengths down the tree are the terms

Start at 1/1 at the top. Go right (R) if the number is bigger, left (L) if it is smaller, and keep going. The moves come in runs, and the runs are the continued fraction: first a₀ moves right, then a₁ left, then a₂ right, and so on. 355/113 = [3; 7, 16] is R³ L⁷ R¹⁵ (the last run is one short, because you stop on the fraction itself), the same rule as in section 26.

The tree in the picture always starts at the deepest node whose branch still covers what you can see. Zoom in and the picture walks down the tree, and what you see below is a copy of the whole tree with different fractions: the same rule at every scale.

The brackets

Each best fraction is a bracket, and the brackets nest

Under the line, each bracket joins two neighboring convergents. The number is always inside, the next bracket is always inside the last one, and the convergents land on alternate sides. Each convergent p/q misses the number by less than 1/q², which is why 355/113 is so good: the next term, 292, is large, so the next bracket is tiny.

Locking

Each term pins the number down

Tap a term in the continued fraction to lock everything up to it. Now try to drag: the point can only reach numbers whose continued fraction starts the same way. Those numbers fill one interval, shaded on the line. Lock [3; 7] and the interval runs from 22/7 to 25/8, 1/56 wide. Lock one more term and it shrinks inside the last one. In general the interval after locking the term with convergent p/q is 1/(q(q + q′)) wide, where q′ is the denominator before it. Each term chooses one of the interval's pieces, and the pieces of each piece, forever: that is what a continued fraction is.

Four famous numbers

Patterns you can see in the path

  • The golden ratio, φ = [1; 1, 1, 1, …]. Every term is 1, so the path zigzags R L R L … forever, and its convergents are ratios of Fibonacci numbers: 2/1, 3/2, 5/3, 8/5, ….
  • √2 = [1; 2, 2, 2, …]. The path goes R, then L L, R R, L L, … in pairs; the convergents 3/2, 7/5, 17/12, 41/29 use the Pell numbers.
  • e = [2; 1, 2, 1, 1, 4, 1, 1, 6, …]. A pattern that keeps stretching: every third term grows by 2.
  • π = [3; 7, 15, 1, 292, 1, 1, 1, 2, …]. No one has found a pattern. Its path has long runs (seven Ls, fifteen Rs, 292 Rs), and each long run means the fraction just before it was unusually good.

A continued fraction repeats exactly when the number solves a quadratic equation with whole-number coefficients, like φ, √2 and √3. Those are the numbers whose pictures look the same at every zoom.