ca_vec.h
#include <flint/ca_vec.h>This module implements vectors of exact real and complex numbers of type ca_t (see ca.h). A ca_vec_t is a growable array with a length that is set by the user: unlike a ca_poly.h polynomial, it is never normalised by removing zero entries. The module is small; it supplies the memory management and the entrywise operations used by ca_poly.h and ca_mat.h.
As in other FLINT modules, functions with a leading underscore work on plain arrays of type ca_ptr (or ca_srcptr for read-only input) with an explicit length, and leave memory management to the caller. Every function takes the context object ctx that the entries belong to. Entries are arbitrary ca_t values, including special values such as Unknown, and arithmetic follows the rules of the scalar functions in ca.h.
Types#
ca_vec_entry(vec, i)Expands to a pointer (ca_ptr) to entry i of vec. The index must be nonnegative and less than the length of vec; this is not checked.
ca_ptr ca_vec_entry_ptr(ca_vec_t vec, slong i)Returns a pointer to entry i of vec, like the macro ca_vec_entry.
Memory management#
ca_ptr _ca_vec_init(slong len, ca_ctx_t ctx)Allocates an array of len entries, each initialised to zero, and returns a pointer to it. Free it with _ca_vec_clear.
void ca_vec_init(ca_vec_t vec, slong len, ca_ctx_t ctx)Initialises vec as a vector of length len with all entries zero. For len = 0 nothing is allocated.
void _ca_vec_clear(ca_ptr vec, slong len, ca_ctx_t ctx)Clears the len entries of vec and frees the array itself.
void ca_vec_clear(ca_vec_t vec, ca_ctx_t ctx)Clears vec, freeing all its entries.
void _ca_vec_swap(ca_ptr vec1, ca_ptr vec2, slong len, ca_ctx_t ctx)void ca_vec_swap(ca_vec_t vec1, ca_vec_t vec2, ca_ctx_t ctx)Swaps the contents of the two vectors, entry by entry for the underscore version (which requires arrays of the same length len), and by exchanging the structures in constant time for ca_vec_swap.
Length#
slong ca_vec_length(const ca_vec_t vec, ca_ctx_t ctx)Returns the length of vec.
void _ca_vec_fit_length(ca_vec_t vec, slong len, ca_ctx_t ctx)Ensures that vec has space for at least len entries, without changing its length. If the array has to grow, it grows to at least twice its previous size, and the new entries are initialised to zero.
void ca_vec_set_length(ca_vec_t vec, slong len, ca_ctx_t ctx)Sets the length of vec to len. A shorter vector is extended with zeros; a longer vector is truncated, and the removed entries are set to zero (their memory is kept for reuse).
Assignment and special vectors#
void _ca_vec_set(ca_ptr res, ca_srcptr src, slong len, ca_ctx_t ctx)void ca_vec_set(ca_vec_t res, const ca_vec_t src, ca_ctx_t ctx)Sets res to a copy of src. The vector version also sets the length of res to that of src.
void _ca_vec_zero(ca_ptr res, slong len, ca_ctx_t ctx)void ca_vec_zero(ca_vec_t res, slong len, ca_ctx_t ctx)Sets the len entries of res to zero. The vector version also sets the length of res to len.
void _ca_vec_unknown(ca_ptr vec, slong len, ca_ctx_t ctx)void _ca_vec_undefined(ca_ptr vec, slong len, ca_ctx_t ctx)void ca_vec_append(ca_vec_t vec, const ca_t f, ca_ctx_t ctx)Appends a copy of f at the end of vec, increasing its length by one. The amortised cost is constant thanks to the doubling strategy of _ca_vec_fit_length.
Input and output#
void ca_vec_print(const ca_vec_t vec, ca_ctx_t ctx)Prints the line ca_vec of length n: followed by the entries of vec, one per line, each printed with ca_print and indented by four spaces, and a blank line.
void ca_vec_printn(const ca_vec_t vec, slong digits, ca_ctx_t ctx)Prints decimal approximations of the entries with digits significant digits (see ca_printn), comma-separated in square brackets, followed by a newline.
Arithmetic#
The arithmetic functions apply the corresponding scalar function of ca.h to each entry. The underscore versions require all arrays to have length len and allow the output to be the same array as an input.
void _ca_vec_neg(ca_ptr res, ca_srcptr src, slong len, ca_ctx_t ctx)void ca_vec_neg(ca_vec_t res, const ca_vec_t src, ca_ctx_t ctx)Sets res to the negation of src. The vector version sets the length of res to that of src. Aliasing of res and src is allowed.
Sets res to the entrywise sum or difference of vec1 and vec2.
Sets res to src multiplied or divided by the scalar c. Division computes c^{-1} once with ca_inv and multiplies by it; if c = 0 the entries become unsigned infinity or Undefined (for zero entries), and Unknown if it cannot be decided whether c = 0.
Adds src multiplied by c to res, or subtracts it from res.
Comparisons and predicates#
truth_t _ca_vec_check_is_zero(ca_srcptr vec, slong len, ca_ctx_t ctx)Checks whether all len entries are zero, using ca_check_is_zero. Returns T_FALSE as soon as one entry is proved nonzero, T_TRUE if all entries are proved zero, and T_UNKNOWN otherwise. The empty vector is zero.
Conversions for rational vectors#
The following helpers are used to pass vectors whose entries happen to be rational numbers to faster algorithms over \mathbb{Q} or \mathbb{Z}. They inspect the representation only: a number that is rational but is represented as an element of a larger field (see ca_is_qq_elem) is not recognised.
int _ca_vec_is_fmpq_vec(ca_srcptr vec, slong len, ca_ctx_t ctx)Returns whether every entry of vec is represented as an element of the field \mathbb{Q}.
int _ca_vec_fmpq_vec_is_fmpz_vec(ca_srcptr vec, slong len, ca_ctx_t ctx)Assuming that every entry is represented as a rational number (see _ca_vec_is_fmpq_vec), returns whether every entry is an integer.
void _ca_vec_fmpq_vec_get_fmpz_vec_den(fmpz * c, fmpz_t den, ca_srcptr vec, slong len, ca_ctx_t ctx)Assuming that every entry is represented as a rational number, sets den to the least common multiple of the denominators and c to the integer vector with \mathit{vec}_i = c_i / \mathit{den}. The array c must have room for len entries.
The FLINT team, “ca_vec.h (module overview),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/ca_vec/index.html (generated 2026-10-20).
@misc{flint-doc-ca-vec-index,
author = {{The FLINT team}},
title = {{ca\_vec.h (module overview)}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/ca_vec/index.html},
note = {Generated 2026-10-20}
}