FLINT3.7.0-dev
Module · 11 functions

fmpz_mod_vec.h

#include <flint/fmpz_mod_vec.h>

This module provides operations on vectors over Z/nZ\mathbb{Z}/n\mathbb{Z} whose entries are canonical residues in [0,n)[0, n) stored as plain fmpz arrays, with the modulus given by an fmpz_mod_ctx_t. Vectors are allocated, cleared, copied and compared with the fmpz_vec functions (_fmpz_vec_init, _fmpz_vec_clear, _fmpz_vec_set, _fmpz_vec_equal, ...). The functions are the building blocks of fmpz_mod_poly and fmpz_mod_mat.

All functions take a vector as a pointer and a length. Unless stated otherwise, inputs must be canonical and the output is canonical, and the output may alias an input of the same length (the loops are elementwise).

Conversion#

void _fmpz_mod_vec_set_fmpz_vec(fmpz * A, const fmpz * B, slong len, const fmpz_mod_ctx_t ctx)

Sets the entries of (A,len)(A, \mathit{len}) to the entries of (B,len)(B, \mathit{len}) reduced modulo nn; BB may contain any integers and may alias AA.

More
void _fmpz_mod_vec_get_fmpz_vec_smod(fmpz * res, const fmpz * vec, slong len, const fmpz_mod_ctx_t ctx)

Given canonical residues (vec,len)(\mathit{vec}, \mathit{len}), sets (res,len)(\mathit{res}, \mathit{len}) to the symmetric residues in (−n/2,n/2](-n/2, n/2]. This is the same as _fmpz_vec_scalar_smod_fmpz but faster, since the input is known to be reduced: each entry costs one comparison and at most one subtraction.

Arithmetic#

void _fmpz_mod_vec_neg(fmpz * A, const fmpz * B, slong len, const fmpz_mod_ctx_t ctx)

Sets (A,len)(A, \mathit{len}) to −(B,len)-(B, \mathit{len}).

void _fmpz_mod_vec_add(fmpz * a, const fmpz * b, const fmpz * c, slong n, const fmpz_mod_ctx_t ctx)
void _fmpz_mod_vec_sub(fmpz * a, const fmpz * b, const fmpz * c, slong n, const fmpz_mod_ctx_t ctx)

Set (a,n)(a, n) to (b,n)+(c,n)(b, n) + (c, n) and (b,n)−(c,n)(b, n) - (c, n), elementwise. Here nn is the length of the vectors, not the modulus.

void _fmpz_mod_vec_mul(fmpz * A, const fmpz * B, const fmpz * C, slong len, const fmpz_mod_ctx_t ctx)

Sets (A,len)(A, \mathit{len}) to the elementwise product of (B,len)(B, \mathit{len}) and (C,len)(C, \mathit{len}).

Scalar multiplication#

void _fmpz_mod_vec_scalar_mul_fmpz_mod(fmpz * A, const fmpz * B, slong len, const fmpz_t c, const fmpz_mod_ctx_t ctx)

Sets (A,len)(A, \mathit{len}) to c⋅(B,len)c \cdot (B, \mathit{len}), for canonical cc. For c=1c = 1 this is a copy.

void _fmpz_mod_vec_scalar_addmul_fmpz_mod(fmpz * A, const fmpz * B, slong len, const fmpz_t c, const fmpz_mod_ctx_t ctx)

Sets (A,len)(A, \mathit{len}) to (A,len)+c⋅(B,len)(A, \mathit{len}) + c \cdot (B, \mathit{len}), for canonical cc. Each entry is updated with one exact fmpz_addmul and one reduction.

void _fmpz_mod_vec_scalar_div_fmpz_mod(fmpz * A, const fmpz * B, slong len, const fmpz_t c, const fmpz_mod_ctx_t ctx)

Sets (A,len)(A, \mathit{len}) to c−1⋅(B,len)c^{-1} \cdot (B, \mathit{len}). Throws an exception (from fmpz_mod_inv) if cc is not invertible modulo nn.

Dot products#

void _fmpz_mod_vec_dot(fmpz_t d, const fmpz * A, const fmpz * B, slong len, const fmpz_mod_ctx_t ctx)
void _fmpz_mod_vec_dot_rev(fmpz_t r, const fmpz * a, const fmpz * b, slong len, const fmpz_mod_ctx_t ctx)

Set the output to ∑iAiBi\sum_{i} A_i B_i, respectively ∑iaiblen−1−i\sum_i a_i b_{\mathit{len} - 1 - i}, modulo nn.

More
Cite this page

The FLINT team, “fmpz_mod_vec.h (module overview),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/fmpz_mod_vec/index.html (generated 2026-11-02).