Build the idea in three steps
- On a clock of size five, the product 2 × 3 = 6 = 1: the multiplication returns exactly to one. When that happens, 3 undoes 2 — division has come home to the clock, and 3 is written a⁻¹.
- The function inv in the excerpt gives a⁻¹ on every clock, and its docstring carries the precise promise: a * a⁻¹ = gcd a.val n. Only when gcd equals one — with a coprime to the clock size — does the product really return to one.
- Prime clocks are the generous ones: any nonzero card is coprime to a prime p, so on ℤ/pℤ division works everywhere except at zero. Composite clocks ration it out. This is the world where the proof reduces curves (traceOfFrobenius counts in exactly such a world).
A small example
The nine-clock turns the trick down but not off: 2⁻¹ = 5 there, since 2 × 5 = 10 = 1 (gcd 2 9 = 1). But 3 has no inverse on it: every multiple of 3 lands on 0, 3 or 6 — never on 1, because gcd 3 9 = 3.