ℕ: 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.
Positional notation writes a number as digits that stop on the left and may run forever on the right: 1/3=0.333…. Turn that around — digits that stop on the right and run forever on the left — and the same long division gives 1/3=…6667, because …6667×3=…0001. Those are the b-adic numbers: the completion of the rationals under the rule that divisible by a high power of b 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 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.
Fixed radix drops the sign. Balanced ternary spells it with negative digits. The b-adics spell it with digits alone, infinitely many of them: −1=…9999, because adding 1 carries forever and leaves zero. A residue system wraps instead — −3 mod 7 is 4 — which is the same idea cut at each modulus.
Positional, balanced, adic, residue. The adic string is the one that makes −3 + 3 = 0 by ordinary column addition.
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, not 99999997. The width does the work — [7] alone reads as −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.
The arithmetic is the ordinary ring arithmetic; the printed form is what a column addition of …999 and 1 leaves behind.
1/3 has no finite decimal — the digits recur to the right. It has no finite 10-adic expansion either — the digits recur to the left — but as a 10-adic integer it is a perfectly good element: …6667, and multiplying by 3 gives 1. A residue system gets there a third way: 1/3 is whatever multiplies 3 to give 1 in each channel independently, which is the modular inverse.
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.
The base decides which rationals are integers. In Z10, 1/3 is an integer and 1/2 is not — there is no 10-adic digit string that 2 multiplies to …0001, since 2× anything ends in an even digit. Same in Z2: 1/3 is the alternating …10101011, and 1/2 has no expansion at all.
1/3 in ℤ₂ and ℤ₁₀; 1/2 declines in both. The last cell is 1/3 in ℤ₇ — every base coprime to 3 has one.
For a prime p the story completes: Qp is a field, and dividing by p just moves the point. 7/25 in Q5 is 0.12 — two digits past the point, because 7/25=2⋅5−2+1⋅5−1. The valuation counts those places: v5(75)=2, v5(3/25)=−2. The norm ∣x∣p=p−v is the distance: 75 is small 5-adically, at 1/25 from zero.
A point in the numeral, and the valuation that says where it goes.
A composite base gives a ring instead, and a strange one. Z10 contains two numbers e,f with e2=e, f2=f, e+f=1, and e⋅f=0 — neither of them is 0 or 1. They come from Hensel lifting x2=x from its roots 5 and 6 mod 10, and they are the reason Z10≅Z2×Z5: one idempotent is (0,1) and the other (1,0). This is the residue system's "independent channels" again, at infinite precision. A residue system with moduli 2k,5k is the 10-adic truncation with its two factors pulled apart.
…890625 and …109376: each is its own square, they sum to 1, and their product is 0. No prime base has anything like them.
Hensel's lemma is Newton's method run in Zp: a simple root mod p lifts to a root mod every pk, doubling its correct digits each step. So 2 exists in Z7 (since 32=9≡2), −7 exists in Z2 (since −7≡1(mod8)), and 3 does not exist in Z7 at all. These values are known only to a precision, and print with their O-term; arithmetic with them carries the precision along.
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 ℤ₇.
| on… | positional base b | residue system [m1,…] | b-adic |
|---|---|---|---|
| n≥0 | digits of n | nmodmi, each channel | the same digits, padded to the cut |
| n<0 | a sign | wraps: nmodmi | infinitely many leading b−1: −1=…999 |
| 1/3 | recurs to the right | 3−1modmi, if it exists | recurs to the left: …6667; an integer |
| 1/2 in base 10 | 0.5 | 2−1modmi, if mi odd | does not exist in Z10 |
| 1/25 in base 5 | 0.04 | needs gcd(25,mi)=1 | 0.01: digits past the point, Q5 |
| 2 in base 7 | irrational, no finite string | a residue mod each mi, no coherence | a genuine element of Z7, by Hensel |
| e2=e, e=0,1 | none | (1,0) and (0,1) across channels | …890625 and …109376 in Z10; none for prime b |
| "close to zero" | small absolute value | — | divisible by a high power of b |
| moduli pik, ∏=bk | — | is the b-adic truncation, split by prime | reads back mod each pik |
The last row is the one to keep. A residue system whose moduli are the prime-power factors of bk carries exactly the information of the last k b-adic digits — the Chinese remainder theorem is the isomorphism Z/bk≅∏Z/pik, and letting k→∞ is what turns the residue system's independent channels into Zb≅∏Zpi.
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 bprec 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, and there is no 10-adic field to put 3/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=1.