Multiplying polynomials with ball coefficients
- Cost
- For well-scaled operands of length at precision , one product of integer polynomials with coefficients of bits, bit operations; for the classical algorithm and in the worst case.
Let and be polynomials whose coefficients are balls , . A ball product must contain for all , and every . The classical algorithm evaluates each such sum as one ball dot product (Dot products of balls), which costs multiplications for length but gives nearly optimal enclosures. Fast algorithms (Karatsuba, FFT) cannot simply be run in ball arithmetic: they rely on cancellations that ball arithmetic does not see, so the radii of the output grow like the sum of the absolute values of all intermediate quantities, which for polynomials with coefficients of very different magnitudes destroys the accuracy entirely ([vdH2008], [Hig2002]). FLINT uses the following algorithm instead: the midpoints are multiplied exactly with fast integer polynomial arithmetic, after a scaling and a splitting into blocks that keep the integers small, and the radii are bounded by a separate product of nonnegative polynomials of low precision, following van der Hoeven [vdH2008] and Johansson [Joh2017].
Error bound for the product#
Write with and , , and likewise . For a polynomial , let denote the polynomial whose coefficients are the absolute values of those of , and write if every coefficient of is at most the corresponding coefficient of .
Lemma 1. With the notation above, and ,
Proof. , and the coefficients of a product of polynomials satisfy by the triangle inequality, with , and . For the square, .
So it suffices to compute the product of the midpoints with rigorously bounded rounding error, and upper bounds for one or two products of polynomials with nonnegative coefficients. These products need only a few bits of relative accuracy, because they bound errors.
Scaling and blocks#
The coefficients of a power series often decay or grow geometrically: the coefficients of are , those of are . Representing all of them as integers with a common exponent would need or bits per coefficient. The substitution , which multiplies the coefficient of by , is exact in binary floating-point arithmetic and commutes with multiplication: if , then , and the coefficients of are those of multiplied by .
FLINT chooses as the nearest integer to the average slope of the exponents between the first and the last nonzero midpoint of the two operands: if the first and last nonzero midpoints of have indices and exponents , and those of indices and exponents , then
This is cheap and gives slowly varying scaled coefficients for power series with similar decay rates; it is not optimal in general.
Next, the scaled midpoints of each operand are split into maximal runs of consecutive indices, called blocks, such that within a block all nonzero midpoints are integer multiples of a common power of two and have absolute value below , where the height is at most for the working precision . A block starting at index thus defines an integer polynomial with , exactly, and similarly . Then
where each is a product of integer polynomials, computed exactly by _fmpz_poly_mulmid (Kronecker substitution, Schönhage–Strassen or the small-prime FFT, see Multiplying polynomials over Z). Each output coefficient is the sum of the contributions of all block pairs; each contribution is rounded to bits when it is added, with the rounding error added to the radius. Well-scaled operands form a single block each, and then the midpoint product is one exact integer polynomial product followed by one rounding per coefficient.
The products of nonnegative polynomials in Lemma 1 are computed in the same way. Their coefficients are mag_t numbers with 30-bit mantissas (Representation of radii and midpoints); after the same scaling they are split into blocks of height at most bits. For a pair of blocks of which the shorter has fewer than 1000 coefficients, the product is computed in double-precision floating-point arithmetic, each coefficient being converted exactly to a double with a fixed exponent offset (the block height guarantees that neither the operands nor the products overflow or underflow); otherwise it is computed exactly with integers. The results are converted to upper bounds with mag_set_d_2exp_fmpz and mag_set_fmpz_2exp_fmpz, which round upwards.
Lemma 2 (Floating-point sums of nonnegative products). Let with nonnegative doubles , , and let be the value computed by multiplying and adding in any order in IEEE double precision with rounding to nearest, without overflow or underflow. Then .
Proof. Each product and each partial sum is rounded once, with a relative error factor , . Since all quantities are nonnegative, each term enters multiplied by a product of at most such factors, each at least , so . Hence for . (A fused multiply-add only removes roundings.)
The implementation multiplies the double results by , a comfortable margin over Lemma 2.
Input: , with ball coefficients, a window of output indices, precision . Output: balls .
- Drop the coefficients of each operand that only contribute below or above , and the trailing zero coefficients.
- If some coefficient is not finite, use the classical algorithm.
- Compute the scaling exponent .
- Radii: compute upper bounds for the coefficients of (or of for a square), omitting the terms with or , by block products as described above, and store them as the radii of .
- Midpoints: split , into blocks of height at most ; for each pair of blocks, compute the exact middle product of the integer polynomials and add its coefficients, times the power of two, to the balls with rounding to bits.
- Multiply by .
Theorem 3. For every choice of and , the coefficient of the product lies in the ball computed by Algorithm 1, for .
Proof. Step 1 only removes terms that do not occur in the requested coefficients. The scaling in steps 3 and 6 is exact. In step 5, the block representation of the midpoints is exact and the block products are exact, so the only errors are the roundings when adding the contributions, which ball addition adds to the radii. The midpoint of the result after step 5 therefore differs from the coefficient of by at most the radius accumulated in step 5. By Lemma 1, the coefficient of the exact product differs from that of by at most the coefficient of the bound polynomial, for which step 4 computed an upper bound: the conversions of midpoints to mag_t in step 4 round upwards, the integer products are exact, the double products are bounded by Lemma 2, and the final conversions round upwards.
The block algorithm is about as accurate as the classical one when the scaled coefficients of each operand vary by much less than , as is typical for power series of analytic functions: each coefficient of the product is then rounded once, to bits relative to the largest term in its sum. For badly scaled operands it degenerates gracefully to many small blocks, and in the worst case (every coefficient a block of its own) to the classical algorithm with more overhead.
Selection and cost#
_arb_poly_mullow uses the classical algorithm if the output or one of the operands has length at most 7, or if the output length or twice the length of the shorter operand is at most a cutoff that is 110 for and clamped to above (increased by 25% for squares at and again at ). At high precision, the integer products are long, and the block algorithm wins earlier.
For operands of length that form single blocks, the midpoint product is one integer polynomial product with -bit coefficients, that is, bit operations, and the radius products cost double operations for (fast in practice, since they are simple dot products) and beyond. The classical algorithm costs .
Complex polynomials#
For complex polynomials, _acb_poly_mullow and _acb_poly_mulmid first try _acb_poly_mulmid_fmpzi, when _acb_poly_mulmid_use_fmpzi predicts that it is faster (roughly, when the number of coefficient products per input coefficient times is at least 240, or 330 for squares). It scales both operands as above, using the larger of the real and imaginary midpoints for the slope, writes all real and imaginary midpoints of each operand as Gaussian integers times a single power of two, and fails if this needs more than bits. The midpoints of the product are then one product of Gaussian integer polynomials (_fmpzi_poly_mulmid), and the radii of the real and imaginary parts are bounded separately: for with radii ,
and symmetrically for the imaginary part, which is Lemma 1 applied to and ; the eight (four for a square) products of nonnegative polynomials are computed by _arb_poly_addmulmid_mag. If the operands are not well-scaled, the transposed algorithm computes the real and imaginary parts of the product with four real products _arb_poly_mulmid, each of which uses its own blocks. The Gauss variant with three real products, , is faster but loses accuracy when and (or and ) differ greatly, since the error of the large products then swamps the small part; it is available but not used by default.
Use in FLINT#
_arb_poly_mullow_blockand_arb_poly_mulmid_blockimplement Algorithm 1;_arb_poly_mullow_classicaland_arb_poly_mulmid_classicalthe classical algorithm witharb_dot;_arb_poly_mullow,_arb_poly_mulmidand_arb_poly_mulchoose between them._arb_poly_addmulmid_magexposes the radius products._acb_poly_mulmid_fmpzi,_acb_poly_mullow_transpose,_acb_poly_mullow_transpose_gaussand_acb_poly_mullow_classicalare the complex algorithms, selected by_acb_poly_mullow.- Over the generic ball contexts of gr_poly.h,
_gr_poly_mullowand_gr_poly_mulmidcall these functions, so that every generic polynomial algorithm overarbandacbcoefficients uses them. - Matrix multiplication uses the same idea of exact integer products of scaled blocks (Ball matrix multiplication).
Referenced from#
- acb_poly.h (module)
- Ball matrix multiplication (algorithm)
- Power series in ball arithmetic (algorithm)
- arb_poly.h (module)
- Multiplying polynomials with ball coefficients
- gr_poly.h (module)
References#
- [vdH2008] J. van der Hoeven. Making fast multiplication of polynomials numerically stable. Technical report 2008-02, Université Paris-Sud, Orsay, 2008.
- [Hig2002] N. J. Higham. Accuracy and Stability of Numerical Algorithms, second edition, chapter 24 (The fast Fourier transform and applications). SIAM, 2002. https://doi.org/10.1137/1.9780898718027
- [Joh2017] F. Johansson. "Arb: efficient arbitrary-precision midpoint-radius interval arithmetic". IEEE Transactions on Computers, vol 66, issue 8, 2017, pp. 1281-1292. https://doi.org/10.1109/TC.2017.2690633
The FLINT team, “Multiplying polynomials with ball coefficients,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/ball-arithmetic/polynomial-multiplication.html (generated 2026-11-02).
@misc{flint-doc-algorithms-ball-arithmetic-polynomial-multiplication,
author = {{The FLINT team}},
title = {{Multiplying polynomials with ball coefficients}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/algorithms/ball-arithmetic/polynomial-multiplication.html},
note = {Generated 2026-11-02}
}