Number

One residue whose powers are all of them

Fermat's theorem says every order divides p − 1. It does not say that anything has order exactly p − 1, which is a separate and stronger claim — and what forces it is a count of how many numbers share each divisor with p − 1.

Worth reading first: Necklaces that prove a theorem · Numbers that wrap.

Necklaces that prove a theorem ends with a remark and moves on: the multiplicative order of a residue divides p1p-1, and that observation is the beginning of a subject. Here is the subject.

Fix a prime and take a residue that is not zero. Multiply it by itself repeatedly. The sequence must eventually repeat, and since multiplication by the residue can be undone, the first repeat is a return to the start — so the powers form a closed ring whose length is the residue’s order. Fermat’s theorem is the statement that the length divides p1p-1.

The powers of 2 modulo 13, as a ring of 12. The non-zero residues modulo 13 placed on a circle, with the successive powers of 2 joined by straight lines into a closed walk of 12 steps.
Fig. 1 The twelve non-zero residues modulo thirteen, placed round a circle in numerical order, with the powers of two joined in the order they arrive. The walk visits every residue and closes after twelve steps, so two has order twelve. Every other residue’s order was computed the same way and each one divides twelve.

What Fermat’s theorem does not say

The ring above has twelve beads and there are twelve residues, so the powers of two are all of them. That is a much stronger statement than the order divides twelve, and nothing in the necklace argument produces it.

To see the gap, take another base on the same modulus.

The powers of 5 modulo 13, as a ring of 4. The non-zero residues modulo 13 placed on a circle, with the successive powers of 5 joined by straight lines into a closed walk of 4 steps.
Fig. 2 The same twelve residues, with the powers of five joined instead: 5, 12, 8, 1, and back. A ring of four rather than twelve, so five has order four — four divides twelve, Fermat’s theorem is satisfied, and the powers of five are a quarter of the residues.

Five has order four. Four divides twelve, so the theorem holds, and the powers of five reach four residues out of twelve. A divisor of p1p-1 is not p1p-1, and a theorem that only bounds the order says nothing about whether anything achieves it.

A residue whose order is exactly p1p-1 is called a primitive root, and the claim that one always exists is a separate theorem. It is also a much more useful one: a primitive root turns multiplication into addition, since every residue is gkg^k for exactly one kk between 00 and p2p-2, and multiplying two residues adds their exponents. Everything multiplicative about the modulus becomes arithmetic on a single dial of p1p-1 positions — and a dial is the object numbers that wrap is about, so the theorem says one wrapping arithmetic sits inside another in a way the notation hides completely.

The count that forces one to exist

The existence proof is a count, and it is the same kind of count an earlier essay runs — partition a set into classes of known size, and read a conclusion off the sizes.

How many residues modulo 13 have each order. A table of the divisors of 12, how many residues modulo 13 have exactly that order, Euler's totient of the divisor, and the residues themselves.
Fig. 3 For each divisor of twelve, how many residues modulo thirteen have exactly that order, beside Euler’s totient of the divisor. The two columns agree in every row, the rows add to twelve, and the last row is the one that matters: four residues have full order, so a generator exists.

The claim is: for every divisor dd of p1p-1, exactly φ(d)\varphi(d) residues have order dd, where φ\varphi counts the numbers up to dd sharing no factor with it. The last row of that table is d=p1d = p-1, and φ\varphi of anything is at least one, so a residue of full order exists.

The argument has two halves and both are worth having, because the first is easy and the second is where the primality is spent.

At most φ(d)\varphi(d) residues have order dd. Suppose one does, say aa. Then the dd powers of aa all satisfy xd=1x^d = 1. A polynomial of degree dd over the residues modulo a prime has at most dd roots — this is where primality enters, and it fails badly for composites — so those dd powers are all the solutions of xd=1x^d = 1. Any residue of order dd satisfies that equation, so it is among the powers of aa; and aka^k has order dd exactly when kk shares no factor with dd. So there are either none of order dd or exactly φ(d)\varphi(d).

That first half is a genuine use of primality and it is worth isolating, because it is the only one. A polynomial of degree dd having at most dd roots is a statement that holds over any field and fails over the residues modulo a composite: x21x^2 - 1 has four roots modulo fifteen, so the bound is not a formality. The same fact settles how many solutions an equation can have over a finite field, and it is the reason the two subjects share their arithmetic.

And the totals leave no room for “none”. Every residue has some order, and every order divides p1p-1, so the counts over the divisors of p1p-1 must add to p1p-1. If any divisor contributed nothing, the total would fall short — because the totients of the divisors of nn already add to exactly nn.

The identity underneath, which is not about primes

The numbers up to 12, sorted by what they share with 12. One row per divisor of 12: the numbers from 1 to 12 whose greatest common divisor with 12 is that divisor's cofactor, with each row's size beside it — Euler's totient of the divisor.
Fig. 4 The numbers one to twelve, sorted by what they share with twelve. The class marked d holds the numbers whose greatest common divisor with twelve is twelve over d, so the class has φ(d) members — and the classes account for all twelve numbers.

The identity dnφ(d)=n\sum_{d \mid n} \varphi(d) = n is the load-bearing part, and its proof is a partition rather than a computation. Sort the numbers 11 to nn by their greatest common divisor with nn. The numbers whose greatest common divisor is n/dn/d are exactly the multiples of n/dn/d that share nothing else with nn, and writing such a number as (n/d)j(n/d)\cdot j, the condition on jj is that it is at most dd and shares no factor with dd. So that class has φ(d)\varphi(d) members.

Every number is in exactly one class, so the classes add to nn. That is the whole proof, and nothing in it mentions primes — the identity is true for every nn, which is worth noticing because it is the half of the existence argument that carries no hypothesis. The hypothesis is all in the polynomial-root bound above, and that is where the composite cases will break.

Counting one set in two ways is the most productive habit in this subject, and the shape here is the standard one: the left-hand side sorts by a property and adds up the classes, the right-hand side counts the whole thing directly, and the identity is the statement that both count the same set. Quadratic reciprocity is the same move on a much larger scale, and Fermat’s own theorem is it on a smaller one.

The other proof, which builds a generator out of pieces

There is a second route to the same theorem and it is worth having, because it constructs rather than counts and because the tool it uses is needed again where the modulus is composite.

Start from a fact about combining orders, which is not the obvious one. If aa has order mm and bb has order nn, the order of abab is not generally mnmn, and it is not generally the least common multiple either — modulo thirteen, 22 has order twelve and 2112^{11} has order twelve, and their product is 2122^{12}, which is one on a dial of thirteen and so has order one. What is true is a restricted version: if mm and nn share no factor, then abab has order exactly mnmn.

The proof of that is short. (ab)mn=1(ab)^{mn} = 1, so the order divides mnmn. Conversely, if (ab)k=1(ab)^k = 1 then raising to the power mm kills aa and leaves bkm=1b^{km} = 1, so nn divides kmkm; since nn shares no factor with mm it divides kk. The same argument the other way gives mkm \mid k, so mnkmn \mid k. The coprimality is used exactly twice and the statement is false without it.

Now the construction. Let λ\lambda be the largest order that occurs among the residues. Every order divides λ\lambda — because if some residue had order tt not dividing λ\lambda, some prime power in tt would exceed the one in λ\lambda, and the combining fact above would build a residue of order larger than λ\lambda out of suitable powers of the two. So every residue satisfies xλ=1x^{\lambda} = 1, an equation of degree λ\lambda with p1p-1 solutions, and the root bound forces λp1\lambda \ge p-1. Since λ\lambda divides p1p-1, it is p1p-1, and the residue achieving it is a generator.

Both proofs spend primality in the same place and nowhere else — the root bound — and they differ in what they hand over. The counting proof gives the exact number of residues of each order and no construction; this one gives a recipe for assembling a high-order element from lower-order ones and no count. Having both is what makes the composite case tractable, because λ\lambda is a quantity in its own right and the argument above is the one that computes it when the modulus is not prime and λ\lambda falls short.

The generators, and how many of them there are

The 4 generators modulo 13. Up to four rings, one per generator modulo 13: the residues on a circle with the successive powers of that generator joined, each walk passing through every residue once.
Fig. 5 The four generators modulo thirteen, each drawn as the walk its powers trace. Every walk visits all twelve residues exactly once, which is what the figure checks; there are four of them because φ(12) is four, and the eight residues not listed have orders 1, 2, 3, 4 or 6.

The table gives the count of generators for free: there are φ(p1)\varphi(p-1) of them. Modulo thirteen that is φ(12)=4\varphi(12) = 4, and the four are 2,6,7,112, 6, 7, 11. Modulo seventeen it is φ(16)=8\varphi(16) = 8, so half the residues generate.

Modulo eleven there are φ(10)=4\varphi(10) = 4, and modulo the small primes the counts are 1,1,2,2,4,4,8,61, 1, 2, 2, 4, 4, 8, 6 — a sequence that does not increase, because it depends on the factorisation of p1p-1 rather than on pp.

The proportion is worth a moment because it is neither small nor predictable. φ(p1)/(p1)\varphi(p-1)/(p-1) can be as large as a half — when p1p-1 is twice a prime — and it can be pushed down towards nothing by choosing p1p-1 with many small prime factors, since each distinct prime factor qq multiplies the proportion by 11/q1 - 1/q. There are primes for which fewer than a fifth of the residues generate, and there is no upper bound on how small the fraction can be made.

How many residues modulo 17 have each order. A table of the divisors of 16, how many residues modulo 17 have exactly that order, Euler's totient of the divisor, and the residues themselves.
Fig. 6 The same table at seventeen, where p − 1 is a power of two. Every order is a power of two, the counts are 1, 1, 2, 4, 8, and eight of the sixteen residues generate — the largest proportion any prime can have.

Nothing in the existence proof locates a generator. The count says four exist modulo thirteen and gives no procedure for finding one beyond testing residues in turn, and testing a residue means computing its order. For a prime of several hundred digits, testing is feasible if the factorisation of p1p-1 is known — a residue is a generator exactly when a(p1)/q1a^{(p-1)/q} \neq 1 for every prime qq dividing p1p-1 — and is not feasible otherwise. So the theorem is an existence statement whose constructive version needs a factorisation, which is the standing shape of this subject.

There is a conjecture that sharpens the question and has been open since 1927. Artin conjectured that a fixed base that is not a perfect square and not 1-1 — two, say — is a primitive root for infinitely many primes, indeed for a positive proportion of them. It is unproved. What is known is due to Heath-Brown in 1986: at most two prime values of the base can fail, so at least one of 22, 33 and 55 satisfies the conjecture and nobody can say which.

The dial the generator provides, and what lives on it

Once a generator is fixed, every unit has an address: the exponent that reaches it. Writing the addresses out turns the multiplicative structure into an additive one, and several facts that are awkward in one language are immediate in the other.

The order of gkg^k is (p1)/gcd(k,p1)(p-1)/\gcd(k, p-1), which is the statement that the powers of gkg^k are the multiples of kk on a dial of p1p-1 positions — and the multiples of kk on such a dial form a sub-dial whose size is p1p-1 divided by what kk and p1p-1 share. That single formula produces every count in the table above: the residues of order dd are the gkg^k with gcd(k,p1)=(p1)/d\gcd(k, p-1) = (p-1)/d, and there are φ(d)\varphi(d) such kk by the same class-counting the identity above is about.

It also explains why the divisor structure of p1p-1 matters so much and the size of pp hardly at all. A prime with p1=2qp-1 = 2q for qq prime has only four divisors, so only four possible orders, and half its residues generate. A prime with p1p-1 highly composite has many orders and few generators. The arithmetic of the modulus has almost dropped out and been replaced by the arithmetic of p1p-1, which is the change of coordinates the generator performs.

The same relabelling is what makes the finite field with pp elements look like a familiar object: its non-zero elements are a single ring under multiplication, and every element is a power of one is that statement for the fields with pkp^k elements as well, where the count of generators is φ(pk1)\varphi(p^k - 1) and the argument is the same one.

Where it fails, and the shape of the failure

Which moduli up to 30 have a generator. A strip of the moduli from 2 to 30, each marked according to whether some residue's powers reach every unit, with the ones that do shaded.
Fig. 7 Every modulus from two to thirty, shaded when some residue’s powers reach every unit. The shading was decided by searching for such a residue, and it agrees exactly with the rule that a generator exists for 1, 2, 4, an odd prime power, and twice an odd prime power — two verdicts computed independently.

For a composite modulus the theorem usually fails, and the figure locates the exceptions rather than describing them. A generator exists modulo nn exactly when nn is 11, 22, 44, a power of an odd prime, or twice one. Eight, twelve, fifteen, sixteen and twenty have none.

The reason is exactly the step the proof spent its primality on. Modulo fifteen the equation x2=1x^2 = 1 has four solutions — 1,4,11,141, 4, 11, 14 — where a prime modulus permits at most two, and the four are what make a generator impossible: a generator’s powers would have to contain all four, but a cyclic ring has only one element of order two.

That failure is not a small exception. It means the units modulo a composite are generally not a single ring but a product of several, and the exponents no longer live on one dial. A later essay is about what replaces the dial, and about a consequence for primality testing that is more than a curiosity: the largest order of a unit modulo nn can be much smaller than the number of units, and a composite whose orders are all small is a composite that Fermat’s test cannot see.

What a generator is for

Three uses, and each is the same observation applied differently.

Logarithms modulo a prime. Fix a generator gg; then every residue is gkg^k for a unique kk, and kk is the discrete logarithm. Multiplication becomes addition of logarithms, exactly as it does for ordinary logarithms, and the tables that were used for hand computation modulo a prime were logarithm tables. Computing the logarithm in the other direction — given gkg^k, find kk — is believed to be hard, and a great deal of cryptography rests on the belief. The contrast with the exponentiation, which is a few hundred squarings, is what makes the asymmetry useful.

Deciding which residues are squares. Written as powers of a generator, the squares are exactly the even powers, so precisely half the residues are squares and the product of two non-squares is a square. Those facts are immediate from the ring and awkward from the definition, and they are what the reciprocity law is a law about.

Constructing things that need every residue once. A generator’s powers are a listing of the units with no repeats, which is what a sequence must be if it is to be used as a source of well-spread values. A linear congruential generator achieves a full period exactly when its multiplier plays the role of a generator for the relevant modulus, and the condition in that essay’s arithmetic is this theorem’s condition.

What the pictures cannot show

Every figure here is drawn at a modulus below forty, and the interest of the subject is at moduli of hundreds of digits. The rings are drawn because a ring of twelve can be seen and a ring of 1060010^{600} cannot, and everything the drawings establish is the mechanism rather than the case.

The orders are computed by walking the orbit, which is the slowest possible method and the only one that needs no theory. At the sizes drawn it is instant and it is also the reason the figures are evidence: nothing consults a formula for an order, so a residue whose order failed to divide p1p-1 would be reported rather than assumed away.

And the ring’s layout carries no information. The residues are placed round the circle in numerical order because some order was needed, and the walk’s shape — a star, a polygon, a tangle — is an artefact of that choice. What is real is which residues the walk visits and how many steps it takes; the prettiness is not part of the mathematics, and a different placement would produce an unrecognisable picture of the same fact.

Still open: how often a fixed base generates

The existence of a generator is settled and the behaviour of any particular base is not. Artin’s conjecture asks for the proportion of primes for which two is a generator and predicts a specific constant, about 0.37395580.3739558, arrived at by treating the conditions at different primes as independent. The heuristic is convincing, the constant has been computed to many places, and the statement is unproved.

What is known is conditional in a way worth noting, because it is the standard situation in this subject. Hooley showed in 1967 that the conjecture follows from the generalised Riemann hypothesis, so the question is not isolated — it is attached to the central open problem about the distribution of primes, and a proof of that would settle this as a corollary.

The other direction is the one the figures are about. The count of residues of each order is exact and elementary, and it settles existence completely for prime moduli and, with more work, for all moduli. What it cannot do is tell anybody which residue to use, and the gap between knowing something exists and being able to produce it is unusually wide here: a prime of six hundred digits has plenty of generators and finding one requires factoring a six-hundred-digit number first.

What the two theorems are each worth

Fermat’s theorem bounds and the existence theorem attains, and the difference between those two kinds of statement is worth carrying past this page.

A bound is cheap and it is what the necklace count gives: partition a set, read off a divisibility, done. Attainment needs more, and in this case it needed a fact about polynomials — that a prime modulus permits no more roots than the degree — which is a statement about the modulus rather than about counting. The extra hypothesis is visible in exactly the place where the theorem fails, which is the most satisfying way for a hypothesis to earn its place.

What the attained version buys is a change of coordinates. Once the residues are the powers of one of them, multiplication is addition, squares are even exponents, and the whole multiplicative structure is a single dial. That is a large return for one existence theorem, and it is the reason the subject bothers with primitive roots at all rather than stopping at the divisibility.

The pattern is worth naming because it recurs. A theorem that bounds a quantity usually comes from a partition — count something two ways and a divisibility falls out. A theorem that says the bound is achieved usually needs a second ingredient from somewhere else, and the second ingredient is what limits the theorem’s scope. Here the ingredient is a fact about polynomials, the scope is the moduli that are prime powers or twice one, and both the ingredient and the scope were invisible until somebody asked the stronger question.

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.

Named objects

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

Counting two waysCyclic groupDivisorGroup actionModular arithmeticOrbitOrderPrimes