Discrete

A remainder read two digits at a time

Lucas' theorem reads a binomial coefficient's remainder on division by a prime off its digits one at a time. On division by the prime's square the same reading is wrong at four odd entries in ten. What replaces it still reads digits — in overlapping pairs, with the prime taken out first and a sign that the carries decide.

Worth reading first: Pascal's triangle, in two colours · The carries decide the divisibility.

Lucas’ theorem says that the remainder of a binomial coefficient on division by a prime pp can be read off the base-pp digits one column at a time: write nn and kk in base pp, take the small coefficient (niki)\binom{n_i}{k_i} in each column, and multiply. Kummer’s theorem answers a different question exactly — how many times pp divides the coefficient — by counting carries. Neither says what the coefficient leaves on division by p2p^2.

The natural guess is that the digit product keeps working one power higher. It does not, and the failure is not rare.

Pascal's triangle modulo 4, where one digit at a time is not enough. 32 rows of Pascal's triangle coloured by remainder modulo 4 — hue for the last base-2 digit, depth for the second. The digit-by-digit product that gives every remainder modulo 2 gets the remainder modulo 4 wrong at 100 of the 243 entries 2 does not divide.
Fig. 1 Thirty-two rows of Pascal’s triangle modulo 4. The colour of each cell is the last binary digit of its remainder, which Lucas’ theorem gets right everywhere, and the depth is the second digit, which it does not see. The dots mark the 100 odd entries, of 243, where multiplying the digit-by-digit coefficients gives the wrong remainder modulo 4; a rule that reads the digits in pairs gives the right one at all 528 entries.

Modulo a prime power a binomial coefficient is still decided by its digits — but by the digits read in overlapping windows, after the prime has been taken out, and with a sign the carries decide. That is Granville’s theorem, and the reason it takes that shape is short enough to give in full.

Where the one-digit proof gives way

Lucas’ theorem has a two-line proof, and the place it stops is exactly one power of pp up.

Write n=n0+n1p+n2p2+n = n_0 + n_1 p + n_2 p^2 + \cdots in base pp. Then (1+x)n(1+x)^n is the product of (1+x)nipi(1+x)^{n_i p^i} over the digits. Modulo pp, raising to the pp-th power is additive, so (1+x)p1+xp(1+x)^p \equiv 1 + x^p, and each factor becomes (1+xpi)ni(1+x^{p^i})^{n_i}. The powers xpix^{p^i} live in separate columns, so the coefficient of xkx^k in the product is the product of one small coefficient per column — which is the theorem.

The step that needs care is (1+x)p1+xp(1+x)^p \equiv 1 + x^p. The coefficients thrown away are (p1),,(pp1)\binom{p}{1}, \dots, \binom{p}{p-1}, and each of them is divisible by pp exactly once. Modulo pp they vanish. Modulo p2p^2 they survive: (1+x)2=1+2x+x2(1+x)^2 = 1 + 2x + x^2, and the 2x2x is nought on a dial of two and not on a dial of four.

So modulo p2p^2 the columns are no longer separate. The surviving middle terms carry a contribution from one digit into its neighbour, and a rule that looks at one column at a time cannot see it. What that suggests, and what turns out to be true, is a rule that looks at two neighbouring columns at a time.

A remainder that needs two digits

Modulo 4 the failure has a particularly simple form, because in binary every small coefficient is (11)\binom{1}{1}, (10)\binom{1}{0} or (00)\binom{0}{0}, and all three are 1. The digit product for an odd entry is therefore always 1. An odd entry is 1 or 3 modulo 4, so the digit product is wrong at exactly the odd entries that leave 3 — the deep-coloured cells of the first figure, and the dots are on precisely those.

Which odd entries leave 3 is itself a statement about digits, and it is a statement about pairs. When (nk)\binom{n}{k} is odd, the ones of kk sit under ones of nn, and nkn - k takes the rest. Look at every place where nn has two ones side by side. Either kk takes both of them, or nkn - k takes both, or they are split, one each. The entry leaves 3 on division by 4 exactly when an odd number of those adjacent pairs are split. The first figure checks that rule at every one of its 243 odd entries.

C(13, 4) modulo 4, read in windows of 2 base-2 digits. The addition of 4 and 9 in base 2 with its carries, and a table reading the digits of n, k and n − k in overlapping windows of 2. The windows' ratios of factorials without multiples of 2 multiply, with a sign from the carries, to 3 — the remainder modulo 4 of the coefficient with its 2s removed.
Fig. 2 (134)=715\binom{13}{4} = 715, which is odd and leaves 3 on division by 4. Thirteen is 11011101 in binary; four is 01000100 and nine is 10011001, so no column carries. The one adjacent pair of ones in thirteen, in the third and fourth places, is split between four and nine, and the only window that is not 1 is the one reading 1111, 0101, 1010. The digit-by-digit product says 1, which is wrong.

(134)=715\binom{13}{4} = 715 is an example. Thirteen in binary is 11011101, with one adjacent pair of ones at the top; four is 01000100 and nine is 10011001, so four takes the lower one of the pair and nine the upper. One split pair, and 715=4×178+3715 = 4 \times 178 + 3. The digit product has no way to know that, because each column on its own looks the same whether the pair is split or not.

The digits come in windows

The table in that figure is the general rule at work. Each row reads a window of two consecutive digits — of nn, of kk and of nkn - k — starting at a given place, and the windows overlap: the window starting at the second digit shares a digit with the one starting at the first.

For each window the rule takes the three numbers the windows spell, forms their factorials with every multiple of pp left out — written (m!)p(m!)_p — and divides the first by the product of the other two, modulo p2p^2. In (134)\binom{13}{4} the window from the third digit reads 1111, 0101 and 1010: three, one and two. Leaving out the even numbers, (3!)2=1×3=3(3!)_2 = 1 \times 3 = 3, (1!)2=1(1!)_2 = 1 and (2!)2=1(2!)_2 = 1, so the ratio is 3. Every other window gives 1, the product is 3, and that is the remainder.

The rule in general, for the prime power pqp^q, is Andrew Granville’s theorem of 1997. Read windows of qq digits. Take the product over all windows of the ratio of pp-free factorials. Multiply by 1-1 once for every carry out of the qq-th column or any column above it, when kk and nkn-k are added in base pp — except modulo 8 and the higher powers of two, where the sign is dropped. The result is the binomial coefficient with every factor of pp removed, modulo pqp^q. With q=1q = 1 every window is a single digit, and when nothing carries the windows’ ratios are the small coefficients (niki)\binom{n_i}{k_i} and the rule is Lucas’ theorem; when something does carry, it says what Lucas’ theorem cannot, namely what the coefficient leaves once its $p$s are gone.

Why a whole run of numbers counts only as a sign

The proof has two steps, and the second is where the windows and the sign come from.

First, take the prime out of each factorial. Among 1,2,,m1, 2, \dots, m the multiples of pp are p,2p,,m/ppp, 2p, \dots, \lfloor m/p \rfloor p, whose product is pm/pp^{\lfloor m/p \rfloor} times m/p!\lfloor m/p \rfloor !. So

m!=pm/pm/p!(m!)p,m! = p^{\lfloor m/p\rfloor} \cdot \lfloor m/p\rfloor! \cdot (m!)_p,

and applying the same thing to m/p!\lfloor m/p \rfloor !, and again, writes m!m! as a power of pp times the product of (m/pj!)p(\lfloor m/p^j \rfloor !)_p over every jj. Doing that to n!n!, k!k! and (nk)!(n-k)! gives (nk)\binom{n}{k} as a power of pp — Kummer’s count of carries — times a ratio of pp-free factorials, one ratio per place jj. That identity is exact, in whole numbers, with no modulus anywhere.

Second, reduce each pp-free factorial modulo pqp^q. A run of pqp^q consecutive numbers contains one number from every remainder class, so the product of its members that pp does not divide is, modulo pqp^q, the product of every unit on the dial of pqp^q. By the extension of Wilson’s theorem that product is 1-1 — for every odd prime power and for 4, with one family of exceptions that the next section is about. So (m!)p(m!)_p modulo pqp^q depends only on the last qq digits of mm, apart from a factor of 1-1 for every complete run — and those last qq digits of m/pj\lfloor m/p^j \rfloor are exactly the window starting at place jj.

The $-1$s have to be counted. For each place, the numbers of complete runs in nn, kk and nkn - k differ by one exactly when a carry crosses into the column where the runs are counted, so the signs that do not cancel number one per carry out of the qq-th column or higher. That is the whole of the theorem. The windows are what a modulus of pqp^q can remember of a factorial; the sign is what it cannot.

The exception that proves where the sign comes from

The product of the units modulo pqp^q is 1-1 for every odd prime power and for 4. It is not 1-1 modulo 8: the units are 1, 3, 5 and 7, and 1×3×5×7=1051 \times 3 \times 5 \times 7 = 105, which leaves 1.

The reason is the proof of Wilson’s theorem itself. Pair every unit with its inverse; the pairs multiply to 1, and what is left is the product of the units that are their own inverses. Modulo a prime there are two of them, 1 and 1-1, and the product is 1-1. Modulo 8 there are four — every unit squares to 1, since 32=93^2 = 9, 52=255^2 = 25 and 72=497^2 = 49 all leave 1 — and their product is +1+1.

That happens because the units modulo 8 are not all powers of one of them: no unit has order four, so the group is not a cycle, and a cycle is what forces a single element of order two. Every odd prime power has a cycle of units, and so does 4; no higher power of 2 does. So Granville’s rule carries its sign for every prime power except 2q2^q with q3q \ge 3, where the sign is dropped — and the exception is not a patch on the theorem but a fact about which dials have a primitive root, arriving in a question about Pascal’s triangle.

Taking the prime out first

When the coefficient is divisible by pp the rule describes what is left after the $p$s are removed, and the figure below takes the pair the essay on carries used, in base five.

C(100, 37) modulo 25, read in windows of 2 base-5 digits. The addition of 37 and 63 in base 5 with its carries, and a table reading the digits of n, k and n − k in overlapping windows of 2. The windows' ratios of factorials without multiples of 5 multiply, with a sign from the carries, to 4 — the remainder modulo 25 of the coefficient with its 5s removed.
Fig. 3 (10037)\binom{100}{37} modulo 25. Thirty-seven and sixty-three are 122122 and 223223 in base five, and adding them carries twice, so 25 divides the coefficient exactly. Read in overlapping windows of two digits, the three ratios of factorials without multiples of five are 23, 21 and 12, whose product leaves 21; one carry comes out of the second column or above, so the sign is minus, and the coefficient with its two fives removed leaves 4.

The table reads the windows 0000, 4040, 0404 of one hundred, 2222, 1212, 0101 of thirty-seven and 2323, 2222, 0202 of sixty-three — each window sliding one digit along from the last. The product of the ratios is 21 modulo 25, the sign flips it to 21-21, which is 4, and the figure checks that against the coefficient itself: (10037)\binom{100}{37} is 52×136,801,181,899,757,525,756,109,5045^2 \times 136{,}801{,}181{,}899{,}757{,}525{,}756{,}109{,}504, and the second factor does leave 4.

Two facts come out of that, and neither is visible from Lucas’ theorem or Kummer’s alone. The coefficient’s remainder modulo 25 is nought, which says nothing. Its remainder modulo 125 is 25×4=10025 \times 4 = 100, because the part left after removing the fives is 4 modulo 5. Kummer supplies the power of the prime; Granville supplies the digits of what the power multiplies. Together they fix the coefficient’s last digits in base pp to as many places as the carries plus the width of a window: first the trailing noughts Kummer counts, one per carry, then qq more digits read from the windows.

The same failure in base three

In base three the small coefficients are no longer all 1 — (21)=2\binom{2}{1} = 2 — so the digit product takes more values than in base two, and it is still wrong.

Pascal's triangle modulo 9, where one digit at a time is not enough. 27 rows of Pascal's triangle coloured by remainder modulo 9 — hue for the last base-3 digit, depth for the second. The digit-by-digit product that gives every remainder modulo 3 gets the remainder modulo 9 wrong at 93 of the 216 entries 3 does not divide.
Fig. 4 Twenty-seven rows modulo 9. The hue is the remainder modulo 3, which is Lucas’ pattern and is self-similar on blocks of three rows; the depth is the second base-three digit. The dots mark the 93 entries, of the 216 that three does not divide, where the digit-by-digit product gives the wrong remainder modulo 9. Granville’s rule is checked at all 378.

The hues repeat on blocks of three, nine and twenty-seven rows exactly as the triangle modulo three did, because hue is what one digit at a time decides. The depths are a different matter. A window of two digits straddles the boundary between one block and the next, so the second digit of a remainder in a lower block depends on the leading digit of nn together with the digit below it — and a block that copies the one above it in hue need not copy it in depth. It already fails in base two at the smallest scale: rows 2 and 3 copy rows 0 and 1 in hue, and (31)=3\binom{3}{1} = 3 stands where (11)=1\binom{1}{1} = 1 stood. In base three the one-digit rule is wrong at 93 of 216 units; that is 43 in a hundred, close to the 41 in a hundred it was wrong at in base two.

The count is not a sign of disorder. Every one of those 378 remainders is computed by a rule with no exceptions, and the figure checks each against the entry itself. What is lost modulo p2p^2 is not structure but the independence of the columns.

Rows that repeat much further than they need to

Lucas’ theorem has one consequence that looks like it should be the end of the story: (pnpk)\binom{pn}{pk} and (nk)\binom{n}{k} leave the same remainder modulo pp, because appending a nought to both nn and kk in base pp appends a column whose small coefficient is (00)=1\binom{0}{0} = 1. Every pp-th row of the triangle, read at every pp-th place, is the triangle again, modulo pp.

It is the triangle again to far more precision than that.

Every fifth row of Pascal's triangle repeats the triangle modulo 125. Two small triangles side by side: the first 7 rows of Pascal's triangle modulo 125, and the entries C(5n, 5k) modulo 125. They agree at 28 of 28 places, and the differences are multiples of 5³.
Fig. 5 Seven rows of Pascal’s triangle modulo 125, beside the entries (5n5k)\binom{5n}{5k} from every fifth row, also modulo 125. They agree at all 28 places — (3015)=155,117,520\binom{30}{15} = 155{,}117{,}520 leaves 20, as (63)=20\binom{6}{3} = 20 does. The agreement modulo 535^3 was checked for every nn up to 24.

For every prime from five on, (pnpk)\binom{pn}{pk} and (nk)\binom{n}{k} agree modulo p3p^3. Charles Babbage proved the case (2p1p1)1\binom{2p-1}{p-1} \equiv 1 modulo p2p^2 in 1819, Joseph Wolstenholme raised it to p3p^3 in 1862, and the general form for every nn and kk came in the middle of the twentieth century, from Wilhelm Ljunggren and Ernst Jacobsthal.

The Babbage–Wolstenholme case has a proof that shows where the cube comes from. Write

(2p1p1)=i=1p1p+ii=i=1p1(1+pi)=1+p1i+p2i<j1ij+,\binom{2p-1}{p-1} = \prod_{i=1}^{p-1} \frac{p+i}{i} = \prod_{i=1}^{p-1}\left(1 + \frac{p}{i}\right) = 1 + p\sum \frac1i + p^2 \sum_{i<j}\frac{1}{ij} + \cdots,

working modulo p3p^3 with 1/i1/i meaning the inverse of ii on that dial. The terms from p3p^3 on vanish, and two correction terms are left.

The first needs the sum of the inverses to be a multiple of p2p^2. Pair ii with pip - i: 1/i+1/(pi)=p/(i(pi))1/i + 1/(p-i) = p/\big(i(p-i)\big), so the sum is pp times half the sum of the fractions 1/(i(pi))1/\big(i(p-i)\big) — and modulo pp each of those is 1/i2-1/i^2. The second needs the sum over pairs i<j1/(ij)\sum_{i<j} 1/(ij) to be a multiple of pp, and that sum is half of the square of the first sum minus the sum of the squared inverses. Both come down to one fact: the squared inverses add up to a multiple of pp. They run over the same values as the squares 12,22,,(p1)21^2, 2^2, \dots, (p-1)^2, whose sum (p1)p(2p1)/6(p-1)p(2p-1)/6 is a multiple of pp as soon as the six in the denominator shares no factor with pp — from five on, and not before.

Every third row of Pascal's triangle repeats it modulo 3², not modulo 27. Two small triangles side by side: the first 7 rows of Pascal's triangle modulo 27, and the entries C(3n, 3k) modulo 27. They agree at 25 of 28 places, and the differences are multiples of 3².
Fig. 6 The same comparison for the prime 3, modulo 27. Twenty-five of the twenty-eight places agree; at the three shaded ones the entries differ — (63)=20\binom{6}{3} = 20 against (21)=2\binom{2}{1} = 2, and 23 against 5 in the sixth row — and every difference is a multiple of nine and not of twenty-seven. For p=3p = 3 the sum of inverses is 1+121 + \tfrac12, a multiple of three only once.

For p=3p = 3 the argument runs out a step early, and the second figure shows the exact place. 1+1/21 + 1/2 is 3/23/2, divisible by three once and not twice, so the pp-term survives modulo 27 and the agreement stops at nine. The shaded cells are where it stops, and the first of them is the entry the proof names: (63)=20\binom{6}{3} = 20 and (21)=2\binom{2}{1} = 2 differ by eighteen.

Where the rule needs its hypotheses

The modulus must be a prime power. A remainder modulo 12 is a remainder modulo 4 and a remainder modulo 3 read together, so a composite modulus is handled by running the rule once per prime power and assembling the answers. There is no single base in which the digits of a composite modulus live, which is why no single digit rule exists for it.

The prime is removed before the rule speaks. Granville’s theorem describes the coefficient divided by its full power of pp, not the coefficient. When that power is qq or more the remainder modulo pqp^q is simply nought and all the information is in what the power multiplies — as (10037)\binom{100}{37} showed, where the useful statement was about the remainder modulo 125.

The sign depends on the dial. It is there for every odd prime power and for 4, and absent for 8, 16 and every higher power of two, for the reason a group of units without a generator has more than one element of order two.

The windows grow with the modulus and the work does not grow much. Modulo pqp^q each window has qq digits and there is one window per digit of nn, so the rule costs a few small factorials per digit — a computation on logn\log n digits, against a coefficient with about nn of them, which is the same saving the carry count made for the power of pp.

Two digits of shading, and a rule with no such limit

The shaded triangles have two digits of remainder to show and a colour for each, which is why they stop at p2p^2: modulo 27 there would be three digits and no honest way to shade the third. The worked table has no such limit, and the rule it computes has none; the figures that draw every entry simply do not go further than a picture can carry.

The pictures also check finitely many cases. Thirty-two rows modulo four and twenty-seven modulo nine is 906 entries, each computed by the rule and compared with the entry; the comparison of every fifth row with the triangle runs to n=24n = 24. That is evidence the rule was implemented correctly. The proof above is what makes it true.

And the split-pair description of the remainder modulo 4 is special to base two. It works because every binary window of an odd entry is either 1111 split, 1111 unsplit or something whose factorials are all 1; in base three the ratio for a window takes more values, and the rule has no description in words as short as that one.

Still open: one power beyond the cube

The Babbage–Wolstenholme congruence says (2p1p1)\binom{2p-1}{p-1} leaves 1 modulo p3p^3 for every prime from five on. For most primes it does not leave 1 modulo p4p^4. The primes for which it does are called Wolstenholme primes, and only two are known — 16,843 and 2,124,679 — although a heuristic count suggests there are infinitely many of them, appearing more and more rarely.

The converse is open too. Every prime from five on satisfies the congruence modulo p3p^3; no composite number nn is known for which (2n1n1)\binom{2n-1}{n-1} leaves 1 modulo n3n^3, and nobody has proved that none exists. If none does, the congruence is a test for primality stated entirely in terms of one entry of Pascal’s triangle — the same shape of statement as Wilson’s characterisation, and like it, far too slow to use.

A rule that fails may have been read too finely

The habit is about what to do when a clean rule stops working one step further out.

Lucas’ theorem fails modulo p2p^2, and the tempting conclusion is that the remainders modulo p2p^2 have no digit rule — that above the first power the triangle turns arithmetic into noise. The dots in the first figure look like evidence for it. The rule that replaces it is still a digit rule; it reads the digits two at a time instead of one. The one-digit rule was not wrong about the kind of answer, only about its width.

That is a common shape, and worth checking for before reaching for a different kind of explanation. When an argument that works column by column breaks, find the term that couples neighbouring columns — here the middle coefficients of (1+x)p(1+x)^p — and ask how far the coupling reaches. If it reaches one column, read pairs; if it reaches q1q - 1 columns, read windows of qq. The failure measured how wide the rule had to be.

What links here

Computed from the collection, not written here: the essays that point at this one.

Shares its objects with

Essays that name at least two of the same things, and that neither author linked.

Named objects

A dashed tag is an object no other essay names yet.

Binomial coefficientCyclic groupDivisibilityKummer's theoremLucas' theoremModular arithmeticPlace valuePrimes