FLINT3.7.0-dev
Algorithm

Multipoint evaluation and interpolation

Cost
O(M(n)log⁡n)O(M(n) \log n) for nn arbitrary points (building the tree, evaluating, interpolating); O(M(n))O(M(n)) for points in geometric progression; O(n2)O(n^2) for the iterative methods used for short inputs.

Evaluating a polynomial of degree less than nn at nn points by Horner's rule costs n2n^2 operations, and Lagrange interpolation through nn points costs the same. Both can be done in O(M(n)log⁡n)O(M(n) \log n) operations by divide and conquer over a binary tree of products of linear factors. This was found independently by Fiduccia [Fid1972] and by Moenck and Borodin [MB1972; BorMoe1974]; Strassen [Str1973] showed that Ω(nlog⁡n)\Omega(n \log n) nonscalar multiplications are necessary for generic points. Textbook accounts are [GG2003, Ch. 10] and [Ber2008], which also describes the scaled remainder tree; Bostan, Lecerf and Schost [BLS2003] use the transposition principle to reduce the constants.

When the points form a geometric progression 1,q,q2,…1, q, q^2, \ldots, evaluation and interpolation are much cheaper: one or two multiplications, by Bluestein's chirp transform [Blu1970] and the algorithm of Bostan and Schost [BS2005].

Throughout, x0,…,xn−1x_0, \ldots, x_{n-1} are the points in R=Z/pZR = \mathbb{Z}/p\mathbb{Z} and M(n)M(n) is the cost of a multiplication of length nn, with M(n)/nM(n)/n nondecreasing.

Generic version#

The subproduct tree is implemented once in gr_poly (_gr_poly_tree_build, _gr_poly_evaluate_vec_fast_precomp, _gr_poly_interpolation_weights, _gr_poly_interpolate_fast_precomp) for any commutative ring. Evaluation needs only divisions by the monic polynomials of the tree and therefore works over every ring; interpolation needs the weights 1/∏j≠i(xi−xj)1 / \prod_{j \ne i} (x_i - x_j) and therefore points whose differences are invertible. nmod_poly, fmpz_mod_poly, fq_poly, arb_poly and acb_poly call these functions with their contexts, and multimodular interpolation over Z\mathbb{Z} (fmpz_poly_interpolate_multi_mod) uses them modulo each prime. Over balls, the tree algorithms give correct enclosures, but the radii can grow much more than with evaluation point by point. The generic gr_poly_interpolate currently uses Newton interpolation with O(n2)O(n^2) operations, which also works over integral domains when the interpolating polynomial has coefficients in the ring; the fast functions must be called explicitly. The algorithms for geometric progressions are specific to nmod_poly.

The subproduct tree#

Assume first n=2kn = 2^k. The subproduct tree has the linear polynomials x−xix - x_i as leaves, and each internal node is the product of its two children. Level ii consists of the n/2in/2^i monic polynomials

Pi,j=∏l=j2i(j+1)2i−1(x−xl),0≤j<n/2i,P_{i,j} = \prod_{l = j 2^i}^{(j+1) 2^i - 1} (x - x_l), \qquad 0 \le j < n/2^i,

of degree 2i2^i, and the root is P=Pk,0=∏l(x−xl)P = P_{k,0} = \prod_l (x - x_l).

Lemma 1. The subproduct tree can be built with O(M(n)log⁡n)O(M(n) \log n) operations.

Proof. Level i+1i + 1 is obtained from level ii by n/2i+1n/2^{i+1} products of polynomials of degree 2i2^i, costing (n/2i+1)M(2i+1)=O(M(n))(n/2^{i+1}) M(2^i + 1) = O(M(n)) since M(n)/nM(n)/n is nondecreasing. There are k=log⁡2nk = \log_2 n levels.

For general nn the same layout is used with k=⌈log⁡2n⌉k = \lceil \log_2 n \rceil; the last node of each level is the product of the remaining n mod 2in \bmod 2^i factors if that number is nonzero.

Evaluation by the remainder tree#

Lemma 2. If AA divides BB, then (f mod B) mod A=f mod A(f \bmod B) \bmod A = f \bmod A. In particular f(xl)=f mod (x−xl)f(x_l) = f \bmod (x - x_l) can be computed by reducing ff successively modulo the nodes on the path from the root to the leaf x−xlx - x_l.

Proof. f−(f mod B)f - (f \bmod B) is a multiple of BB, hence of AA.

Algorithm 1: Fast multipoint evaluation

Input: ff of length at most nn, the subproduct tree of x0,…,xn−1x_0, \ldots, x_{n-1}.

Output: f(x0),…,f(xn−1)f(x_0), \ldots, f(x_{n-1}).

  1. rk,0←f mod Pr_{k,0} \gets f \bmod P (nothing to do if deg⁡f<n\deg f < n).
  2. For i=k−1,…,0i = k - 1, \ldots, 0 and all jj: ri,j←ri+1,⌊j/2⌋ mod Pi,jr_{i,j} \gets r_{i+1, \lfloor j/2 \rfloor} \bmod P_{i,j}.
  3. Return f(xl)=r0,lf(x_l) = r_{0,l}.

Correctness is Lemma 2. Each level costs n/2in/2^i divisions of a polynomial of degree less than 2i+12^{i+1} by one of degree 2i2^i, which with Newton division (Division with remainder) costs O(M(n))O(M(n)) per level. Hence evaluation costs O(M(n)log⁡n)O(M(n) \log n), in addition to the tree. The constant can be lowered by precomputing the inverses of the reversed tree nodes, or by the transposed and scaled remainder trees of [BLS2003] and [Ber2008], which replace the divisions by middle products; FLINT uses the plain remainder tree.

Interpolation#

Let y0,…,yn−1y_0, \ldots, y_{n-1} be values and the xlx_l pairwise distinct with all xl−xmx_l - x_m invertible. The interpolating polynomial of degree less than nn is given by Lagrange's formula

f=∑l=0n−1ylwlPx−xl,wl=∏m≠l(xl−xm)−1.f = \sum_{l=0}^{n-1} y_l w_l \frac{P}{x - x_l}, \qquad w_l = \prod_{m \ne l} (x_l - x_m)^{-1}.

Lemma 3. wl=1/P′(xl)w_l = 1/P'(x_l).

Proof. P′=∑l∏m≠l(x−xm)P' = \sum_l \prod_{m \ne l} (x - x_m), and at x=xlx = x_l all terms but the ll-th vanish.

So the weights are obtained by one multipoint evaluation of P′P' and nn inversions (or one batch inversion). The sum can then be computed going up the tree:

Lemma 4. For a node N=NLNRN = N_L N_R with children NLN_L and NRN_R and coefficients clc_l, let S(N)=∑l∈NclN/(x−xl)S(N) = \sum_{l \in N} c_l N/(x - x_l), the sum over the leaves below NN. Then S(N)=S(NL)NR+S(NR)NLS(N) = S(N_L) N_R + S(N_R) N_L.

Proof. For a leaf ll below NLN_L, N/(x−xl)=NR⋅NL/(x−xl)N/(x - x_l) = N_R \cdot N_L/(x - x_l), and similarly for NRN_R.

Algorithm 2: Fast interpolation

Input: the subproduct tree of distinct x0,…,xn−1x_0, \ldots, x_{n-1}, values y0,…,yn−1y_0, \ldots, y_{n-1}.

Output: the ff of length at most nn with f(xl)=ylf(x_l) = y_l.

  1. Compute P′P' (from the root, or from the two top nodes) and evaluate it at the xlx_l by Algorithm 1; wl←1/P′(xl)w_l \gets 1/P'(x_l).
  2. cl←wlylc_l \gets w_l y_l; these are SS at the leaves.
  3. Going up, compute SS at each node by Lemma 4.
  4. Return f=S(P)f = S(P).

The cost is O(M(n)log⁡n)O(M(n) \log n): one evaluation and, for the combination, two products per node, O(M(n))O(M(n)) per level.

For few points, quadratic methods are faster:

  • Newton interpolation: divided differences O(n2)O(n^2), then conversion from the Newton basis ∏m<l(x−xm)\prod_{m < l} (x - x_m) to the monomial basis in O(n2)O(n^2).
  • Barycentric (Lagrange) interpolation: compute PP, the weights wlw_l directly as products, and add up ylwlP/(x−xl)y_l w_l P/(x - x_l), each quotient obtained by synthetic division (_nmod_poly_div_root).

Geometric progressions#

Let the points be xj=qjx_j = q^j, 0≤j<n0 \le j < n, and write q=r2q = r^2 (FLINT is given rr, so that no square root is needed).

Lemma 5 (Bluestein's trick). Let ff have length ℓ\ell. Since ij=12((i+j)2−i2−j2)ij = \tfrac{1}{2}\bigl((i+j)^2 - i^2 - j^2\bigr), we have qij=r(i+j)2r−i2r−j2q^{ij} = r^{(i+j)^2} r^{-i^2} r^{-j^2} and

f(qj)=r−j2∑i=0ℓ−1(fir−i2)r(i+j)2.f(q^j) = r^{-j^2} \sum_{i=0}^{\ell - 1} \bigl(f_i r^{-i^2}\bigr) r^{(i+j)^2}.

The sum is a correlation of the vector (fir−i2)(f_i r^{-i^2}) with the "chirp" sequence ck=rk2c_k = r^{k^2}, 0≤k<ℓ+n−10 \le k < \ell + n - 1: with aa the reversal of (fir−i2)(f_i r^{-i^2}), f(qj)f(q^j) is r−j2r^{-j^2} times coefficient ℓ−1+j\ell - 1 + j of a⋅ca \cdot c, a middle product (Middle products and the transposition principle). So evaluation at nn points of a geometric progression costs one middle product and O(n)O(n) multiplications. This is the chirp z-transform [RSR1969], also used to compute DFTs of arbitrary length; see [ASU1975] for its use in polynomial evaluation.

Interpolation at a geometric progression uses a qq-analogue of Newton interpolation [BS2005, §5]. With ui=∏k=1i(qk−1)u_i = \prod_{k=1}^{i} (q^k - 1) and Qi=qi(i−1)/2Q_i = q^{i(i-1)/2}, the Newton coefficients of the interpolant are the low coefficients of a single product

(∑iyiuixi)(∑i(−1)iQiuixi),\Bigl(\sum_i \frac{y_i}{u_i} x^i\Bigr)\Bigl(\sum_i (-1)^i \frac{Q_i}{u_i} x^i\Bigr),

up to scaling by QiQ_i, and the change from the Newton basis ∏m<l(x−qm)\prod_{m < l} (x - q^m) to the monomial basis is again one (transposed) product. Hence interpolation costs two products of length nn and O(n)O(n) multiplications. It requires qk−1q^k - 1 to be invertible for 1≤k<n1 \le k < n: the points must be distinct, and for composite modulus their differences must be invertible.

Extrapolation, computing f(qk)f(q^k) for kk outside [0,ℓ)[0, \ell) from the values f(q0),…,f(qℓ−1)f(q^0), \ldots, f(q^{\ell - 1}) of a polynomial of length ℓ\ell, is a single middle product as well:

Lemma 6. For k∉[0,ℓ)k \notin [0, \ell),

f(qk)=∏j=0ℓ−1(qk−qj)∑i=0ℓ−1f(qi) wi q−iqk−i−1,wi=∏j≠i(qi−qj)−1.f(q^k) = \prod_{j=0}^{\ell-1} (q^k - q^j) \sum_{i=0}^{\ell-1} \frac{f(q^i) \, w_i \, q^{-i}}{q^{k-i} - 1}, \qquad w_i = \prod_{j \ne i} (q^i - q^j)^{-1}.

The sum is a convolution of the sequence f(qi)wiq−if(q^i) w_i q^{-i} with the sequence 1/(qm−1)1/(q^m - 1), and the prefactors are products of the numbers qm−1q^m - 1 times powers of qq.

Proof. This is Lagrange's formula f(z)=P(z)∑if(qi)wi/(z−qi)f(z) = P(z) \sum_i f(q^i) w_i/(z - q^i), valid for zz not a node, with z=qkz = q^k and qk−qi=qi(qk−i−1)q^k - q^i = q^i (q^{k-i} - 1).

Use in FLINT#

Arbitrary points.

Geometric progressions. nmod_geometric_progression_init prepares the evaluation, interpolation and extrapolation data for the points 1,r2,r4,…,r2(ℓ−1)1, r^2, r^4, \ldots, r^{2(\ell - 1)}; _nmod_geometric_progression_init_function selects which of the three to prepare and can also store fft_small transforms of the fixed factors (the chirp sequence, the interpolation series and the extrapolation series), so that each later product needs two transforms instead of three. The products of evaluation and extrapolation are middle products in which the fixed factor vv is the long operand, and these are computed as transposed products (Transposed FFT): the precomputation stores the images of vv through the transposed inverse transform (_mul_precomp_init_tr), one transform of length vnv_n rounded up to a multiple of 256 per prime, with vn=2ℓ−1v_n = 2\ell - 1 for the chirp sequence and vn=ℓ−1v_n = \ell - 1 for each of the two extrapolation series, instead of a power of two at least vnv_n; each call then transforms the reversed short operand and applies the transposed forward transform (_nmod_poly_mul_tr_precomp). The interpolation series is stored as an ordinary transform (_mul_precomp_init). A call uses the stored images of vv only if the product would use fft_small anyway, if it fits, and if this is estimated to be cheaper than what _nmod_poly_mulmid_fft_small would do without the precomputation. For p<2FLINT_BITS−1p < 2^{\mathtt{FLINT\_BITS} - 1} the evaluation and interpolation data are computed with Shoup multiplication for the many products by powers of rr. Then

These are the methods of choice whenever the evaluation points can be chosen freely, for example in evaluation–interpolation schemes for products of multivariate or matrix polynomials.

The functions are described, with examples, in Multipoint evaluation and interpolation.

Referenced from#

References#

  • [Fid1972] C. M. Fiduccia, "Polynomial evaluation via the division algorithm: the fast Fourier transform revisited", Proceedings of the 4th Annual ACM Symposium on Theory of Computing (STOC 1972), 88–93
  • [MB1972] R. Moenck and A. Borodin, "Fast modular transforms via division", Proceedings of the 13th Annual Symposium on Switching and Automata Theory (1972), 90–96
  • [BorMoe1974] A. Borodin and R. Moenck, "Fast modular transforms", Journal of Computer and System Sciences 8:3 (1974), 366–386
  • [Str1973] V. Strassen, "Die Berechnungskomplexität von elementarsymmetrischen Funktionen und von Interpolationskoeffizienten", Numerische Mathematik 20 (1973), 238–251
  • [GG2003] J. von zur Gathen and J. Gerhard, Modern Computer Algebra, second edition, Cambridge University Press (2003)
  • [Ber2008] D. J. Bernstein, "Fast multiplication and its applications", in Algorithmic Number Theory, MSRI Publications 44 (2008), 325–384
  • [BLS2003] A. Bostan, G. Lecerf and É. Schost, "Tellegen's principle into practice", ISSAC 2003, 37–44
  • [Blu1970] L. I. Bluestein. A linear filtering approach to the computation of discrete Fourier transform. IEEE Transactions on Audio and Electroacoustics 18:4 (1970), 451–455. https://doi.org/10.1109/TAU.1970.1162132
  • [BS2005] A. Bostan and É. Schost. Polynomial evaluation and interpolation on special sets of points. Journal of Complexity 21 (2005), 420–446.
  • [RSR1969] L. R. Rabiner, R. W. Schafer and C. M. Rader. The chirp z-transform algorithm. IEEE Transactions on Audio and Electroacoustics 17:2 (1969), 86–92. https://doi.org/10.1109/TAU.1969.1162034
  • [ASU1975] A. V. Aho, K. Steiglitz and J. D. Ullman. Evaluating polynomials at fixed sets of points. SIAM Journal on Computing 4 (1975), 533–539.
Cite this page

The FLINT team, “Multipoint evaluation and interpolation,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/polynomials/subproduct-tree.html (generated 2026-11-02).