FLINT3.7.0-dev
Module · 239 functions

fmpz_mod_mpoly_factor.h

#include <flint/fmpz_mod_mpoly_factor.h>

This module factors polynomials of fmpz_mod_mpoly.h over a prime field \mathbb{F}_p, where p is given as an fmpz. Factorisations are stored in an fmpz_mod_mpoly_factor_t, a constant times a product of powers of polynomials, with the same interface as nmod_mpoly_factor (see nmod_mpoly_factor).

If p fits in a word, the factorisation functions convert to nmod_mpoly and use nmod_mpoly_factor_algo, which handles small fields through extension fields. Otherwise p > 2^{\mathtt{FLINT\_BITS}} and random evaluation points in \mathbb{F}_p are good with overwhelming probability, so only the algorithms over \mathbb{F}_p itself are implemented here: content removal, separable factorisation, bivariate factorisation by Hensel lifting and recombination, and lifting by Wang's method, sparse Hensel lifting or Zassenhaus recombination [Wan1978] [MonTun2020] [Zas1969]. See Factoring over finite fields for the methods and Multivariate Hensel lifting for the lifting steps.

The header also declares the dense bivariate types and the GCD algorithms used by fmpz_mod_mpoly_gcd (GCDs over small finite fields), documented in the internal section.

Types and memory management#

A factorisation c \prod_i f_i^{e_i}, with the fields constant (an fmpz_t), poly (the bases), exp (the fmpz exponents), num and alloc.

Initialises f as the empty product with constant 1.

Free f, change its allocation to alloc factors, or ensure space for len factors.

Basic manipulation#

Swap two factorisations, and set f to the empty product with constant 1.

Return the number of factors, and set c to the constant.

Set p to the base of index i or swap it with p, and return the exponent of index i, which must fit an slong.

Appends the factor A^e to f, swapping A into it (so A is changed).

Set A to the product represented by f (returning 0 for negative or too large exponents), and test whether f represents a.

Sort the factors by exponent and then by base, and compare two factorisations (constant, number of factors, then factor by factor).

Prints the constant followed by one line *(base)^exp per factor.

Factorisation#

These functions assume that the modulus is prime, which is not checked. They set f to a factorisation of A whose constant is the leading coefficient of A and whose bases are monic, and return 1 for success (0 only when exponents do not fit one word per field after removing the content).

Sets f to a factorisation into variables and polynomials primitive with respect to every variable.

Set f to a factorisation with squarefree, pairwise coprime bases. With sep = 1, fmpz_mod_mpoly_factor_separable also makes each base g satisfy \partial g/\partial x_i = 0 or \gcd(g, \partial g/\partial x_i) = 1 for every variable, as nmod_mpoly_factor_separable.

Sets f to the factorisation of A into monic irreducible factors.

Internal functions#

These functions support the factorisation and the GCD algorithms of fmpz_mod_mpoly. Their interfaces may change without notice.

Dense and recursive types#

A dense bivariate polynomial: an array (coeffs, alloc, length) of fmpz_mod_poly_struct, the coefficient of index i being the coefficient of x^i as a polynomial in y; and an array of bivariate polynomials (used for lists of factors).

Sparse polynomials in up to three variables with packed exponents (exps) and fmpz coefficients (polyu), or with fmpz_mod_poly coefficients in one more variable (polyun).

Sparse univariate polynomials with fmpz_mod_mpoly coefficients, and multivariate polynomials with fmpz_mod_poly coefficients in the last variable, as the corresponding nmod_mpoly types.

Vectors of polynomials (coeffs, alloc, length), and precomputed data for multivariate partial fractions.

Stacks#

Initialise and clear a stack; fit_request ensures that k more objects are available and returns a pointer to them, request also reserves them, take_top reserves one fitted object, give_back releases the k most recently reserved objects, and size returns the number of reserved objects.

Univariate helpers#

void fmpz_mod_poly_eval2_pow(fmpz_t evalp, fmpz_t evalm, const fmpz_mod_poly_t P, fmpz_mod_poly_t alphapow, const fmpz_mod_ctx_t ctx)

The degree of a; A = B + d_0 C; A = B + (d_1 x + d_0) C; A = x^k A + c; evaluation of P at \alpha, and at \pm\alpha simultaneously, using the cached powers alphapow of \alpha.

Operations on vectors of univariate polynomials: maximum degree, monic GCD of the entries (and division by it), multiplication and exact division by g, and scaling.

Start a cache c of powers of b, and set a = a \cdot b^e using and extending the cache.

As nmod_mat_is_reduced and nmod_mat_init_nullspace_tr: test whether the rows of N describe a partition of the columns, and compute a basis of the right nullspace of tmp as the rows of X.

Bivariate and sparse polynomials#

void fmpz_mod_bpoly_print_pretty(const fmpz_mod_bpoly_t A, const char * xvar, const char * yvar, const fmpz_mod_ctx_t ctx)

Memory management, assignment, coefficient access, degrees in the main (gen0) and the inner (gen1) variable, conversion from univariate polynomials in either variable, and printing of dense bivariate polynomials.

Arithmetic of bivariate polynomials: products, and products and division with the inner variable truncated to order terms; exact division (returning 1 if exact); making the polynomial monic as a series in the inner variable, or removing its content g (a polynomial in the inner variable); the derivative with respect to the main variable; the substitutions x \mapsto x + \alpha and y \mapsto y + c; and swapping the variables.

Conversions between polynomials in two variables of the context and dense or sparse bivariate representations.

void fmpz_mod_polyu3_degrees(slong * deg0, slong * deg1, slong * deg2, const fmpz_mod_polyu_t A)
void fmpz_mod_polyu3_print_pretty(const fmpz_mod_polyu_t A, const char * var0, const char * var1, const char * var2, const fmpz_mod_ctx_t ctx)
void fmpz_mod_polyu1n_print_pretty(const fmpz_mod_polyun_t A, const char * var0, const char * varlast, const fmpz_mod_ctx_t ctx)
void fmpz_mod_polyu2n_print_pretty(const fmpz_mod_polyun_t A, const char * var0, const char * var1, const char * varlast, const fmpz_mod_ctx_t ctx)
void fmpz_mod_polyu3n_print_pretty(const fmpz_mod_polyun_t A, const char * var0, const char * var1, const char * var2, const char * varlast, const fmpz_mod_ctx_t ctx)

Memory management, assignment, degrees and printing of the sparse types with one, two or three packed main variables.

void fmpz_mod_mpolyn_print_pretty(const fmpz_mod_mpolyn_t poly, const char ** x, const fmpz_mod_mpoly_ctx_t ctx)
void fmpz_mod_mpoly_to_mpolyn_perm_deflate(fmpz_mod_mpolyn_t A, const fmpz_mod_mpoly_ctx_t nctx, const fmpz_mod_mpoly_t B, const fmpz_mod_mpoly_ctx_t ctx, const slong * perm, const ulong * shift, const ulong * stride)
void fmpz_mod_mpoly_from_mpolyn_perm_inflate(fmpz_mod_mpoly_t A, flint_bitcnt_t Abits, const fmpz_mod_mpoly_ctx_t ctx, const fmpz_mod_mpolyn_t B, const fmpz_mod_mpoly_ctx_t nctx, const slong * perm, const ulong * shift, const ulong * stride)

Operations on fmpz_mod_mpolyn_t and conversions from and to fmpz_mod_mpoly_t (with the variable var moved into the univariate coefficients, or with a permutation and deflation of the variables).

Interpolation#

The evaluation (reduce, at \alpha or at \pm\alpha), first-image (lift) and Chinese remaindering (crt) steps of Brown's algorithm, as for nmod_mpoly; the crt functions return whether the interpolant changed and update lastdeg.

int _fmpz_mod_zip_vand_solve(fmpz * coeffs, const fmpz * monomials, slong mlength, const fmpz * evals, slong elength, const fmpz * master, fmpz * scratch, const fmpz_mod_ctx_t ctx)
void _fmpz_mod_zip_eval_step(fmpz_t ev, fmpz * cur, const fmpz * inc, const fmpz * coeffs, slong length, const fmpz_mod_ctx_t ctx)
void mpoly_monomial_evals_fmpz_mod(fmpz_mod_poly_t EH, const ulong * Aexps, slong Alen, flint_bitcnt_t Abits, fmpz_mod_poly_struct * alpha_caches, slong start, slong stop, const mpoly_ctx_t mctx, const fmpz_mod_ctx_t fpctx)
void mpoly1_monomial_evals_fmpz_mod(fmpz_mod_polyun_t EH, const ulong * Aexps, flint_bitcnt_t Abits, const ulong * Amarks, slong Amarkslen, fmpz_mod_poly_struct * alpha_caches, slong m, const mpoly_ctx_t mctx, const fmpz_mod_ctx_t fpctx)
void mpoly2_monomial_evals_fmpz_mod(fmpz_mod_polyun_t EH, const ulong * Aexps, flint_bitcnt_t Abits, ulong * Amarks, slong Amarkslen, fmpz_mod_poly_struct * alpha_caches, slong m, const mpoly_ctx_t mctx, const fmpz_mod_ctx_t fpctx)

Sparse interpolation of polynomials with known support: the monomial evaluations at powers of the evaluation points, the master polynomials \prod (z - m_i) of the monomial values (product_roots, returning the maximum number of terms), the incremental evaluation of the next image, and the solution of the transposed Vandermonde systems (returning 1 for success and 0 or -1 if the images are inconsistent).

GCD algorithms#

Computes the GCD G and, if Abar and Bbar are not NULL, the cofactors of the nonzero A and B with the algorithms in the bit mask algo (MPOLY_GCD_USE_BROWN, MPOLY_GCD_USE_HENSEL, MPOLY_GCD_USE_ZIPPEL, MPOLY_GCD_USE_ZIPPEL2, MPOLY_GCD_USE_PRS or MPOLY_GCD_USE_ALL). For a word-size modulus it calls _nmod_mpoly_gcd_algo_small. Returns 1 for success.

int fmpz_mod_mpolyl_gcd_zippel2_smprime(fmpz_mod_mpoly_t rG, const slong * rGdegs, fmpz_mod_mpoly_t rAbar, fmpz_mod_mpoly_t rBbar, const fmpz_mod_mpoly_t A, const slong * Adegs, const fmpz_mod_mpoly_t B, const slong * Bdegs, const fmpz_mod_mpoly_t gamma, const slong * gammadegs, const fmpz_mod_mpoly_ctx_t ctx)

The GCD algorithms with evaluation points in \mathbb{F}_p: Brown's dense algorithm (bivariate and multivariate), Zippel's algorithm in the variables up to var, sparse interpolation with two main variables given the leading coefficient of the GCD, and Hensel lifting. Return 1 for success, also setting the cofactors.

Factoring algorithms#

Get, or replace by c, the leading coefficient of a polynomial viewed as a polynomial in variable 0.

Sets f to the factorisation nf computed in the nmod_mpoly context nctx with the same modulus.

GCD of Alen polynomials (returning 1 for success), and exact division or multiplication of all of them by c.

Factors the bivariate B, separable in the main variable: sets c to its content and F to its irreducible factors, by evaluation of the inner variable at a point of \mathbb{F}_p (only 0 unless allow_shift), Hensel lifting and recombination by linear algebra [Lec2006]. Returns 0 if no suitable point is found.

Bivariate (and trivariate) Hensel lifting of two or r factors modulo powers of y - \alpha, as the n_bpoly_mod versions in nmod_mpoly_factor.

int fmpz_mod_mpoly_hlift(slong m, fmpz_mod_mpoly_struct * f, slong r, const fmpz * alpha, const fmpz_mod_mpoly_t A, const slong * degs, const fmpz_mod_mpoly_ctx_t ctx)
int fmpz_mod_mpoly_hlift_zippel(slong m, fmpz_mod_mpoly_struct * B, slong r, const fmpz * alpha, const fmpz_mod_mpoly_t A, const slong * degs, const fmpz_mod_mpoly_ctx_t ctx, flint_rand_t state)

Multivariate partial fractions and Hensel lifting, dense or by sparse interpolation, as the corresponding nmod_mpoly functions.

Wang's leading coefficient distribution [Wan1978], as nmod_mpoly_factor_lcc_wang.

Irreducible factorisation of a monic squarefree polynomial in at least three variables with evaluation points in \mathbb{F}_p. Return 1 for success, 0 if they ran out of evaluation points and -1 for a failure that other points would not fix.

int _fmpz_mod_mpoly_evaluate_rest_fmpz_mod_poly(fmpz_mod_poly_struct * E, slong * starts, slong * ends, slong * stops, ulong * es, const fmpz * Acoeffs, const ulong * Aexps, slong Alen, slong var, const fmpz_mod_poly_struct * alphas, const slong * offsets, const slong * shifts, slong N, ulong mask, slong nvars, const fmpz_mod_ctx_t ctx)

Evaluate all but the first one or two variables, giving univariate or bivariate images.

References#

  • [Wan1978] P. S. Wang. An improved multivariate polynomial factoring algorithm. Mathematics of Computation 32 (1978), 1215–1231. https://doi.org/10.1090/S0025-5718-1978-0568284-3
  • [MonTun2020] M. Monagan and B. Tuncer. The complexity of sparse Hensel lifting and sparse polynomial factorization. Journal of Symbolic Computation 99 (2020), 189–230. https://doi.org/10.1016/j.jsc.2019.05.001
  • [Zas1969] H. Zassenhaus. On Hensel factorization, I. Journal of Number Theory 1 (1969), 291–311. https://doi.org/10.1016/0022-314X(69)90047-X
  • [Lec2006] G. Lecerf. Sharp precision in Hensel lifting for bivariate polynomial factorization. Mathematics of Computation 75 (2006), 921–933.
Cite this page

The FLINT team, “fmpz_mod_mpoly_factor.h (module overview),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/fmpz_mod_mpoly_factor/index.html (generated 2026-10-20).