FLINT3.7.0-dev
Module · 85 functions

fq_default_poly.h

#include <flint/fq_default_poly.h>

This module implements dense univariate polynomials over a finite field given by an fq_default_ctx_t (see fq_default.h). A polynomial is a union of the polynomial types of the five representations (fq_zech_poly, fq_nmod_poly, fq_poly, nmod_poly and fmpz_mod_poly), and every function calls the function of the representation of the context. The semantics are those of fq_poly.h, where the algorithms are described: polynomials are normalised, outputs may be aliased with inputs, and the fast algorithms (Kronecker substitution multiplication, Newton division, half-GCD, Brent–Kung modular composition) are used automatically. Over prime fields the functions of nmod_poly and fmpz_mod_poly are used. Factorisation and root finding are in fq_default_poly_factor.h.

OverviewMultiplying polynomials over Z/nZHow nmod_poly multiplies: classical products built on modular dot products, Kronecker substitution (KS, KS2, KS4), and the small-prime FFT of fft_small, with the length and modulus-size cutoffs that choose between them for full, low, middle and high products.

Types#

A polynomial over an fq_default field: a union of an fq_poly_t, an fq_nmod_poly_t, an fq_zech_poly_t, an nmod_poly_t and an fmpz_mod_poly_t, of which the member matching the context is used. fq_default_poly_t is an array of one union.

Memory management#

Initialise poly as the zero polynomial; fq_default_poly_init2 allocates space for alloc coefficients.

Change the allocation to alloc coefficients (truncating if needed), respectively ensure room for at least len coefficients.

Frees the memory used by poly.

Sets the length of poly to len without normalising, as _fq_poly_set_length; for internal use.

Truncate poly to length len, respectively set poly1 to poly2 truncated to length len.

Length, degree and comparison#

Return the length, respectively the degree (−1-1 for zero).

Returns the number of nonzero coefficients.

Return whether the polynomials are equal, equal modulo xnx^n, respectively whether poly is the constant cc.

Return whether the polynomial is 0, 1, xx, respectively a nonzero constant.

Assignment and conversion#

Copy, respectively swap, polynomials.

Set the polynomial to 0, 1, xx, respectively the constant cc.

Set rop to the image of a polynomial over Fp\mathbb{F}_p (whose modulus must be pp), respectively over Z\mathbb{Z} (with coefficients reduced modulo pp), in Fq[x]\mathbb{F}_q[x].

Sets rop to op divided by its leading coefficient (zero stays zero).

Sets res to the reversal of poly as a polynomial of length nn, xn−1f(1/x)x^{n-1} f(1/x) for ff = poly truncated to length nn.

void fq_default_poly_deflate(fq_default_poly_t result, const fq_default_poly_t input, ulong deflation, const fq_default_ctx_t ctx)
void fq_default_poly_inflate(fq_default_poly_t result, const fq_default_poly_t input, ulong inflation, const fq_default_ctx_t ctx)

Return the largest kk such that input is a polynomial in xkx^k, write f(xk)f(x^k) as g(x)g(x), respectively compute f(xk)f(x^k), as for fq_poly.

Coefficients#

Sets xx to the coefficient of xnx^n (zero beyond the length).

Set the coefficient of xnx^n to the element xx, respectively to the image of the integer xx in Fp\mathbb{F}_p.

Random polynomials#

Random polynomials of length at most len (nonzero for the second function, which requires len >0> 0), random monic polynomials of length len, and random monic irreducible polynomials of length len, for testing.

Arithmetic#

Set rop to the sum, the difference, respectively the negation.

Sets rop to op1+c\mathit{op1} + c, with cc mapped to Fp\mathbb{F}_p.

Set rop to the sum, respectively difference, truncated to length nn.

Set rop to x⋅opx \cdot \mathit{op}, op/x\mathit{op} / x (for x≠0x \ne 0), respectively add x⋅opx \cdot \mathit{op} to or subtract it from rop.

Set rop to op1⋅op2\mathit{op1} \cdot \mathit{op2}, respectively op2\mathit{op}^2; see Multiplying polynomials over finite fields for the algorithms over extension fields.

Sets rop to the product truncated to length nn.

Sets rop to a polynomial whose coefficients of index at least start are those of the product op1⋅op2\mathit{op1} \cdot \mathit{op2}; the lower coefficients are zero for the extension field representations and unspecified (zero or those of the product) for prime fields.

Sets res to poly1⋅poly2 mod f\mathit{poly1} \cdot \mathit{poly2} \bmod f for f≠0f \ne 0.

Set the output to ope\mathit{op}^e, respectively polye mod xtrunc\mathit{poly}^e \bmod x^{\mathit{trunc}}, with op0=1\mathit{op}^0 = 1.

Set res to polye mod f\mathit{poly}^e \bmod f for e≥0e \ge 0 and f≠0f \ne 0, by binary exponentiation.

Set rop to xn⋅opx^n \cdot \mathit{op}, respectively ⌊op/xn⌋\lfloor \mathit{op} / x^n \rfloor.

Sets rop to the formal derivative of op.

Division and GCD#

Compute the quotient QQ and the remainder RR of the division of AA by B≠0B \ne 0, with A=BQ+RA = BQ + R and deg⁡R<deg⁡B\deg R < \deg B, respectively only the remainder. QQ and RR must be distinct.

Returns 1 and sets Q=A/BQ = A/B if BB divides AA, and returns 0 otherwise. BB must be nonzero.

Removes the highest power of gg (of degree at least 1) dividing ff and returns its exponent.

Sets rop to the monic GCD of the two polynomials (zero if both are zero).

Computes the monic GCD GG of AA and BB and cofactors with SA+TB=GSA + TB = G, as fq_poly_xgcd. GG, SS and TT must be distinct.

Power series#

Set the output to 1/Q mod xn1/Q \bmod x^n, respectively A/B mod xnA/B \bmod x^n, for a power series with nonzero constant term.

Set rop to op\sqrt{\mathit{op}}, respectively 1/op1/\sqrt{\mathit{op}}, modulo xnx^n, for a power series with constant term 1, in odd characteristic.

If op is the square of a polynomial, sets rop to a square root and returns 1; otherwise returns 0.

Evaluation and composition#

Sets res to f(a)f(a).

Sets rop to g(h(x))g(h(x)) for gg = op1 and hh = op2.

Sets res to f(g) mod hf(g) \bmod h for ff = poly1, gg = poly2 and hh = poly3 ≠0\ne 0 (Composition and modular composition).

Characteristic and minimal polynomial of a matrix#

Set pp to the characteristic polynomial det⁡(xI−M)\det(xI - M), respectively the minimal polynomial, of a square matrix over the field (see fq_mat_charpoly and fq_mat_minpoly).

Input and output#

int fq_default_poly_fprint(FILE * file, const fq_default_poly_t poly, const fq_default_ctx_t ctx)

Print the polynomial, or return it as a newly allocated string, in the plain format of the representation.

int fq_default_poly_fprint_pretty(FILE * file, const fq_default_poly_t poly, const char * x, const fq_default_ctx_t ctx)
int fq_default_poly_print_pretty(const fq_default_poly_t poly, const char * x, const fq_default_ctx_t ctx)
char * fq_default_poly_get_str_pretty(const fq_default_poly_t poly, const char * x, const fq_default_ctx_t ctx)

Print the polynomial in the variable x, or return it as a newly allocated string, with coefficients in parentheses in the readable format of the field (for example x^2+(a+1)*x+(a)).

Cite this page

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