nf.h
#include <flint/nf.h>This module defines the type nf_t of a number field K = \mathbf{Q}(\theta) = \mathbf{Q}[x]/(f), given by a defining polynomial f \in \mathbf{Q}[x] of degree d \ge 1, and computes the data that the element arithmetic of nf_elem.h needs: the representation used for elements (special ones for degree 1 and 2), a precomputed inverse of the leading coefficient, the powers x^i \bmod f used for reduction, and the power sums of the roots of f used for traces. The module goes back to the ANTIC library [Har2015]. The generic ring interface for number fields is gr_ctx_init_nf in gr.h; algebraic number fields as subfields of \mathbf{C} are handled by qqbar.h and ca.h.
Types#
A number field. The fields are pol (the defining polynomial, an fmpq_poly_t), pinv (a precomputed inverse of the leading coefficient of the numerator of pol, used for division in the non-monic generic case), powers (precomputed reductions of x^{d}, \ldots, x^{2d-2} modulo pol for 3 \le d < NF_POWERS_CUTOFF), traces (the power sums S_k = \sum_i \theta_i^k of the roots \theta_i of pol for 0 \le k < d, as an fmpq_poly_t) and flag.
Bits of the field flag. NF_MONIC is set if pol has integer coefficients and leading coefficient 1, NF_LINEAR for d = 1, NF_QUADRATIC for d = 2, and NF_GAUSSIAN in addition for f = x^2 + 1 exactly; NF_GENERIC is the value 0. Elements of linear and quadratic fields use the representations lnf_elem_t and qnf_elem_t of nf_elem.h.
The bound 30 on the length of the defining polynomial up to which the powers of x modulo f are precomputed for reduction.
Functions#
void nf_init(nf_t nf, const fmpq_poly_t pol)Initialises nf for the defining polynomial pol, which must have degree at least 1 (otherwise the function throws). The polynomial is not checked to be irreducible: with a reducible polynomial the arithmetic is that of the ring \mathbf{Q}[x]/(f), and the result of inverting a zero divisor is meaningless (_nf_elem_invertible_check tests for this).
void nf_init_randtest(nf_t nf, flint_rand_t state, slong len, flint_bitcnt_t bits_in)Initialises nf with a random defining polynomial of length at most len (that is, degree at most len - 1) with coefficients of at most bits_in bits, for testing. Linear and quadratic fields, monic polynomials and x^2 + 1 are chosen with increased probability. The polynomial need not be irreducible. Throws if len < 2 or bits_in < 1.
References#
- [Har2015] W. B. Hart. "ANTIC: Algebraic number theory in C". Computeralgebra-Rundbrief: Vol. 56, 2015
The FLINT team, “nf.h (module overview),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/nf/index.html (generated 2026-10-20).
@misc{flint-doc-nf-index,
author = {{The FLINT team}},
title = {{nf.h (module overview)}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/nf/index.html},
note = {Generated 2026-10-20}
}