p-adic integer (source code)

= p-adic integer
{c}
{title2=$\mathbb Z_p$}

The <p-adic integers> retain arithmetic information modulo arbitrarily high powers of one <prime number> $p$. They form the <subring>
$$
\boxed{\mathbb Z_p=\{x\in\mathbb Q_p:|x|_p\leq1\}}
$$
of the <P-adic numbers>. Their <p-adic absolute value> bounds the allowed denominators: \b[$1/3$ belongs to $\mathbb Z_2$, while $1/2$ does not]. The name therefore describes a local arithmetic <ring>, not just the ordinary <integers>.<P-adic numbers by Jan-Hendrik Evertse>[§3, printed pp. 6–7: definition of Zp, rational denominators and units]{ref}

A concrete description gives an element by a compatible <sequence> of <congruence classes>:
$$
\mathbb Z_p=\varprojlim_{n\geq1}\mathbb Z/p^n\mathbb Z,\qquad
r_{n+1}\equiv r_n\pmod{p^n}.
$$
The <inverse limit> condition says that gaining more precision must preserve the digits already determined. Each $r_n$ is a residue modulo $p^n$; choosing its least nonnegative <integer> representative gives $0\leq r_n<p^n$. The ordinary integer $13$ gives residues $1,1,5,13$ modulo $2,4,8,16$.

\Image[/padic-compatible-binary-residue-tree.png]
{title=Compatible binary residues describe successive finite precisions of a 2-adic integer}
{description=Original full residue tree through modulus $16$. Each edge reduces a residue to its parent modulus; the highlighted path follows the integer $13$. Four binary digits determine the entire <coset> $13+16\mathbb Z_2$, leaving infinitely many higher-digit choices. Choosing all later digits zero selects the ordinary integer $13$.}

The useful feature is that one exact object organizes an unlimited family of finite <modular arithmetic> calculations. <Addition> and <multiplication> are performed modulo each $p^n$, and the results remain compatible. A <p-adic digit> expansion makes this concrete:
$$
x=\sum_{j\geq0}b_jp^j,\qquad b_j\in\{0,1,\ldots,p-1\},\qquad
r_n=\sum_{j=0}^{n-1}b_jp^j.
$$
The expansion is unique and converges in the <p-adic metric>; its higher powers have smaller <p-adic absolute value>. The <digit agreement and p-adic distance> criterion tells exactly which finite digits a precision bound preserves.<P-adic numbers by Jan-Hendrik Evertse>[§3, Theorem 3.4 and digit/congruence discussion, printed pp. 7–9: unique expansion and agreement of low-order digits]{ref}