Lucas's Theorem

lean4-proofnumber-theoryvisualization
(mn)i(mini)(modp)\binom{m}{n} \equiv \prod_{i} \binom{m_i}{n_i} \pmod{p}

Statement

Let pp be a prime. Write mm and nn in base pp:

m=mkpk++m1p+m0,n=nkpk++n1p+n0.m = m_k p^k + \cdots + m_1 p + m_0, \qquad n = n_k p^k + \cdots + n_1 p + n_0.

Then

(mn)i=0k(mini)(modp),\binom{m}{n} \equiv \prod_{i=0}^{k} \binom{m_i}{n_i} \pmod{p},

where (mini)=0\binom{m_i}{n_i} = 0 whenever ni>min_i > m_i.

A crucial corollary: for 0<k<p0 < k < p,

(pk)0(modp).\binom{p}{k} \equiv 0 \pmod{p}.

Visualization

Take p=5p = 5 and compute (mk)mod5\binom{m}{k} \bmod 5 for mm ranging from 0 to 24 (rows) and kk from 0 to 4 (cols). Lucas says the answer is determined by the base-5 digits.

Pascal mod 5  (· = 0, digit shown otherwise)
     k: 0  1  2  3  4
m=  0: 1  .  .  .  .
    1: 1  1  .  .  .
    2: 1  2  1  .  .
    3: 1  3  3  1  .
    4: 1  4  1  4  1
    5: 1  .  .  .  .   ← new "row 1" in base 5
    6: 1  1  .  .  .
    7: 1  2  1  .  .
   10: 1  .  .  .  .   ← 10 = 2·5+0; top digit row repeats
   12: 1  2  1  .  .
   24: 1  4  1  4  1

The pattern tiles: Pascal's triangle mod pp is a fractal (Sierpiński-like for p=2p = 2) because each p×pp \times p block of the big triangle is a scalar multiple of the first-row entry times the whole small triangle.

Proof Sketch

  1. Generating function: In Fp[x]\mathbb{F}_p[x], we have (1+x)p=1+xp(1 + x)^p = 1 + x^p (by the freshman's dream: (pk)0\binom{p}{k} \equiv 0 for 0<k<p0 < k < p).

  2. Digit decomposition: Write m=m0+pmm = m_0 + p \cdot m' and n=n0+pnn = n_0 + p \cdot n'. Then

(1+x)m=(1+x)m0((1+x)p)m=(1+x)m0(1+xp)m.(1+x)^m = (1+x)^{m_0} \cdot ((1+x)^p)^{m'} = (1+x)^{m_0} \cdot (1+x^p)^{m'}.
  1. Extract coefficient: The coefficient of xn=xn0xpnx^n = x^{n_0} \cdot x^{p n'} on the right factors as (m0n0)(mn)\binom{m_0}{n_0} \cdot \binom{m'}{n'}.

  2. Induction: Apply the same argument to mm' and nn', inducting on the number of base-pp digits.

Connections

Lucas's theorem is a powerful tool in combinatorics and number theory. It generalises to prime powers via Granville's theorem. The key ingredient — that p(pk)p \mid \binom{p}{k} for 0<k<p0 < k < p — also drives the binomial theorem proof of Fermat's Little TheoremFermat's Little Theoremapa(modp)a^p \equiv a \pmod{p}For prime p, a^p is congruent to a mod pRead more →. The digit-wise structure connects to pp-adic numbers and to Multiplicative FunctionsMultiplicative Functionsgcd(m,n)=1f(mn)=f(m)f(n)\gcd(m,n)=1 \Rightarrow f(mn)=f(m)f(n)Arithmetic functions that split over coprime inputs: f(mn) = f(m)f(n) when gcd(m,n) = 1Read more → (since the number of kk with (mk)≢0(modp)\binom{m}{k} \not\equiv 0 \pmod p is multiplicative in the digit sense). Lucas sequences also play a role in primality tests related to Wilson's TheoremWilson's Theorem(p1)!1(modp)(p-1)! \equiv -1 \pmod{p}A natural number p > 1 is prime if and only if (p-1)! ≡ -1 mod pRead more →.

Lean4 Proof

/-- For a prime `p` and `0 < k < p`, `p` divides the binomial coefficient C(p, k).
    This is the key lemma behind Lucas's theorem and the freshman's dream identity.
    Mathlib proves it as `Nat.Prime.dvd_choose_self`. -/
theorem prime_dvd_binom_self (p k : ) (hp : Nat.Prime p) (hk : k  0) (hkp : k < p) :
    p  Nat.choose p k :=
  hp.dvd_choose_self hk hkp

/-- Freshman's dream: in characteristic p, (1 + x)^p = 1 + x^p.
    Mathlib provides `CharP.add_pow_char` for this identity in a ring of char p. -/
theorem freshman_dream (p : ) [hp : Fact p.Prime] (R : Type*) [CommRing R] [CharP R p]
    (a b : R) : (a + b) ^ p = a ^ p + b ^ p :=
  add_pow_char R a b