Kronecker substitution
- Cost
- One integer product of about bits (KS), or two (KS2) or four (KS4) products of a half or a quarter of that size, plus word operations.
Kronecker substitution reduces polynomial multiplication to integer multiplication. The coefficients of each factor are written into the bits of one large integer, with enough space between them that the coefficients of the product do not overlap, and one integer product yields all coefficients of the polynomial product. The idea goes back to Kronecker [Kro1882]; Schönhage used it to multiply polynomials with integer and complex coefficients [Sch1982], and it is discussed in [GG2003, §8.4] and [Ber2008]. Its strength is that it inherits all the work that has gone into integer multiplication: FLINT's and GMP's basecase and Toom–Cook code, and the FFTs.
Harvey [Har2009a] observed that evaluating at several points, and , replaces the single integer product by two or four products of a half or a quarter of the size. Since integer multiplication costs more than linear time, this is faster. FLINT's implementations of these variants, KS2 and KS4, come from Harvey's zn_poly library.
Throughout, and have lengths and coefficients in , has length , and is the bit length of (NMOD_BITS). We write for the coefficients of the product of and as polynomials with integer coefficients. Each is a sum of at most products, so
All three methods compute the integers exactly and reduce them modulo at the end, with one-, two- or three-word reductions (NMOD_RED, NMOD2_RED2, NMOD_RED3).
Plain Kronecker substitution#
Lemma 1. Let and let have integer coefficients . Then is the integer formed by bits of .
Proof. The binary expansions of the terms occupy disjoint bit ranges, so their sum is formed without carries.
Input: , as above.
Output: .
- Choose with .
- Form the integers and by writing the coefficients into -bit fields (bit packing).
- Compute the integer product .
- Read the from the -bit fields of (bit unpacking) and reduce each modulo .
Correctness is Lemma 1 applied to the integer polynomial , since . The integers and have about and bits, so the cost is one integer product of bits plus linear work. The field size grows only logarithmically with the length, but for small moduli a large part of each field holds the bits of the sums rather than of the inputs, which is the waste that KS2 and KS4 reduce.
_nmod_poly_mulmid_KS, which implements the full, low and middle products by substitution, takes , and if this fits in a word replaces it by the exact bit length of . It packs with _nmod_poly_bit_pack, multiplies with flint_mpn_mul (or flint_mpn_sqr for squares) and extracts only the requested range of coefficients with _nmod_poly_bit_unpack, which reduces each field of one to three words. Before packing it drops the low coefficients of the operands that cannot contribute to the requested range, but otherwise it forms the whole integer product.
Evaluation at and (KS2)#
Write for the even and odd parts, and similarly for and . Let .
Lemma 2. and . If the coefficients of are less than , the coefficients of and are the -bit fields of and .
Proof. The identities follow from . The second statement is Lemma 1 with in place of .
With about half the field size of KS, KS2 computes two integer products and , each of about bits, half the size of the single product of KS. The evaluations are cheap: and are packings of the even and odd coefficients into -bit fields, the second shifted by bits, and is their sum or difference. Since may be negative, FLINT stores absolute values and tracks the sign of the product.
Input: , as above, .
Output: .
- , , .
- Pack , , and (
_nmod_poly_KS2_pack); form and with an addition and a signed subtraction each. - , .
- Unpack the -bit fields of to obtain , and of to obtain (
_nmod_poly_KS2_unpack); reduce modulo into the even and odd positions of the output (_nmod_poly_KS2_reduce).
The bound makes Lemma 2 applicable. For a square only two integer squarings are needed.
Adding the reciprocal points (KS4)#
The reversal satisfies , so evaluating reversed polynomials at amounts to evaluating at in integer arithmetic. KS4 runs the KS2 evaluation twice, on and on their reversals, with about a quarter of the field size of KS. Now a coefficient of may have up to bits while the fields of are only bits wide, so neighbouring coefficients overlap. The low halves of the coefficients can be read from the normal evaluation, starting at the low end, and the high halves from the reversed one, starting at the high end.
Theorem 3 (Recovery from two overlapping evaluations). Let and let be integers with , and . Let
with base- digits and for . Set . Then for ,
where is 1 if the condition holds and 0 otherwise. In particular the are determined by and and are computed in increasing order of with digit operations.
Proof. Digits of . Coefficient contributes to position and to position . Let be the carry into position . Then ; the left side is at most , so carries are 0 or 1. Reducing modulo gives , and exactly when the subtraction borrows.
Digits of . Here contributes to position and to position . Let be the carry into position . Position receives (with ). Since , this sum reaches , which makes , exactly when its residue is less than . Position receives , hence , with no wrap-around because . Subtracting gives . Each step needs only and , which are known by then.
In KS4, , the are the coefficients of (and then of ), is from the normal evaluation and is the corresponding value from the reversed one. The hypothesis on holds with FLINT's choice of :
Proposition 4. Let with , and , as in _nmod_poly_mul_KS4. Then every satisfies .
Proof. Since and ,
If , then and , so , which is the claim. If , then , so .
Input: , as above, .
Output: .
- , , .
- As in Algorithm 2, compute and from them and .
- Do the same with and . This gives the even and odd parts of at , which are the reversals of and , exchanged if the length of is even (FLINT compensates with shifts by bits).
- Split the four integers into -bit digits and apply Theorem 3 to obtain the even and the odd coefficients, reducing each modulo (
_nmod_poly_KS2_recover_reduce).
Cost#
Let be the cost of multiplying two -bit integers and let be the size of the product formed by KS. Up to linear terms,
Since grows faster than linearly, KS4 is the fastest for large . The gain is large where integer multiplication is quadratic or Toom–Cook, and shrinks to a modest constant factor in the FFT range [Har2009a]. The linear overhead (more packing, signed additions and the recovery) is larger for KS2 and KS4, so plain KS is preferred for short products; the crossovers used by _nmod_poly_mul are given in Cutoffs. For truncated and middle products, substitution offers no saving beyond shortening the operands, since the whole integer product is formed.
Use in FLINT#
_nmod_poly_mul_KS,_nmod_poly_mullow_KSand_nmod_poly_mulmid_KSimplement Algorithm 1;_nmod_poly_mul_KS2and_nmod_poly_mul_KS4implement Algorithm 2 and Algorithm 3._nmod_poly_mul,_nmod_poly_mullowand_nmod_poly_mulmidchoose among them by length and modulus size, and above tuned lengths use the small-prime FFT instead (Multiplying polynomials over Z/nZ)._nmod_poly_mulhighgoes through_nmod_poly_mulmidfor all but tiny inputs.- The integer products go through
flint_mpn_mul, which uses FLINT's basecase and Toom-2 code, GMP'smpn_muland, above a tuned size, the small-prime FFT offft_smallor, when that is not available, the Schönhage–Strassen FFT (Schönhage–Strassen multiplication). - The low-level helpers
_nmod_poly_bit_pack,_nmod_poly_bit_unpack,_nmod_poly_KS2_pack,_nmod_poly_KS2_unpack,_nmod_poly_KS2_reduceand_nmod_poly_KS2_recover_reduceare public. - In other modules,
_fmpz_poly_mul_KSand its truncated and middle forms substitute integer polynomials with signed coefficients;fq_poly_mul_KSpacks elements of into integers and multiplies the resulting integer polynomials (Multiplying polynomials over finite fields);fq_nmod_poly_mul_univariatesubstitutes to turn a product in into one product in ; andnmod_poly_mat_mul_KSpacks polynomial matrices into integer matrices.
Referenced from#
- FFTs in FLINT (overview)
- Multiplication with several primes and CRT (algorithm)
- Multiplying integers (overview)
- Multiplying polynomials over Z (overview)
- Multiplying polynomials over Z/nZ (overview)
- Polynomial arithmetic over generic rings and its specialisations (overview)
- fmpz_poly.h (module)
_fmpz_poly_mul_KS,fmpz_poly_mul_KS,_fmpz_poly_mullow_KS,fmpz_poly_mullow_KS,_fmpz_poly_mulmid_KS,fmpz_poly_mulmid_KS,_fmpz_poly_sqr_KS,fmpz_poly_sqr_KS,_fmpz_poly_sqrlow_KS,fmpz_poly_sqrlow_KS- Multiplying polynomials
- fq_mat.h (module)
- Multiplying polynomials over finite fields
_gr_poly_mulmid_bivariate_KS,gr_poly_mulmid_bivariate_KS,_gr_poly_mullow_bivariate_KS,gr_poly_mullow_bivariate_KS- nmod_poly.h (module)
- Multiplying polynomials
References#
- [Kro1882] L. Kronecker, "Grundzüge einer arithmetischen Theorie der algebraischen Grössen", Journal für die reine und angewandte Mathematik 92 (1882), 1–122
- [Sch1982] A. Schönhage, "Asymptotically fast algorithms for the numerical multiplication and division of polynomials with complex coefficients", Computer Algebra (EUROCAM '82), LNCS 144 (1982), 3–15
- [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
- [Har2009a] D. Harvey, "Faster polynomial multiplication via multipoint Kronecker substitution", Journal of Symbolic Computation 44:10 (2009), 1502–1510
The FLINT team, “Kronecker substitution,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/polynomials/kronecker.html (generated 2026-11-02).
@misc{flint-doc-algorithms-polynomials-kronecker,
author = {{The FLINT team}},
title = {{Kronecker substitution}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/algorithms/polynomials/kronecker.html},
note = {Generated 2026-11-02}
}