Hensel Code System

Exact rational arithmetic via p-adic numbers — no floating-point errors, ever.

Ostrowski (1916) + Hensel (1904) + Krishnamurthy (1977) → ℚp completes ℚ exactly

🧮 Calculator
🚀 Patriot Missile
🌳 Bruhat-Tits Tree
📐 Theory

🧮 Interactive Exact Arithmetic Calculator

Enter any rational numbers (decimals or fractions). Compare exact Hensel code results against IEEE 754 floating-point — see the difference for yourself.

✅ Hensel Code EXACT

Press Compute to see results…

⚠️ IEEE 754 Float APPROXIMATE

Press Compute to see results…
QUICK PRESETS

🚀 Patriot Missile Scenario

In 1991, a Patriot missile system tracked time in 1/10 second increments using 24-bit binary. Each tick of 0.1 accumulated a tiny rounding error. After 100 hours, the drift reached 0.34 seconds — missing an incoming Scud missile. 28 soldiers died.

Below: 36,000 ticks of 0.1 seconds (1 hour simulation — enough to see the drift).

Hensel Code (p=7, k=30)
IEEE 754 Float64

🌳 Bruhat-Tits Tree (p=3)

The p-adic integers ℤp form an infinite regular tree. Each level groups numbers that agree modulo pⁿ. Two numbers are "close" if they share a deep ancestor. This is an ultrametric — every triangle is isosceles.

Root (all ℤ₃) Level 1 (mod 3) Level 2 (mod 9) Level 3 (mod 27)

↕ d(x, y) = p−LCA_level — ultrametric: d(x,z) ≤ max(d(x,y), d(y,z))

📐 Theoretical Foundation

Ostrowski's Theorem (1916)

Every non-trivial absolute value on ℚ (the rational numbers) is equivalent to exactly one of: the real absolute value (completing to ℝ) or a p-adic absolute value (completing to ℚp). These are the only completions of ℚ. Both are equally fundamental. Current computing uses only ℝ; adding ℚp gives us exactness.

Hensel's Lemma (1904)

Any root modulo p lifts uniquely to higher powers of p via a constructive algorithm. This means every rational a/b (with p ∤ b) has a unique p-adic expansion computable digit by digit — the foundation for Hensel codes.

Hensel Codes (Krishnamurthy, 1977)

H(a/b) = a · b⁻¹ (mod pᵏ) — a single integer. All four arithmetic operations are exact integer operations modulo pᵏ. Zero rounding error. Recovery via Extended Euclidean Algorithm.

The Bruhat-Tits Tree

The p-adic integers form an infinite regular tree. Any finite ultrametric (e.g., a dendrogram from hierarchical clustering) embeds into this tree. This provides natural clustering and distance metrics for exact arithmetic results.

Constraints

• Denominators must be coprime to the chosen prime p — pick p larger than any expected denominator.
• Irrationals (π, e, √2) require symbolic representation — this system handles rationals exactly.
• Practical use: p = 257 or p = 65537 for general-purpose exact arithmetic.