The row that proves a prime
Worth reading first: Necklaces that prove a theorem · The exponent that is smaller than Euler's.
Necklaces that prove a theorem counted the strings of beads in colours. The constant strings stand alone; every other string lies on a ring of exactly rotations, because is prime and no rotation short of a full turn can carry a mixed string onto itself. So divides , which is Fermat’s little theorem.
The theorem is a test for primality with a famous flaw. The exponent that is smaller than Euler’s met the Carmichael numbers — , , and infinitely many more — which pass it for every base they share no factor with, although they are composite. The count that proved the theorem cannot tell them from primes, because it counts all the strings at once and the numbers happen to come out right.
This essay counts more carefully. Fix not the colours but how many beads are black, and the same necklace argument gives a statement that no composite number can fake.
There are ways to choose three black beads out of seven places on a ring. Group them by rotation and there are five necklaces, each standing for exactly seven arrangements. Seven divides thirty-five, and the reason is the same as in Fermat’s theorem: a prime number of places admits no partial symmetry.
One necklace that repeats too soon
For a composite number of beads, the argument can fail, and the failure is visible.
With six beads and two black, there are fifteen arrangements. Two of the necklaces are full rings of six. The third — two black beads directly opposite each other — comes back to itself after three steps, so its ring has only three arrangements. Fifteen is six plus six plus three, and six does not divide fifteen.
That is the general picture. The size of every necklace’s ring divides the number of beads, and the ring is short exactly when the necklace has a rotational symmetry — when its pattern repeats with some period that divides . For a prime there is no such period except , which only the all-black and all-white necklaces have. For a composite , take to be its smallest prime factor and the necklace with black beads spaced evenly round the ring: it repeats after steps. That short ring is enough to spoil the divisibility, and a computation with the factor shows that is never a multiple of .
A row that only a prime can fill
So the necklaces with a fixed number of black beads give a characterisation, not just a necessary condition.
A number greater than one is prime exactly when it divides every entry with . The figure shows the rows of Pascal’s triangle from to with each middle entry marked by whether the row’s number divides it. The prime rows are filled from end to end; every composite row has a gap. Row has gaps at , and — the opposite-beads necklace at and , and at the necklace of alternating colours, which repeats after two steps; row at and ; row at the multiples of and . The pattern of the gaps is Pascal’s triangle read modulo the row’s factors, where Lucas’s theorem computes each entry’s remainder from the digits of and in the base of a prime.
The Carmichael numbers cannot hide here. passes Fermat’s test for every base prime to it, but its row of Pascal’s triangle has gaps — at , and among other places, where the evenly spaced necklaces repeat early. The test that counts all colours at once adds up the row in a way that makes the gaps cancel; the test that looks at each entry separately sees them.
Where the gaps fall
Which entries of a composite row fail has an exact answer, and it is written in the digits of the numbers involved.
Ernst Kummer proved in 1852 that the power of a prime dividing is the number of carries that occur when and are added in base — the rule the carries decide the divisibility drew. So is a multiple of exactly when, for every prime power dividing , adding and in base produces at least carries. For a prime , adding and in base always carries once, since the last digits add up to ; that is the necklace argument in the language of digits.
For the rule has to be satisfied in three bases at once, and it fails often: counting shows that of the middle entries of row are not multiples of , starting at . Each is a place where some addition in base , or goes through without a carry — which is the digit form of a necklace repeating early. The Carmichael number has one hundred and fourteen necklace classes that betray it, and Fermat’s test consults none of them individually.
How the total hides the gaps
Fermat’s test is the sum of the row. Choosing each of the beads black or white, the strings that are not constant are the necklaces with black beads, so
If every term is a multiple of , so is the sum, and that is the necklace proof of Fermat’s theorem for the base . A composite can make the sum a multiple of while leaving terms that are not. The number does exactly that: is a multiple of , so passes Fermat’s test with the base — it is the smallest number that does so without being prime — while of the middle entries of its row — beginning at — are not multiples of . Their remainders cancel in the total.
A test that sees only the sum cannot see the cancellation, and every pseudoprime is a row whose failures add up to nothing. The polynomial test refuses to add them up, and that is the whole of its advantage over Fermat’s.
The row as a polynomial
The row of Pascal’s triangle is the list of coefficients of , and the characterisation can be written as a single identity. Saying that divides every middle coefficient is saying that
as polynomials, with every coefficient reduced modulo . More generally, for any sharing no factor with ,
holds exactly when is prime. Setting gives , which is Fermat’s theorem; so the polynomial identity implies Fermat’s theorem and is strictly stronger, because a composite can make the constant term come out right while leaving other coefficients behind.
The number is a pseudoprime to the base : , and Fermat’s test with that base is fooled. The polynomial reduced modulo is not fooled at all. Eighteen of its middle coefficients are not multiples of , one at each multiple of and each multiple of below , and the identity fails in eighteen places at once. The polynomial form of Fermat’s theorem cannot be fooled, because it asks every necklace class separately rather than asking for their total.
The same fact as the freshman’s dream
The identity — the “freshman’s dream”, since it is the mistake beginners make with ordinary numbers — is the necklace count once more, and its reach goes far beyond primality.
It says that raising to the -th power is additive when arithmetic is done modulo a prime. That makes the map a symmetry of any number system built with arithmetic modulo — the Frobenius map — and the finite fields are organised around it. In the field with four elements squaring swaps the two elements that are not or ; in the plane of order the translation hyperovals of every power of x that draws a hyperoval are the graphs of powers of the Frobenius map, and they work because it is additive. A fact about necklaces with a prime number of beads is the reason a whole branch of algebra has a distinguished symmetry.
Too many coefficients, and how to cut them down
As a practical test, the polynomial identity is useless as it stands. It has coefficients, and for a number with a hundred digits is a hundred-digit number of coefficients — no better than trying every possible factor.
Manindra Agrawal, Neeraj Kayal and Nitin Saxena found in 2002 how to cut it down. Wrap the polynomial round: work modulo as well as modulo , so that is replaced by , by , and so on. Every polynomial then has only coefficients, and can be computed with about squarings of polynomials of that size. The identity still holds for every prime; the question is whether composites can now slip through, since wrapping loses information.
Their theorem is that they cannot, provided is chosen so that has a large order modulo — larger than — and the identity is checked for enough values of , up to about . Then an that passes, is not a perfect power and has no factor below must be prime. Such an exists below about , so the whole test takes a number of steps bounded by a power of the number of digits of . The figure runs the wrapped test on three primes and the three smallest Carmichael numbers: with between and , the primes pass and every Carmichael number fails, for the first value of tried.
Why the test asks first about perfect powers
The wrapped test has a preliminary step that looks like a technicality and is not: before any polynomial is powered, it checks whether is a perfect power — a square, a cube, some with — and declares composite if so.
The reason is in the shape of the proof. Its argument shows that if the wrapped identity holds for enough values of , then has a prime factor for which a large collection of polynomials behave, modulo , as if were a power of ; counting those polynomials in two ways then forces to be a power of . The count cannot distinguish from or , so the proof ends at “ is a power of a prime”, and the perfect-power check removes the powers. Checking whether a number is a perfect power is quick — for each exponent up to , compute an integer -th root by bisection and raise it back — and it closes the one gap the polynomial argument leaves.
The unwrapped identity has no such gap. modulo keeps the coefficient , which leaves , and prime powers fail the full row test exactly as other composites do. The cost of wrapping is the loss of that information, and the perfect-power check is what buys it back. Two primes where Fermat holds twice met the same distinction between a prime and its square from the other side: the squares of primes are where Fermat’s congruence can hold more strongly than it has to.
What was new about it
Fast primality tests existed long before 2002. The Miller–Rabin test, a strengthening of Fermat’s that checks square roots of one along the way, is fast and fooled by no composite for more than a quarter of bases, so forty random bases make an error astronomically unlikely. And an order that proves a prime showed that every prime has a short certificate anyone can check.
What neither supplies is a procedure that is fast, never wrong and needs no luck and no certificate. Miller–Rabin is fast and could in principle be wrong; made deterministic by trying every base up to a bound, it needs the generalised Riemann hypothesis to be sure the bound suffices. The polynomial test of Agrawal, Kayal and Saxena is unconditionally correct and deterministically fast, and its proof uses nothing deeper than finite fields and a counting argument about how many polynomials an impostor would have to satisfy. That it was found by a professor and two undergraduates, in a subject worked on for two thousand years, is part of why it was celebrated.
In practice it is not used. Its running time, even after improvements by Hendrik Lenstra and Carl Pomerance brought the exponent down to about the sixth power of the number of digits, is far slower than Miller–Rabin, and primes that need certifying are certified by elliptic-curve methods that produce short proofs. The polynomial test’s importance is that it settled a question — primality is decidable in polynomial time — not that it is how primes are found.
What the rings and rows cannot show
The necklaces are drawn for seven and six beads. The claim that prime lengths admit no short rings is general and simple; the claim that every composite length has a short ring is proved in words, with the evenly-spaced necklace, and illustrated at six.
Pascal’s triangle is drawn to row twenty. The figure checks the characterisation for every row it draws; the characterisation for every row is the necklace argument above.
The wrapped test is run with parameters chosen as the theorem requires, on six numbers below two thousand, and with one value of . The theorem’s guarantee needs many values of in general; that one sufficed for these Carmichael numbers is an observation about them, not a replacement for the theorem.
Still open: a wrapped test that needs one value of a
The polynomial test is slow because it must try many values of and use a large . A conjecture, going back to the work of Rajat Bhattacharjee and Prashant Pandey and stated in the paper of Agrawal, Kayal and Saxena, would remove both costs: if is a prime not dividing , and modulo and , then either is prime or . It has been checked by computer for all below a very large bound and every small , and if true it would give a test with running time about the cube of the number of digits, faster than any proven deterministic test.
Lenstra and Pomerance gave a heuristic argument that counterexamples should exist, built from numbers with many prime factors of a special form, and none has been found. So the conjecture is supported by computation, opposed by a heuristic, and unproved — a small version of the relationship between Fermat’s test and the Carmichael numbers, one level up.
Counting each class, not the total
The habit worth keeping is the refinement of the count.
Fermat’s theorem came from counting all the strings of beads at once and noticing that the total, minus the constant strings, was a multiple of . A total can be right for the wrong reasons, and the Carmichael numbers are totals that are right for the wrong reasons. Counting the strings with each number of black beads separately — each entry of the row of Pascal’s triangle on its own — asks the same question times, and a composite number cannot answer all of them correctly. A sum of counts can be fooled; the counts themselves cannot, and the polynomial identity is the device that keeps them apart.
What links here
Computed from the collection, not written here: the essays that point at this one.
Reads more easily once this is understood
Essays that name this one as worth reading first.
Shares its objects with
Essays that name at least two of the same things, and that neither author linked.
- A remainder read two digits at a time — both name binomial coefficient, modular arithmetic, primes
- A sum of two sets modulo a prime cannot be small — both name binomial coefficient, modular arithmetic, polynomial
- Every power sum, from the coefficients alone — both name fermats little theorem, polynomial, primality test
- Numbers that wrap — both name fermats little theorem, modular arithmetic, primes
- Solutions that come in multiples of p — both name fermats little theorem, modular arithmetic, polynomial
- A factorisation that hides its primes — both name modular arithmetic, primes
Named objects
A dashed tag is an object no other essay names yet.
Binomial coefficientComplexityFermats little theoremModular arithmeticNecklacePolynomialPrimality testPrimes