FLINT3.7.0-dev
Algorithm

Arithmetic in number fields

Cost
Multiplication in degree dd: one product of degree-(d−1)(d-1) integer polynomials plus O(d2)O(d^2) coefficient operations for the reduction; inverse: one extended GCD over Q\mathbf{Q}; norm: one resultant; trace: O(d)O(d) operations.

A number field K=Q(θ)K = \mathbf{Q}(\theta) of degree dd is represented as Q[x]/(f)\mathbf{Q}[x]/(f) for the minimal polynomial f∈Q[x]f \in \mathbf{Q}[x] of θ\theta, and its elements as polynomials of degree less than dd. 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 α=(a0+a1θ+⋯+ad−1θd−1)/q\alpha = (a_0 + a_1\theta + \cdots + a_{d-1}\theta^{d-1})/q is stored as an integer numerator polynomial and one positive denominator qq, in lowest terms (an fmpq_poly_t). A single denominator keeps additions and multiplications in Z[x]\mathbb{Z}[x], 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 d=1d = 1 the element is a rational number, a numerator and a denominator (lnf_elem_t);
  • for d=2d = 2 the numerator is a fixed array of three integers (qnf_elem_t), so that no memory management is needed and a product (a0+a1θ)(b0+b1θ)(a_0 + a_1\theta)(b_0 + b_1\theta) can be stored before reduction;
  • for f=x2+1f = x^2 + 1 (K=Q(i)K = \mathbf{Q}(i)) a dedicated multiplication is used.

Multiplication and reduction#

To multiply α=A(θ)/q\alpha = A(\theta)/q and β=B(θ)/r\beta = B(\theta)/r, nf_elem_mul computes C=AB∈Z[x]C = AB \in \mathbb{Z}[x] of degree at most 2d−22d - 2 with _fmpz_poly_mul, the denominator qrqr, and then reduces CC modulo ff and removes the common content of numerator and denominator.

For 3≤d<303 \le d < 30 the reduction uses the precomputed remainders Pk=xk mod fP_k = x^k \bmod f for d≤k≤2d−2d \le k \le 2d - 2, stored in the nf_t.

Algorithm 1: Reduction with precomputed powers

Input: C=∑k≤2d−2ckxkC = \sum_{k \le 2d - 2} c_k x^k, the remainders PkP_k.

Output: C mod fC \bmod f.

  1. For k=d,…,deg⁡Ck = d, \ldots, \deg C: add ckPkc_k P_k to the low part ∑k<dckxk\sum_{k < d} c_k x^k.
  2. Return the low part.

The algorithm is correct since C≡∑k<dckxk+∑k≥dckPk(modf)C \equiv \sum_{k < d} c_k x^k + \sum_{k \ge d} c_k P_k \pmod f. It costs (d−1)2(d - 1)^2 multiplications of coefficients, like division with remainder, but has no dependency between the steps: the remainders do not depend on CC. If ff is monic with integer coefficients, the PkP_k are integral and the reduction stays in Z[x]\mathbb{Z}[x] (_fmpz_poly_rem_powers_precomp); otherwise the PkP_k have denominators that are powers of the leading coefficient of ff and the rational version _fmpq_poly_rem_powers_precomp is used. For d≥30d \ge 30 the product is reduced by division with remainder, _fmpz_poly_divrem for monic integral ff and _fmpq_poly_rem with a precomputed inverse of the leading coefficient otherwise.

For d=2d = 2, a single step suffices: with f=f2x2+f1x+f0f = f_2x^2 + f_1x + f_0, c2θ2=−c2(f1θ+f0)/f2c_2\theta^2 = -c_2(f_1\theta + f_0)/f_2, and for monic ff this is two multiply-subtracts. For Q(i)\mathbf{Q}(i) the product (a+bi)(c+di)=(ac−bd)+(ad+bc)i(a + bi)(c + di) = (ac - bd) + (ad + bc)i 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 =0= 0 skips the reduction, so that a sum ∑jαjβj\sum_j \alpha_j\beta_j can be accumulated in unreduced form and reduced once at the end, which saves d−1d - 1 reductions per term.

Inversion and division#

Since ff is irreducible, any nonzero AA of degree less than dd is coprime to ff, and the extended Euclidean algorithm gives S,T∈Q[x]S, T \in \mathbf{Q}[x] with SA+Tf=1SA + Tf = 1, so A(θ)−1=S(θ)A(\theta)^{-1} = S(\theta). nf_elem_inv uses fmpq_poly_xgcd (and _fmpq_poly_xgcd for d=2d = 2), which takes out contents and denominators and calls the multimodular _fmpz_poly_xgcd_modular; for coprime integer polynomials that function returns the resultant rr and integer cofactors with sA+tf=rsA + tf = r (GCDs of polynomials over Z). For d=1d = 1 the inverse is the reciprocal of a rational number. Division is multiplication by the inverse. If ff is reducible, which nf_init does not exclude, an element sharing a factor with ff has no inverse.

Norm#

Proposition 1. Let f=c∏j=1d(x−θj)f = c\prod_{j=1}^d (x - \theta_j) and let A∈Q[x]A \in \mathbf{Q}[x] be nonzero of degree m<dm < d. Then NK/Q(A(θ))=Res⁡(f,A)/cmN_{K/\mathbf{Q}}(A(\theta)) = \operatorname{Res}(f, A) / c^m.

Proof. The norm is the product of the conjugates A(θj)A(\theta_j), and by the product formula for resultants Res⁡(f,A)=cm∏jA(θj)\operatorname{Res}(f, A) = c^m \prod_j A(\theta_j).

_nf_elem_norm computes the resultant of the integer numerator of ff and the numerator of α\alpha with _fmpq_poly_resultant, which takes out the contents and denominators and calls _fmpz_poly_resultant (multimodular for large inputs), and divides by cmc^m for the leading coefficient cc of the numerator of ff; the denominator of ff 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 α=∑kakθk/q\alpha = \sum_k a_k\theta^k / q is ∑kakSk/q\sum_k a_k S_k / q, where Sk=∑jθjkS_k = \sum_j \theta_j^k are the power sums of the roots of ff. nf_init computes S0=d,S1,…,Sd−1S_0 = d, S_1, \ldots, S_{d-1} once, by Newton's identities

cdSk+cd−1Sk−1+⋯+cd−k+1S1+k cd−k=0,1≤k<d,c_d S_k + c_{d-1} S_{k-1} + \cdots + c_{d-k+1} S_1 + k\,c_{d-k} = 0, \qquad 1 \le k < d,

for f=∑kckxkf = \sum_k c_k x^k [Coh1996, p. 163]. Since SkS_k has denominator dividing cdkc_d^k, the values are stored with the common denominator cdd−1c_d^{d-1}. A trace then costs dd multiplications.

Representation matrices and modular reduction#

The matrix of multiplication by α\alpha in the basis 1,θ,…,θd−11, \theta, \ldots, \theta^{d-1} has as row jj the coordinates of θjα\theta^j\alpha; 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 α\alpha, 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 mm with reduced coefficients, as needed in multimodular and pp-adic algorithms over KK. For nf_elem_coprime_den, write the denominator as q=q1q2q = q_1q_2 where q1q_1 contains exactly the primes dividing mm; then q2q_2 is invertible modulo mq1mq_1, and replacing the numerator AA by Aq2−1 mod mq1A q_2^{-1} \bmod mq_1 and the denominator by q1q_1 changes α\alpha by an element whose denominator divides q2q_2 and whose numerator is divisible by mm.

Use in FLINT#

Referenced from#

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
Cite this page

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).