🔢 p-adic Number Ultrametric Space

Visualize p-adic numbers as a fractal tree. The p-adic distance |x-y|ₚ = p-vₚ(x-y) where vₚ is the p-adic valuation. Numbers close in the p-adic metric are widely separated in reals.

MathematicsInteractive
A and B are highlighted on the tree · R redraw

How it Works

The p-adic integers ℤₚ form a complete metric space under the p-adic absolute value. They have a natural fractal tree structure: the root represents all integers; each node at depth d represents a residue class modulo pd; each node branches into exactly p children corresponding to the p residue classes mod pd+1 that extend it.

Two integers are p-adically close if their difference is divisible by a high power of p. On the tree, this means they share a long common path from the root. The p-adic distance between integers A and B is p-vₚ(A-B) where vₚ(n) = max{k : pk | n}.

v_p(n) = max{k ∈ ℕ : pᵀ | n}
|x|_p = p^{-v_p(x)},   |0|_p = 0
d_p(A,B) = |A-B|_p = p^{-v_p(A-B)}
Ultrametric: d(x,z) ≤ max(d(x,y), d(y,z))

The tree visualization places numbers at leaf nodes according to their p-adic expansion. Numbers sharing a common p-adic prefix appear on adjacent branches. The highlighted path from the root to each of A and B illustrates their common ancestor depth, which equals vₚ(A-B).

Frequently Asked Questions

What are p-adic numbers?

p-adic numbers are a system of numbers built on a prime p. Every rational number has a p-adic expansion — an infinite series in powers of p going leftward. The p-adic numbers ℚₚ complete the rationals with respect to the p-adic absolute value rather than the usual absolute value.

What is the p-adic valuation?

The p-adic valuation vₚ(n) of an integer n is the largest power of p that divides n. For example v₂(12) = 2 since 12 = 4×3 = 2²×3. For a fraction vₚ(a/b) = vₚ(a) - vₚ(b).

What is the p-adic absolute value?

The p-adic absolute value of a rational number x is |x|ₚ = p-vₚ(x) (with |0|ₚ = 0). Numbers divisible by high powers of p are close to zero p-adically. For example |8|₂ = 2-3 = 1/8 — the number 8 is "small" in the 2-adic sense.

What is an ultrametric space?

An ultrametric space satisfies the strong triangle inequality: d(x,z) ≤ max(d(x,y), d(y,z)). This implies every triangle is isosceles, and every ball is both open and closed (clopen). The p-adic metric is a classic example.

Why is the p-adic metric an ultrametric?

Because vₚ(x+y) ≥ min(vₚ(x), vₚ(y)), so |x+y|ₚ ≤ max(|x|ₚ, |y|ₚ). This follows because if p divides both x and y, it divides x+y. Taking absolute values gives the ultrametric inequality.

What is Ostrowski's theorem?

Ostrowski's theorem (1916) states that every non-trivial absolute value on ℚ is equivalent to either the usual absolute value or a p-adic absolute value for some prime p. Thus ℝ and the fields ℚₚ are all possible completions of ℚ.

How are p-adic numbers visualized as a tree?

The p-adic integers ℤₚ have a natural tree structure: each node at depth d represents a residue class mod pd; each node has exactly p children. Two numbers are p-adically close if and only if they share a long common root path in this tree.

What is Hensel's lemma?

Hensel's lemma is a p-adic analog of Newton's method: if a polynomial f has a simple root mod p, that root lifts uniquely to a root in ℤₚ. Used to solve equations in p-adic numbers with applications in algebraic number theory and cryptography.

Are there p-adic analogs of real analysis?

Yes. p-adic analysis develops calculus over ℚₚ: power series, exponential and logarithm functions, p-adic measures, and integration. A key difference: a sequence converges in ℚₚ if and only if its terms tend to zero.

What are the applications of p-adic numbers?

p-adic numbers appear in algebraic number theory, Fermat's Last Theorem proof, the Langlands program, p-adic string theory in physics, cryptographic protocols, error-correcting codes, and the study of L-functions and modular forms.

About this simulation

This simulation renders the p-adic integers as a branching tree: pick a prime p, and every integer sits at a leaf reached by following digits of its base-p expansion. Two numbers A and B are compared directly — the depth where their paths diverge equals the p-adic valuation vp(A-B), and their p-adic distance p-vp shrinks the more they share a common prefix, even when their ordinary real-number difference is large.

🔬 What it shows

A fractal p-ary tree for primes p=2,3,5,7 with depth 2-7. The paths from the root to leaf A and leaf B are highlighted in indigo and amber, with the shared ancestor path shown in violet — visually encoding the p-adic valuation.

🎮 How to use

Choose a prime with the Prime p selector, adjust Tree depth, then drag the Number A and Number B sliders (1-100). The Statistics panel updates v_p(A), v_p(B), the p-adic distance |A-B|_p, and the ordinary real distance live. Press R to redraw.

💡 Did you know?

In the 2-adic metric, 1024 and 0 are extremely close (divisible by 2^10), while 1 and 2 are far apart — the opposite of how they'd rank on the real number line. This inverted notion of "closeness" underlies deep results like Hensel's lemma.

Frequently asked questions

Why do close p-adic numbers look far apart on the tree's real-axis labels?

The tree encodes closeness by shared digit prefixes in base p, not by numeric size. Two numbers can differ by a huge real amount yet be p-adically close if their difference is divisible by a high power of p, meaning they follow the same branch for many levels before separating.

What happens if I set A equal to B?

The p-adic distance becomes 0 and the two paths coincide entirely down to the chosen tree depth — the simulation will show a single highlighted path since there's no divergence point within the visible depth.

Why does increasing the prime p change the tree shape so much?

Each node branches into exactly p children, so p=2 gives a slim binary tree while p=7 gives a wide, shallow tree at the same depth. Larger primes pack more numbers into fewer levels, which changes how quickly paths for two given numbers diverge.

Does the tree depth slider affect the actual p-adic distance?

No — the mathematical distance |A-B|_p is fixed by the valuation of A-B and doesn't depend on how many tree levels you render. The depth slider only controls how much of the infinite tree is drawn, so very close numbers may look identical until you increase depth enough to see them separate.

Is there a real-world use for p-adic numbers, or is this purely theoretical?

p-adic numbers are central to modern number theory (they were essential in the proof of Fermat's Last Theorem) and also appear in cryptography, coding theory, and p-adic string theory in physics, making this more than an abstract curiosity.