FLINT3.7.0-dev
Overview

Multivariate polynomials: representations and algorithms

FLINT represents multivariate polynomials sparsely, as sorted lists of terms with packed exponent vectors, in one module per coefficient ring. The algorithms are shared between the modules as far as possible: the monomial code is in mpoly.h, and most GCD and factoring algorithms exist in a version over \mathbb{Z} and versions over finite fields, with the rational and rational function modules built on top of the integer one.

CoefficientsPolynomialsFactorisationFractions
any gr ringgr_mpoly
\mathbb{Z}fmpz_mpoly.hfmpz_mpoly_factorfmpz_mpoly_q.h
\mathbb{Q}fmpq_mpoly.h (content times fmpz_mpoly)fmpq_mpoly_factor
\mathbb{Z}/n\mathbb{Z}, word-size nnmod_mpolynmod_mpoly_factor
\mathbb{Z}/n\mathbb{Z}, any nfmpz_mod_mpolyfmpz_mod_mpoly_factorfmpz_mod_mpoly_q
\mathbb{F}_qfq_nmod_mpoly, fq_zech_mpolyfq_nmod_mpoly_factor, fq_zech_mpoly_factor

The generic gr_mpoly implements arithmetic (heap multiplication and division, threaded versions) for any coefficient ring; the gr contexts for the specialised types (gr_ctx_init_fmpz_mpoly and others) call the specialised functions, which are faster and also provide GCDs and factorisation.

Representation#

AlgorithmMonomial orderings and exponent packingHow FLINT stores sparse multivariate polynomials: terms sorted by a monomial ordering, exponent vectors packed into machine words so that comparing, multiplying and dividing monomials are word operations, with guard bits for overflow detection; and the deflations, repackings and changes of variables that the algorithms apply to this representation.

A polynomial is stored with its terms sorted for one of the orderings ORD_LEX, ORD_DEGLEX, ORD_DEGREVLEX, and the exponent vectors packed into words with a guard bit per field, so that comparing, multiplying and testing divisibility of monomials are word operations. The packing width grows automatically. The ordering affects the speed of some operations (the dense array methods differ for lex and degree orderings) but not the results of GCDs and factorisations, which are computed in lex order internally and converted back.

Arithmetic#

AlgorithmSparse and dense multiplicationMultiplication of sparse multivariate polynomials with Johnson's heap algorithm and the improvements of Monagan and Pearce (packed monomials, chaining, small heaps, three-word accumulation, parallel splitting of the output), dense array accumulation, Kronecker substitution for dense inputs, and powering by the FPS recurrence.
OperationMethodUsed whenFunctions
multiplicationJohnson's heap with chainingsparse inputs, any ringfmpz_mpoly_mul_johnson, gr_mpoly_mul_heap
parallel heaplarge inputs, several threadsfmpz_mpoly_mul_heap_threaded
dense array accumulationproduct dense in a box of moderate sizefmpz_mpoly_mul_array
Kronecker substitutiondense inputsfmpz_mpoly_mul_dense
poweringFPS recurrence\mathbb{Z}, exponent \ge 3fmpz_mpoly_pow_fps
repeated multiplicationfinite fieldsnmod_mpoly_pow_rmul

fmpz_mpoly_mul and nmod_mpoly_mul choose automatically; the rules are described in Multiplication.

AlgorithmDivision, exact division and square rootsMultivariate division with remainder with respect to a monomial ordering, and its heap implementation by Monagan and Pearce, in which a heap of size at most the number of terms of the divisor supplies the terms of the current remainder; early termination of exact division, quasi-division over the integers, division by several polynomials, parallel exact division, and the analogous heap algorithm for square roots with its non-square certificates.
OperationMethodFunctions
exact divisionheap division with early termination; threads for large dividendsfmpz_mpoly_divides
division with remainderheap division (floor division of coefficients over \mathbb{Z})fmpz_mpoly_divrem
pseudo-divisionheap division with scalingfmpz_mpoly_quasidivrem
division by several polynomialsheapfmpz_mpoly_divrem_ideal
square rootheap, with non-square certificatesfmpz_mpoly_sqrt

GCDs and resultants#

AlgorithmGreatest common divisorsHow FLINT computes GCDs of multivariate polynomials over the integers: reductions that make most inputs easy (monomial content, deflation, missing variables, univariate cases), degree bounds from random images, and the four modular algorithms it chooses between (Brown's dense algorithm, Zippel's sparse algorithm, the Berlekamp–Massey based algorithm of Hu and Monagan, and EEZ-GCD Hensel lifting), with their correctness proofs and the cost model behind the choice.

fmpz_mpoly_gcd first reduces the problem (monomial contents, deflation, missing variables, univariate cases, divisibility tests) and then chooses between Brown's dense modular algorithm (two variables, dense inputs), the Berlekamp–Massey based sparse algorithm of Hu and Monagan (sparse inputs in three or more variables) and Zippel's sparse algorithm, using degree and term count estimates from random images. Hensel lifting (EEZ-GCD) and subresultants are available on request. Over finite fields, nmod_mpoly_gcd also uses Hensel lifting, and computes over extension fields when the field is too small:

Resultants and discriminants (fmpz_mpoly_resultant, fmpz_mpoly_discriminant) use the subresultant algorithm of Ducos [Duc2000] on univariate polynomials with multivariate coefficients, except that bivariate dense inputs go through a multimodular evaluation and interpolation method:

AlgorithmBivariate resultants by evaluation and interpolationThe resultant \mathrm{Res}_y(A, B) \in \mathbb{F}_p[x] of two bivariate polynomials, computed from univariate resultants at many values of x (a geometric progression or roots of unity) and interpolation, with the degree bound, the correction for specialisations that lower the degree, and FLINT's cutoffs.

Factorisation#

StageMethodFunctions
contentGCDs of coefficients with respect to each variablefmpz_mpoly_factor_content
squarefreeYun's algorithm (with p-th roots in characteristic p)fmpz_mpoly_factor_squarefree
simplificationunimodular compression of exponents; Newton polytope testmpoly_compression_set
low degreelinear and quadratic in the main variablefmpz_mpoly_factor
bivariate denseHensel lifting and recombinationfmpz_bpoly_factor
generalevaluation, degree pruning, then Wang (dense lifting), Zippel (sparse lifting) or Zassenhaus (lifting with recombination)fmpz_mpoly_factor_wang, fmpz_mpoly_factor_zippel, fmpz_mpoly_factor_zassenhaus

Factoring over finite fields follows the same stages, with the changes described in:

AlgorithmFactoring over finite fieldsThe multivariate factorisation pipeline of nmod_mpoly_factor and fq_nmod_mpoly_factor, with what is specific to characteristic p: separable factorisation with p-th roots, deflation by powers of p, factoring over extension fields with recombination of Frobenius orbits when the field is too small for good evaluation points, quadratic equations in characteristic 2, bivariate factorisation with recombination by linear algebra, and Wang's leading coefficients along random curves.

Practical advice#

  • Use the specialised modules rather than gr_mpoly over \mathbb{Z}, \mathbb{Q} and finite fields: they accumulate coefficients without intermediate reductions, use dense methods when they pay, and provide GCDs and factorisation.
  • The ordering only matters for the leading terms (and hence for division with remainder and Gröbner bases) and for the speed of the array methods; lex order is the natural one for recursive computations.
  • Threads (flint_set_num_threads) are used by multiplication and exact division of large polynomials, and by Brown's GCD algorithm in nmod_mpoly_gcd.
  • GCDs and factorisations are randomised but never return wrong results: every algorithm verifies its output, by exact division or by a proof of its stopping criterion. Their running time can vary with the random choices.

Referenced from#

References#

Cite this page

The FLINT team, “Multivariate polynomials: representations and algorithms,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/multivariate/overview.html (generated 2026-10-20).