FLINT3.7.0-dev
Module · 32 functions

fq_nmod_poly_factor.h

#include <flint/fq_nmod_poly_factor.h>

This module factors polynomials over a finite field \mathbb{F}_q in the representation of fq_nmod.h (a prime p < 2^{\mathtt{FLINT\_BITS}}, elements stored as nmod_poly), tests irreducibility and squarefreeness, and finds roots. It is generated from the same template as fq_poly_factor and has the same functions, with fq_nmod in place of fq; each function links to the fq_poly_factor version, which has the details. All algorithms are those of the generic module gr_poly.h, see Factoring polynomials over finite fields.

AlgorithmFactoring polynomials over finite fieldsSquarefree, distinct-degree and equal-degree factorisation over \mathbb{F}_q; the Cantor–Zassenhaus, Berlekamp and Kaltofen–Shoup algorithms, the baby-step giant-step distinct-degree factorisation with modular composition, the trace and minimal-polynomial splittings, and how the generic implementation in gr_poly chooses between them.

Factorisation structure#

A factorisation: an array poly of alloc initialised polynomials and an array exp of exponents, of which the first num pairs are used. The factored polynomial is the product of poly[i]^exp[i] (times a leading coefficient that is returned separately). fq_nmod_poly_factor_t is an array of one structure.

Initialises fac as an empty factorisation, with room for 5 factors.

More

Frees the memory used by fac.

More

fq_nmod_poly_factor_realloc changes the allocation to alloc factors (clearing factors beyond it; alloc = 0 reinitialises fac). fq_nmod_poly_factor_fit_length ensures room for len factors, at least doubling the allocation when it grows.

More

Sets res to a copy of fac.

More

Multiplies the factorisation by poly^exp: if poly is already one of the factors, exp is added to its exponent, otherwise poly is appended with exponent exp. Constant polynomials are ignored.

More

Inserts all factors of fac into res with fq_nmod_poly_factor_insert.

More

Multiplies all exponents by exp, raising the factored polynomial to the power exp.

More

Sets z to the factor of index i, 0 \le i < \mathit{num}.

More
void fq_nmod_poly_factor_print_pretty(const fq_nmod_poly_factor_t fac, const char * var, const fq_nmod_ctx_t ctx)

Print the factors to stdout, one per line, each followed by ^ and its exponent, in the format of fq_nmod_poly_print, respectively of fq_nmod_poly_print_pretty with the variable name var.

More

Squarefree and irreducible polynomials#

Return whether f is squarefree, that is, not divisible by the square of a polynomial of positive degree. Polynomials of length at most 2 other than 0 are squarefree, and 0 is not. This is a wrapper of gr_poly_is_squarefree, which computes \gcd(f, f') and handles p-th powers.

More

Sets res to a squarefree factorisation of f: pairwise coprime monic squarefree polynomials g_i with distinct exponents e_i such that f = c \prod g_i^{e_i}, where c is the leading coefficient of f. Previous contents of res are discarded; for f of length at most 1 the factorisation is empty.

More

Return whether f is irreducible. Unlike gr_poly_is_irreducible, these functions return 1 for all polynomials of length at most 2, including constants and zero.

More

Factorisation#

void fq_nmod_poly_factor(fq_nmod_poly_factor_t result, fq_nmod_t leading_coeff, const fq_nmod_poly_t input, const fq_nmod_ctx_t ctx)

Factors input as c \prod g_i^{e_i} with distinct monic irreducible g_i: sets result to the factors and exponents (discarding previous contents) and leading_coeff to c. For the zero polynomial c = 0 and the factorisation is empty; for a constant, c is the constant.

More

As fq_nmod_poly_factor, but factoring the squarefree parts with the Cantor–Zassenhaus algorithm (distinct-degree factorisation followed by equal-degree splitting), Berlekamp's algorithm (a basis of the kernel of the Frobenius map minus the identity, followed by random splitting), or the Kaltofen–Shoup algorithm (distinct-degree factorisation with baby-step giant-step Frobenius computations by modular composition).

More

As the _with_ functions, without returning the leading coefficient: the output is the factorisation of the monic polynomial f / c. Previous contents of the output are discarded.

More

Distinct-degree factorisation of the squarefree polynomial poly: appends to res, with exponent 1, polynomials g_1, g_2, \ldots such that \operatorname{monic}(\mathit{poly}) = \prod g_i and each g_i is the product of all irreducible factors of degree d_i, and writes the degrees d_i to (*degs)[0], (*degs)[1], .... The caller must provide room for \deg(\mathit{poly}) entries in *degs. The result is undefined if poly is not squarefree. This is a wrapper of gr_poly_factor_distinct_deg.

More

Equal-degree factorisation: appends to factors, with exponent 1, the irreducible factors of pol, which must be a monic squarefree product of irreducible polynomials of degree d. The factors are found by random splitting (Cantor–Zassenhaus), using an internal random state.

More

Sets linfactor to one monic linear factor x - a of input, which must split into linear factors (not necessarily distinct). If input has degree 1 it is copied. Throws FLINT_ERROR if no root is found. This is the step used by fq_nmod_embed_gens to find a root of a defining polynomial in an extension field.

More

Sets rop[i] to x^{q^i} \bmod v for 0 \le i < n, where vinv is the inverse of the reversal of v (see fq_nmod_poly_reverse and fq_nmod_poly_inv_series). The array rop must contain n initialised polynomials. If FQ_NMOD_POLY_ITERATED_FROBENIUS_CUTOFF returns 1, the powers after the first are computed by modular composition with a precomputed Brent–Kung matrix (x^{q^{i}} = x^{q^{i-1}}(x^q)), otherwise by exponentiation.

More

Returns 1 if fq_nmod_poly_iterated_frobenius_preinv should use modular composition for a modulus of length length, which is the case if 2 \log_2 q < 3(\lfloor \sqrt{\mathit{length}} \rfloor + 1).

Roots#

void fq_nmod_poly_roots(fq_nmod_poly_factor_t r, const fq_nmod_poly_t f, int with_multiplicity, const fq_nmod_ctx_t ctx)

Sets r to the roots of the nonzero polynomial f in \mathbb{F}_q, stored as the monic linear factors x - a. If with_multiplicity is nonzero, the exponents are the multiplicities of the roots; otherwise they are 1. Previous contents of r are discarded. This is a wrapper of gr_poly_roots_finite_field, which splits \gcd(f, x^q - x) by equal-degree factorisation; see Roots of polynomials over finite fields.

More

Example#

Cite this page

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