These settings apply to every instrument on the page. Sound starts only when you press a play button.

The Rhythm of Numbers · Chapter VII

Fractals: the same rule at every scale

Teddy Rook’s way of picturing it: pi is a number, then a smaller number after it, then a smaller one after that, and so on forever. Do fractals fit that picture? They do, and this chapter shows how.

The precise version. Write a number as its whole part plus a leftover, and turn the leftover upside down: $x = a_0 + \frac{1}{x_1}$. Then do the same to $x_1$: $x_1 = a_1 + \frac{1}{x_2}$, and again, forever. For pi that gives

$$\pi = 3 + \cfrac{1}{7 + \cfrac{1}{15 + \cfrac{1}{1 + \cfrac{1}{292 + \cdots}}}}$$

Here is the fractal idea. The part after the first “1 over” is itself a continued fraction, built by the same rule. So is the part after the next one. Zoom into the “smaller number after it” and you find the same kind of object again. Seeing the same thing at every scale is called self-similarity, and it is what makes a fractal a fractal.

Each step also gets smaller, as Teddy Rook guessed. Stopping after each level gives a fraction $p/q$ (a convergent: 3, 22/7, 333/106, 355/113, …), and each one misses by less than $1/q^2$. For 22/7 that is less than 1/49; it misses by 0.00126. For 355/113 it is less than 1/12,769; it misses by 0.000000267.

6
Terms
Does each zoom look the same?

Each row is the stretch between two convergents, blown up to fill the width. Its ticks are the in-between fractions, one for each step of the next term; the amber stretch is where the number hides, and the row below zooms into it. The zoom factor is on the right.

Where it is exact, and where it is not. Try the golden ratio, φ = [1; 1, 1, 1, …], or √2 = [1; 2, 2, 2, …], in the bar. Their terms repeat, so the tail is the number itself again, and every row of the zoom is the same picture (flipped left to right on every other row, because the convergents land on alternate sides). Pi’s terms, 7, 15, 1, 292, 1, 1, 1, 2, …, show no pattern that anyone has found. Pi uses the same rule at every level, but the levels never repeat. It is self-similar in its rule, not in its shape. That is not a flaw in the picture; it is one of the most interesting things about pi.

Remix

24 · A twist

Pi does have a pattern, if the tops can change

In an ordinary continued fraction every top number is 1. Let the tops be other numbers and you get a generalized continued fraction, and then pi has beautiful patterns. Teddy Rook’s “never-ending string of continued fractions” is exactly right here, with a clean rule all the way down.

Brouncker’s fraction, found by William Brouncker about AD 1655 and published by John Wallis in 1656:

$$\frac{4}{\pi} = 1 + \cfrac{1^2}{2 + \cfrac{3^2}{2 + \cfrac{5^2}{2 + \cfrac{7^2}{2 + \cdots}}}}$$

Lange’s fraction (L. J. Lange, 1999), with the same odd squares on top and 6s below:

$$\pi = 3 + \cfrac{1^2}{6 + \cfrac{3^2}{6 + \cfrac{5^2}{6 + \cdots}}}$$

The arctangent fraction, from the continued fraction for the arctangent (a close cousin of the fraction for the tangent that Johann Lambert used to prove that pi is irrational, in a paper read in 1761 and printed in 1768):

$$\pi = \cfrac{4}{1 + \cfrac{1^2}{3 + \cfrac{2^2}{5 + \cfrac{3^2}{7 + \cdots}}}}$$

10
FractionValue after these levelsDigits right
  • Brouncker
  • Lange
  • arctangent

All three follow a rule, and they show three speeds. Brouncker’s gains a digit only when the number of levels grows ten times: after 1,000 levels it is still off by 0.001. In fact its stopping points are exactly the sums 4(1 − 1/3 + 1/5 − …), the famous slow series for pi. Lange’s stopping points are exactly the sums of Nilakantha’s series, 3 + 4/(2·3·4) − 4/(4·5·6) + …, and gain three digits for each tenfold. The arctangent fraction shrinks its error about 5.8 times at every level, so it gains about three digits every four levels: 20 levels give 15 digits.

Remix

25 · Ford circles

A circle on every fraction, and the same picture at every zoom

In 1938 Lester R. Ford drew a circle resting on the number line at every fraction $p/q$ (in lowest terms), with radius $1/(2q^2)$. Big denominators make small circles. The circles never overlap, and two of them touch exactly when $|ps - qr| = 1$, which is when the two fractions are neighbors in a Farey sequence. Between any two touching circles sits a third that touches both, at the fraction $(p+r)/(q+s)$. Zoom in anywhere and you see the same picture again.

View
Circles the line passes through
Tapped circle
tap or click a circle
  • a convergent of the bar’s number
  • the number
  • the tapped circle and the circles it touches

Now drop a straight line down onto the bar’s number. Every circle the line passes through belongs to a convergent: if $|x - p/q| < 1/(2q^2)$, then $p/q$ is a convergent (Legendre’s theorem). And of any two convergents in a row, at least one has its circle pierced. For pi − 3, the line goes through the circles of 1/7 and 16/113 (that is 22/7 and 355/113), slips past 15/106, and goes on through 4703/33215. Keep pressing Dive: the circles get smaller and the pattern stays the same.

Remix

26 · The Stern–Brocot tree

Every fraction once, and the way down spells the continued fraction

Start with 0/1 and 1/0. Between two neighbors, put their mediant: add the tops and add the bottoms. 1/1 comes first, then 1/2 and 2/1, then 1/3, 2/3, 3/2, 3/1, and so on. Moritz Stern described this tree in 1858. Achille Brocot, a French clockmaker, found it again in 1861 and used it to choose gear sizes for clocks. Every positive fraction appears in the tree exactly once, already in lowest terms.

To find a number, start at the top and go left (L) if the number is smaller, right (R) if it is bigger. The way down is a string of runs, and the run lengths are the continued fraction: 355/113 = [3; 7, 16] is R³ L⁷ R¹⁵ (the last run is one short, because you stop on the fraction itself). Pi is R³ L⁷ R¹⁵ L R²⁹² …, and the golden ratio is R L R L R L … forever.

0
The way down (for the whole number)
Picture starts at

Slide the start down the path and the tree below looks like the whole tree again, with the same branching and only the fractions changed. The sound plays a low note for each L and a high note for each R, so the runs become phrases.

Remix

27 · Minkowski’s question-mark function

Continued fractions in, binary out: a fractal staircase

In 1904 Hermann Minkowski defined a function, written $?(x)$, that turns a continued fraction into a binary number. For $x = [0; a_1, a_2, a_3, \ldots]$ the binary digits of $?(x)$ are $a_1 - 1$ zeros, then $a_2$ ones, then $a_3$ zeros, then $a_4$ ones, and so on: each term becomes one run of digits. As a formula,

$$?(x) = 2\left(2^{-a_1} - 2^{-(a_1+a_2)} + 2^{-(a_1+a_2+a_3)} - \cdots\right)$$

It climbs from 0 to 1 and always goes up, yet it is flat almost everywhere: pick a point at random, and the slope there is zero. All the climbing happens on a thin dust of points. The left half of the graph is the whole graph, squashed by half, because $?(x/(x+1)) = ?(x)/2$. Repeating numbers come out as fractions: $?(φ - 1) = 2/3$, $?(\sqrt2 - 1) = 2/5$, $?(\sqrt3 - 1) = 6/7$.

?(the bar’s number)
In binary

The dashed line is y = x. “Hear the staircase” walks across the view in 48 steps and plays ?(x) as pitch: long flat stretches are repeated notes, and the climbs come in bursts.

Remix

28 · The devil’s staircase

Plateaus inside plateaus, labeled by Farey fractions

Section 7 on the first page showed clocks locking to fractions. Here is the same circle map, θ → θ + Ω − (K/2π) sin 2πθ, with its staircase: across is the natural rotation Ω, up is the rotation the system really makes. Each flat step is a locked fraction p/q. At full coupling (K = 1) the steps fill the whole line except for a dust of points, and that dust is a fractal of dimension about 0.87 (Jensen, Bak and Bohr, 1983). Tap between two steps to zoom in: the biggest step between two neighboring steps p/q and r/s is their Farey sum, (p + r)/(q + s), and the zoomed picture looks like the whole again.

1.00
View
Widest steps here

Remix

29 · Cantor dust

Allow only small terms and the numbers crumble into dust

Which numbers between 0 and 1 have a continued fraction that uses only 1s and 2s? Each term you fix keeps a few small pieces of the line and throws away the rest. Do it forever and what is left is a dust, like the Cantor set: no length at all, but more than a point’s worth. Its fractal (Hausdorff) dimension is 0.531280506…, a number I. J. Good pinned between 0.5306 and 0.5320 in 1941, and Oliver Jenkinson and Mark Pollicott found to 25 places in 2001 and later proved to 100. Choose the allowed terms below; the dimension shown was computed for this page by the same kind of method.

Allowed terms
Fractal dimension
Pieces in the bottom row
The bar’s number

Remix

30 · The Mandelbrot set

Its bulbs are fractions, in Farey order

The Mandelbrot set has a heart-shaped main body with bulbs all around its edge. Each bulb is named by a fraction p/q: walk p/q of the way around the heart and that bulb is attached there. Inside the p/q bulb, the rule z → z² + c settles into a cycle of exactly q points, which jump around p/q of a turn at each step, and the bulb’s antenna usually has q spokes. Between the 1/2 bulb and the 1/3 bulb the biggest bulb is 2/5, the Farey sum. Between 2/5 and 1/3 it is 3/8, and the Fibonacci numbers appear: 1/2, 1/3, 2/5, 3/8, 5/13, … (Robert Devaney, 1999, measures “biggest” by the share of the set’s outside that leads into each limb, 1/(2q − 1); by area the rule holds for most bulbs but not all.)

Farey parents
Cycle
Its share of the outside
  • the chosen bulb and its cycle of q points
  • its Farey parents
  • the bar’s number, walked around the heart

Remix

31 · The Fibonacci word fractal

Walk the golden rhythm and it draws a fractal

The first page played each number as a beat: hit, rest, hit, hit, rest, … For the golden ratio that pattern is the Fibonacci word. In 2009 Alexis Monnerot-Dumaine turned it into a drawing: take one step forward for every beat, and on a hit turn a quarter turn, left on even beats and right on odd ones. The golden rhythm draws a curve made of smaller copies of itself, with fractal dimension 3 log φ / log(1 + √2) ≈ 1.638. Change the number in the bar and see which rhythms make clean fractals.

Number
The path

Remix

32 · The Gauss map

Is pi a typical number?

The machine that reads off the terms is one map, done over and over: $x \to 1/x - \lfloor 1/x \rfloor$. Each pass drops the whole part, which is the next term, and keeps the leftover. Gauss guessed, and Rodion Kuzmin proved in 1928, that for almost every number the terms come out with fixed odds: a term equals $k$ with probability

$$P(k) = -\log_2\!\left(1 - \frac{1}{(k+1)^2}\right)$$

That is 41.5% ones, 17.0% twos, 9.3% threes, and so on. Aleksandr Khinchin showed in 1935 that for almost every number the terms’ geometric mean tends to the same constant, 2.685452…. Nobody has proved that pi is “almost every number”. But we can count. Here are pi’s first 10,000 terms, computed for this page.

Terms read (left)
Share of 1s
Geometric mean
Fit to the law
  • counted
  • the Gauss–Kuzmin law

Pi passes. Its 10,000 terms have 4,206 ones (42.1%, against 41.5%), 1,672 twos and 882 threes; a standard fit test over the 13 groups in the chart puts it well within chance (p ≈ 0.33). Its geometric mean is 2.663, near Khinchin’s 2.685 and wandering the way a random number’s does. Its biggest term so far is 20,776, at position 431. The number e fails on purpose: its terms are 1, 2, 1, 1, 4, 1, 1, 6, …, far too many 1s and a mean that keeps growing. So does every repeating number, like φ and √2.

Remix

33 · Threads and sources

Threads to pull

Open

Is pi typical?

Nobody knows whether pi’s terms follow the Gauss–Kuzmin law forever, or whether they are even unbounded. Every count so far says “typical”.

Known

Repeating means quadratic

A continued fraction repeats exactly when the number solves a quadratic equation with whole-number coefficients (Euler and Lagrange). Those are the numbers with exactly self-similar pictures, and Minkowski’s function sends each of them to a fraction.

Try

Your own terms

Choose “Type the terms…” in the bar and enter a pattern, like 1, 2, 1, 2 or 3, 3, 3. Then visit each picture: the circles, the tree, the staircase, the dust and the path all show the pattern.

Notes and sources

Every number on this page was computed for it in Python (mpmath, NumPy, SciPy) and checked against the page’s own code: pi’s first 10,000 terms from 11,500 digits, the three patterned fractions to 60 digits, the Stern–Brocot paths, the question-mark values, the staircase step widths, the dust dimensions (a transfer-operator method that matches the published 0.5312805062772 to 13 places), and the period of every Mandelbrot bulb with q up to 12.

← Back to The Rhythm of Numbers · the map of every section

@teddyrookbook GitHub Sources and credits