FLINT3.7.0-dev
Algorithm

Precision and representation of p-adic numbers

Cost
Representation only; reduction modulo pN−vp^{N - v} costs one division of an integer of O((N−v)log⁡p)O((N - v)\log p) bits.

A pp-adic number can only be stored approximately, as a residue class modulo a power of pp. 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 x∈Qpx \in \mathbf{Q}_p can be written uniquely as x=pvux = p^v u with v=ord⁡p(x)∈Zv = \operatorname{ord}_p(x) \in \mathbb{Z} and uu a pp-adic unit, that is, u∈Zp×u \in \mathbf{Z}_p^\times. We write x+O(pN)x + O(p^N) for the set x+pNZpx + p^N \mathbf{Z}_p, the ball of radius p−Np^{-N} around xx. An approximation x+O(pN)x + O(p^N) has absolute precision NN; if ord⁡p(x)=v<N\operatorname{ord}_p(x) = v < N it has relative precision N−vN - v, the number of known pp-adic digits of the unit. If v≥Nv \ge N the approximation is indistinguishable from zero.

In FLINT the unit is an integer uu, so the approximation is pvu+O(pN)p^v u + O(p^N) with u∈Zu \in \mathbb{Z}, p∤up \nmid u, and uu reduced modulo pN−vp^{N - v}. Storing uu (an fmpz, or a radix_integer_t in padic_radix) and vv separately has two advantages over storing the integer pvup^v u: 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 pp. 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 ord⁡p(x)=v\operatorname{ord}_p(x) = v, ord⁡p(y)=w\operatorname{ord}_p(y) = w, and let δ,ε\delta, \varepsilon have valuations at least aa and bb, with a>va > v and b>wb > w. Then

  1. (x+δ)±(y+ε)∈x±y+O(pmin⁡(a,b))(x + \delta) \pm (y + \varepsilon) \in x \pm y + O(p^{\min(a, b)});
  2. (x+δ)(y+ε)∈xy+O(pmin⁡(a+w,b+v))(x + \delta)(y + \varepsilon) \in xy + O(p^{\min(a + w, b + v)});
  3. 1/(x+δ)∈1/x+O(pa−2v)1/(x + \delta) \in 1/x + O(p^{a - 2v});
  4. (x+δ)e∈xe+O(pa+(e−1)v)(x + \delta)^e \in x^e + O(p^{a + (e - 1)v}) for e≥1e \ge 1.

In each case the precision on the right cannot be improved in general.

Proof. The first statement is the ultrametric inequality. For the second, (x+δ)(y+ε)−xy=xε+yδ+δε(x + \delta)(y + \varepsilon) - xy = x\varepsilon + y\delta + \delta\varepsilon, whose terms have valuations at least v+bv + b, w+aw + a and a+b>max⁡(v+b,w+a)a + b > \max(v + b, w + a). For the third, 1/(x+δ)−1/x=−δ/(x(x+δ))1/(x + \delta) - 1/x = -\delta / (x(x + \delta)) and ord⁡p(x+δ)=v\operatorname{ord}_p(x + \delta) = v since a>va > v. The fourth follows from (x+δ)e−xe=∑i≥1(ei)xe−iδi(x + \delta)^e - x^e = \sum_{i \ge 1} \binom{e}{i} x^{e - i} \delta^i, whose terms have valuation at least (e−i)v+ia≥(e−1)v+a(e - i)v + ia \ge (e - 1)v + a. Taking δ=pa\delta = p^a and ε=pb\varepsilon = p^b 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 rr and ss is known to relative precision min⁡(r,s)\min(r, s), 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 uu be a unit of Zp\mathbf{Z}_p and ord⁡p(δ)≥a≥1\operatorname{ord}_p(\delta) \ge a \ge 1.

  1. If pp is odd and u=s2u = s^2, then u+δu + \delta has a square root in s+O(pa)s + O(p^a). If p=2p = 2, a≥3a \ge 3 and u=s2u = s^2, then u+δu + \delta has a square root in s+O(2a−1)s + O(2^{a - 1}).
  2. If exp⁡(x)\exp(x) converges, then exp⁡(x+δ)∈exp⁡(x)(1+O(pa))\exp(x + \delta) \in \exp(x)(1 + O(p^a)), provided exp⁡(δ)\exp(\delta) converges.
  3. If log⁡(u)\log(u) converges, then log⁡(u+δ)∈log⁡(u)+O(pa)\log(u + \delta) \in \log(u) + O(p^a).

Proof. For the first statement, (u+δ)/u=1+δ/u(u + \delta)/u = 1 + \delta/u and ord⁡p(δ/u)=a\operatorname{ord}_p(\delta/u) = a. For odd pp the binomial series 1+t=∑(1/2k)tk\sqrt{1 + t} = \sum \binom{1/2}{k} t^k has coefficients in Zp\mathbf{Z}_p, so 1+δ/u∈1+O(pa)\sqrt{1 + \delta/u} \in 1 + O(p^a); for p=2p = 2 the coefficients (1/2k)\binom{1/2}{k} have 2-adic valuation at least −2k+1-2k + 1 for k≥1k \ge 1, so for a≥3a \ge 3 the series converges and lies in 1+O(2a−1)1 + O(2^{a - 1}). Multiplying by ss gives the claim. The second statement is the functional equation exp⁡(x+δ)=exp⁡(x)exp⁡(δ)\exp(x + \delta) = \exp(x) \exp(\delta) together with exp⁡(δ)∈1+O(pa)\exp(\delta) \in 1 + O(p^a) (Lemma 1 of The p-adic exponential and logarithm). For the third, log⁡(u+δ)=log⁡(u)+log⁡(1+δ/u)\log(u + \delta) = \log(u) + \log(1 + \delta/u), and the logarithm of 1+t1 + t with ord⁡p(t)≥a\operatorname{ord}_p(t) \ge a has valuation at least aa, because ord⁡p(ti/i)≥ia−log⁡pi≥a\operatorname{ord}_p(t^i / i) \ge ia - \log_p i \ge a.

The fixed-precision model of padic and qadic#

In padic, every variable has a precision NN that is set when it is initialised. The value pvup^v u is kept reduced: uu is a nonnegative integer coprime to pp and smaller than pN−vp^{N - v}, or u=v=0u = v = 0. A function computes the exact result of the operation applied to the stored values, which are elements of Z[1/p]\mathbb{Z}[1/p] (or, for a square root or logarithm, of Qp\mathbf{Q}_p), and reduces it modulo pNp^N for the precision NN 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 p20p^{20} 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 pvg(X)p^v g(X) of Qq\mathbf{Q}_q, where gg is a polynomial whose coefficients are reduced modulo pN−vp^{N - v} and not all divisible by pp, 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 w>vw > v is stored to relative precision N−wN - w, and coefficients of valuation at least NN are zero.

Overviewp-adic arithmetic in FLINTThe modules for p-adic numbers, their precision models and representations, and which algorithm each function uses for inversion, square roots, the exponential and logarithm, Teichmüller lifts, the Frobenius map, norms and traces.

The ball model of padic_radix#

In padic_radix, an element is a ball pvu+O(pN)p^v u + O(p^N) with its own absolute precision NN, or an exact element without error term. The context fixes a default relative precision rr and absolute precision aa, 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 min⁡(Nx,Ny)\min(N_x, N_y), a product min⁡(Nx+vy,Ny+vx)\min(N_x + v_y, N_y + v_x), a quotient the smaller relative precision of its operands, and a square root for p=2p = 2 one digit less than its operand. The result is then truncated to precision min⁡(a,v+r)\min(a, v + r) for its valuation vv, 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 Z[1/p]\mathbb{Z}[1/p].

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#

Referenced from#

References#

Cite this page

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).