Skip to content

b-adic Numbers ​

Positional notation writes a number as digits that stop on the left and may run forever on the right: 1/3=0.333…1/3 = 0.333\ldots. Turn that around — digits that stop on the right and run forever on the left — and the same long division gives 1/3=…66671/3 = \ldots 6667, because …6667×3=…0001\ldots 6667 × 3 = \ldots 0001. Those are the bb-adic numbers: the completion of the rationals under the rule that divisible by a high power of bb means small.

AdicNumeral(b, x) is the value; AdicNumerals(b) is the matching numeral system in the base slot of IntegerDigits. On the non-negative integers the two directions agree digit for digit. Everywhere else they part ways, and this page is a tour of where.

The same digits, the other way round ​

ℕ: nothing changes

The 10-adic digits of 42 are the decimal digits of 42, padded to the cut: the expansion has no left end, so the width is part of the numeral. The residue system with moduli 16 and 625 reads the same last four digits mod each.

InIntegerDigits(42,10)\mathrm{IntegerDigits}(42, 10)Out[4,2]\bigl\lbrack4, 2\bigr\rbrackInIntegerDigits(42,AdicNumerals(10,6))\mathrm{IntegerDigits}(42, \mathrm{AdicNumerals}(10, 6))Out[0,0,0,0,4,2]\bigl\lbrack0, 0, 0, 0, 4, 2\bigr\rbrackInAdicExpansion(AdicNumeral(10,42))\mathrm{AdicExpansion}(\mathrm{AdicNumeral}(10, 42))Out42\text{42}InIntegerDigits(42,ResidueNumerals([16,625]))\mathrm{IntegerDigits}(42, \mathrm{ResidueNumerals}(\bigl\lbrack16, 625\bigr\rbrack))Out[10,42]\bigl\lbrack10, 42\bigr\rbrack
source · editable

Negatives: a sign, or infinitely many nines ​

Fixed radix drops the sign. Balanced ternary spells it with negative digits. The bb-adics spell it with digits alone, infinitely many of them: −1=…9999-1 = \ldots 9999, because adding 1 carries forever and leaves zero. A residue system wraps instead — −3-3 mod 7 is 4 — which is the same idea cut at each modulus.

−3, four ways

Positional, balanced, adic, residue. The adic string is the one that makes −3 + 3 = 0 by ordinary column addition.

InIntegerDigits(−3,10)\mathrm{IntegerDigits}(-3, 10)Out[3]\bigl\lbrack3\bigr\rbrackInIntegerDigits(−3,BalancedNumerals(3))\mathrm{IntegerDigits}(-3, \mathrm{BalancedNumerals}(3))Out[−1,0]\bigl\lbrack-1, 0\bigr\rbrackInAdicExpansion(AdicNumeral(10,−3),8)\mathrm{AdicExpansion}(\mathrm{AdicNumeral}(10, -3), 8)Out…99999997\text{…99999997}InIntegerDigits(−3,AdicNumerals(10,8))\mathrm{IntegerDigits}(-3, \mathrm{AdicNumerals}(10, 8))Out[9,9,9,9,9,9,9,7]\bigl\lbrack9, 9, 9, 9, 9, 9, 9, 7\bigr\rbrackInFromDigits([9,9,9,9,9,9,9,7],AdicNumerals(10))\mathrm{FromDigits}(\bigl\lbrack9, 9, 9, 9, 9, 9, 9, 7\bigr\rbrack, \mathrm{AdicNumerals}(10))Out−3-3InIntegerDigits((−3) mod 77,ResidueNumerals([7,11]))\mathrm{IntegerDigits}((-3)\bmod77, \mathrm{ResidueNumerals}(\bigl\lbrack7, 11\bigr\rbrack))Out[4,8]\bigl\lbrack4, 8\bigr\rbrack
source · editable

FromDigits with AdicNumerals reads a digit string back as the residue nearest zero, which is what makes the negatives round-trip: eight nines and a seven is −3-3, not 99 999 99799\,999\,997. The width does the work — [7] alone reads as −3-3 too. That is the price of a system with no left end: a numeral is a string of a given width, exactly as in two's complement.

Adding −1 and 1

The arithmetic is the ordinary ring arithmetic; the printed form is what a column addition of …999 and 1 leaves behind.

InAdicNumeral(10,−1)+1\mathrm{AdicNumeral}(10, -1)+1OutAdicNumeral(10,0)\mathrm{AdicNumeral}(10, 0)InAdicExpansion(AdicNumeral(10,−1),6)\mathrm{AdicExpansion}(\mathrm{AdicNumeral}(10, -1), 6)Out…999999\text{…999999}InAdicExpansion(AdicNumeral(2,−1),8)\mathrm{AdicExpansion}(\mathrm{AdicNumeral}(2, -1), 8)Out…11111111\text{…11111111}
source · editable

Rationals: to the right, to the left, or in every channel at once ​

1/31/3 has no finite decimal — the digits recur to the right. It has no finite 1010-adic expansion either — the digits recur to the left — but as a 1010-adic integer it is a perfectly good element: …6667\ldots 6667, and multiplying by 3 gives 1. A residue system gets there a third way: 1/31/3 is whatever multiplies 3 to give 1 in each channel independently, which is the modular inverse.

1/3

Left: 10-adic, and its check. Right: the residue system's answer is 26, because 26 × 3 = 78 ≡ 1 mod 77 — and 26 is exactly what the last two adic digits give mod 100: 67 × 3 = 201.

InAdicExpansion(AdicNumeral(10,13),8)\mathrm{AdicExpansion}(\mathrm{AdicNumeral}(10, \frac{1}{3}), 8)Out…66666667\text{…66666667}In3AdicNumeral(10,13)3\mathrm{AdicNumeral}(10, \frac{1}{3})OutAdicNumeral(10,1)\mathrm{AdicNumeral}(10, 1)InIntegerDigits(PowerMod(3,−1,77),ResidueNumerals([7,11]))\mathrm{IntegerDigits}(\mathrm{PowerMod}(3, -1, 77), \mathrm{ResidueNumerals}(\bigl\lbrack7, 11\bigr\rbrack))Out[5,4]\bigl\lbrack5, 4\bigr\rbrackInFromDigits([5,4],ResidueNumerals([7,11]))\mathrm{FromDigits}(\bigl\lbrack5, 4\bigr\rbrack, \mathrm{ResidueNumerals}(\bigl\lbrack7, 11\bigr\rbrack))Out2626In67×3 mod 10067×3\bmod100Out11
source · editable

The base decides which rationals are integers. In Z10\mathbb{Z}_{10}, 1/31/3 is an integer and 1/21/2 is not — there is no 1010-adic digit string that 2 multiplies to …0001\ldots 0001, since 2×2 × anything ends in an even digit. Same in Z2\mathbb{Z}_2: 1/31/3 is the alternating …10101011\ldots 10101011, and 1/21/2 has no expansion at all.

Which rationals are integers

1/3 in ℤ₂ and ℤ₁₀; 1/2 declines in both. The last cell is 1/3 in ℤ₇ — every base coprime to 3 has one.

InAdicExpansion(AdicNumeral(2,13),8)\mathrm{AdicExpansion}(\mathrm{AdicNumeral}(2, \frac{1}{3}), 8)Out…10101011\text{…10101011}InAdicNumeral(10,12)\mathrm{AdicNumeral}(10, \frac{1}{2})OutAdicNumeral(10,12)\mathrm{AdicNumeral}(10, \frac{1}{2})InAdicNumeral(2,12)\mathrm{AdicNumeral}(2, \frac{1}{2})OutAdicNumeral(2,12)\mathrm{AdicNumeral}(2, \frac{1}{2})InAdicExpansion(AdicNumeral(7,13),8)\mathrm{AdicExpansion}(\mathrm{AdicNumeral}(7, \frac{1}{3}), 8)Out…44444445\text{…44444445}
source · editable

Prime bases are fields; composite bases have zero divisors ​

For a prime pp the story completes: Qp\mathbb{Q}_p is a field, and dividing by pp just moves the point. 7/257/25 in Q5\mathbb{Q}_5 is 0.120.12 — two digits past the point, because 7/25=2⋅5−2+1⋅5−17/25 = 2 \cdot 5^{-2} + 1 \cdot 5^{-1}. The valuation counts those places: v5(75)=2v_5(75) = 2, v5(3/25)=−2v_5(3/25) = -2. The norm ∣x∣p=p−v|x|_p = p^{-v} is the distance: 7575 is small 55-adically, at 1/251/25 from zero.

ℚ₅

A point in the numeral, and the valuation that says where it goes.

InAdicExpansion(AdicNumeral(5,725),8)\mathrm{AdicExpansion}(\mathrm{AdicNumeral}(5, \frac{7}{25}), 8)Out0.12\text{0.12}InAdicNumeral(5,3)5\frac{\mathrm{AdicNumeral}(5, 3)}{5}OutAdicNumeral(5,35)\mathrm{AdicNumeral}(5, \frac{3}{5})InAdicValuation(AdicNumeral(5,75))\mathrm{AdicValuation}(\mathrm{AdicNumeral}(5, 75))Out22InAdicNorm(AdicNumeral(5,75))\mathrm{AdicNorm}(\mathrm{AdicNumeral}(5, 75))Out125\frac{1}{25}InAdicUnitPart(AdicNumeral(5,75))\mathrm{AdicUnitPart}(\mathrm{AdicNumeral}(5, 75))OutAdicNumeral(5,3)\mathrm{AdicNumeral}(5, 3)
source · editable

A composite base gives a ring instead, and a strange one. Z10\mathbb{Z}_{10} contains two numbers e,fe, f with e2=ee^2 = e, f2=ff^2 = f, e+f=1e + f = 1, and e⋅f=0e \cdot f = 0 — neither of them is 00 or 11. They come from Hensel lifting x2=xx^2 = x from its roots 55 and 66 mod 1010, and they are the reason Z10≅Z2×Z5\mathbb{Z}_{10} ≅ \mathbb{Z}_2 × \mathbb{Z}_5: one idempotent is (0,1)(0, 1) and the other (1,0)(1, 0). This is the residue system's "independent channels" again, at infinite precision. A residue system with moduli 2k,5k2^k, 5^k is the 1010-adic truncation with its two factors pulled apart.

Zero divisors in ℤ₁₀

…890625 and …109376: each is its own square, they sum to 1, and their product is 0. No prime base has anything like them.

InAdicExpansion(HenselLift(x2−x,5,10,8))\mathrm{AdicExpansion}(\mathrm{HenselLift}(x^2-x, 5, 10, 8))Out…12890625 + O(10^8)\text{…12890625 + O(10\textasciicircum{}8)}InAdicExpansion(HenselLift(x2−x,6,10,8))\mathrm{AdicExpansion}(\mathrm{HenselLift}(x^2-x, 6, 10, 8))Out…87109376 + O(10^8)\text{…87109376 + O(10\textasciicircum{}8)}InHenselLift(x2−x,5,10,8)HenselLift(x2−x,6,10,8)\mathrm{HenselLift}(x^2-x, 5, 10, 8)\mathrm{HenselLift}(x^2-x, 6, 10, 8)OutAdicNumeral(10,0,8)\mathrm{AdicNumeral}(10, 0, 8)InHenselLift(x2−x,5,10,8)+HenselLift(x2−x,6,10,8)\mathrm{HenselLift}(x^2-x, 5, 10, 8)+\mathrm{HenselLift}(x^2-x, 6, 10, 8)OutAdicNumeral(10,1,8)\mathrm{AdicNumeral}(10, 1, 8)InIntegerDigits(12 890 625,ResidueNumerals([256,390 625]))\mathrm{IntegerDigits}(12\,890\,625, \mathrm{ResidueNumerals}(\bigl\lbrack256, 390\,625\bigr\rbrack))Out[1,0]\bigl\lbrack1, 0\bigr\rbrack
source · editable

Roots that exist nowhere else ​

Hensel's lemma is Newton's method run in Zp\mathbb{Z}_p: a simple root mod pp lifts to a root mod every pkp^k, doubling its correct digits each step. So 2\sqrt{2} exists in Z7\mathbb{Z}_7 (since 32=9≡23^2 = 9 ≡ 2), −7\sqrt{-7} exists in Z2\mathbb{Z}_2 (since −7≡1(mod8)-7 ≡ 1 \pmod 8), and 3\sqrt{3} does not exist in Z7\mathbb{Z}_7 at all. These values are known only to a precision, and print with their O-term; arithmetic with them carries the precision along.

Hensel

A square root of 2 in ℤ₇ to six digits, squared back; the same root by HenselLift; −7's root in ℤ₂; and 3's absence in ℤ₇.

InAdicSqrt(AdicNumeral(7,2),6)\mathrm{AdicSqrt}(\mathrm{AdicNumeral}(7, 2), 6)OutAdicNumeral(7,38 181,6)\mathrm{AdicNumeral}(7, 38\,181, 6)InAdicSqrt(AdicNumeral(7,2),6)2\mathrm{AdicSqrt}(\mathrm{AdicNumeral}(7, 2), 6)^2OutAdicNumeral(7,2,6)\mathrm{AdicNumeral}(7, 2, 6)InHenselLift(x2−2,3,7,6)\mathrm{HenselLift}(x^2-2, 3, 7, 6)OutAdicNumeral(7,38 181,6)\mathrm{AdicNumeral}(7, 38\,181, 6)InAdicExpansion(AdicSqrt(AdicNumeral(2,−7),10))\mathrm{AdicExpansion}(\mathrm{AdicSqrt}(\mathrm{AdicNumeral}(2, -7), 10))Out…0010110101 + O(2^10)\text{…0010110101 + O(2\textasciicircum{}10)}InAdicSqrt(AdicNumeral(7,3))\mathrm{AdicSqrt}(\mathrm{AdicNumeral}(7, 3))OutAdicSqrt(AdicNumeral(7,3))\mathrm{AdicSqrt}(\mathrm{AdicNumeral}(7, 3))
source · editable

Where they align and where they differ ​

on…positional base bbresidue system [m1,…][m_1, \ldots]bb-adic
n≥0n ≥ 0digits of nnn mod min \bmod m_i, each channelthe same digits, padded to the cut
n<0n < 0a signwraps: n mod min \bmod m_iinfinitely many leading b−1b-1: −1=…999-1 = \ldots 999
1/31/3recurs to the right3−1 mod mi3^{-1} \bmod m_i, if it existsrecurs to the left: …6667\ldots 6667; an integer
1/21/2 in base 100.50.52−1 mod mi2^{-1} \bmod m_i, if mim_i odddoes not exist in Z10\mathbb{Z}_{10}
1/251/25 in base 50.040.04needs gcd⁡(25,mi)=1\gcd(25, m_i) = 10.010.01: digits past the point, Q5\mathbb{Q}_5
2\sqrt{2} in base 7irrational, no finite stringa residue mod each mim_i, no coherencea genuine element of Z7\mathbb{Z}_7, by Hensel
e2=ee^2 = e, e≠0,1e ≠ 0, 1none(1,0)(1, 0) and (0,1)(0, 1) across channels…890625\ldots 890625 and …109376\ldots 109376 in Z10\mathbb{Z}_{10}; none for prime bb
"close to zero"small absolute value—divisible by a high power of bb
moduli pikp_i^{k}, ∏=bk\prod = b^k—is the bb-adic truncation, split by primereads back mod each pikp_i^k

The last row is the one to keep. A residue system whose moduli are the prime-power factors of bkb^k carries exactly the information of the last kk bb-adic digits — the Chinese remainder theorem is the isomorphism Z/bk≅∏Z/pik\mathbb{Z}/b^k ≅ \prod \mathbb{Z}/p_i^{k}, and letting k→∞k → ∞ is what turns the residue system's independent channels into Zb≅∏Zpi\mathbb{Z}_b ≅ \prod \mathbb{Z}_{p_i}.

Things worth knowing ​

Exact until it isn't. AdicNumeral(10, 1/3) is an exact rational, and its expansion can be produced to any depth. A Hensel lift is known only modulo bprecb^{prec} and says so with + O(b^prec); anything computed from it inherits the cap. The default precision is 20 digits.

Composite bases decline division by non-units. AdicNumeral(10, 3) / 2 is left standing: 2 has no inverse in Z10\mathbb{Z}_{10}, and there is no 1010-adic field to put 3/23/2 in. Prime bases divide by anything non-zero.

Digits are listed least significant first. AdicDigits lists from the valuation upward, because that is the end the expansion has; AdicExpansion prints them the familiar way round with the infinite end marked by an ellipsis.

Pinned against Sage. Expansions, valuations, square roots and products are checked against Sage's Zp/Qp for prime bases; Sage has no composite bases, so those are pinned by their algebra — the idempotents, the zero divisor, 1/3×3=11/3 × 3 = 1.