Arithmetic in number fields
- Cost
- Multiplication in degree : one product of degree- integer polynomials plus coefficient operations for the reduction; inverse: one extended GCD over ; norm: one resultant; trace: operations.
A number field of degree is represented as for the minimal polynomial of , and its elements as polynomials of degree less than . The modules nf and nf_elem originate in the ANTIC library [Har2015]; the standard reference for the mathematics and the general algorithms is [Coh1996, Ch. 4].
Representation#
An element is stored as an integer numerator polynomial and one positive denominator , in lowest terms (an fmpq_poly_t). A single denominator keeps additions and multiplications in , where FLINT's fast polynomial arithmetic applies, at the cost of a content computation for canonicalisation.
Small degrees get special representations, selected by nf_init:
- for the element is a rational number, a numerator and a denominator (
lnf_elem_t); - for the numerator is a fixed array of three integers (
qnf_elem_t), so that no memory management is needed and a product can be stored before reduction; - for () a dedicated multiplication is used.
Multiplication and reduction#
To multiply and , nf_elem_mul computes of degree at most with _fmpz_poly_mul, the denominator , and then reduces modulo and removes the common content of numerator and denominator.
For the reduction uses the precomputed remainders for , stored in the nf_t.
Input: , the remainders .
Output: .
- For : add to the low part .
- Return the low part.
The algorithm is correct since . It costs multiplications of coefficients, like division with remainder, but has no dependency between the steps: the remainders do not depend on . If is monic with integer coefficients, the are integral and the reduction stays in (_fmpz_poly_rem_powers_precomp); otherwise the have denominators that are powers of the leading coefficient of and the rational version _fmpq_poly_rem_powers_precomp is used. For the product is reduced by division with remainder, _fmpz_poly_divrem for monic integral and _fmpq_poly_rem with a precomputed inverse of the leading coefficient otherwise.
For , a single step suffices: with , , and for monic this is two multiply-subtracts. For the product is formed with two fused multiply-add operations (fmpz_fmms, fmpz_fmma), and the denominator is reduced by a three-term GCD.
nf_elem_mul_red with red skips the reduction, so that a sum can be accumulated in unreduced form and reduced once at the end, which saves reductions per term.
Inversion and division#
Since is irreducible, any nonzero of degree less than is coprime to , and the extended Euclidean algorithm gives with , so . nf_elem_inv uses fmpq_poly_xgcd (and _fmpq_poly_xgcd for ), which takes out contents and denominators and calls the multimodular _fmpz_poly_xgcd_modular; for coprime integer polynomials that function returns the resultant and integer cofactors with (GCDs of polynomials over Z). For the inverse is the reciprocal of a rational number. Division is multiplication by the inverse. If is reducible, which nf_init does not exclude, an element sharing a factor with has no inverse.
Norm#
Proposition 1. Let and let be nonzero of degree . Then .
Proof. The norm is the product of the conjugates , and by the product formula for resultants .
_nf_elem_norm computes the resultant of the integer numerator of and the numerator of with _fmpq_poly_resultant, which takes out the contents and denominators and calls _fmpz_poly_resultant (multimodular for large inputs), and divides by for the leading coefficient of the numerator of ; the denominator of does not change the roots. _nf_elem_norm_div divides the resultant by a known factor during the multimodular computation, so that only enough primes for the quotient (with a given bound on its bit size) are needed; this is useful when the norm is known to be divisible by a large number, as in ideal arithmetic.
Trace#
The trace of is , where are the power sums of the roots of . nf_init computes once, by Newton's identities
for [Coh1996, p. 163]. Since has denominator dividing , the values are stored with the common denominator . A trace then costs multiplications.
Representation matrices and modular reduction#
The matrix of multiplication by in the basis has as row the coordinates of ; nf_elem_rep_mat computes the rows with nf_elem_mul_gen, one shift and one reduction step each. Its characteristic polynomial is the characteristic polynomial of , whose constant term and second coefficient give the norm and trace again.
The functions nf_elem_mod_fmpz, nf_elem_smod_fmpz and nf_elem_coprime_den replace an element by one congruent to it modulo an integer with reduced coefficients, as needed in multimodular and -adic algorithms over . For nf_elem_coprime_den, write the denominator as where contains exactly the primes dividing ; then is invertible modulo , and replacing the numerator by and the denominator by changes by an element whose denominator divides and whose numerator is divisible by .
Use in FLINT#
- Representation and precomputation:
nf_init,nf_elem_init,nf_elem_canonicalise. - Multiplication and reduction:
nf_elem_mul,nf_elem_mul_red,_nf_elem_mul_red,nf_elem_reduce,_nf_elem_reduce,nf_elem_mul_gen,nf_elem_pow. - Inverse and division:
nf_elem_inv,nf_elem_div. - Norm and trace:
nf_elem_norm,nf_elem_norm_div,nf_elem_trace. - Matrices and modular reduction:
nf_elem_rep_mat,nf_elem_rep_mat_fmpz_mat_den,nf_elem_mod_fmpz,nf_elem_smod_fmpz,nf_elem_coprime_den. - The generic ring
gr_ctx_init_nfuses these functions;qqbarandcausenf_elemfor elements of number fields.
Referenced from#
- Primes and number theory (overview)
- nf.h (module)
- nf_elem.h (module)
nf_elem_mul,nf_elem_mul_red_nf_elem_norm,nf_elem_norm
References#
- [Har2015] W. B. Hart. "ANTIC: Algebraic number theory in C". Computeralgebra-Rundbrief: Vol. 56, 2015
- [Coh1996] Cohen, Henri : A course in computational algebraic number theory, Springer, 1996
The FLINT team, “Arithmetic in number fields,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/number-theory/number-fields.html (generated 2026-11-02).
@misc{flint-doc-algorithms-number-theory-number-fields,
author = {{The FLINT team}},
title = {{Arithmetic in number fields}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/algorithms/number-theory/number-fields.html},
note = {Generated 2026-11-02}
}