ca_field.h
#include <flint/ca_field.h>A ca_field_t is the parent field K = \mathbb{Q}(a_1, \ldots, a_n) of ca_t numbers (see ca.h): a list of pointers to extension numbers a_1, \ldots, a_n (see ca_ext.h) together with an ideal I \subset \mathbb{Z}[X_1, \ldots, X_n] of polynomial relations satisfied by them. An element of K is represented by a rational function in the generators, and arithmetic is done in the formal field \operatorname{Frac}(\mathbb{Q}[X_1, \ldots, X_n] / I), reducing numerators and denominators modulo I.
Three kinds of field are distinguished, which mainly affects how elements are stored:
- the field \mathbb{Q}, with no generators, whose elements are
fmpqvalues; - a number field \mathbb{Q}(a) with a single algebraic generator a given by a
qqbar_t, whose elements are nf_elem.h values modulo the minimal polynomial of a (the ideal is not stored); - a generic field \mathbb{Q}(a_1, \ldots, a_n), whose elements are fmpz_mpoly_q.h rational functions in n variables.
Users do not normally create fields: the context object keeps a cache of fields, and the functions of ca.h find or create the field they need, for example ca_merge_fields when combining elements of different fields. The generators of a field are sorted by the structural order of ca_ext_cmp_repr (reversed), so that a lexicographic monomial order eliminates the most complicated generators first. When a field is created, its ideal of relations is built by the heuristics described in Formal fields and the ideal of relations: minimal polynomials of algebraic generators, defining equations of roots and powers, Vieta's formulas for conjugates, integer relations between logarithms and between exponentials and powers found by LLL and proved exactly, and functional equations of the error and gamma functions, followed by a Gröbner basis computation.
Types and macros#
A field. The structure holds the number of generators length, the array ext of pointers to the extension numbers, the ideal ideal (an fmpz_mpoly_vec_struct) and a hash value. A ca_field_t is an array of one structure.
CA_FIELD_EXT(K)CA_FIELD_EXT_ELEM(K, i)Access the number n of generators of K (0 for \mathbb{Q}), the array of pointers to the extension numbers, the pointer to the generator with index i (starting from 0), and the hash value.
Test whether K is \mathbb{Q}, a number field \mathbb{Q}(a) with one algebraic generator, or a generic field. A number field is marked by an ideal length of -1.
CA_FIELD_NF(K)CA_FIELD_IDEAL_ELEM(K, i)For a generic field: the ideal of relations as an fmpz_mpoly_vec_struct pointer, its element with index i as an fmpz_mpoly_struct pointer, the number of polynomials, the allocated number, and the array of polynomials.
CA_FIELD_MCTX(K, ctx)For a generic field with n generators: the fmpz_mpoly_ctx_struct pointer for polynomials in n variables, owned by the context ctx and shared by all fields with n generators. The monomial order is the context option CA_OPT_MPOLY_ORD.
The multiplier used to combine the hashes of the generators into the hash of a field.
Memory management#
void ca_field_init_qq(ca_field_t K, ca_ctx_t ctx)Initialises K as the field \mathbb{Q}.
void ca_field_init_nf(ca_field_t K, const qqbar_t x, ca_ctx_t ctx)Initialises K as the number field \mathbb{Q}(x), inserting the extension number x into the cache of ctx.
void ca_field_init_const(ca_field_t K, calcium_func_code func, ca_ctx_t ctx)void ca_field_init_fx(ca_field_t K, calcium_func_code func, const ca_t x, ca_ctx_t ctx)void ca_field_init_fxy(ca_field_t K, calcium_func_code func, const ca_t x, const ca_t y, ca_ctx_t ctx)Initialises K as the generic field \mathbb{Q}(a) with the single generator a given by the constant func (for example CA_Pi), the function value f(x) or the function value f(x, y), inserting the extension number into the cache of ctx. The ideal is empty; it is not built by these functions.
void ca_field_init_multi(ca_field_t K, slong len, ca_ctx_t ctx)Initialises K as a generic field with len generators, which must then be assigned one by one with ca_field_set_ext. The ideal is empty.
void ca_field_set_ext(ca_field_t K, slong i, ca_ext_srcptr x, ca_ctx_t ctx)Sets the generator with index i of K to the extension number x and updates the hash. Only a pointer is stored, so x must outlive K; extension numbers from the cache of the context do.
void ca_field_clear(ca_field_t K, ca_ctx_t ctx)Clears K and its ideal. The extension numbers are not cleared, since the field only holds references to them.
Input and output#
void ca_field_print(const ca_field_t K, ca_ctx_t ctx)Prints a description of K to standard output, of the form QQ(x1, x2) where {x1 = ..., x2 = ...} with ideal {...}, with the generators printed by ca_ext_print and the ideal (if not empty) in the variables x1, x2, ....
Ideal of relations#
void ca_field_build_ideal(ca_field_t K, ca_ctx_t ctx)Builds the ideal of relations of the generic field K, whose generators have been assigned, in place. Nothing is done for \mathbb{Q} and for number fields. The relations found are always valid, but they need not generate the full ideal of relations between the generators. If CA_OPT_USE_GROEBNER is set and the relations have total degree at most CA_OPT_QQBAR_DEG_LIMIT, the ideal is replaced by its reduced Gröbner basis when Buchberger's algorithm finishes within the limits set by the context options. See Formal fields and the ideal of relations for the relations that are searched for.
void ca_field_build_ideal_erf(ca_field_t K, ca_ctx_t ctx)Adds relations between error functions among the generators of K that follow from \operatorname{erf}(-x) = -\operatorname{erf}(x), \operatorname{erfc}(x) = 1 - \operatorname{erf}(x) and \operatorname{erfi}(x) = -i \operatorname{erf}(ix), when the arguments are proved to be equal or opposite (or related by a factor i). Called by ca_field_build_ideal.
void ca_field_build_ideal_gamma(ca_field_t K, ca_ctx_t ctx)Adds the relations \Gamma(x + n) = x (x+1) \cdots (x + n - 1) \Gamma(x) between generators \Gamma(x + n) and \Gamma(x) of K whose arguments differ by an integer n with |n| \le 10 (and \Gamma(x) = \Gamma(y) when x = y), provided the factors x + k can be expressed in K. Called by ca_field_build_ideal.
Comparison#
int ca_field_cmp(const ca_field_t K1, const ca_field_t K2, ca_ctx_t ctx)Compares the fields K1 and K2 in a total structural order (number of generators, then the generators with ca_ext_cmp_repr), returning -1, 0 or 1. The order says nothing about the fields as mathematical objects.
Cache#
A set of fields: an array of pointers to heap-allocated fields and a hash table indexed by the generators. Each context object contains one such cache.
void ca_field_cache_init(ca_field_cache_t cache, ca_ctx_t ctx)void ca_field_cache_clear(ca_field_cache_t cache, ca_ctx_t ctx)Initialises cache as empty, or clears it, freeing all fields in it.
ca_field_ptr ca_field_cache_insert_ext(ca_field_cache_t cache, ca_ext_struct ** x, slong length, ca_ctx_t ctx)Returns a pointer to the field in cache whose generators are the length extension numbers x (compared as pointers, in the given order), creating it if needed. A newly created field is \mathbb{Q} if length is 0, a number field if it has one algebraic generator, and otherwise a generic field whose ideal is built immediately with ca_field_build_ideal. The extension numbers must belong to the cache of ctx.
The FLINT team, “ca_field.h (module overview),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/ca_field/index.html (generated 2026-10-20).
@misc{flint-doc-ca-field-index,
author = {{The FLINT team}},
title = {{ca\_field.h (module overview)}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/ca_field/index.html},
note = {Generated 2026-10-20}
}