FLINT3.7.0-dev
Algorithm

The p-adic exponential and logarithm

Cost
For an argument of valuation vv to precision NN: rectangular splitting O(N/v)O(\sqrt{N/v}) multiplications of O(Nlog⁡p)O(N \log p)-bit integers plus O(N/v)O(N/v) cheap operations; balanced method O(M(N(log⁡p+log⁡N))log⁡2N)O(M(N(\log p + \log N)) \log^2 N) bit operations.

The exponential and the logarithm of pp-adic numbers are defined by the same power series as over the reals,

exp⁡(x)=∑i≥0xii!,log⁡(1−y)=−∑i≥1yii,\exp(x) = \sum_{i \ge 0} \frac{x^i}{i!}, \qquad \log(1 - y) = -\sum_{i \ge 1} \frac{y^i}{i},

but the series converge only on small discs, and the denominators i!i! and ii are divisible by pp for large ii. The same algorithms are used in Qp\mathbf{Q}_p (padic, padic_radix) and in the unramified extensions Qq\mathbf{Q}_q (qadic), where the arguments are polynomials reduced modulo the defining polynomial but the coefficients of the series are the same rational numbers.

Convergence and truncation#

Legendre's formula gives ord⁡p(i!)=(i−sp(i))/(p−1)\operatorname{ord}_p(i!) = (i - s_p(i))/(p - 1), where sp(i)≥1s_p(i) \ge 1 is the sum of the base-pp digits of i≥1i \ge 1. Hence ord⁡p(i!)≤(i−1)/(p−1)\operatorname{ord}_p(i!) \le (i - 1)/(p - 1), with equality when ii is a power of pp.

Lemma 1 (Terms of the exponential). If ord⁡p(x)=v\operatorname{ord}_p(x) = v then ord⁡p(xi/i!)≥iv−(i−1)/(p−1)\operatorname{ord}_p(x^i / i!) \ge iv - (i - 1)/(p - 1), with equality for i=pki = p^k. The series exp⁡(x)\exp(x) converges if and only if v>1/(p−1)v > 1/(p - 1), that is, v≥1v \ge 1 for odd pp and v≥2v \ge 2 for p=2p = 2. In that case every term with i≥1i \ge 1 has valuation at least vv, so exp⁡(x)∈1+xZp\exp(x) \in 1 + x\mathbf{Z}_p is a unit.

Proof. The bound follows from Legendre's formula. If v>1/(p−1)v > 1/(p - 1), the right-hand side i(v−1/(p−1))+1/(p−1)i(v - 1/(p - 1)) + 1/(p - 1) tends to infinity, and it is at least vv for i≥1i \ge 1 because it is increasing in ii. If v≤1/(p−1)v \le 1/(p - 1), the terms with i=pki = p^k have valuation pk(v−1/(p−1))+1/(p−1)≤1/(p−1)<1p^k(v - 1/(p - 1)) + 1/(p - 1) \le 1/(p - 1) < 1, so infinitely many terms are not divisible by pp and the series diverges.

Theorem 2 (Truncation of the exponential). Let 1/(p−1)<v<N1/(p - 1) < v < N and

n=⌈(p−1)N−1(p−1)v−1⌉.n = \left\lceil \frac{(p - 1)N - 1}{(p - 1)v - 1} \right\rceil .

Then ord⁡p(xi/i!)≥N\operatorname{ord}_p(x^i/i!) \ge N for all i≥ni \ge n, so exp⁡(x)≡∑i<nxi/i!(modpN)\exp(x) \equiv \sum_{i < n} x^i / i! \pmod{p^N}.

Proof. For i≥ni \ge n we have i((p−1)v−1)≥(p−1)N−1i((p - 1)v - 1) \ge (p - 1)N - 1, which is equivalent to iv−(i−1)/(p−1)≥Niv - (i - 1)/(p - 1) \ge N; apply Lemma 1.

_padic_exp_bound returns this nn when pp fits in a slong. For larger pp it returns ⌈N/v⌉\lceil N/v \rceil, which is correct because then n≤N<pn \le N < p and i!i! is a unit for all i<pi < p.

Theorem 3 (Truncation of the logarithm). Let ord⁡p(y)=v≥1\operatorname{ord}_p(y) = v \ge 1. Then ord⁡p(yi/i)≥iv−⌊log⁡pi⌋\operatorname{ord}_p(y^i / i) \ge iv - \lfloor \log_p i \rfloor, the series log⁡(1−y)\log(1 - y) converges, and ord⁡p(yi/i)≥N\operatorname{ord}_p(y^i/i) \ge N for every i≥bi \ge b whenever bv−⌈log⁡pb⌉≥Nbv - \lceil \log_p b \rceil \ge N and b≥2b \ge 2.

Proof. The first statement holds because pord⁡p(i)≤ip^{\operatorname{ord}_p(i)} \le i. The function g(i)=iv−⌈log⁡pi⌉g(i) = iv - \lceil \log_p i \rceil satisfies g(i+1)−g(i)≥v−1≥0g(i + 1) - g(i) \ge v - 1 \ge 0, since ⌈log⁡pi⌉\lceil \log_p i \rceil increases by at most one from ii to i+1i + 1; hence g(i)≥g(b)≥Ng(i) \ge g(b) \ge N for i≥bi \ge b, and iv−ord⁡p(i)≥g(i)iv - \operatorname{ord}_p(i) \ge g(i).

_padic_log_bound starts from the estimate b=⌈(c+⌈log⁡pc⌉+1)/v⌉b = \lceil (c + \lceil \log_p c \rceil + 1)/v \rceil with c=N−⌊log⁡pv⌋c = N - \lfloor \log_p v \rfloor and decreases bb while bv−⌈log⁡pb⌉≥Nbv - \lceil \log_p b \rceil \ge N still holds, returning the least such b≥2b \ge 2. The logarithm converges for v≥1v \ge 1 for every pp, including p=2p = 2; then log⁡(1−y)\log(1 - y) has valuation at least vv.

Rectangular splitting#

A polynomial ∑i<ncixi\sum_{i < n} c_i x^i can be evaluated with m+n/mm + n/m multiplications of full-size elements, by computing the powers x2,…,xmx^2, \ldots, x^m once and writing the sum as ∑j(∑i<mcjm+ixi)xjm\sum_j \bigl(\sum_{i < m} c_{jm + i} x^i\bigr) x^{jm}, evaluated by Horner's rule in xmx^m; the inner sums need only multiplications by the scalars cic_i [PS1973]. With m≈nm \approx \sqrt n this is about 2n2\sqrt n multiplications.

For the exponential, the coefficients 1/i!1/i! are not pp-adic integers, so FLINT multiplies through by (n−1)!(n - 1)!: the coefficients (n−1)!/i!(n - 1)!/i! are integers, built block by block as products of small integers, and the sum S=∑i<n((n−1)!/i!)xiS = \sum_{i < n} ((n-1)!/i!) x^i is computed modulo pN+kp^{N + k} with k=⌊(n−2)/(p−1)⌋≥ord⁡p((n−1)!)k = \lfloor (n - 2)/(p - 1) \rfloor \ge \operatorname{ord}_p((n - 1)!). Since exp⁡(x)\exp(x) is a unit, ord⁡p(S)=ord⁡p((n−1)!)\operatorname{ord}_p(S) = \operatorname{ord}_p((n - 1)!); the factors of pp are removed from SS and (n−1)!(n-1)!, and the unit part of (n−1)!(n - 1)! is inverted modulo pNp^N (Hensel lifting of inverses, square roots and Teichmüller lifts). The guard digits kk guarantee that S/(n−1)!S / (n-1)! is correct modulo pNp^N. The logarithm is handled in the same way, with the block denominators ∏i(jb+i)\prod_{i} (jb + i) in place of (n−1)!(n - 1)! and k=⌊log⁡pn⌋k = \lfloor \log_p n \rfloor guard digits; each block is scaled by its own inverted denominator times pkp^k, and the total is divided by pkp^k at the end.

The cost is O(n)O(\sqrt{n}) multiplications of integers of O((N+k)log⁡p)O((N + k) \log p) bits, where n≈N/vn \approx N/v, plus O(n)O(n) multiplications by single-word integers. Small arguments (n≤3n \le 3) are handled by explicit formulas.

The balanced method#

Brent's bit-burst method [Bre1976b] evaluates exp⁡(x)\exp(x) for a real xx by splitting xx into pieces with exponentially growing numbers of bits and handling each piece by binary splitting. FLINT uses the pp-adic analogue. Write the integer representative of xx modulo pNp^N in base pp and cut it at the digit positions 2,4,8,…2, 4, 8, \ldots:

x=x0+x1+x2+⋯ ,xj∈pwjZ,0≤xj<p2wj,wj=2j,x = x_0 + x_1 + x_2 + \cdots, \qquad x_j \in p^{w_j}\mathbb{Z}, \quad 0 \le x_j < p^{2 w_j}, \quad w_j = 2^j,

where x0x_0 consists of the digits below p2p^2. Then exp⁡(x)=∏jexp⁡(xj)\exp(x) = \prod_j \exp(x_j), and each factor is a series with argument of valuation at least wjw_j, so by Theorem 2 about N/wjN/w_j terms are needed, while the argument has only 2wj2w_j digits.

Algorithm 1: Binary splitting for a short exponential series

Input: an integer xx and 1≤a<b1 \le a < b.

Output: integers P=xb−aP = x^{b - a}, Q=(b−1)!/(a−1)!Q = (b-1)!/(a-1)! and TT with T/Q=∑i=ab−1xi−a+1(a−1)!/i!T/Q = \sum_{i=a}^{b-1} x^{i - a + 1}(a-1)!/i!.

  1. If b−a≤2b - a \le 2, return the values directly.
  2. Otherwise let m=⌊(a+b)/2⌋m = \lfloor (a + b)/2 \rfloor, compute (P1,Q1,T1)(P_1, Q_1, T_1) for [a,m)[a, m) and (P2,Q2,T2)(P_2, Q_2, T_2) for [m,b)[m, b) recursively, and return P1P2P_1 P_2, Q1Q2Q_1 Q_2 and T1Q2+P1T2T_1 Q_2 + P_1 T_2.

The values are exact integers. At the top level, with a=1a = 1, exp⁡(xj)=1+T/Q\exp(x_j) = 1 + T/Q, and since exp⁡(xj)\exp(x_j) is a unit, ord⁡p(T+Q)=ord⁡p(Q)\operatorname{ord}_p(T + Q) = \operatorname{ord}_p(Q): the common power of pp is removed and the unit part of QQ inverted modulo pNp^N. For the piece xjx_j with nj≈N/wjn_j \approx N/w_j terms the integers at the root have O(nj⋅wjlog⁡p+njlog⁡nj)=O(Nlog⁡p+njlog⁡nj)O(n_j \cdot w_j \log p + n_j \log n_j) = O(N \log p + n_j \log n_j) bits, so the binary splitting costs O(M(N(log⁡p+log⁡N))log⁡N)O(M(N(\log p + \log N)) \log N), and the O(log⁡N)O(\log N) pieces together cost O(M(N(log⁡p+log⁡N))log⁡2N)O(M(N(\log p + \log N)) \log^2 N). For p=2p = 2 the first piece is zero, since xx has valuation at least 2.

For the logarithm a product decomposition is needed instead. With x=1−yx = 1 - y, write y=r0+sy = r_0 + s where r0r_0 holds the digits of yy below p2p^2. Then

1−y=(1−r0)(1−s1−r0),1 - y = (1 - r_0)\Bigl(1 - \frac{s}{1 - r_0}\Bigr),

and t=s/(1−r0)t = s/(1 - r_0) has valuation at least 2. Repeating the step on tt with the cut at p4p^4, then p8p^8, and so on, gives log⁡(1−y)=∑jlog⁡(1−rj)\log(1 - y) = \sum_j \log(1 - r_j) with rjr_j of valuation at least 2j2^j and fewer than 2j+12^{j+1} digits. Each logarithm is summed by binary splitting of ∑i≥1rji/i\sum_{i \ge 1} r_j^i / i (with QQ the product of the indices), and the divisions by 1−rj1 - r_j are inversions modulo pNp^N that reuse one set of precomputed powers (_padic_inv_precomp). The cost is of the same order as for the exponential.

The Satoh–Skjernaa–Taguchi reduction#

Lemma 4. If ord⁡p(a−1)≥1\operatorname{ord}_p(a - 1) \ge 1 then ord⁡p(ap−1)≥ord⁡p(a−1)+1\operatorname{ord}_p(a^p - 1) \ge \operatorname{ord}_p(a - 1) + 1; hence ord⁡p(apk−1)≥k+1\operatorname{ord}_p(a^{p^k} - 1) \ge k + 1.

Proof. Write a=1+ha = 1 + h with ord⁡p(h)=w≥1\operatorname{ord}_p(h) = w \ge 1. Then ap−1=ph+(p2)h2+⋯+hpa^p - 1 = ph + \binom{p}{2}h^2 + \cdots + h^p. The middle binomial coefficients are divisible by pp, so those terms have valuation at least 1+2w1 + 2w, and hph^p has valuation pw≥w+1pw \ge w + 1.

Since log⁡(apk)=pklog⁡(a)\log(a^{p^k}) = p^k \log(a), the logarithm of aa modulo pNp^N is p−kp^{-k} times the logarithm of apka^{p^k} modulo pN+kp^{N + k}, and by Lemma 4 the series for the latter has argument of valuation at least k+1k + 1, so only about (N+k)/(k+1)(N + k)/(k + 1) terms. Satoh, Skjernaa and Taguchi used this to compute logarithms in point counting [SST2003]. _padic_log_satoh takes k=⌊N⌋k = \lfloor \sqrt N \rfloor, computes apka^{p^k} modulo pN+kp^{N + k} by fmpz_powm, evaluates its logarithm by rectangular splitting and divides by pkp^k exactly; for N<16N < 16 it calls _padic_log_rectangular directly.

Use in FLINT#

FunctionMethodSelected by default
_padic_exp_rectangular, padic_exp_rectangularrectangular splitting_padic_exp for N<1024N < 1024
_padic_exp_balanced, padic_exp_balancedbit-burst with binary splitting_padic_exp for N≥1024N \ge 1024
_padic_log_rectangular, padic_log_rectangularrectangular splitting_padic_log for N<512/⌈log⁡2(p+1)⌉N < 512/\lceil\log_2 (p+1)\rceil
_padic_log_balanced, padic_log_balancedproduct decomposition with binary splitting_padic_log otherwise
_padic_log_satoh, padic_log_satohpower apka^{p^k}, then rectangular splittingnever
_qadic_exp_rectangular, _qadic_exp_balancedas for padic, in Zq\mathbf{Z}_q_qadic_exp for N<8192/⌈log⁡2(p+1)⌉N < 8192/\lceil\log_2 (p+1)\rceil, resp. otherwise
_qadic_log_rectangular, _qadic_log_balancedas for padic, in Zq\mathbf{Z}_q_qadic_log for N<1024/⌈log⁡2(p+1)⌉N < 1024/\lceil\log_2 (p+1)\rceil, resp. otherwise
_padic_radix_exp_rectangular, _padic_radix_exp_balancedas above, in radix arithmeticrectangular for NN below 80 to 200, depending on the size of pp
_padic_radix_log_rectangular, _padic_radix_log_balancedas above, in radix arithmeticrectangular for NN below 80 to 350, depending on the size of pp

qadic_norm_analytic computes norms as exp⁡(Tr⁡log⁡(x))\exp(\operatorname{Tr} \log(x)) with these functions (Norm).

The radix versions in padic_radix refine the methods: the rectangular splitting works in fixed point on limbs of radix pep^e and defers all denominators to a single inversion; the balanced exponential tracks the factor pwjp^{w_j} of each piece as a digit shift, so that the series is evaluated with a working precision of about N−wjN - w_j digits, and uses a precomputed table of powers in the binary splitting tree (the scheme of _arb_exp_sum_bs_powtab).

Referenced from#

References#

  • [PS1973] M. S. Paterson and L. J. Stockmeyer, "On the number of nonscalar multiplications necessary to evaluate polynomials", SIAM J. Comput (1973)
  • [Bre1976b] R. P. Brent. The complexity of multiple-precision evaluation of elementary functions. In J. F. Traub (ed.), Analytic Computational Complexity, Academic Press, 1976, 151–176.
  • [SST2003] T. Satoh, B. Skjernaa and Y. Taguchi. Fast computation of canonical lifts of elliptic curves and its application to point counting. Finite Fields and Their Applications 9 (2003), 89–101. https://doi.org/10.1016/S1071-5797(02)00013-8
Cite this page

The FLINT team, “The p-adic exponential and logarithm,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/p-adic/exp-log.html (generated 2026-11-02).