Precision and representation of p-adic numbers
- Cost
- Representation only; reduction modulo costs one division of an integer of bits.
A -adic number can only be stored approximately, as a residue class modulo a power of . FLINT uses two models: the fixed-precision model of padic, qadic, padic_poly and padic_mat, where every variable has a precision and inputs are treated as exact, and the ball model of padic_radix, where every element carries its own error term. [Car2017] compares these and other models in detail.
Valuation, absolute and relative precision#
Every nonzero can be written uniquely as with and a -adic unit, that is, . We write for the set , the ball of radius around . An approximation has absolute precision ; if it has relative precision , the number of known -adic digits of the unit. If the approximation is indistinguishable from zero.
In FLINT the unit is an integer , so the approximation is with , , and reduced modulo . Storing (an fmpz, or a radix_integer_t in padic_radix) and separately has two advantages over storing the integer : elements of negative valuation need no special treatment, and the size of the stored integer is proportional to the relative precision, not the absolute precision.
Precision of arithmetic operations#
The following statements describe what is determined about the result when the inputs are known only modulo powers of . They are the rules that padic_radix applies to its error terms, and the rules a user of padic must follow to know which digits of a result are meaningful.
Proposition 1 (Precision of ring operations). Let , , and let have valuations at least and , with and . Then
- ;
- ;
- ;
- for .
In each case the precision on the right cannot be improved in general.
Proof. The first statement is the ultrametric inequality. For the second, , whose terms have valuations at least , and . For the third, and since . The fourth follows from , whose terms have valuation at least . Taking and shows that the bounds are attained.
In terms of relative precision the statements are simpler: a product or quotient of elements known to relative precisions and is known to relative precision , a power to the relative precision of its base, and a sum to an absolute precision that may correspond to a much smaller relative precision if the leading digits cancel.
Proposition 2 (Precision of roots and transcendental functions). Let be a unit of and .
- If is odd and , then has a square root in . If , and , then has a square root in .
- If converges, then , provided converges.
- If converges, then .
Proof. For the first statement, and . For odd the binomial series has coefficients in , so ; for the coefficients have 2-adic valuation at least for , so for the series converges and lies in . Multiplying by gives the claim. The second statement is the functional equation together with (Lemma 1 of The p-adic exponential and logarithm). For the third, , and the logarithm of with has valuation at least , because .
The fixed-precision model of padic and qadic#
In padic, every variable has a precision that is set when it is initialised. The value is kept reduced: is a nonnegative integer coprime to and smaller than , or . A function computes the exact result of the operation applied to the stored values, which are elements of (or, for a square root or logarithm, of ), and reduces it modulo for the precision of the output. This is the analogue of correct rounding in MPFR, and it makes every function deterministic and every result as precise as the output variable allows. It also means that the results are exact functions of the stored representatives, so that, for example, padic_sub of two variables that agree modulo returns their exact difference with as many digits as the output can hold. The precision rules above are not applied; the caller must apply them to know which digits are meaningful.
The same model is used by qadic for elements of , where is a polynomial whose coefficients are reduced modulo and not all divisible by , and by padic_poly and padic_mat, where one valuation and one precision are shared by all coefficients. In these structures a coefficient of valuation is stored to relative precision , and coefficients of valuation at least are zero.
The ball model of padic_radix#
In padic_radix, an element is a ball with its own absolute precision , or an exact element without error term. The context fixes a default relative precision and absolute precision , either of which may be infinite. The functions propagate the error terms by the rules of Proposition 1 and Proposition 2: a sum has precision , a product , a quotient the smaller relative precision of its operands, and a square root for one digit less than its operand. The result is then truncated to precision for its valuation , and the truncation is recorded in the error term. An exact result that fits within this precision is kept exact, so that, with both precisions infinite, the arithmetic is exact arithmetic in .
Applying these rules operation by operation always gives valid error terms, but not always the smallest ones: the guaranteed precision of a result depends on the algorithm. For sums of products and block products, see Error terms of dot products, matrix products and polynomial products; for linear algebra, where full pivoting on valuations and the differential of the function give the optimal precision, see Optimal precision in p-adic linear algebra.
Predicates follow the conventions of the generic rings: padic_radix_equal returns T_FALSE if the balls are disjoint, T_TRUE only if both elements are exact and equal, and T_UNKNOWN otherwise; division by an element that may be zero returns GR_UNABLE.
Use in FLINT#
padic_reduce,_padic_canonicaliseand_padic_reduceimplement canonicalisation and reduction forpadic_t;padic_poly_reduce,padic_poly_canonicalise,padic_mat_reduceandqadic_reducedo the same for the other structures.padic_pow_siandpadic_poly_powstate the precision loss of Proposition 1 for negative valuations but do not apply it.padic_radix_add,padic_radix_mul,padic_radix_div,padic_radix_inv,padic_radix_sqrt,padic_radix_expandpadic_radix_logapply the rules above to their error terms;padic_radix_dotapplies them to whole sums of products (The error term of a sum of products).
Referenced from#
- Error terms of dot products, matrix products and polynomial products (algorithm)
- Optimal precision in p-adic linear algebra (algorithm)
- p-adic arithmetic in FLINT (overview)
- Arithmetic in unramified extensions (algorithm)
- padic.h (module)
padic_pow_si- Precision in the padic module
- padic_poly.h (module)
padic_poly_pow- padic_radix.h (module)
- Interpolation over the p-adic numbers: precision and Mahler's basis (tutorial)
References#
- [Car2017] X. Caruso. Computations with p-adic numbers. Les cours du CIRM 5 (2017), Journées Nationales de Calcul Formel. https://arxiv.org/abs/1701.06794
The FLINT team, “Precision and representation of p-adic numbers,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/p-adic/precision.html (generated 2026-11-02).
@misc{flint-doc-algorithms-p-adic-precision,
author = {{The FLINT team}},
title = {{Precision and representation of p-adic numbers}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/algorithms/p-adic/precision.html},
note = {Generated 2026-11-02}
}