Digit agreement and p-adic distance (source code)

= Digit agreement and p-adic distance
{title2=$x\equiv y\pmod{p^n}\iff d_p(x,y)\leq p^{-n}$}

Two <p-adic integers> agree in their first $n$ low-order <p-adic digits> precisely when their difference is divisible by $p^n$. Equivalently,
$$
x\equiv y\pmod{p^n}\quad\Longleftrightarrow\quad
v_p(x-y)\geq n\quad\Longleftrightarrow\quad
|x-y|_p\leq p^{-n}.
$$
If the first differing digit has index $j$, the remaining leading coefficient is nonzero modulo $p$, giving exact <P-adic valuation> $j$ and <p-adic metric> $p^{-j}$. If no digit differs, the two elements are equal and their distance is zero. Truncating at $r_n$ therefore gives $|x-r_n|_p\leq p^{-n}$, with a stricter bound possible when further digits are zero.