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.
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#
void fq_default_poly_init(fq_default_poly_t poly, const fq_default_ctx_t ctx)void fq_default_poly_init2(fq_default_poly_t poly, slong alloc, const fq_default_ctx_t ctx)Initialise poly as the zero polynomial; fq_default_poly_init2 allocates space for alloc coefficients.
void fq_default_poly_realloc(fq_default_poly_t poly, slong alloc, const fq_default_ctx_t ctx)void fq_default_poly_fit_length(fq_default_poly_t poly, slong len, const fq_default_ctx_t ctx)Change the allocation to alloc coefficients (truncating if needed), respectively ensure room for at least len coefficients.
void fq_default_poly_clear(fq_default_poly_t poly, const fq_default_ctx_t ctx)Frees the memory used by poly.
void _fq_default_poly_set_length(fq_default_poly_t poly, slong len, const fq_default_ctx_t ctx)Sets the length of poly to len without normalising, as _fq_poly_set_length; for internal use.
void fq_default_poly_truncate(fq_default_poly_t poly, slong len, const fq_default_ctx_t ctx)void fq_default_poly_set_trunc(fq_default_poly_t poly1, fq_default_poly_t poly2, slong len, const fq_default_ctx_t ctx)Truncate poly to length len, respectively set poly1 to poly2 truncated to length len.
Length, degree and comparison#
slong fq_default_poly_length(const fq_default_poly_t poly, const fq_default_ctx_t ctx)slong fq_default_poly_degree(const fq_default_poly_t poly, const fq_default_ctx_t ctx)Return the length, respectively the degree ( for zero).
slong fq_default_poly_hamming_weight(const fq_default_poly_t op, const fq_default_ctx_t ctx)Returns the number of nonzero coefficients.
int fq_default_poly_equal(const fq_default_poly_t poly1, const fq_default_poly_t poly2, const fq_default_ctx_t ctx)int fq_default_poly_equal_trunc(const fq_default_poly_t poly1, const fq_default_poly_t poly2, slong n, const fq_default_ctx_t ctx)int fq_default_poly_equal_fq_default(const fq_default_poly_t poly, const fq_default_t c, const fq_default_ctx_t ctx)Return whether the polynomials are equal, equal modulo , respectively whether poly is the constant .
int fq_default_poly_is_zero(const fq_default_poly_t poly, const fq_default_ctx_t ctx)int fq_default_poly_is_one(const fq_default_poly_t op, const fq_default_ctx_t ctx)int fq_default_poly_is_gen(const fq_default_poly_t poly, const fq_default_ctx_t ctx)int fq_default_poly_is_unit(const fq_default_poly_t op, const fq_default_ctx_t ctx)Return whether the polynomial is 0, 1, , respectively a nonzero constant.
Assignment and conversion#
void fq_default_poly_set(fq_default_poly_t rop, const fq_default_poly_t op, const fq_default_ctx_t ctx)void fq_default_poly_swap(fq_default_poly_t op1, fq_default_poly_t op2, const fq_default_ctx_t ctx)Copy, respectively swap, polynomials.
void fq_default_poly_zero(fq_default_poly_t poly, const fq_default_ctx_t ctx)void fq_default_poly_one(fq_default_poly_t poly, const fq_default_ctx_t ctx)void fq_default_poly_gen(fq_default_poly_t f, const fq_default_ctx_t ctx)void fq_default_poly_set_fq_default(fq_default_poly_t poly, const fq_default_t c, const fq_default_ctx_t ctx)Set the polynomial to 0, 1, , respectively the constant .
void fq_default_poly_set_nmod_poly(fq_default_poly_t rop, const nmod_poly_t op, const fq_default_ctx_t ctx)void fq_default_poly_set_fmpz_mod_poly(fq_default_poly_t rop, const fmpz_mod_poly_t op, const fq_default_ctx_t ctx)void fq_default_poly_set_fmpz_poly(fq_default_poly_t rop, const fmpz_poly_t op, const fq_default_ctx_t ctx)Set rop to the image of a polynomial over (whose modulus must be ), respectively over (with coefficients reduced modulo ), in .
void fq_default_poly_make_monic(fq_default_poly_t rop, const fq_default_poly_t op, const fq_default_ctx_t ctx)Sets rop to op divided by its leading coefficient (zero stays zero).
void fq_default_poly_reverse(fq_default_poly_t res, const fq_default_poly_t poly, slong n, const fq_default_ctx_t ctx)Sets res to the reversal of poly as a polynomial of length , for = poly truncated to length .
ulong fq_default_poly_deflation(const fq_default_poly_t input, const fq_default_ctx_t ctx)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 such that input is a polynomial in , write as , respectively compute , as for fq_poly.
Coefficients#
void fq_default_poly_get_coeff(fq_default_t x, const fq_default_poly_t poly, slong n, const fq_default_ctx_t ctx)Sets to the coefficient of (zero beyond the length).
void fq_default_poly_set_coeff(fq_default_poly_t poly, slong n, const fq_default_t x, const fq_default_ctx_t ctx)void fq_default_poly_set_coeff_fmpz(fq_default_poly_t poly, slong n, const fmpz_t x, const fq_default_ctx_t ctx)Set the coefficient of to the element , respectively to the image of the integer in .
Random polynomials#
void fq_default_poly_randtest(fq_default_poly_t f, flint_rand_t state, slong len, const fq_default_ctx_t ctx)void fq_default_poly_randtest_not_zero(fq_default_poly_t f, flint_rand_t state, slong len, const fq_default_ctx_t ctx)void fq_default_poly_randtest_monic(fq_default_poly_t f, flint_rand_t state, slong len, const fq_default_ctx_t ctx)void fq_default_poly_randtest_irreducible(fq_default_poly_t f, flint_rand_t state, slong len, const fq_default_ctx_t ctx)Random polynomials of length at most len (nonzero for the second function, which requires len ), random monic polynomials of length len, and random monic irreducible polynomials of length len, for testing.
Arithmetic#
void fq_default_poly_add(fq_default_poly_t rop, const fq_default_poly_t op1, const fq_default_poly_t op2, const fq_default_ctx_t ctx)void fq_default_poly_sub(fq_default_poly_t rop, const fq_default_poly_t op1, const fq_default_poly_t op2, const fq_default_ctx_t ctx)void fq_default_poly_neg(fq_default_poly_t rop, const fq_default_poly_t op, const fq_default_ctx_t ctx)Set rop to the sum, the difference, respectively the negation.
void fq_default_poly_add_si(fq_default_poly_t rop, const fq_default_poly_t op1, slong c, const fq_default_ctx_t ctx)Sets rop to , with mapped to .
void fq_default_poly_add_series(fq_default_poly_t rop, const fq_default_poly_t op1, const fq_default_poly_t op2, slong n, const fq_default_ctx_t ctx)void fq_default_poly_sub_series(fq_default_poly_t rop, const fq_default_poly_t op1, const fq_default_poly_t op2, slong n, const fq_default_ctx_t ctx)Set rop to the sum, respectively difference, truncated to length .
void fq_default_poly_scalar_mul_fq_default(fq_default_poly_t rop, const fq_default_poly_t op, const fq_default_t x, const fq_default_ctx_t ctx)void fq_default_poly_scalar_div_fq_default(fq_default_poly_t rop, const fq_default_poly_t op, const fq_default_t x, const fq_default_ctx_t ctx)void fq_default_poly_scalar_addmul_fq_default(fq_default_poly_t rop, const fq_default_poly_t op, const fq_default_t x, const fq_default_ctx_t ctx)void fq_default_poly_scalar_submul_fq_default(fq_default_poly_t rop, const fq_default_poly_t op, const fq_default_t x, const fq_default_ctx_t ctx)Set rop to , (for ), respectively add to or subtract it from rop.
void fq_default_poly_mul(fq_default_poly_t rop, const fq_default_poly_t op1, const fq_default_poly_t op2, const fq_default_ctx_t ctx)void fq_default_poly_sqr(fq_default_poly_t rop, const fq_default_poly_t op, const fq_default_ctx_t ctx)Set rop to , respectively ; see Multiplying polynomials over finite fields for the algorithms over extension fields.
void fq_default_poly_mullow(fq_default_poly_t rop, const fq_default_poly_t op1, const fq_default_poly_t op2, slong n, const fq_default_ctx_t ctx)Sets rop to the product truncated to length .
void fq_default_poly_mulhigh(fq_default_poly_t rop, const fq_default_poly_t op1, const fq_default_poly_t op2, slong start, const fq_default_ctx_t ctx)Sets rop to a polynomial whose coefficients of index at least start are those of the product ; the lower coefficients are zero for the extension field representations and unspecified (zero or those of the product) for prime fields.
void fq_default_poly_mulmod(fq_default_poly_t res, const fq_default_poly_t poly1, const fq_default_poly_t poly2, const fq_default_poly_t f, const fq_default_ctx_t ctx)Sets res to for .
void fq_default_poly_pow(fq_default_poly_t rop, const fq_default_poly_t op, ulong e, const fq_default_ctx_t ctx)void fq_default_poly_pow_trunc(fq_default_poly_t res, const fq_default_poly_t poly, ulong e, slong trunc, const fq_default_ctx_t ctx)Set the output to , respectively , with .
void fq_default_poly_powmod_ui_binexp(fq_default_poly_t res, const fq_default_poly_t poly, ulong e, const fq_default_poly_t f, const fq_default_ctx_t ctx)void fq_default_poly_powmod_fmpz_binexp(fq_default_poly_t res, const fq_default_poly_t poly, const fmpz_t e, const fq_default_poly_t f, const fq_default_ctx_t ctx)Set res to for and , by binary exponentiation.
void fq_default_poly_shift_left(fq_default_poly_t rop, const fq_default_poly_t op, slong n, const fq_default_ctx_t ctx)void fq_default_poly_shift_right(fq_default_poly_t rop, const fq_default_poly_t op, slong n, const fq_default_ctx_t ctx)Set rop to , respectively .
void fq_default_poly_derivative(fq_default_poly_t rop, const fq_default_poly_t op, const fq_default_ctx_t ctx)Sets rop to the formal derivative of op.
Division and GCD#
void fq_default_poly_divrem(fq_default_poly_t Q, fq_default_poly_t R, const fq_default_poly_t A, const fq_default_poly_t B, const fq_default_ctx_t ctx)void fq_default_poly_rem(fq_default_poly_t R, const fq_default_poly_t A, const fq_default_poly_t B, const fq_default_ctx_t ctx)Compute the quotient and the remainder of the division of by , with and , respectively only the remainder. and must be distinct.
int fq_default_poly_divides(fq_default_poly_t Q, const fq_default_poly_t A, const fq_default_poly_t B, const fq_default_ctx_t ctx)Returns 1 and sets if divides , and returns 0 otherwise. must be nonzero.
ulong fq_default_poly_remove(fq_default_poly_t f, const fq_default_poly_t g, const fq_default_ctx_t ctx)Removes the highest power of (of degree at least 1) dividing and returns its exponent.
void fq_default_poly_gcd(fq_default_poly_t rop, const fq_default_poly_t op1, const fq_default_poly_t op2, const fq_default_ctx_t ctx)Sets rop to the monic GCD of the two polynomials (zero if both are zero).
void fq_default_poly_xgcd(fq_default_poly_t G, fq_default_poly_t S, fq_default_poly_t T, const fq_default_poly_t A, const fq_default_poly_t B, const fq_default_ctx_t ctx)Computes the monic GCD of and and cofactors with , as fq_poly_xgcd. , and must be distinct.
Power series#
void fq_default_poly_inv_series(fq_default_poly_t Qinv, const fq_default_poly_t Q, slong n, const fq_default_ctx_t ctx)void fq_default_poly_div_series(fq_default_poly_t Q, const fq_default_poly_t A, const fq_default_poly_t B, slong n, const fq_default_ctx_t ctx)Set the output to , respectively , for a power series with nonzero constant term.
void fq_default_poly_sqrt_series(fq_default_poly_t rop, const fq_default_poly_t op, slong n, fq_default_ctx_t ctx)void fq_default_poly_invsqrt_series(fq_default_poly_t rop, const fq_default_poly_t op, slong n, fq_default_ctx_t ctx)Set rop to , respectively , modulo , for a power series with constant term 1, in odd characteristic.
int fq_default_poly_sqrt(fq_default_poly_t rop, const fq_default_poly_t op, fq_default_ctx_t ctx)If op is the square of a polynomial, sets rop to a square root and returns 1; otherwise returns 0.
Evaluation and composition#
void fq_default_poly_evaluate_fq_default(fq_default_t res, const fq_default_poly_t f, const fq_default_t a, const fq_default_ctx_t ctx)Sets res to .
void fq_default_poly_compose(fq_default_poly_t rop, const fq_default_poly_t op1, const fq_default_poly_t op2, const fq_default_ctx_t ctx)Sets rop to for = op1 and = op2.
void fq_default_poly_compose_mod(fq_default_poly_t res, const fq_default_poly_t poly1, const fq_default_poly_t poly2, const fq_default_poly_t poly3, const fq_default_ctx_t ctx)Sets res to for = poly1, = poly2 and = poly3 (Composition and modular composition).
Characteristic and minimal polynomial of a matrix#
void fq_default_mat_charpoly(fq_default_poly_t p, const fq_default_mat_t M, const fq_default_ctx_t ctx)void fq_default_mat_minpoly(fq_default_poly_t p, const fq_default_mat_t X, const fq_default_ctx_t ctx)Set to the characteristic polynomial , 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)int fq_default_poly_print(const fq_default_poly_t poly, const fq_default_ctx_t ctx)char * fq_default_poly_get_str(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)).
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).
@misc{flint-doc-fq-default-poly-index,
author = {{The FLINT team}},
title = {{fq\_default\_poly.h (module overview)}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/fq_default_poly/index.html},
note = {Generated 2026-11-02}
}