fmpz_vec.h – vectors of integers¶
Memory management¶
Randomisation¶
-
void _fmpz_vec_randtest(fmpz *f, flint_rand_t state, slong len, flint_bitcnt_t bits)¶
Sets the entries of a vector of the given length to random integers with up to the given number of bits per entry.
-
void _fmpz_vec_randtest_unsigned(fmpz *f, flint_rand_t state, slong len, flint_bitcnt_t bits)¶
Sets the entries of a vector of the given length to random unsigned integers with up to the given number of bits per entry.
Bit sizes and norms¶
-
slong _fmpz_vec_max_bits(const fmpz *vec, slong len)¶
If \(b\) is the maximum number of bits of the absolute value of any coefficient of
vec
, then if any coefficient ofvec
is negative, \(-b\) is returned, else \(b\) is returned.
-
slong _fmpz_vec_max_bits_ref(const fmpz *vec, slong len)¶
If \(b\) is the maximum number of bits of the absolute value of any coefficient of
vec
, then if any coefficient ofvec
is negative, \(-b\) is returned, else \(b\) is returned. This is a slower reference implementation of_fmpz_vec_max_bits
.
-
void _fmpz_vec_sum_max_bits(slong *sumabs, slong *maxabs, const fmpz *vec, slong len)¶
Sets
sumabs
to the bit count of the sum of the absolute values of the elements ofvec
. Setsmaxabs
to the bit count of the maximum of the absolute values of the elements ofvec
.
-
slong _fmpz_vec_max_limbs(const fmpz *vec, slong len)¶
Returns the maximum number of limbs needed to store the absolute value of any entry in
(vec, len)
. If all entries are zero, returns zero.
Input and output¶
-
int _fmpz_vec_fread(FILE *file, fmpz **vec, slong *len)¶
Reads a vector from the stream
file
and stores it at*vec
. The format is the same as the output format of_fmpz_vec_fprint()
, followed by either any character or the end of the file.The interpretation of the various input arguments depends on whether or not
*vec
isNULL
:If
*vec == NULL
, the value of*len
on input is ignored. Once the length has been read fromfile
,*len
is set to that value and a vector of this length is allocated at*vec
. Finally,*len
coefficients are read from the input stream. In case of a file or parsing error, clears the vector and sets*vec
and*len
toNULL
and0
, respectively.Otherwise, if
*vec != NULL
, it is assumed that(*vec, *len)
is a properly initialised vector. If the length on the input stream does not match*len
, a parsing error is raised. Attempts to read the right number of coefficients from the input stream. In case of a file or parsing error, leaves the vector(*vec, *len)
in its current state.In case of success, returns a positive value. In case of failure, returns a non-positive value.
-
int _fmpz_vec_read(fmpz **vec, slong *len)¶
Reads a vector from
stdin
and stores it at*vec
.For further details, see
_fmpz_vec_fread()
.
-
int _fmpz_vec_fprint(FILE *file, const fmpz *vec, slong len)¶
Prints the vector of given length to the stream
file
. The format is the length followed by two spaces, then a space separated list of coefficients. If the length is zero, only \(0\) is printed.In case of success, returns a positive value. In case of failure, returns a non-positive value.
Conversions¶
-
void _fmpz_vec_get_nmod_vec(nn_ptr res, const fmpz *poly, slong len, nmod_t mod)¶
Reduce the coefficients of
(poly, len)
modulo the given modulus and set(res, len)
to the result.
-
void _fmpz_vec_set_nmod_vec(fmpz *res, nn_srcptr poly, slong len, nmod_t mod)¶
Set the coefficients of
(res, len)
to the symmetric modulus of the coefficients of(poly, len)
, i.e. convert the given coefficients modulo the given modulus \(n\) to their signed integer representatives in the range \([-n/2, n/2)\).
-
void _fmpz_vec_get_fft(ulong **coeffs_f, const fmpz *coeffs_m, slong l, slong length)¶
Convert the vector of coeffs
coeffs_m
to an fft vectorcoeffs_f
of the givenlength
withl
limbs per coefficient with an additional limb for overflow.
-
void _fmpz_vec_set_fft(fmpz *coeffs_m, slong length, const nn_ptr *coeffs_f, slong limbs, slong sign)¶
Convert an fft vector
coeffs_f
of fully reduced Fermat numbers of the givenlength
to a vector offmpz
’s. Each is assumed to be the given number of limbs in length with an additional limb for overflow. If the output coefficients are to be signed then setsign
, otherwise clear it. The resultingfmpz``s will be in the range `[-n,n]` in the signed case and in the range `[0,2n]` in the unsigned case where ``n = 2^(FLINT_BITS*limbs - 1)
.
-
slong _fmpz_vec_get_d_vec_2exp(double *appv, const fmpz *vec, slong len)¶
Export the array of
len
entries starting at the pointervec
to an array of doublesappv
, each entry of which is notionally multiplied by a single returned exponent to give the original entry. The returned exponent is set to be the maximum exponent of all the original entries so that all the doubles inappv
have a maximum absolute value of 1.0.
Assignment and basic manipulation¶
-
void _fmpz_vec_set(fmpz *vec1, const fmpz *vec2, slong len2)¶
Makes a copy of
(vec2, len2)
intovec1
.
-
void _fmpz_vec_swap(fmpz *vec1, fmpz *vec2, slong len2)¶
Swaps the integers in
(vec1, len2)
and(vec2, len2)
.
Comparison¶
-
int _fmpz_vec_equal(const fmpz *vec1, const fmpz *vec2, slong len)¶
Compares two vectors of the given length and returns \(1\) if they are equal, otherwise returns \(0\).
-
int _fmpz_vec_is_zero(const fmpz *vec, slong len)¶
Returns \(1\) if
(vec, len)
is zero, and \(0\) otherwise.
Sorting¶
Addition and subtraction¶
Scalar multiplication and division¶
-
void _fmpz_vec_scalar_mul_fmpz(fmpz *vec1, const fmpz *vec2, slong len2, const fmpz_t x)¶
Sets
(vec1, len2)
to(vec2, len2)
multiplied by \(c\), where \(c\) is anfmpz_t
.
-
void _fmpz_vec_scalar_mul_si(fmpz *vec1, const fmpz *vec2, slong len2, slong c)¶
Sets
(vec1, len2)
to(vec2, len2)
multiplied by \(c\), where \(c\) is aslong
.
-
void _fmpz_vec_scalar_mul_ui(fmpz *vec1, const fmpz *vec2, slong len2, ulong c)¶
Sets
(vec1, len2)
to(vec2, len2)
multiplied by \(c\), where \(c\) is anulong
.
-
void _fmpz_vec_scalar_mul_2exp(fmpz *vec1, const fmpz *vec2, slong len2, ulong exp)¶
Sets
(vec1, len2)
to(vec2, len2)
multiplied by2^exp
.
-
void _fmpz_vec_scalar_divexact_fmpz(fmpz *vec1, const fmpz *vec2, slong len2, const fmpz_t x)¶
Sets
(vec1, len2)
to(vec2, len2)
divided by \(x\), where the division is assumed to be exact for every entry invec2
.
-
void _fmpz_vec_scalar_divexact_si(fmpz *vec1, const fmpz *vec2, slong len2, slong c)¶
Sets
(vec1, len2)
to(vec2, len2)
divided by \(x\), where the division is assumed to be exact for every entry invec2
.
-
void _fmpz_vec_scalar_divexact_ui(fmpz *vec1, const fmpz *vec2, slong len2, ulong c)¶
Sets
(vec1, len2)
to(vec2, len2)
divided by \(x\), where the division is assumed to be exact for every entry invec2
.
-
void _fmpz_vec_scalar_fdiv_q_fmpz(fmpz *vec1, const fmpz *vec2, slong len2, const fmpz_t c)¶
Sets
(vec1, len2)
to(vec2, len2)
divided by \(c\), rounding down towards minus infinity whenever the division is not exact.
-
void _fmpz_vec_scalar_fdiv_q_si(fmpz *vec1, const fmpz *vec2, slong len2, slong c)¶
Sets
(vec1, len2)
to(vec2, len2)
divided by \(c\), rounding down towards minus infinity whenever the division is not exact.
-
void _fmpz_vec_scalar_fdiv_q_ui(fmpz *vec1, const fmpz *vec2, slong len2, ulong c)¶
Sets
(vec1, len2)
to(vec2, len2)
divided by \(c\), rounding down towards minus infinity whenever the division is not exact.
-
void _fmpz_vec_scalar_fdiv_q_2exp(fmpz *vec1, const fmpz *vec2, slong len2, ulong exp)¶
Sets
(vec1, len2)
to(vec2, len2)
divided by2^exp
, rounding down towards minus infinity whenever the division is not exact.
-
void _fmpz_vec_scalar_fdiv_r_2exp(fmpz *vec1, const fmpz *vec2, slong len2, ulong exp)¶
Sets
(vec1, len2)
to the remainder of(vec2, len2)
divided by2^exp
, rounding down the quotient towards minus infinity whenever the division is not exact.
-
void _fmpz_vec_scalar_tdiv_q_fmpz(fmpz *vec1, const fmpz *vec2, slong len2, const fmpz_t c)¶
Sets
(vec1, len2)
to(vec2, len2)
divided by \(c\), rounding towards zero whenever the division is not exact.
-
void _fmpz_vec_scalar_tdiv_q_si(fmpz *vec1, const fmpz *vec2, slong len2, slong c)¶
Sets
(vec1, len2)
to(vec2, len2)
divided by \(c\), rounding towards zero whenever the division is not exact.
-
void _fmpz_vec_scalar_tdiv_q_ui(fmpz *vec1, const fmpz *vec2, slong len2, ulong c)¶
Sets
(vec1, len2)
to(vec2, len2)
divided by \(c\), rounding towards zero whenever the division is not exact.
-
void _fmpz_vec_scalar_tdiv_q_2exp(fmpz *vec1, const fmpz *vec2, slong len2, ulong exp)¶
Sets
(vec1, len2)
to(vec2, len2)
divided by2^exp
, rounding down towards zero whenever the division is not exact.
-
void _fmpz_vec_scalar_addmul_fmpz(fmpz *vec1, const fmpz *vec2, slong len2, const fmpz_t c)¶
Adds
(vec2, len2)
times \(c\) to(vec1, len2)
.
-
void _fmpz_vec_scalar_addmul_si_2exp(fmpz *vec1, const fmpz *vec2, slong len2, slong c, ulong exp)¶
Adds
(vec2, len2)
timesc * 2^exp
to(vec1, len2)
, where \(c\) is aslong
.
-
void _fmpz_vec_scalar_submul_fmpz(fmpz *vec1, const fmpz *vec2, slong len2, const fmpz_t x)¶
Subtracts
(vec2, len2)
times \(c\) from(vec1, len2)
, where \(c\) is afmpz_t
.
Sums and products¶
Reduction mod \(p\)¶
Gaussian content¶
-
void _fmpz_vec_content(fmpz_t res, const fmpz *vec, slong len)¶
Sets
res
to the non-negative content of the entries invec
. The content of a zero vector, including the case when the length is zero, is defined to be zero.
Dot product¶
-
void _fmpz_vec_dot_general_naive(fmpz_t res, const fmpz_t initial, int subtract, const fmpz *a, const fmpz *b, int reverse, slong len)¶
-
void _fmpz_vec_dot_general(fmpz_t res, const fmpz_t initial, int subtract, const fmpz *a, const fmpz *b, int reverse, slong len)¶
Computes the dot product of the vectors a and b, setting res to \(s + (-1)^{subtract} \sum_{i=0}^{len-1} a_i b_i\). The initial term s is optional and can be omitted by passing NULL (equivalently, \(s = 0\)). The parameter subtract must be 0 or 1. If the reverse flag is 1, the second vector is reversed.
Aliasing is allowed between
res
andinitial
but not betweenres
and the entries ofa
andb
.The naive version is used for testing purposes.