P-adic wheels

In the usual (real) number line, two numbers are “close” if their leading digits agree: {3.14159} is closer to {3.14160} than to {3.2}. The p-adic world flips that intuition: closeness is governed by agreement of the low-order digits (divisibility by powers of a prime).

This post introduces a small Pygame visualization (shown as circles inside circles inside circles) for the 3-adic integers {\mathbb{Z}_3}. The picture is inspired by the beautiful illustrations of Heiko Knospe, and the app is meant to make two ideas feel tangible: (1) what it means for numbers to be p-adically close, and (2) how addition behaves in this nested, ultrametric geometry.

Hensel’s “invention” of the p-adic numbers

The p-adic numbers were first systematically introduced by Kurt Hensel (1861–1941), a German mathematician who studied in Berlin and Bonn and was strongly influenced by Leopold Kronecker; from 1901 onward he was a professor in Marburg. Around 1897, Hensel realized that one can build a number system by completing the rationals not with the usual absolute value, but with a new absolute value {|\cdot|_p} that measures divisibility by a fixed prime {p}.

A compact way to say “p-adic closeness” is: two integers {x} and {y} are close in the p-adic sense if {x-y} is divisible by a large power of {p}. Write {v_p(x-y)} for the exponent of {p} in {x-y}. Then {|x-y|_p = p^{-v_p(x-y)}} is small exactly when {v_p(x-y)} is large.

If you’d like a classic reference from Hensel himself, see his book Zahlentheorie (1913), where p-adic methods appear in a mature, systematic form.

From congruences to nested circles

The 3-adic integers {\mathbb{Z}_3} can be viewed as an infinite limit of congruence systems, and that viewpoint is perfect for visualization. A basic “clopen” (closed-and-open) 3-adic ball has the form {a + 3^n\mathbb{Z}_3}, which you can read as “all 3-adic integers that are congruent to {a} modulo {3^n}.”

In the app, those balls become nested circles:

  • The big circle is the whole space (schematically).
  • Inside it are 3 circles: the residue classes mod 3 (the least significant ternary digit {d_0\in\{0,1,2\}}).
  • Inside each of those are 3 circles: refining to mod 9 (digit {d_1}).
  • Inside each of those are 3 circles: refining to mod 27 (digit {d_2}).
  • And one more layer gives mod 81 (digit {d_3}), for a total of {3^4=81} innermost circles labeled 0–80.

Two numbers land in the same small circle precisely when they agree modulo a high power of 3. That’s the visual meaning of “3-adically close”: sharing deeper circles means sharing more low-order ternary digits, i.e., {x\equiv y\ (\mathrm{mod}\ 3^n)} for larger and larger {n}.

Addition as a ternary wheel

The app animates the operation {x\mapsto x+1} (wrapping {80\mapsto 0}), and highlights (i) the active innermost circle and (ii) every circle that contains it. Conceptually, this is the “wheel” behavior of ternary digits: the last digit ticks 0→1→2→0, and whenever it rolls over, a carry moves to the next digit.

The nesting makes carries feel geometric. When a carry happens, the highlight doesn’t merely move to a nearby leaf; it “jumps” to a different region determined by the next digit layer. In p-adic terms, carries change higher digits, while leaving lower congruence information intact.

Here is a simple invariant you can read directly from the circles: adding 3 does not change the residue mod 3, because {3\equiv 0\ (\mathrm{mod}\ 3)}. In the visualization, that means {x} and {x+3} stay inside the same one of the three outer circles.

Likewise, adding 9 does not change the residue mod 9, because {9\equiv 0\ (\mathrm{mod}\ 9)}. So {x} and {x+9} keep the same position in the second layer (the mod 9 refinement), even though they may move around in deeper layers.

Why this picture is helpful (and what it is not)

This is not an isometric embedding of {\mathbb{Z}_3} into the Euclidean plane. It is a schematic drawing that encodes the key ultrametric fact: balls are nested, and each ball splits cleanly into three disjoint sub-balls at the next scale.

If you want to generalize, the same idea works for any prime {p}: each ball splits into {p} sub-balls, and p-adic closeness is agreement modulo {p^n}. The circles then become a compact way to “see” both topology (nested clopen sets) and arithmetic (addition with carries).


Credits & references

Leave a comment