Ball matrix multiplication
- Cost
- For matrices at bits: one exact integer matrix product of -bit entries per block (typically one block), using the fast algorithms of fmpz_mat, plus double operations for the radii, against multiplications at bits for the classical algorithm.
The product of an matrix and an matrix with ball entries , must satisfy for all matrices , . Since
the entrywise bound
holds (with absolute values and inequalities taken entrywise), so it is enough to compute an enclosure of the midpoint product and an upper bound for the radius product on the right. The classical algorithm computes each entry as a dot product in ball arithmetic (arb_dot, see Dot products of balls), which does exactly this entry by entry with multiplications of -bit numbers. For large matrices, both parts can instead be done with fast matrix multiplication, as observed by Rump for midpoint-radius interval matrices in floating-point arithmetic [Rum1999]; FLINT does this in arb_mat_mul_block, with exact integer products for the midpoints.
Midpoints: exact integer matrix products#
Every midpoint is a binary floating-point number with an odd integer of at most bits. If all entries in row of are multiples of and have absolute value less than , then times the row is a row of integers of at most bits, and similarly for the columns of with exponents . The scaled product of integer matrices is then exact, and .
Input: , , precision . Let be the largest number of bits of any midpoint and .
- Split the inner index range into consecutive blocks , each as long as possible subject to the condition that in each row of (restricted to the columns in ) and in each column of (restricted to the rows in ), the nonzero entries span at most bits, from the lowest set bit of any of them to the highest.
- For a block with at least 30 indices, convert the block to integer matrices , with the row and column scalings above, compute exactly with
fmpz_mat_mul, round each entry of to bits and add it to in ball arithmetic. - For a shorter block (at least 30 indices are taken anyway), add the dot products of the midpoints over the block with
arb_dot.
For matrices whose entries in each row and column have similar magnitudes, which is the common case, there is a single block, and the computed midpoint of each entry has a single rounding error of at most half an ulp at bits: the result is as accurate as the classical algorithm, which also rounds each dot product once. With blocks, each entry accumulates at most roundings. Entries of very different magnitude in the same row (for example, a matrix with a huge first column) create several blocks, and a matrix with huge dynamic range degenerates to classical multiplication in blocks of 30. The bound of about bits allows the integer entries to be somewhat longer than the precision, so that ordinary dynamic range within a row does not split blocks; the constant 192 accommodates low-precision inputs.
The integer matrix multiplication fmpz_mat_mul chooses its algorithm from the dimension and the entry size (fmpz_mat.h). At precisions of a few hundred bits, its multimodular method, which replaces the -bit products by matrix products modulo word-size primes, gives most of the speedup over the classical algorithm.
Radii: products in double precision#
The radius term needs only an upper bound of moderate accuracy, so it is computed with matrices of nonnegative double numbers. The magnitudes , , , are converted to mag_t upper bounds (30-bit mantissas), and _arb_mat_addmul_rad_mag_fast again splits the inner dimension into blocks in which the exponents of each row and column span at most 900 bits. In a block, each row and each column is scaled by a power of two so that all entries are representable as normal double numbers without rounding, and the product is computed with ordinary double arithmetic in cache-friendly blocks.
Lemma 1. Let be double numbers and let be the result of summing the products , , in any order with rounding to nearest, without overflow or underflow. Then .
Proof. With unit roundoff , each computed product and each partial sum of nonnegative terms has relative error at most , and the standard error analysis of summation gives , since each term passes through at most roundings (one multiplication and at most additions) [Hig2002]. For (larger would need matrices with about columns), , which is well below the stated factor; the margin also covers the rounding of the final multiplication by the factor.
The scaled double products are multiplied by this factor and added, with rounding upwards, to the radii of ; blocks of at most 5 indices use mag_t arithmetic directly. The radius computation costs floating-point operations in the worst case, but these are much cheaper than -bit multiplications, and for exact inputs (all radii zero) it is skipped. If only one factor is exact, only one radius product is computed.
Theorem 2. The matrix computed by arb_mat_mul_block contains for all and .
Proof. The midpoint part encloses : in each block, the integer product is exact and the rounding to bits and the addition are performed in ball arithmetic, which adds the rounding errors to the radius. The radius part adds an upper bound for by Lemma 1 and the upward rounding of the conversions between mag_t and double, which bounds by the identity at the beginning of this section.
Algorithm selection#
arb_mat_mul uses the classical algorithm (threaded if several threads are available and the matrices are not tiny) when one of the dimensions is at most 60 (for ), 50 (for ) or 40, and arb_mat_mul_block otherwise. The block algorithm itself falls back to classical multiplication if some midpoint has more than 8000 bits, if both matrices have less than 10% nonzero entries and , or if some exponent is too large for the fast integer exponent arithmetic.
For complex matrices, acb_mat_mul_reorder writes and and computes the real and imaginary parts and with four real block multiplications (two if one of the matrices is real, one if both are). acb_mat_mul uses it when the inner dimension and the number of columns of satisfy , where is the minimum of and the largest number of bits of a midpoint; otherwise it multiplies classically (threaded if possible).
Use in FLINT#
arb_mat_mul,arb_mat_mul_classical,arb_mat_mul_threaded,arb_mat_mul_block,arb_mat_sqr,_arb_mat_addmul_rad_mag_fast(arb_mat.h);acb_mat_mul,acb_mat_mul_reorder(acb_mat.h).gr_mat_mulover the contextsgr_ctx_init_real_arbandgr_ctx_init_complex_acbcallsarb_mat_mulandacb_mat_mul(gr_mat.h).- The same idea of exact integer products of blocks of similar magnitude is used for polynomials in Multiplying polynomials with ball coefficients.
- Preconditioned linear solving (Verified linear algebra) and the eigenvalue enclosures (Eigenvalue enclosures) spend most of their time in these products.
Referenced from#
- acb_mat.h (module)
- Dot products of balls (algorithm)
- Verified linear algebra (algorithm)
- Multiplying polynomials with ball coefficients (algorithm)
- arb_mat.h (module)
arb_mat_mul_classical,arb_mat_mul_threaded,arb_mat_mul_block,arb_mat_mul
References#
- [Rum1999] S. M. Rump. Fast and parallel interval arithmetic. BIT Numerical Mathematics 39:3 (1999), 534–554. https://doi.org/10.1023/A:1022374804152
- [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
The FLINT team, “Ball matrix multiplication,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/ball-arithmetic/matrix-multiplication.html (generated 2026-11-02).
@misc{flint-doc-algorithms-ball-arithmetic-matrix-multiplication,
author = {{The FLINT team}},
title = {{Ball matrix multiplication}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/algorithms/ball-arithmetic/matrix-multiplication.html},
note = {Generated 2026-11-02}
}