Discrete

Numbers that wrap

A clock does arithmetic. It has finitely many numbers, addition never leaves it, and multiplication behaves entirely differently depending on one property of the size of the dial.
19 min read 7 figures Throwing things awaySmall cases lie

Nine hours after eight o’clock is five o’clock. That is arithmetic, it is correct, and it is not the arithmetic of the whole numbers — in that arithmetic, 8+98 + 9 is 1717.

Arithmetic on a dial of 12A dial with 12 positions. Starting at 8 and stepping forward 9 places lands on 5, because the walk passes the top 1 time on the way.012345678910118 + 9= 17= 5 (mod 12)1 lap of the dial,then the remainder
Fig. 1 A dial of twelve. Starting at 88 and stepping forward nine places lands on 55, and the walk passes the top exactly once. The generator counts those passes off the drawn walk and requires them to agree with the quotient the division discards.

What has been discarded is the number of times the hand passed twelve, and what has been kept is the remainder. That is the whole definition: two numbers are the same modulo mm when they differ by a multiple of mm, and the arithmetic on the dial is the arithmetic of the whole numbers with that identification made.

The interest is not in the definition. It is that the resulting system is well-behaved in one operation and startlingly badly behaved in the other, and that the difference turns on a single property of mm.

Nothing is lost by wrapping

The first thing to establish is that the arithmetic is consistent — that the answer does not depend on which representatives are chosen. If aa and aa' differ by a multiple of mm, and so do bb and bb', then a+ba+b and a+ba'+b' differ by a multiple of mm, and so do abab and aba'b'. Both are one line of algebra.

That is not a formality. It is the statement that the dial is a structure rather than a notation: addition and multiplication descend from the integers to the residues, so every identity that holds for whole numbers holds on the dial. Commutativity, associativity, distributivity — all inherited, none re-proved.

Addition on a dial of 12Every row of the table is the row above it, shifted one place. Addition on a dial of 12 never loses information.0123456789101112345678910110234567891011013456789101101245678910110123567891011012346789101101234578910110123456891011012345679101101234567810110123456789110123456789100011223344556677889910101111+12 is composite12 of 12 rows are rearrangementsof every residue
Fig. 2 The whole addition table on a dial of twelve, each cell coloured by its value. Every row is the row above it shifted one place, so every row contains each residue exactly once — the generator checks all twelve.

Addition’s table is a Latin square: every residue appears exactly once in every row and every column. That is the same as saying addition by any fixed amount is a permutation of the dial, which is obvious once seen — adding kk rotates the dial by kk places and a rotation loses nothing.

So addition is as good as it could be. Every element has an inverse (add mkm - k), the operation is closed, and cancellation works: if a+c=b+ca + c = b + c then a=ba = b.

Multiplication is a different animal

Now multiply.

Multiplication on a dial of 12Multiplication on a dial of 12. The modulus is composite, so some rows repeat themselves and some products land on zero without either factor being zero.0000000000000123456789101102468100246810036903690369048048048048051038161149270606060606060729411618310508408408408409630963096301086420108642011109876543210011223344556677889910101111×12 is composite4 of 12 rows are rearrangementsof every residuea red cell is a product of twonon-zero numbers that is zero
Fig. 3 Multiplication on the same dial. Some rows are still rearrangements of all twelve residues; most are not. The red cells are products of two non-zero numbers that come out zero, and there are a great many of them.

The table is not a Latin square, and the failures are dramatic. Row 66 reads 0,6,0,6,0,6,0, 6, 0, 6, 0, 6, \ldots — it takes two values out of twelve. Row 44 takes three. And 3×4=03 \times 4 = 0, with neither factor zero.

That last is the one worth naming. In the integers, a product of two non-zero numbers is never zero, and a very large amount of ordinary algebra rests on it: it is why an equation can be solved by factoring, why a polynomial of degree nn has at most nn roots, and why cancellation works. On a dial of twelve, none of that is safe. The equation x2=4x^2 = 4 has four solutions modulo 1212 — namely 22, 44, 88 and 1010 — which is more roots than the degree allows.

Numbers like 33 and 44 here are zero divisors, and their presence is exactly what makes the dial of twelve a worse place to do algebra than the integers.

The condition is primality

Which rows are permutations? The multipliers coprime to mm — those sharing no factor with it.

The reason is Euclid’s algorithm. If gcd(k,m)=1\gcd(k, m) = 1, the algorithm produces integers u,vu, v with ku+mv=1ku + mv = 1, so ku1ku \equiv 1 on the dial and kk has a multiplicative inverse. Multiplying by something invertible is a permutation. Conversely, if kk and mm share a factor d>1d > 1, then k(m/d)0k \cdot (m/d) \equiv 0 and kk is a zero divisor, which no invertible element can be.

So the count of permutation rows is the count of residues coprime to mm, which is Euler’s totient function — and the generator computes it and checks the row count against it rather than taking the claim on trust.

Now the punchline. If mm is prime, every non-zero residue is coprime to it. So every non-zero row is a permutation, every non-zero element has an inverse, there are no zero divisors, and the dial is a field — a number system in which all four operations work exactly as they do in the rationals.

Multiplication on a dial of 13Multiplication on a dial of 13. The modulus is prime, so every non-zero row is a rearrangement of all the residues.000000000000001234567891011120246810121357911036912258111471004812371126101590510271249161138061251141039281707182931041151260831161941272105095110621173128401074111852129630119753112108642012111098765432100112233445566778899101011111212×13 is prime12 of 13 rows are rearrangementsof every residue
Fig. 4 The same table with thirteen positions instead of twelve. Every non-zero row is now a rearrangement of every non-zero residue, there is not a single red cell below the top row, and the dial has become a system in which division always works.

Twelve and thirteen differ by one and their multiplication tables are different kinds of object. That is the sharpest illustration this site has of what primality actually does: it is not a fact about which numbers are interesting, it is the condition under which arithmetic keeps working.

The gap between the two tables is also a decent answer to a question this site keeps running into: why do the primes matter so much, given that they are defined by a negative property — having no factors? The answer visible here is that the negative property is exactly the absence of the obstruction. A composite modulus has factors, factors give zero divisors, and zero divisors break division. Primes are not special because they are rare or irregular; they are special because they are the moduli with nothing in the way, and their irregular distribution is a separate fact that happens to be true of the same numbers.

Orbits, and a theorem about polygons

Start at 11 and keep multiplying by the same number. Since the dial is finite, the sequence must repeat, and since multiplication by an invertible element is reversible, it must return to where it started rather than falling into a cycle it entered from outside.

Multiplying by 2, over and over, on a dial of 13Starting at 1 and multiplying by 2 each time closes after 12 steps, visiting 12 of the 12 non-zero residues. 12 divides 12, as it must.0123456789101112order of 212 steps to return2^12 = 1 (mod 13)12 divides 12
Fig. 5 Repeatedly multiplying by 22 on a dial of thirteen, drawn as the path it traces. It closes after twelve steps, having visited every non-zero residue — so 22 is a generator, and the path is a single star polygon through all of them.

The number of steps before returning is the order of that multiplier. For a prime dial, the order always divides m1m - 1, which is Fermat’s little theorem in the form am11a^{m-1} \equiv 1, and the generator checks the divisibility on every orbit it draws.

Multiplying by 3, over and over, on a dial of 13Starting at 1 and multiplying by 3 each time closes after 3 steps, visiting 3 of the 12 non-zero residues. 3 divides 12, as it must.0123456789101112order of 33 steps to return3^3 = 1 (mod 13)3 divides 12
Fig. 6 The same dial, multiplying by 33. This one closes after three steps rather than twelve, so it visits three residues and leaves nine untouched. Three divides twelve, as it must.
Multiplying by 5, over and over, on a dial of 13Starting at 1 and multiplying by 5 each time closes after 4 steps, visiting 4 of the 12 non-zero residues. 4 divides 12, as it must.0123456789101112order of 54 steps to return5^4 = 1 (mod 13)4 divides 12
Fig. 7 Multiplying by 55: four steps, a quadrilateral. Every orbit on this dial has length 11, 22, 33, 44, 66 or 1212 — the divisors of twelve — and no other length is possible, which is a strong statement about a system with no apparent structure to enforce it.

The reason the order divides m1m-1 is worth stating because it is one line and it is a real proof. The orbit of 11 under multiplication by aa is a subgroup, and multiplying that whole orbit by any other residue produces a set of the same size, disjoint or identical. So the non-zero residues split into equal-sized blocks, and the block size divides the total. That is Lagrange’s theorem, in the case where it is easiest to see.

This has a consequence used constantly and worth stating plainly: on a prime dial, exponents can be reduced modulo m1m-1. Computing 210002^{1000} modulo 1313 needs no large numbers at all, because 1000=83×12+41000 = 83 \times 12 + 4, so the answer is 24=1632^4 = 16 \equiv 3.

What it costs, and what it buys

Everything here is cheap. Addition and multiplication on a dial cost one operation and one remainder; exponentiation by squaring costs log\log of the exponent. Finding an inverse costs a run of Euclid’s algorithm, which is famously fast — the number of steps is bounded by about five times the digit count, by Lamé’s theorem.

What it buys is the whole of public-key cryptography, and the reason is an asymmetry that has appeared nowhere else in this essay. Exponentiation on a dial is easy. Its inverse — given aa, mm and akmodma^k \bmod m, recover kk — is the discrete logarithm problem, and nobody knows how to do it quickly for a well-chosen prime. The orbit figures above show why intuition is no help: the star polygon a generator traces visits the residues in an order with no visible relationship to their size, so knowing where a walk ended says nothing about how many steps it took.

That is the honest reason to draw those figures. The scrambling is the security, and it is visible.

Two smaller uses are worth naming because they are everywhere and nobody notices. A hash table is a dial: an index is a key reduced modulo the table size, and the classical advice to make that size prime is exactly the observation above — a composite modulus lets keys sharing a factor with it collide systematically rather than by the birthday coincidence they should. And every check digit scheme, from ISBNs to bank account numbers, is a linear equation on a dial chosen so that the two commonest human errors — a mistyped digit and a transposed pair — both break it.

Where the small cases lie

The dial of two is the parity that runs through much of this site: even and odd, with 1+1=01 + 1 = 0. It is a field, since two is prime, and it is the smallest one.

It is also profoundly misleading as an example, and worth flagging because it is the case everyone meets first. Modulo two, squaring does nothing (02=00^2 = 0, 12=11^2 = 1), addition and subtraction are the same operation, and every non-zero element is its own inverse. All three of those are accidents of smallness that fail at every larger prime, and a reader who forms intuitions on them will find every one of those intuitions broken at three.

Colouring Pascal’s triangle by parity is the same dial in its most spectacular use, and it is worth noting that the fractal there is not a fact about the number two: the same construction modulo three or five produces different and equally structured patterns, governed by Lucas’ theorem, which is a statement about writing numbers in base pp. Two is where the picture is prettiest, not where the mathematics lives.

Where it fails, and where it goes instead

The residues modulo a composite mm are not a field, and the repair is not to give up but to take the dial apart. If m=12=3×4m = 12 = 3 \times 4, then knowing a number modulo 33 and modulo 44 determines it modulo 1212, and every arithmetic operation can be done in the two smaller dials independently. That is the Chinese remainder theorem, and it says that a composite dial is a product of coprime prime-power dials rather than a damaged version of a prime one.

So the messy multiplication table above is not one bad structure; it is two good ones interleaved, and the zero divisors are the pairs that are zero in one factor and not the other. The structure was never wrong, only badly presented by a single dial.

What genuinely fails is order. The integers are ordered and the residues cannot be: if 1>01 > 0 then adding 11 repeatedly should keep increasing, and on a dial it comes back. So no ordering compatible with addition exists on any finite dial, and everything in mathematics that depends on order — inequalities, limits, calculus — has no analogue here. That is a large amount to give up, and it is the price of finiteness.

The loss is worth measuring against what finiteness gives back. A question about the integers may need an infinite search; the same question on a dial can always be settled by trying every residue, so decidability comes free. Whether x22x^2 \equiv 2 has a solution modulo 77 is answered in seven multiplications. Whether x2=2x^2 = 2 has a rational solution is a proof rather than a check, and a famous one.

That trade — order for decidability — is why modular arithmetic is the first thing tried against a hard question about integers. If an equation has no solution on some dial, it has none in the integers, and the dial is checkable. The converse fails, which is what makes the method a filter rather than an answer, and the exact extent of that failure is the local–global problem that a large part of modern number theory is about.

What the picture cannot show

The dial figures show one modulus at a time, and everything that matters is a comparison across moduli — twelve against thirteen, prime against composite. Two tables side by side is the closest a static figure gets to a statement about all mm, and it is not close.

The orbit figures show a path closing after a certain number of steps, and the theorem is that the number divides m1m - 1. Divisibility is not a visual property: a twelve-step orbit and a three-step orbit look like a dense polygon and a sparse one, and nothing in either picture says the second number divides the first. The generator checks it; the drawing cannot.

And the discrete logarithm’s hardness is unshowable in the strongest sense. The orbit figure suggests scrambling, and suggestion is not evidence — the problem is believed hard and not known to be, and a picture of thirteen residues is no evidence at all about a modulus with six hundred digits.

The ladder from here

Rungs above: the Chinese remainder theorem drawn as a lattice. Euler’s totient function and its multiplicativity. Primitive roots, and which dials have them. Quadratic residues and the reciprocity law, which is the deepest elementary fact about these dials. Fermat’s little theorem as a necklace-counting argument, where the divisibility becomes a statement about beads. The RSA construction, and the exact point at which its security is a conjecture rather than a theorem. Finite fields of prime-power order, which are not dials at all. And modular forms, where the word starts meaning something else entirely.

The lesson is about what a definition includes

The dial was introduced as a convenience — a way of talking about remainders — and it arrived carrying a complete algebraic structure that nobody put there.

That is the recurring experience of the subject and it is worth naming. A definition made for one reason turns out to determine a great deal that the definition never mentioned: that addition is a rotation, that multiplication’s behaviour depends on the factorisation of the modulus, that a finite system cannot be ordered, that exponentiation is easy and its inverse may not be. None of that was decided. All of it was implied by identify numbers that differ by a multiple of mm, and the work of the subject is finding out what was implied.

The same thing happens whenever an identification is made rather than a construction performed. Gluing the ends of a strip after a half-turn is a one-sentence instruction that determines one-sidedness, one edge, and what happens when the result is cut. Adding a single point to the plane determines that circles and lines become one kind of object. In each case the definition is short and the consequences are not, and there is no way to read the consequences off the definition except by working them out.

Gauss, who set all this out in the Disquisitiones Arithmeticae of 1801 and invented the \equiv notation for it at twenty-four, was explicit that the notation was the point — it was chosen to look like equality so that the identities of ordinary arithmetic could be written down unchanged and used without re-derivation. That is the same design decision Leibniz made about the integral sign, and it worked for the same reason.