Primes paint fractals

Pascal's triangle is built by a rule a child can follow: every number is the sum of the two above it. Now divide every number by a prime and keep only the remainder. Colour the cells by that remainder, zoom out, and the plain triangle of sums turns into a fractal: the same picture inside itself, again and again. With 2 you get the Sierpinski triangle. With 3, 5 and 7 you get its cousins. With 4, 6 or 10 the magic breaks, and you can see exactly why.

Scroll or pinch to zoom · drag to move · point at a cell · arrow keys move the cell

Choose what divides

Every number is divided by
Chosen cell
Prime moduli
Composite moduli, for contrast

Colour the cells by

Zoom out by exactly the modulus: for a prime, the picture returns to itself. For a composite number it does not.

The truth behind the colours

Point at any cell of the triangle, or type its address: row n and place k, both counted from 0. Everything below is recomputed for that cell and checked against the exact number.

Lucas' theorem (1878)

Write n and k in base p, one above the other. The remainder of C(n, k) after dividing by the prime p is the product of the small binomials of the digit pairs. One digit of k larger than the digit of n above it makes the whole product 0.

Proven Kummer's theorem (1852)

Add k and n − k in base p as you would at school, with carries. The number of carries is exactly the number of times p divides C(n, k). Every carry is a spark; no spark means the cell is coloured.

Proven Glaisher's count (1899)

How many odd numbers are in a row? Write the row number in binary and count the 1s: the answer is 2 to that power. For any prime p (Fine, 1947): add 1 to every base-p digit of n and multiply.

Proven The prime row test

A number n is prime exactly when every number in row n, apart from the two 1s at the ends, is divisible by n. Pascal's triangle is a prime detector: the prime rows are the ones that go completely dark.

A fractal with a dimension between 1 and 2

A line has dimension 1 and a filled triangle has dimension 2. The coloured cells are something in between: more than a line, yet they cover less and less of the triangle as it grows. Count them, and the in-between dimension comes out exactly.

dimension of the fractal

Cells not divisible by the modulus, counted in the picture itself

rowscounted cellsformula share of the trianglelog cells / log rows

Why a prime makes a fractal

Take the modulus 2. The first two rows, 1 and 1 1, hold three odd numbers. Rows 2 and 3 repeat that little triangle twice, on the left and on the right, and leave a hole of even numbers in the middle. Rows 4 to 7 repeat the whole thing twice again, with a bigger hole. This never stops: the first 2, 4, 8, 16 … rows always look the same.

The reason is a rule that holds for every prime p. Cut the triangle into blocks of p rows. The remainder of any cell is the remainder of its block times the remainder of its place inside the block. So every block is a copy of the top triangle multiplied by one number, and with a prime a product of non-zero remainders is never zero: no copy is ever wiped out. This is the copy rule, known as Lucas' theorem. Use it for blocks of p, p², p³ … rows and you get triangles within triangles at every scale, p(p + 1)/2 copies each time.

Kummer saw the same picture through school addition. A cell is dark exactly when adding k and n − k in base p needs a carry, and the number of carries says how many times p divides the cell. Switch the colouring to Carries: the dark holes turn out to have inner layers of their own.

Why 4, 6, 9 and 10 break the pattern

Choose 6. A number is divisible by 6 when it is divisible by 2 and by 3, so the picture is two fractals laid over each other: the triangle of 2, which returns when you zoom by 2, and the triangle of 3, which returns when you zoom by 3. No single zoom brings both back at once, because no power of 2 is a power of 3. The same happens for 10 = 2 · 5 and for 12.

Choose 4 or 9, the square of a prime. Now a cell goes dark only when the addition has at least two carries. Cells with exactly one carry stay lit and partly fill the holes of the prime picture. It still looks like triangles, but it is no longer a plain copy of itself. Switch on Show the cells where the copy rule breaks to see every such cell, and how many there are.

The deeper reason: with a prime, multiplying two non-zero remainders never gives zero. With 4 it does (2 · 2 = 4), and with 6 as well (2 · 3 = 6). Primes are exactly the numbers for which this cannot happen, and that is why only primes paint a perfect fractal.

For mathematicians: exact statements, one-line proofs, references

Notation: C(n, k) is the binomial coefficient, v_p the exponent of the prime p (the p-adic valuation), s_p(n) the sum of the base-p digits of n, and n_i, k_i the base-p digits of n and k. The picture shows C(n, k) mod m for 0 ≤ k ≤ n < N, with N = 4096 on large screens and N = 2048 on small ones.

Proven Lucas' theorem

C(n, k) ≡ ∏i C(ni, ki) (mod p),   n = ∑ ni pi,  k = ∑ ki pi,  0 ≤ ni, ki < p

Proof in one line: (1 + x)^p ≡ 1 + x^p (mod p), hence (1 + x)^n ≡ ∏ (1 + x^(p^i))^(n_i); compare the coefficients of x^k. Consequence used by the picture: the first p^(j+1) rows consist of p(p + 1)/2 copies of the first p^j rows, each multiplied by a non-zero constant C(a, b) with a < p, separated by blocks of zeros. The page does not assume this: the residues are computed with the addition rule of Pascal's triangle, and the digit product is compared with them cell by cell.

Proven Kummer's theorem

vp(C(n, k)) = #{carries in k + (n − k), base p} = (sp(k) + sp(n − k) − sp(n)) / (p − 1)

It follows from Legendre's formula v_p(n!) = (n − s_p(n)) / (p − 1). The colouring “Carries” shows v_p(C(n, k)), capped at 7. For a composite modulus m = ∏ q^e the rule is: m divides C(n, k) exactly when, for every prime power q^e of m, the addition in base q has at least e carries. This one statement explains all the composite pictures.

Proven Glaisher (p = 2) and Fine (any prime)

#{k : p ∤ C(n, k)} = ∏i (ni + 1);   p = 2:  2s₂(n)

A direct consequence of Lucas' theorem: C(n, k) is not divisible by p exactly when every digit of k is at most the digit of n above it, which leaves n_i + 1 choices for each digit. For p = 2 this is 2^(s_2(n)), Gould's sequence (OEIS A001316).

Proven Counting and dimension

#{(n, k) : n < pj, p ∤ C(n, k)} = (p(p + 1)/2)j,   Dp = log(p(p + 1)/2) / log p

Summing Fine's product over all n < p^j gives (1 + 2 + … + p)^j = (p(p + 1)/2)^j. After rescaling, the limit set is exactly self-similar with p(p + 1)/2 pieces scaled by 1/p, so its similarity dimension, which equals its box-counting and Hausdorff dimension, is log(p(p + 1)/2) / log p (Wolfram 1984). The share of entries not divisible by p among the first p^j rows is ((p + 1)/(2p))^j · 2p^j/(p^j + 1), which tends to 0. For every modulus m, prime or not, almost all binomial coefficients are divisible by m (Singmaster 1974).

Proven The prime row test

n prime ⇔ n | C(n, k) for all 0 < k < n

If n is prime, then n divides n!/(k!(n − k)!) for 0 < k < n, because n divides the numerator and not the denominator. If n is composite and p is its smallest prime factor, then v_p(C(n, p)) = v_p(n) − 1, so n does not divide C(n, p). In the colouring “Prime rows” a cell is lit when n does not divide C(n, k), decided with Kummer's theorem for every prime power of n. The same fact, written as (x + 1)^n ≡ x^n + 1 (mod n), is the starting point of the AKS primality test. It is a beautiful criterion, not a fast one: row n has n + 1 numbers.

Proven Composite moduli

For m = 2 · 3 the zero set is the intersection of the zero sets mod 2 and mod 3 (Chinese remainder theorem); the two patterns scale by 2 and by 3, and no power of 2 is a power of 3. For a prime power p^e the picture still has a hierarchical structure, and Lucas' theorem has extensions to prime powers (Davis and Webb 1990, Granville 1997), but one tile is no longer enough. Lucas' digit rule in base m fails for every composite m: if p is a prime factor of m, then C(m, p) is not divisible by m, while its digit product is C(1, 0) · C(0, p) = 0.

What this page checks itself

A separate verification program recomputes everything with exact big integers: Lucas and Kummer for the primes 2 to 13 on every cell of the first 260 rows and on random cells up to row 4095; Glaisher's and Fine's counts; the exact counts (p(p + 1)/2)^j up to 2048 rows; the row test for every n below 260 with big integers and for every n below 2048 with digit sums; and the failure of the digit rule for 4, 6, 8, 9, 10 and 12. The table and the check marks on this page are computed live in your browser from the picture itself, not typed in.

Honesty note: nothing here is new, and nothing here predicts primes. These are classical theorems about the divisibility of binomial coefficients; the page only makes them visible. The slopes shown for composite moduli are observations in the stated range, not theorems.

References

  • É. Lucas, Théorie des fonctions numériques simplement périodiques, American Journal of Mathematics 1 (1878), 184–240 and 289–321.
  • E. E. Kummer, Über die Ergänzungssätze zu den allgemeinen Reciprocitätsgesetzen, Journal für die reine und angewandte Mathematik 44 (1852), 93–146.
  • J. W. L. Glaisher, On the residue of a binomial-theorem coefficient with respect to a prime modulus, Quarterly Journal of Pure and Applied Mathematics 30 (1899), 150–156.
  • N. J. Fine, Binomial coefficients modulo a prime, American Mathematical Monthly 54 (1947), 589–592.
  • D. Singmaster, Notes on binomial coefficients III: any integer divides almost all binomial coefficients, Journal of the London Mathematical Society (2) 8 (1974), 555–560.
  • S. Wolfram, Geometry of binomial coefficients, American Mathematical Monthly 91 (1984), 566–571.
  • K. S. Davis and W. A. Webb, Lucas' theorem for prime powers, European Journal of Combinatorics 11 (1990), 229–233; A. Granville, Arithmetic properties of binomial coefficients I: binomial coefficients modulo prime powers, CMS Conference Proceedings 20 (1997), 253–275.
  • M. Agrawal, N. Kayal and N. Saxena, PRIMES is in P, Annals of Mathematics 160 (2004), 781–793.
  • OEIS A047999 · A001316 · A006046 · A083093 · A006047
  • Independent verification program (available on request)