Choosing a representation for exact numbers
An exact number is one that is represented symbolically, so that the value is determined without error and can be approximated to any precision. FLINT has four exact representations of increasing generality, and they differ less in what they can express than in what they can decide: whether two numbers are equal, whether a number is real, positive or rational. The more general the representation, the more expensive arithmetic becomes and the weaker the guarantees.
The representations#
| Representation | Numbers | Element stored as | Equality | Typical cost |
|---|---|---|---|---|
fmpq | \mathbb{Q} | reduced fraction | canonical | quasi-linear in the bit size |
| nf_elem.h | a fixed number field \mathbb{Q}(a) | polynomial in a of degree less than [\mathbb{Q}(a) : \mathbb{Q}] | canonical | polynomial arithmetic modulo the defining polynomial |
| qqbar.h | \overline{\mathbb{Q}} | minimal polynomial and isolating ball | decidable | resultants and factorisation; degrees multiply |
| ca.h | real and complex numbers built from \mathbb{Q} by arithmetic, roots, \exp, \log, \pi, trigonometric and some special functions | element of a formal field \mathbb{Q}(a_1, \ldots, a_n) reduced modulo proved relations | semi-decidable: answers may be unknown | multivariate rational functions, relation searches, numerical evaluation |
The two exact algebraic representations behave very differently. A nf_elem.h is cheap, but all numbers must belong to one field fixed in advance, which is not always known and whose degree can be large. A qqbar.h number carries its own minimal polynomial, so any two algebraic numbers can be combined; arithmetic is self-contained and canonical, but an operation may need a resultant and its factorisation, and the degree of the result can be as large as the degree of the compositum, so long computations become expensive (see Arithmetic with algebraic numbers).
A ca.h number represents its value as an element of a formal field whose generators are algebraic numbers or transcendental extension numbers such as \pi, e^{\sqrt 2} or \log 3. Field arithmetic is formal and cheap compared with resultants, several algebraic generators can coexist without computing a primitive element, and transcendental numbers can be represented at all. The price is that equality is not canonical: a zero test combines numerical evaluation with exact reductions and can fail (see Zero testing). When all generators are algebraic, ca can fall back on qqbar.h and decide equality, within the degree limit CA_OPT_QQBAR_DEG_LIMIT.
The gr.h interface provides contexts for all of them (see Number fields and algebraic numbers and Real and complex numbers): qqbar through gr_ctx_init_real_qqbar and gr_ctx_init_complex_qqbar, and ca through gr_ctx_init_real_ca, gr_ctx_init_complex_ca, their algebraic variants and gr_ctx_init_complex_extended_ca. Generic polynomial and matrix algorithms then work over exact numbers and return GR_UNABLE when a zero test fails. Symbolic expressions (fexpr.h) are not numbers but trees; they are used to construct, print and convert exact numbers.
Which algorithm is used#
| Task | Method | Functions |
|---|---|---|
| Create an algebraic number | factor the defining polynomial, isolate the roots, certify with interval Newton | qqbar_roots_fmpz_poly; Creating algebraic numbers |
| Refine an enclosure | certified Newton iteration, recomputation of all roots as fallback | qqbar_get_acb, qqbar_cache_enclosure; Refining an enclosure |
| Compare algebraic numbers | minimal polynomials, then enclosures | qqbar_equal, qqbar_cmp_re; Deciding predicates |
| Add or multiply algebraic numbers | closed forms for quadratics, subfield and cyclotomic detection, guessing with proof, composed polynomials and factor selection | qqbar_add, qqbar_mul, qqbar_binary_op; Arithmetic with algebraic numbers |
| Create a field with given generators | ideal of relations: minimal polynomials, logarithmic and multiplicative relations, Gröbner basis | ca_field_build_ideal; Formal fields and the ideal of relations |
Arithmetic in ca | formal arithmetic in the common field of the operands, reduction modulo the ideal | ca_add, ca_mul, ca_merge_fields; Formal fields and the ideal of relations |
| Decide x = 0 | numerical evaluation, algebraic evaluation, normal form rewriting, factoring | ca_check_is_zero (Zero tests and equality); Zero testing |
| Simplify, recognise closed forms | canonical number field forms, rewriting rules, LLL with exact verification | ca_condense_field, qqbar_guess, qqbar_get_fexpr_formula; Simplification and closed forms |
| Roots of polynomials | squarefree factorisation, rational factors via qqbar.h, formulas up to degree 3 | ca_poly_roots (Roots and squarefree factorisation) |
| Linear algebra | simplest-first pivoting, fraction-free and division-free methods, rational and number field specialisations | ca_mat_det, ca_mat_rank, ca_mat_eigenvalues; Linear algebra over exact numbers |
Practical advice#
- Use
fmpqor nf_elem.h when the numbers are known to lie in \mathbb{Q} or in one known number field: arithmetic is much faster than withqqbarorca. - Use qqbar.h for algebraic numbers when exact answers to all predicates are required and degrees stay moderate. Computations whose intermediate degrees explode, such as sums of many square roots, can be cheaper in ca.h, which keeps them in a field with several quadratic generators.
- Use ca.h whenever transcendental numbers occur, and check the
truth_tresults of predicates:T_UNKNOWNis a legitimate answer. The options of the context (see Context options) bound the work spent on zero tests and relation searches. - For numerical values only, arb.h and acb.h are much faster;
ca_get_acbandqqbar_get_acbconvert exact numbers to balls of any precision.
Referenced from#
- Exact real and complex numbers (overview)
- ca.h (module)
- Using ca
- Choosing types (overview)
- nf_elem.h (module)
The FLINT team, “Choosing a representation for exact numbers,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/exact/overview.html (generated 2026-10-20).
@misc{flint-doc-algorithms-exact-overview,
author = {{The FLINT team}},
title = {{Choosing a representation for exact numbers}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/algorithms/exact/overview.html},
note = {Generated 2026-10-20}
}