FLINT3.7.0-dev
Algorithm

Reduction modulo the defining polynomial

Cost
(ℓ−d)(t−1)(\ell - d)(t - 1) multiplications in Fp\mathbb{F}_p for a polynomial of length ℓ\ell and a defining polynomial with tt nonzero terms; 2M(d)+O(d)2M(d) + O(d) for Newton division.

In the polynomial representations of fq and fq_nmod, an element of Fq=Fp[x]/(f)\mathbb{F}_q = \mathbb{F}_p[x]/(f), deg⁡f=d\deg f = d, is stored as its representative of degree less than dd. A product of two elements is computed as a product of polynomials, of length at most 2d−12d - 1, and then reduced modulo ff. For the small degrees that are common in practice the reduction costs about as much as the product, so FLINT chooses defining polynomials with few nonzero terms when it can (Defining polynomials) and exploits them.

Throughout, let f~=f/lc⁡(f)=xd+∑kakxjk\tilde f = f / \operatorname{lc}(f) = x^d + \sum_{k} a_k x^{j_k}, with tt nonzero terms in total, so that the sum runs over t−1t - 1 exponents 0≤jk<d0 \le j_k < d. The context stores the coefficients aka_k and the exponents jkj_k of the monic polynomial f~\tilde f, which generates the same ideal as ff.

Sparse elimination#

Algorithm 1: Sparse reduction

Input: R=∑i<ℓrixiR = \sum_{i < \ell} r_i x^i.

Output: R mod fR \bmod f, in the coefficients r0,…,rd−1r_0, \ldots, r_{d-1}.

  1. For i=ℓ−1,ℓ−2,…,di = \ell - 1, \ell - 2, \ldots, d: for every kk, rjk+i−d←rjk+i−d−riakr_{j_k + i - d} \gets r_{j_k + i - d} - r_i a_k; then ri←0r_i \gets 0.
  2. Reduce r0,…,rd−1r_0, \ldots, r_{d-1} modulo pp.

Proposition 1. Algorithm 1 computes R mod fR \bmod f with (ℓ−d)(t−1)(\ell - d)(t - 1) multiplications.

Proof. Step 1 replaces RR by R−rixi−df~R - r_i x^{i-d} \tilde f, which does not change its class modulo ff and clears the coefficient of xix^i, since xi−df~x^{i-d} \tilde f has leading term xix^i; the coefficients modified have indices jk+i−d<ij_k + i - d < i. After the iteration for ii, all coefficients of index at least ii are zero, so at the end deg⁡R<d\deg R < d. Each iteration costs t−1t - 1 multiplications.

For a product, ℓ=2d−1\ell = 2d - 1, so a trinomial costs 2(d−1)2(d - 1) multiplications, much less than a product of polynomials of degree d−1d - 1. _fq_sparse_reduce works with unreduced integer coefficients (fmpz_submul) and reduces modulo pp only at the end, so the coefficients grow by about log⁡2p\log_2 p bits per elimination that touches them; this is cheaper than reducing after every step for the small tt for which the method is used. _fq_nmod_sparse_reduce reduces after each step and has four variants: for p=2p = 2 the update is an exclusive or of bits; if all aka_k are 1 (as for xd+xj+1x^d + x^j + 1 and other polynomials with unit coefficients), only subtractions are needed; for p<2FLINT_BITS/2p < 2^{\mathtt{FLINT\_BITS}/2} the update r+ri(p−ak)r + r_i (p - a_k) fits in one word and is reduced with a Barrett reduction (n_mod_barrett); otherwise nmod_addmul is used.

Newton division#

For a dense defining polynomial, the reduction is a division with remainder by ff using a precomputed power series inverse. Let rev⁡n(g)=xn−1g(1/x)\operatorname{rev}_n(g) = x^{n-1} g(1/x) denote the reversal of a polynomial of length nn. When the context is created, the series v=rev⁡d+1(f)−1 mod xd+1v = \operatorname{rev}_{d+1}(f)^{-1} \bmod x^{d+1} is computed and stored (ctx->inv).

Proposition 2. Let deg⁡R=ℓ−1\deg R = \ell - 1 with d≤ℓ−1≤2d−1d \le \ell - 1 \le 2d - 1, and let R=Qf+SR = Qf + S with deg⁡S<d\deg S < d. Then rev⁡ℓ−d(Q)=rev⁡ℓ(R)⋅v mod xℓ−d\operatorname{rev}_{\ell - d}(Q) = \operatorname{rev}_\ell(R) \cdot v \bmod x^{\ell - d}.

Proof. Reversing R=Qf+SR = Qf + S gives rev⁡ℓ(R)=rev⁡ℓ−d(Q)rev⁡d+1(f)+xℓ−drev⁡d(S)\operatorname{rev}_\ell(R) = \operatorname{rev}_{\ell - d}(Q) \operatorname{rev}_{d+1}(f) + x^{\ell - d} \operatorname{rev}_d(S). Modulo xℓ−dx^{\ell - d} the last term vanishes, and multiplying by vv, the inverse of rev⁡d+1(f)\operatorname{rev}_{d+1}(f) modulo xd+1x^{d+1} and hence modulo xℓ−dx^{\ell - d} because ℓ−d≤d+1\ell - d \le d + 1, gives the claim.

The quotient thus costs one truncated product of length ℓ−d≤d\ell - d \le d and the remainder S=R−QfS = R - Qf another product, about 2M(d)2M(d) operations in all, independently of the number of terms of ff [GG2003, §9.1]. _fq_dense_reduce and _fq_nmod_dense_reduce call _fmpz_mod_poly_divrem_newton_n_preinv and _nmod_poly_divrem_newton_n_preinv, which require ℓ≤2d\ell \le 2d; this is the precondition of fq_reduce and fq_nmod_reduce for dense moduli. The sparse method has no such limit, and fq_set_fmpz_poly and fq_nmod_set_nmod_poly use a general division for longer inputs.

_fq_reduce and _fq_nmod_reduce use Algorithm 1 if ff has at most five nonzero terms (the flag sparse_modulus, set when the context is created) and Newton division otherwise. With t≤5t \le 5 and ℓ=2d−1\ell = 2d - 1, the sparse method costs at most 4(d−1)4(d - 1) multiplications.

Delayed reduction#

Since reduction is linear, a sum ∑iaibi\sum_i a_i b_i of products of elements can be reduced once: the products of the representatives are accumulated as an unreduced polynomial of length 2d−12d - 1, over Z\mathbb{Z} for fq or modulo pp for fq_nmod, and only the sum is reduced. The dot products of _fq_vec_dot and _fq_nmod_vec_dot (implemented in the gr contexts), and hence the classical matrix and polynomial multiplications, which are built on them, save all but one reduction per output entry. Kronecker substitution (Multiplying polynomials over finite fields, fq_mat_mul_KS) goes further: the whole product is computed over Z\mathbb{Z} and each output coefficient is reduced once when it is unpacked.

Use in FLINT#

Referenced from#

References#

  • [GG2003] J. von zur Gathen and J. Gerhard, Modern Computer Algebra, second edition, Cambridge University Press (2003)
Cite this page

The FLINT team, “Reduction modulo the defining polynomial,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/finite-fields/reduction.html (generated 2026-11-02).