ALL: Add flint

This commit is contained in:
2014-05-19 00:03:37 +02:00
parent a15ef46ea6
commit d51d8e3652
3752 changed files with 446416 additions and 0 deletions

37
external/flint-2.4.3/fmpz_vec/add.c vendored Normal file
View File

@@ -0,0 +1,37 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 William Hart
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_add(fmpz * res, const fmpz * vec1, const fmpz * vec2, slong len2)
{
slong i;
for (i = 0; i < len2; i++)
fmpz_add(res + i, vec1 + i, vec2 + i);
}

39
external/flint-2.4.3/fmpz_vec/clear.c vendored Normal file
View File

@@ -0,0 +1,39 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 William Hart
******************************************************************************/
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_clear(fmpz * vec, slong len)
{
slong i;
for (i = 0; i < len; i++)
fmpz_clear(vec + i);
flint_free(vec);
}

38
external/flint-2.4.3/fmpz_vec/content.c vendored Normal file
View File

@@ -0,0 +1,38 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_content(fmpz_t res, const fmpz * vec, slong len)
{
fmpz_zero(res);
while (len--)
fmpz_gcd(res, res, vec + len);
}

View File

@@ -0,0 +1,438 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 William Hart
******************************************************************************/
*******************************************************************************
Memory management
*******************************************************************************
fmpz * _fmpz_vec_init(slong len)
Returns an initialised vector of \code{fmpz}'s of given length.
void _fmpz_vec_clear(fmpz * vec, slong len)
Clears the entries of \code{(vec, len)} and frees the space allocated
for \code{vec}.
*******************************************************************************
Randomisation
*******************************************************************************
void _fmpz_vec_randtest(fmpz * f, flint_rand_t state,
slong len, mp_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, mp_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 \code{vec}, then if any coefficient of \code{vec} 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 \code{vec}, then if any coefficient of \code{vec} is
negative, $-b$ is returned, else $b$ is returned.
This is a slower reference implementation of \code{_fmpz_vec_max_bits}.
ulong _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 \code{(vec, len)}. If all entries are zero, returns
zero.
void _fmpz_vec_height(fmpz_t height, const fmpz * vec, slong len)
Computes the height of \code{(vec, len)}, defined as the largest of the
absolute values the coefficients. Equivalently, this gives the infinity
norm of the vector. If \code{len} is zero, the height is $0$.
slong _fmpz_vec_height_index(const fmpz * vec, slong len)
Returns the index of an entry of maximum absolute value in the vector.
The the length must be at least 1.
*******************************************************************************
Input and output
*******************************************************************************
int _fmpz_vec_fread(FILE * file, fmpz ** vec, slong * len)
Reads a vector from the stream \code{file} and stores it at
\code{*vec}. The format is the same as the output format of
\code{_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 \code{*vec} is \code{NULL}:
If \code{*vec == NULL}, the value of \code{*len} on input is ignored.
Once the length has been read from \code{file}, \code{*len} is set
to that value and a vector of this length is allocated at \code{*vec}.
Finally, \code{*len} coefficients are read from the input stream. In
case of a file or parsing error, clears the vector and sets \code{*vec}
and \code{*len} to \code{NULL} and \code{0}, respectively.
Otherwise, if \code{*vec != NULL}, it is assumed that \code{(*vec, *len)}
is a properly initialised vector. If the length on the input stream
does not match \code{*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 \code{(*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 \code{stdin} and stores it at \code{*vec}.
For further details, see \code{_fmpz_vec_fread()}.
int _fmpz_vec_fprint(FILE * file, const fmpz * vec, slong len)
Prints the vector of given length to the stream \code{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.
int _fmpz_vec_print(const fmpz * vec, slong len)
Prints the vector of given length to \code{stdout}.
For further details, see \code{_fmpz_vec_fprint()}.
*******************************************************************************
Conversions
*******************************************************************************
void _fmpz_vec_get_nmod_vec(mp_ptr res,
const fmpz * poly, slong len, nmod_t mod)
Reduce the coefficients of \code{(poly, len)} modulo the given
modulus and set \code{(res, len)} to the result.
void _fmpz_vec_set_nmod_vec(fmpz * res,
mp_srcptr poly, slong len, nmod_t mod)
Set the coefficients of \code{(res, len)} to the symmetric modulus
of the coefficients of \code{(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)$.
slong _fmpz_vec_get_fft(mp_limb_t ** coeffs_f,
const fmpz * coeffs_m, slong l, slong length)
Convert the vector of coeffs \code{coeffs_m} to an fft vector
\code{coeffs_f} of the given \code{length} with \code{l} limbs per
coefficient with an additional limb for overflow.
void _fmpz_vec_set_fft(fmpz * coeffs_m, slong length,
const mp_ptr * coeffs_f, slong limbs, slong sign)
Convert an fft vector \code{coeffs_f} of the given \code{length}
to a vector of \code{fmpz}'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 set \code{sign},
otherwise clear it.
*******************************************************************************
Assignment and basic manipulation
*******************************************************************************
void _fmpz_vec_set(fmpz * vec1, const fmpz * vec2, slong len2)
Makes a copy of \code{(vec2, len2)} into \code{vec1}.
void _fmpz_vec_swap(fmpz * vec1, fmpz * vec2, slong len2)
Swaps the integers in \code{(vec1, len2)} and \code{(vec2, len2)}.
void _fmpz_vec_zero(fmpz * vec, slong len)
Zeros the entries of \code{(vec, len)}.
void _fmpz_vec_neg(fmpz * vec1, const fmpz * vec2, slong len2)
Negates \code{(vec2, len2)} and places it into \code{vec1}.
*******************************************************************************
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 \code{(vec, len)} is zero, and $0$ otherwise.
*******************************************************************************
Sorting
*******************************************************************************
void _fmpz_vec_sort(fmpz * vec, slong len)
Sorts the coefficients of \code{vec} in ascending order.
*******************************************************************************
Addition and subtraction
*******************************************************************************
void _fmpz_vec_add(fmpz * res, const fmpz * vec1,
const fmpz * vec2, slong len2)
Sets \code{(res, len2)} to the sum of \code{(vec1, len2)}
and \code{(vec2, len2)}.
void _fmpz_vec_sub(fmpz * res, const fmpz * vec1,
const fmpz * vec2, slong len2)
Sets \code{(res, len2)} to \code{(vec1, len2)} minus \code{(vec2, len2)}.
*******************************************************************************
Scalar multiplication and division
*******************************************************************************
void _fmpz_vec_scalar_mul_fmpz(fmpz * vec1,
const fmpz * vec2, slong len2, const fmpz_t x)
Sets \code{(vec1, len2)} to \code{(vec2, len2)} multiplied by $c$,
where $c$ is an \code{fmpz_t}.
id _fmpz_vec_scalar_mul_si(fmpz * vec1, const fmpz * vec2, slong len2, slong c)
Sets \code{(vec1, len2)} to \code{(vec2, len2)} multiplied by $c$,
where $c$ is a \code{slong}.
void _fmpz_vec_scalar_mul_ui(fmpz * vec1,
const fmpz * vec2, slong len2, ulong c)
Sets \code{(vec1, len2)} to \code{(vec2, len2)} multiplied by $c$,
where $c$ is an \code{ulong}.
void _fmpz_vec_scalar_mul_2exp(fmpz * vec1,
const fmpz * vec2, slong len2, ulong exp)
Sets \code{(vec1, len2)} to \code{(vec2, len2)} multiplied by \code{2^exp}.
void _fmpz_vec_scalar_divexact_fmpz(fmpz * vec1,
const fmpz * vec2, slong len2, const fmpz_t x)
Sets \code{(vec1, len2)} to \code{(vec2, len2)} divided by $x$, where the
division is assumed to be exact for every entry in \code{vec2}.
void _fmpz_vec_scalar_divexact_si(fmpz * vec1,
const fmpz * vec2, slong len2, slong c)
Sets \code{(vec1, len2)} to \code{(vec2, len2)} divided by $x$, where the
division is assumed to be exact for every entry in \code{vec2}.
void _fmpz_vec_scalar_divexact_ui(fmpz * vec1,
const fmpz * vec2, ulong len2, ulong c)
Sets \code{(vec1, len2)} to \code{(vec2, len2)} divided by $x$, where the
division is assumed to be exact for every entry in \code{vec2}.
void _fmpz_vec_scalar_fdiv_q_fmpz(fmpz * vec1,
const fmpz * vec2, slong len2, const fmpz_t c)
Sets \code{(vec1, len2)} to \code{(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 \code{(vec1, len2)} to \code{(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 \code{(vec1, len2)} to \code{(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 \code{(vec1, len2)} to \code{(vec2, len2)} divided by \code{2^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 \code{(vec1, len2)} to the remainder of \code{(vec2, len2)}
divided by \code{2^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 \code{(vec1, len2)} to \code{(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 \code{(vec1, len2)} to \code{(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 \code{(vec1, len2)} to \code{(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 \code{(vec1, len2)} to \code{(vec2, len2)} divided by \code{2^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 \code{(vec2, len2)} times $c$ to \code{(vec1, len2)}, where $c$ is a
\code{fmpz_t}.
void _fmpz_vec_scalar_addmul_si(fmpz * vec1,
const fmpz * vec2, slong len2, slong c)
Adds \code{(vec2, len2)} times $c$ to \code{(vec1, len2)}, where $c$ is a
\code{slong}.
void _fmpz_vec_scalar_addmul_si_2exp(fmpz * vec1,
const fmpz * vec2, slong len2, slong c, ulong exp)
Adds \code{(vec2, len2)} times \code{c * 2^exp} to \code{(vec1, len2)},
where $c$ is a \code{slong}.
void _fmpz_vec_scalar_submul_fmpz(fmpz * vec1,
const fmpz * vec2, slong len2, const fmpz_t x)
Subtracts \code{(vec2, len2)} times $c$ from \code{(vec1, len2)},
where $c$ is a \code{fmpz_t}.
void _fmpz_vec_scalar_submul_si(fmpz * vec1,
const fmpz * vec2, slong len2, slong c)
Subtracts \code{(vec2, len2)} times $c$ from \code{(vec1, len2)},
where $c$ is a \code{slong}.
void _fmpz_vec_scalar_submul_si_2exp(fmpz * vec1,
const fmpz * vec2, slong len2, slong c, ulong e)
Subtracts \code{(vec2, len2)} times $c \times 2^e$
from \code{(vec1, len2)}, where $c$ is a \code{slong}.
*******************************************************************************
Sums and products
*******************************************************************************
void _fmpz_vec_sum(fmpz_t res, const fmpz * vec, slong len)
Sets \code{res} to the sum of the entries in \code{(vec, len)}.
Aliasing of \code{res} with the entries in \code{vec} is not permitted.
void _fmpz_vec_prod(fmpz_t res, const fmpz * vec, slong len)
Sets \code{res} to the product of the entries in \code{(vec, len)}.
Aliasing of \code{res} with the entries in \code{vec} is not permitted.
Uses binary splitting.
*******************************************************************************
Reduction mod $p$
*******************************************************************************
void _fmpz_vec_scalar_mod_fmpz(fmpz *res,
const fmpz *vec, slong len, const fmpz_t p)
Reduces all entries in \code{(vec, len)} modulo $p > 0$.
void _fmpz_vec_scalar_smod_fmpz(fmpz *res,
const fmpz *vec, slong len, const fmpz_t p)
Reduces all entries in \code{(vec, len)} modulo $p > 0$, choosing
the unique representative in $(-p/2, p/2]$.
*******************************************************************************
Gaussian content
*******************************************************************************
void _fmpz_vec_content(fmpz_t res, const fmpz * vec, slong len)
Sets \code{res} to the non-negative content of the entries in \code{vec}.
The content of a zero vector, including the case when the length is zero,
is defined to be zero.
void _fmpz_vec_lcm(fmpz_t res, const fmpz * vec, slong len)
Sets \code{res} to the nonnegative least common multiple of the entries
in \code{vec}. The least common multiple is zero if any entry in
the vector is zero. The least common multiple of a length zero vector is
defined to be one.

43
external/flint-2.4.3/fmpz_vec/equal.c vendored Normal file
View File

@@ -0,0 +1,43 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2008, 2009, 2010 William Hart
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
int
_fmpz_vec_equal(const fmpz * vec1, const fmpz * vec2, slong len)
{
slong i;
if (vec1 == vec2)
return 1;
for (i = 0; i < len; i++)
if (!fmpz_equal(vec1 + i, vec2 + i))
return 0;
return 1;
}

65
external/flint-2.4.3/fmpz_vec/fprint.c vendored Normal file
View File

@@ -0,0 +1,65 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2008, 2009, 2010 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
/*
Recall the return value conventions for fputc (of type int)
``If there are no errors, the same character that has been written is
returned. If an error occurs, EOF is returned and the error indicator
is set''
where the EOF macro expands to a negative int, and flint_fprintf (of type int)
``On success, the total number of characters written is returned.
On failure, a negative number is returned.''
*/
int _fmpz_vec_fprint(FILE * file, const fmpz * vec, slong len)
{
int r;
slong i;
r = flint_fprintf(file, "%li", len);
if ((len > 0) && (r > 0))
{
r = fputc(' ', file);
for (i = 0; (i < len) && (r > 0); i++)
{
r = fputc(' ', file);
if (r > 0)
r = fmpz_fprint(file, vec + i);
}
}
return r;
}

87
external/flint-2.4.3/fmpz_vec/fread.c vendored Normal file
View File

@@ -0,0 +1,87 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
int _fmpz_vec_fread(FILE * file, fmpz ** vec, slong * len)
{
int alloc, r;
slong i;
mpz_t t;
alloc = (*vec == NULL);
mpz_init(t);
r = mpz_inp_str(t, file, 10);
if (r == 0)
{
if (alloc)
*len = 0;
mpz_clear(t);
return 0;
}
if (!mpz_fits_slong_p(t))
{
flint_printf("Exception (_fmpz_vec_fread). Length does not fit into a slong.\n");
abort();
}
if (alloc)
{
*len = flint_mpz_get_si(t);
*vec = _fmpz_vec_init(*len);
}
else
{
if (*len != flint_mpz_get_si(t))
{
mpz_clear(t);
return 0;
}
}
mpz_clear(t);
for (i = 0; i < *len; i++)
{
r = fmpz_fread(file, (*vec) + i);
if (r <= 0)
{
if (alloc)
{
_fmpz_vec_clear(*vec, *len);
*vec = NULL;
*len = 0;
}
return r;
}
}
return 1;
}

102
external/flint-2.4.3/fmpz_vec/get_fft.c vendored Normal file
View File

@@ -0,0 +1,102 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2008-2011 William Hart
******************************************************************************/
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "fmpz_poly.h"
#include "fft.h"
slong _fmpz_vec_get_fft(mp_limb_t ** coeffs_f,
const fmpz * coeffs_m, slong l, slong length)
{
slong size_f = l + 1;
mp_limb_t * coeff;
mp_limb_t mask = WORD(-1);
slong bits = 0, limbs = 0, size_j, i, c;
int sign = 1, signed_c;
for (i = 0; i < length; i++, coeffs_m++)
{
c = *coeffs_m;
signed_c = 0;
if (!COEFF_IS_MPZ(c)) /* coeff is small */
{
size_j = 1;
if (c < 0)
{
signed_c = 1;
c = -c;
coeff = (mp_limb_t *) &c;
} else
coeff = (mp_limb_t *) coeffs_m;
} else /* coeff is an mpz_t */
{
__mpz_struct * mpz_ptr = COEFF_TO_PTR(c);
size_j = mpz_ptr->_mp_size;
if (size_j < 0)
{
signed_c = 1;
size_j = -size_j;
}
coeff = mpz_ptr->_mp_d;
}
if (signed_c) sign = -1;
if (size_j > limbs + 1) /* coeff is at least 1 limb bigger */
{
limbs = size_j - 1;
bits = FLINT_BIT_COUNT(coeff[size_j - 1]);
if (bits == FLINT_BITS) mask = WORD(0);
else mask = WORD(-1) - ((WORD(1)<<bits) - 1);
} else if (size_j == limbs + 1) /* coeff is same size as prev biggest */
{
if (coeff[size_j - 1] & mask) /* see if we have more bits than before */
{
bits = FLINT_BIT_COUNT(coeff[size_j - 1]);
if (bits == FLINT_BITS) mask = WORD(0);
else mask = WORD(-1) - ((WORD(1)<<bits) - 1);
}
}
if (signed_c) /* write out FFT coefficient, ensuring sign is correct */
{
mpn_neg_n(coeffs_f[i], coeff, size_j);
flint_mpn_store(coeffs_f[i] + size_j, size_f - size_j, WORD(-1));
} else
{
flint_mpn_copyi(coeffs_f[i], coeff, size_j);
flint_mpn_zero(coeffs_f[i] + size_j, size_f - size_j);
}
}
return sign*(FLINT_BITS*limbs + bits);
}

View File

@@ -0,0 +1,40 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "fmpz_poly.h"
#include "nmod_poly.h"
void
_fmpz_vec_get_nmod_vec(mp_ptr res, const fmpz * poly, slong len, nmod_t mod)
{
slong i;
for (i = 0; i < len; i++)
res[i] = fmpz_fdiv_ui(poly + i, mod.n);
}

42
external/flint-2.4.3/fmpz_vec/height.c vendored Normal file
View File

@@ -0,0 +1,42 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_height(fmpz_t height, const fmpz * vec, slong len)
{
if (len)
{
slong pos = _fmpz_vec_height_index(vec, len);
fmpz_abs(height, vec + pos);
}
else
fmpz_zero(height);
}

View File

@@ -0,0 +1,95 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2012 Fredrik Johansson
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
slong
_fmpz_vec_height_index(const fmpz * vec, slong len)
{
if (len == 1)
{
return 0;
}
else
{
fmpz c;
mp_srcptr max_d;
slong max_mpz_limbs, i, max_i, max_coeff, mpz_limbs;
max_coeff = 0;
max_i = 0;
for (i = 0; i < len; i++)
{
c = vec[i];
if (!COEFF_IS_MPZ(c))
{
c = FLINT_ABS(c);
if (c > max_coeff)
{
max_coeff = c;
max_i = i;
}
}
else
{
__mpz_struct * mpz_ptr = COEFF_TO_PTR(c);
max_d = mpz_ptr->_mp_d;
max_mpz_limbs = mpz_ptr->_mp_size;
max_mpz_limbs = FLINT_ABS(max_mpz_limbs);
max_i = i;
i++;
break;
}
}
for ( ; i < len; i++)
{
c = vec[i];
/* we have found at least one mpz, so only look for those */
if (COEFF_IS_MPZ(c))
{
__mpz_struct * mpz_ptr = COEFF_TO_PTR(c);
mpz_limbs = mpz_ptr->_mp_size;
mpz_limbs = FLINT_ABS(mpz_limbs);
if (mpz_limbs > max_mpz_limbs ||
((mpz_limbs == max_mpz_limbs) &&
(mpn_cmp(mpz_ptr->_mp_d, max_d, max_mpz_limbs) > 0)))
{
max_d = mpz_ptr->_mp_d;
max_mpz_limbs = mpz_limbs;
max_i = i;
}
}
}
return max_i;
}
}

36
external/flint-2.4.3/fmpz_vec/init.c vendored Normal file
View File

@@ -0,0 +1,36 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 William Hart
******************************************************************************/
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
fmpz *
_fmpz_vec_init(slong len)
{
return (fmpz *) flint_calloc(len, sizeof(fmpz));
}

39
external/flint-2.4.3/fmpz_vec/is_zero.c vendored Normal file
View File

@@ -0,0 +1,39 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
int
_fmpz_vec_is_zero(const fmpz * vec, slong len)
{
slong i;
for (i = 0; i < len; i++)
if (vec[i] != WORD(0))
return 0;
return 1;
}

41
external/flint-2.4.3/fmpz_vec/lcm.c vendored Normal file
View File

@@ -0,0 +1,41 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_lcm(fmpz_t res, const fmpz * vec, slong len)
{
slong i;
fmpz_one(res);
for (i = 0; i < len && !fmpz_is_zero(res); i++)
fmpz_lcm(res, res, vec + i);
fmpz_abs(res, res);
}

View File

@@ -0,0 +1,91 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
slong
_fmpz_vec_max_bits(const fmpz * vec, slong len)
{
slong i, sign, max_limbs;
mp_limb_t max_limb;
mp_size_t limbs;
sign = 1;
max_limb = 0;
for (i = 0; i < len; i++)
{
fmpz c = vec[i];
if (c >= 0)
{
if (c > COEFF_MAX)
goto bignum;
max_limb |= c;
}
else
{
if (c < COEFF_MIN)
goto bignum;
max_limb |= -c;
sign = -1;
}
}
return sign * FLINT_BIT_COUNT(max_limb);
bignum:
max_limbs = 1;
for ( ; i < len; i++)
{
fmpz c = vec[i];
if (COEFF_IS_MPZ(c))
{
__mpz_struct * z = COEFF_TO_PTR(c);
limbs = z->_mp_size;
if (limbs < 0)
{
sign = -1;
limbs = -limbs;
}
if (limbs == max_limbs)
max_limb |= z->_mp_d[limbs - 1];
else if (limbs > max_limbs)
{
max_limb = z->_mp_d[limbs - 1];
max_limbs = limbs;
}
}
else if (c < 0)
sign = -1;
}
return sign * ((max_limbs - 1) * FLINT_BITS + FLINT_BIT_COUNT(max_limb));
}

View File

@@ -0,0 +1,46 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 William Hart
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
slong
_fmpz_vec_max_bits_ref(const fmpz * vec, slong len)
{
slong i, bits, max_bits = 0, sign = 1;
for (i = 0; i < len; i++)
{
bits = fmpz_bits(vec + i);
if (bits > max_bits)
max_bits = bits;
if (fmpz_sgn(vec + i) < 0)
sign = WORD(-1);
}
return max_bits * sign;
}

View File

@@ -0,0 +1,45 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 William Hart
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
mp_size_t
_fmpz_vec_max_limbs(const fmpz * vec, slong len)
{
slong i;
mp_size_t limbs, max_limbs = 0;
for (i = 0; i < len; i++)
{
limbs = fmpz_size(vec + i);
if (limbs > max_limbs)
max_limbs = limbs;
}
return max_limbs;
}

37
external/flint-2.4.3/fmpz_vec/neg.c vendored Normal file
View File

@@ -0,0 +1,37 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 William Hart
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_neg(fmpz * vec1, const fmpz * vec2, slong len2)
{
slong i;
for (i = 0; i < len2; i++)
fmpz_neg(vec1 + i, vec2 + i);
}

59
external/flint-2.4.3/fmpz_vec/prod.c vendored Normal file
View File

@@ -0,0 +1,59 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_prod(fmpz_t res, const fmpz * vec, slong len)
{
if (len <= 1)
{
if (len == 1)
fmpz_set(res, vec);
else
fmpz_one(res);
}
else if (len <= 3)
{
slong i;
fmpz_mul(res, vec, vec + 1);
for (i = 2; i < len; i++)
fmpz_mul(res, res, vec + i);
}
else
{
slong m = len / 2;
fmpz_t tmp;
fmpz_init(tmp);
_fmpz_vec_prod(res, vec, m);
_fmpz_vec_prod(tmp, vec + m, len - m);
fmpz_mul(res, res, tmp);
fmpz_clear(tmp);
}
}

View File

@@ -0,0 +1,82 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009, 2010 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_randtest(fmpz * f, flint_rand_t state,
slong len, mp_bitcnt_t bits)
{
slong i, sparseness;
if (n_randint(state, 2))
{
for (i = 0; i < len; i++)
fmpz_randtest(f + i, state, bits);
}
else
{
sparseness = 1 + n_randint(state, FLINT_MAX(2, len));
for (i = 0; i < len; i++)
{
if (n_randint(state, sparseness))
fmpz_zero(f + i);
else
fmpz_randtest(f + i, state, bits);
}
}
}
void
_fmpz_vec_randtest_unsigned(fmpz * f, flint_rand_t state,
slong len, mp_bitcnt_t bits)
{
slong i, sparseness;
if (n_randint(state, 2))
{
for (i = 0; i < len; i++)
fmpz_randtest_unsigned(f + i, state, bits);
}
else
{
sparseness = 1 + n_randint(state, FLINT_MAX(2, len));
for (i = 0; i < len; i++)
{
if (n_randint(state, sparseness))
fmpz_zero(f + i);
else
fmpz_randtest_unsigned(f + i, state, bits);
}
}
}

View File

@@ -0,0 +1,54 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 William Hart
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_scalar_addmul_fmpz(fmpz * poly1, const fmpz * poly2, slong len2,
const fmpz_t x)
{
fmpz c = *x;
if (!COEFF_IS_MPZ(c))
{
if (c == 0)
return;
else if (c == 1)
_fmpz_vec_add(poly1, poly1, poly2, len2);
else if (c == -1)
_fmpz_vec_sub(poly1, poly1, poly2, len2);
else
_fmpz_vec_scalar_addmul_si(poly1, poly2, len2, c);
}
else
{
slong i;
for (i = 0; i < len2; i++)
fmpz_addmul(poly1 + i, poly2 + i, x);
}
}

View File

@@ -0,0 +1,42 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 William Hart
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_scalar_addmul_si(fmpz * vec1, const fmpz * vec2, slong len2, slong c)
{
slong i;
if (c >= 0)
for (i = 0; i < len2; i++)
fmpz_addmul_ui(vec1 + i, vec2 + i, c);
else
for (i = 0; i < len2; i++)
fmpz_submul_ui(vec1 + i, vec2 + i, -c);
}

View File

@@ -0,0 +1,86 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 William Hart
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_scalar_addmul_si_2exp(fmpz * vec1, const fmpz * vec2, slong len2,
slong c, ulong exp)
{
slong i;
fmpz_t temp;
if (c == 0)
return; /* nothing to add */
if (exp == 0) /* just do addmul */
{
_fmpz_vec_scalar_addmul_si(vec1, vec2, len2, c);
return;
}
fmpz_init(temp);
if (c == 1) /* scalar is 1, just add c * 2^exp times c */
{
for (i = 0; i < len2; i++)
{
fmpz_mul_2exp(temp, vec2 + i, exp);
fmpz_add(vec1 + i, vec1 + i, temp);
}
}
else if (c == -1) /* scalar is -1, subtract c * 2^exp */
{
for (i = 0; i < len2; i++)
{
fmpz_mul_2exp(temp, vec2 + i, exp);
fmpz_sub(vec1 + i, vec1 + i, temp);
}
}
else /* generic case */
{
if (c > 0)
{
for (i = 0; i < len2; i++)
{
fmpz_mul_2exp(temp, vec2 + i, exp);
fmpz_addmul_ui(vec1 + i, temp, c);
}
}
else
{
for (i = 0; i < len2; i++)
{
fmpz_mul_2exp(temp, vec2 + i, exp);
fmpz_submul_ui(vec1 + i, temp, -c);
}
}
}
fmpz_clear(temp);
}

View File

@@ -0,0 +1,53 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_scalar_divexact_fmpz(fmpz * vec1, const fmpz * vec2,
slong len2, const fmpz_t x)
{
fmpz c = *x;
if (!COEFF_IS_MPZ(c))
{
if (c == 1)
_fmpz_vec_set(vec1, vec2, len2);
else if (c == -1)
_fmpz_vec_neg(vec1, vec2, len2);
else
_fmpz_vec_scalar_divexact_si(vec1, vec2, len2, c);
}
else
{
slong i;
for (i = 0; i < len2; i++)
fmpz_divexact(vec1 + i, vec2 + i, x);
}
}

View File

@@ -0,0 +1,38 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_scalar_divexact_si(fmpz * vec1, const fmpz * vec2, slong len2, slong c)
{
slong i;
for (i = 0; i < len2; i++)
fmpz_divexact_si(vec1 + i, vec2 + i, c);
}

View File

@@ -0,0 +1,39 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_scalar_divexact_ui(fmpz * vec1, const fmpz * vec2,
slong len2, ulong c)
{
slong i;
for (i = 0; i < len2; i++)
fmpz_divexact_ui(vec1 + i, vec2 + i, c);
}

View File

@@ -0,0 +1,39 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_scalar_fdiv_q_2exp(fmpz * vec1, const fmpz * vec2, slong len2,
ulong exp)
{
slong i;
for (i = 0; i < len2; i++)
fmpz_fdiv_q_2exp(vec1 + i, vec2 + i, exp);
}

View File

@@ -0,0 +1,39 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_scalar_fdiv_q_fmpz(fmpz * vec1, const fmpz * vec2, slong len2,
const fmpz_t c)
{
slong i;
for (i = 0; i < len2; i++)
fmpz_fdiv_q(vec1 + i, vec2 + i, c);
}

View File

@@ -0,0 +1,38 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_scalar_fdiv_q_si(fmpz * vec1, const fmpz * vec2, slong len2, slong c)
{
slong i;
for (i = 0; i < len2; i++)
fmpz_fdiv_q_si(vec1 + i, vec2 + i, c);
}

View File

@@ -0,0 +1,38 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_scalar_fdiv_q_ui(fmpz * vec1, const fmpz * vec2, slong len2, ulong c)
{
slong i;
for (i = 0; i < len2; i++)
fmpz_fdiv_q_ui(vec1 + i, vec2 + i, c);
}

View File

@@ -0,0 +1,40 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 William Hart
Copyright (C) 2010, 2012 Sebastian Pancratz
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_scalar_fdiv_r_2exp(fmpz * vec1, const fmpz * vec2, slong len2,
ulong exp)
{
slong i;
for (i = 0; i < len2; i++)
fmpz_fdiv_r_2exp(vec1 + i, vec2 + i, exp);
}

View File

@@ -0,0 +1,38 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2011 Sebastian Pancratz
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void _fmpz_vec_scalar_mod_fmpz(fmpz *res, const fmpz *vec, slong len, const fmpz_t p)
{
slong i;
for (i = 0; i < len; i++)
fmpz_mod(res + i, vec + i, p);
}

View File

@@ -0,0 +1,38 @@
/*============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===============================================================================*/
/****************************************************************************
Copyright (C) 2010 William Hart
*****************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_scalar_mul_2exp(fmpz * vec1, const fmpz * vec2, slong len2, ulong exp)
{
slong i;
for (i = 0; i < len2; i++)
fmpz_mul_2exp(vec1 + i, vec2 + i, exp);
}

View File

@@ -0,0 +1,54 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 William Hart
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_scalar_mul_fmpz(fmpz * poly1, const fmpz * poly2, slong len2,
const fmpz_t x)
{
fmpz c = *x;
if (!COEFF_IS_MPZ(c))
{
if (c == 0)
_fmpz_vec_zero(poly1, len2);
else if (c == 1)
_fmpz_vec_set(poly1, poly2, len2);
else if (c == -1)
_fmpz_vec_neg(poly1, poly2, len2);
else
_fmpz_vec_scalar_mul_si(poly1, poly2, len2, c);
}
else
{
slong i;
for (i = 0; i < len2; i++)
fmpz_mul(poly1 + i, poly2 + i, x);
}
}

View File

@@ -0,0 +1,37 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 William Hart
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_scalar_mul_si(fmpz * vec1, const fmpz * vec2, slong len2, slong c)
{
slong i;
for (i = 0; i < len2; i++)
fmpz_mul_si(vec1 + i, vec2 + i, c);
}

View File

@@ -0,0 +1,37 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 William Hart
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_scalar_mul_ui(fmpz * vec1, const fmpz * vec2, slong len2, ulong c)
{
slong i;
for (i = 0; i < len2; i++)
fmpz_mul_ui(vec1 + i, vec2 + i, c);
}

View File

@@ -0,0 +1,51 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2011 Sebastian Pancratz
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void _fmpz_vec_scalar_smod_fmpz(fmpz *res, const fmpz *vec, slong len, const fmpz_t p)
{
slong i;
fmpz_t pdiv2;
fmpz_init(pdiv2);
fmpz_fdiv_q_2exp(pdiv2, p, 1);
for (i = 0; i < len; i++)
{
fmpz_mod(res + i, vec + i, p);
if (fmpz_cmp(res + i, pdiv2) > 0)
{
fmpz_sub(res + i, res + i, p);
}
}
fmpz_clear(pdiv2);
}

View File

@@ -0,0 +1,55 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_scalar_submul_fmpz(fmpz * vec1, const fmpz * vec2, slong len2,
const fmpz_t x)
{
fmpz c = *x;
if (!COEFF_IS_MPZ(c))
{
if (c == 0)
return;
else if (c == 1)
_fmpz_vec_sub(vec1, vec1, vec2, len2);
else if (c == -1)
_fmpz_vec_add(vec1, vec1, vec2, len2);
else
_fmpz_vec_scalar_submul_si(vec1, vec2, len2, c);
}
else
{
slong i;
for (i = 0; i < len2; i++)
fmpz_submul(vec1 + i, vec2 + i, x);
}
}

View File

@@ -0,0 +1,43 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_scalar_submul_si(fmpz * vec1, const fmpz * vec2, slong len2, slong c)
{
slong i;
if (c >= 0)
for (i = 0; i < len2; i++)
fmpz_submul_ui(vec1 + i, vec2 + i, c);
else
for (i = 0; i < len2; i++)
fmpz_addmul_ui(vec1 + i, vec2 + i, -c);
}

View File

@@ -0,0 +1,87 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_scalar_submul_si_2exp(fmpz * vec1, const fmpz * vec2, slong len2,
slong c, ulong exp)
{
slong i;
fmpz_t temp;
if (c == 0)
return; /* nothing to add */
if (exp == 0) /* just do submul */
{
_fmpz_vec_scalar_submul_si(vec1, vec2, len2, c);
return;
}
fmpz_init(temp);
if (c == 1) /* scalar is 1, just subtract c * 2^exp times c */
{
for (i = 0; i < len2; i++)
{
fmpz_mul_2exp(temp, vec2 + i, exp);
fmpz_sub(vec1 + i, vec1 + i, temp);
}
}
else if (c == -1) /* scalar is -1, add c * 2^exp */
{
for (i = 0; i < len2; i++)
{
fmpz_mul_2exp(temp, vec2 + i, exp);
fmpz_add(vec1 + i, vec1 + i, temp);
}
}
else /* generic case */
{
if (c >= 0)
{
for (i = 0; i < len2; i++)
{
fmpz_mul_2exp(temp, vec2 + i, exp);
fmpz_submul_ui(vec1 + i, temp, c);
}
}
else
{
for (i = 0; i < len2; i++)
{
fmpz_mul_2exp(temp, vec2 + i, exp);
fmpz_addmul_ui(vec1 + i, temp, -c);
}
}
}
fmpz_clear(temp);
}

View File

@@ -0,0 +1,39 @@
/*============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===============================================================================*/
/****************************************************************************
Copyright (C) 2010 William Hart
*****************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_scalar_tdiv_q_2exp(fmpz * vec1, const fmpz * vec2, slong len2,
ulong exp)
{
slong i;
for (i = 0; i < len2; i++)
fmpz_tdiv_q_2exp(vec1 + i, vec2 + i, exp);
}

View File

@@ -0,0 +1,38 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_scalar_tdiv_q_fmpz(fmpz * vec1, const fmpz * vec2, slong len2,
const fmpz_t c)
{
slong i;
for (i = 0; i < len2; i++)
fmpz_tdiv_q(vec1 + i, vec2 + i, c);
}

View File

@@ -0,0 +1,37 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_scalar_tdiv_q_si(fmpz * vec1, const fmpz * vec2, slong len2, slong c)
{
slong i;
for (i = 0; i < len2; i++)
fmpz_tdiv_q_si(vec1 + i, vec2 + i, c);
}

View File

@@ -0,0 +1,37 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_scalar_tdiv_q_ui(fmpz * vec1, const fmpz * vec2, slong len2, ulong c)
{
slong i;
for (i = 0; i < len2; i++)
fmpz_tdiv_q_ui(vec1 + i, vec2 + i, c);
}

37
external/flint-2.4.3/fmpz_vec/set.c vendored Normal file
View File

@@ -0,0 +1,37 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 William Hart
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_set(fmpz * vec1, const fmpz * vec2, slong len2)
{
slong i;
for (i = 0; i < len2; i++)
fmpz_set(vec1 + i, vec2 + i);
}

84
external/flint-2.4.3/fmpz_vec/set_fft.c vendored Normal file
View File

@@ -0,0 +1,84 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2008-2011 William Hart
******************************************************************************/
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "fmpz_poly.h"
#include "fft.h"
void _fmpz_vec_set_fft(fmpz * coeffs_m, slong length,
const mp_ptr * coeffs_f, slong limbs, slong sign)
{
slong i, size;
mp_limb_t * data;
__mpz_struct * mpz_ptr;
if (sign)
{
for (i = 0; i < length; i++)
{
mpz_ptr = _fmpz_promote(coeffs_m);
if (mpz_ptr->_mp_alloc < limbs) _mpz_realloc(mpz_ptr, limbs);
data = mpz_ptr->_mp_d;
if ((coeffs_f[i][limbs - 1] >> (FLINT_BITS - 1)) || coeffs_f[i][limbs])
{
mpn_neg_n(data, coeffs_f[i], limbs);
mpn_add_1(data, data, limbs, WORD(1));
size = limbs;
while ((size) && (data[size - 1] == 0)) size--; /* normalise */
mpz_ptr->_mp_size = -size;
if (size >= WORD(-1)) _fmpz_demote_val(coeffs_m); /* coefficient may be small*/
} else
{
flint_mpn_copyi(data, coeffs_f[i], limbs);
size = limbs;
while ((size) && (data[size - 1] == WORD(0))) size--; /* normalise */
mpz_ptr->_mp_size = size;
if (size <= 1) _fmpz_demote_val(coeffs_m); /* coefficient may be small */
}
coeffs_m++;
}
} else
{
for (i = 0; i < length; i++)
{
mpz_ptr = _fmpz_promote(coeffs_m);
if (mpz_ptr->_mp_alloc < limbs) _mpz_realloc(mpz_ptr, limbs);
data = mpz_ptr->_mp_d;
flint_mpn_copyi(data, coeffs_f[i], limbs);
size = limbs;
while ((size) && (data[size - 1] == WORD(0))) size--; /* normalise */
mpz_ptr->_mp_size = size;
if (size <= 1) _fmpz_demote_val(coeffs_m); /* coefficient may be small */
coeffs_m++;
}
}
}

View File

@@ -0,0 +1,40 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "fmpz_poly.h"
#include "nmod_poly.h"
void
_fmpz_vec_set_nmod_vec(fmpz * res, mp_srcptr poly, slong len, nmod_t mod)
{
slong i;
for (i = 0; i < len; i++)
fmpz_set_ui_smod(res + i, poly[i], mod.n);
}

39
external/flint-2.4.3/fmpz_vec/sort.c vendored Normal file
View File

@@ -0,0 +1,39 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 Fredrik Johansson
******************************************************************************/
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#ifndef __compar_fn_t
typedef int (*__compar_fn_t) (__const void *, __const void *);
#endif
void _fmpz_vec_sort(fmpz * vec, slong len)
{
qsort(vec, len, sizeof(fmpz), (__compar_fn_t) fmpz_cmp);
}

37
external/flint-2.4.3/fmpz_vec/sub.c vendored Normal file
View File

@@ -0,0 +1,37 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 William Hart
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_sub(fmpz * res, const fmpz * vec1, const fmpz * vec2, slong len2)
{
slong i;
for (i = 0; i < len2; i++)
fmpz_sub(res + i, vec1 + i, vec2 + i);
}

50
external/flint-2.4.3/fmpz_vec/sum.c vendored Normal file
View File

@@ -0,0 +1,50 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_sum(fmpz_t res, const fmpz * vec, slong len)
{
if (len <= 1)
{
if (len == 1)
fmpz_set(res, vec);
else
fmpz_zero(res);
}
else
{
slong i;
fmpz_add(res, vec, vec + 1);
for (i = 2; i < len; i++)
fmpz_add(res, res, vec + i);
}
}

37
external/flint-2.4.3/fmpz_vec/swap.c vendored Normal file
View File

@@ -0,0 +1,37 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_swap(fmpz * vec1, fmpz * vec2, slong len2)
{
slong i;
for (i = 0; i < len2; i++)
fmpz_swap(vec1 + i, vec2 + i);
}

View File

@@ -0,0 +1,107 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009, 2010 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("add....");
fflush(stdout);
/* Check aliasing of a and c */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b, *c;
slong len = n_randint(state, 100);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
c = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_randtest(b, state, len, 200);
_fmpz_vec_add(c, a, b, len);
_fmpz_vec_add(a, a, b, len);
result = (_fmpz_vec_equal(a, c, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(c, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
_fmpz_vec_clear(c, len);
}
/* Check aliasing of b and c */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b, *c;
slong len = n_randint(state, 100);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
c = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_randtest(b, state, len, 200);
_fmpz_vec_add(c, a, b, len);
_fmpz_vec_add(b, a, b, len);
result = (_fmpz_vec_equal(b, c, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
_fmpz_vec_print(c, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
_fmpz_vec_clear(c, len);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,85 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("content....");
fflush(stdout);
/* Check that content(a f) = abs(a) content(f) */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz_t a, c, d;
fmpz *f;
slong len = n_randint(state, 100);
fmpz_init(a);
fmpz_init(c);
fmpz_init(d);
f = _fmpz_vec_init(len);
_fmpz_vec_randtest(f, state, len, 200);
fmpz_randtest(a, state, 100);
_fmpz_vec_content(c, f, len);
_fmpz_vec_scalar_mul_fmpz(f, f, len, a);
fmpz_abs(a, a);
fmpz_mul(c, a, c);
_fmpz_vec_content(d, f, len);
result = (fmpz_equal(c, d));
if (!result)
{
flint_printf("FAIL:\n");
fmpz_print(c), flint_printf("\n\n");
fmpz_print(d), flint_printf("\n\n");
abort();
}
fmpz_clear(a);
fmpz_clear(c);
fmpz_clear(d);
_fmpz_vec_clear(f, len);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,131 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009, 2011 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fft.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("get/set_fft....");
fflush(stdout);
/* convert back and forth and compare */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz * a, * b;
mp_bitcnt_t bits;
slong len, limbs;
mp_limb_t ** ii, * ptr;
slong i, bt;
bits = n_randint(state, 300) + 1;
len = n_randint(state, 300) + 1;
limbs = 2*((bits - 1)/FLINT_BITS + 1);
ii = flint_malloc((len + len*(limbs + 1))*sizeof(mp_limb_t));
ptr = (mp_limb_t *) ii + len;
for (i = 0; i < len; i++, ptr += (limbs + 1))
ii[i] = ptr;
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, bits);
bt = _fmpz_vec_get_fft(ii, a, limbs, len);
for (i = 0; i < len; i++)
mpn_normmod_2expp1(ii[i], limbs);
_fmpz_vec_set_fft(b, len, ii, limbs, bt < 0);
result = (_fmpz_vec_equal(a, b, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
abort();
}
flint_free(ii);
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
}
/* convert back and forth unsigned and compare */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz * a, * b;
mp_bitcnt_t bits;
slong len, limbs;
mp_limb_t ** ii, * ptr;
slong i, bt;
bits = n_randint(state, 300) + 1;
len = n_randint(state, 300) + 1;
limbs = 2*((bits - 1)/FLINT_BITS + 1);
ii = flint_malloc((len + len*(limbs + 1))*sizeof(mp_limb_t));
ptr = (mp_limb_t *) ii + len;
for (i = 0; i < len; i++, ptr += (limbs + 1))
ii[i] = ptr;
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
_fmpz_vec_randtest_unsigned(a, state, len, bits);
bt = _fmpz_vec_get_fft(ii, a, limbs, len);
_fmpz_vec_set_fft(b, len, ii, limbs, bt < 0);
result = (_fmpz_vec_equal(a, b, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
abort();
}
flint_free(ii);
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,96 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009, 2010 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
#include "nmod_vec.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("get/set_nmod_vec....");
fflush(stdout);
/* Check conversion to and from nmod_vec */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b;
mp_ptr c;
nmod_t mod;
slong i;
mp_limb_t t;
slong len = n_randint(state, 100);
mp_limb_t n = n_randtest_not_zero(state);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
c = _nmod_vec_init(len);
nmod_init(&mod, n);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_get_nmod_vec(c, a, len, mod);
_fmpz_vec_set_nmod_vec(b, c, len, mod);
for (i = 0; i < len; i++)
{
fmpz_mod_ui(a + i, a + i, n);
t = fmpz_get_ui(a + i);
if (t > n / 2)
fmpz_sub_ui(a + i, a + i, n);
}
result = (_fmpz_vec_equal(a, b, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
_nmod_vec_clear(c);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,83 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("height....");
fflush(stdout);
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a;
fmpz_t h;
slong len, bits, bits2;
fmpz_init(h);
len = n_randint(state, 100);
a = _fmpz_vec_init(len);
bits = n_randint(state, 200);
_fmpz_vec_randtest(a, state, len, bits);
bits2 = _fmpz_vec_max_bits(a, len);
_fmpz_vec_height(h, a, len);
result = (fmpz_bits(h) == FLINT_ABS(bits2)) && (fmpz_sgn(h) >= 0);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("bits = %wd, bits2 = %wd\n", bits, bits2);
flint_printf("Computed height:\n");
fmpz_print(h);
flint_printf("\n");
abort();
}
fmpz_clear(h);
_fmpz_vec_clear(a, len);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,87 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2012 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
static slong
refimpl(const fmpz * v, slong len)
{
slong i, max = 0;
for (i = 1; i < len; i++)
if (fmpz_cmpabs(v + i, v + max) > 0)
max = i;
return max;
}
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("height_index....");
fflush(stdout);
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a;
slong len, bits, p1, p2;
len = 1 + n_randint(state, 100);
a = _fmpz_vec_init(len);
bits = n_randint(state, 200);
_fmpz_vec_randtest(a, state, len, bits);
p1 = _fmpz_vec_height_index(a, len);
p2 = refimpl(a, len);
result = (p1 == p2);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("bits = %wd, p1 = %wd, p2 = %wd\n", bits, p1, p2);
abort();
}
_fmpz_vec_clear(a, len);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,61 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i;
FLINT_TEST_INIT(state);
flint_printf("init/clear....");
fflush(stdout);
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a;
slong j, len = n_randint(state, 100) + 1;
a = _fmpz_vec_init(len);
for (j = 0; j < len; j++)
fmpz_zero(a + j);
_fmpz_vec_clear(a, len);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,92 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009, 2010 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("is_zero....");
fflush(stdout);
/* Check zero vector */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a;
slong len = n_randint(state, 100);
a = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_zero(a, len);
result = (_fmpz_vec_is_zero(a, len));
if (!result)
{
flint_printf("FAIL1:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
}
/* Check non-zero vector */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a;
slong len = n_randint(state, 100) + 1;
a = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
fmpz_set_ui(a + (len - 1), UWORD(1));
result = (!_fmpz_vec_is_zero(a, len));
if (!result)
{
flint_printf("FAIL2:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,93 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("lcm....");
fflush(stdout);
/* Check that lcm(a f) = abs(a) lcm(f) */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz_t a, c, d;
fmpz *f;
slong len = n_randint(state, 100);
fmpz_init(a);
fmpz_init(c);
fmpz_init(d);
f = _fmpz_vec_init(len);
_fmpz_vec_randtest(f, state, len, 200);
fmpz_randtest(a, state, 100);
_fmpz_vec_lcm(c, f, len);
if (len == 0)
{
result = fmpz_is_one(c);
}
else
{
_fmpz_vec_scalar_mul_fmpz(f, f, len, a);
fmpz_abs(a, a);
fmpz_mul(c, a, c);
_fmpz_vec_lcm(d, f, len);
result = (fmpz_equal(c, d));
}
if (!result)
{
fmpz_print(c), flint_printf("\n\n");
fmpz_print(d), flint_printf("\n\n");
abort();
}
fmpz_clear(a);
fmpz_clear(c);
fmpz_clear(d);
_fmpz_vec_clear(f, len);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,74 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("max_bits....");
fflush(stdout);
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a;
slong len, bits, bits2, bits3;
len = n_randint(state, 100);
a = _fmpz_vec_init(len);
bits = n_randint(state, 200);
_fmpz_vec_randtest(a, state, len, bits);
bits2 = _fmpz_vec_max_bits(a, len);
bits3 = _fmpz_vec_max_bits_ref(a, len);
result = (bits >= FLINT_ABS(bits2) && bits2 == bits3);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("bits = %wd, bits2 = %wd bits3 = %wd\n", bits, bits2, bits3);
abort();
}
_fmpz_vec_clear(a, len);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,79 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("max_limbs....");
fflush(stdout);
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a;
slong len, bits;
mp_size_t limbs, limbs2;
len = n_randint(state, 100);
a = _fmpz_vec_init(len);
bits = n_randint(state, 200);
limbs = (bits + FLINT_BITS - 1) / FLINT_BITS;
_fmpz_vec_randtest(a, state, len, bits);
limbs2 = _fmpz_vec_max_limbs(a, len);
result = (limbs >= limbs2);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("bits = %wd\n", bits);
flint_printf("limbs = %wd\n", limbs);
flint_printf("a = {"), _fmpz_vec_print(a, len), flint_printf("}\n");
flint_printf("limbs2 = %wd\n", limbs2);
abort();
}
_fmpz_vec_clear(a, len);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,101 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009, 2010 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("neg....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b;
slong len = n_randint(state, 100);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_neg(b, a, len);
_fmpz_vec_neg(a, a, len);
result = (_fmpz_vec_equal(a, b, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
}
/* Check -(-a) == a */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b;
slong len = n_randint(state, 100);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_neg(b, a, len);
_fmpz_vec_neg(b, b, len);
result = (_fmpz_vec_equal(a, b, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,88 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009, 2010 William Hart
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("prod....");
fflush(stdout);
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b;
fmpz_t x, y, z;
slong len1 = n_randint(state, 100);
slong len2 = n_randint(state, 100);
a = _fmpz_vec_init(len1 + len2);
b = a + len1;
_fmpz_vec_randtest(a, state, len1 + len2, 200);
fmpz_init(x);
fmpz_init(y);
fmpz_init(z);
_fmpz_vec_prod(x, a, len1);
_fmpz_vec_prod(y, b, len2);
fmpz_mul(x, x, y);
_fmpz_vec_prod(z, a, len1 + len2);
result = (fmpz_equal(x, z));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len1), flint_printf("\n\n");
_fmpz_vec_print(b, len2), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len1 + len2);
fmpz_clear(x);
fmpz_clear(y);
fmpz_clear(z);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,124 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009, 2010 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("scalar_addmul_fmpz....");
fflush(stdout);
/* Compare with fmpz_vec_scalar_addmul_si */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b, *c;
fmpz_t n1;
slong len, n;
len = n_randint(state, 100);
n = (slong) n_randbits(state, FLINT_BITS - 1);
if (n_randint(state, 2))
n = -n;
fmpz_init(n1);
fmpz_set_si(n1, n);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
c = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_randtest(b, state, len, 200);
_fmpz_vec_set(c, b, len);
_fmpz_vec_scalar_addmul_fmpz(b, a, len, n1);
_fmpz_vec_scalar_addmul_si(c, a, len, n);
result = (_fmpz_vec_equal(c, b, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(c, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
abort();
}
fmpz_clear(n1);
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
_fmpz_vec_clear(c, len);
}
/* Compute a different way */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b, *c, *d;
slong len = n_randint(state, 100);
fmpz_t n1;
fmpz_init(n1);
fmpz_randtest(n1, state, 200);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
c = _fmpz_vec_init(len);
d = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_randtest(b, state, len, 200);
_fmpz_vec_set(c, b, len);
_fmpz_vec_scalar_addmul_fmpz(b, a, len, n1);
_fmpz_vec_scalar_mul_fmpz(d, a, len, n1);
_fmpz_vec_add(c, c, d, len);
result = (_fmpz_vec_equal(c, b, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(c, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
abort();
}
fmpz_clear(n1);
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
_fmpz_vec_clear(c, len);
_fmpz_vec_clear(d, len);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,90 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
#include "long_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("scalar_addmul_si....");
fflush(stdout);
/* Compare with alternative method of computation */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b, *c, *d;
slong len, x;
len = n_randint(state, 100);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
c = _fmpz_vec_init(len);
d = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_randtest(b, state, len, 200);
_fmpz_vec_set(c, b, len);
x = z_randtest(state);
_fmpz_vec_scalar_addmul_si(b, a, len, x);
_fmpz_vec_scalar_mul_si(d, a, len, x);
_fmpz_vec_add(c, c, d, len);
result = (_fmpz_vec_equal(b, c, len));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("x = %wd\n", x);
_fmpz_vec_print(b, len), flint_printf("\n\n");
_fmpz_vec_print(c, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
_fmpz_vec_clear(c, len);
_fmpz_vec_clear(d, len);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,91 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
#include "long_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("scalar_addmul_si_2exp....");
fflush(stdout);
/* Compare with alternative method of computation */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b, *c, *d;
slong len, x;
mp_bitcnt_t exp;
len = n_randint(state, 100);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
c = _fmpz_vec_init(len);
d = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_randtest(b, state, len, 200);
_fmpz_vec_set(c, b, len);
x = z_randtest(state);
exp = n_randint(state, 200);
_fmpz_vec_scalar_addmul_si_2exp(b, a, len, x, exp);
_fmpz_vec_scalar_mul_2exp(d, a, len, exp);
_fmpz_vec_scalar_addmul_si(c, d, len, x);
result = (_fmpz_vec_equal(b, c, len));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("x = %wd, exp = %wu\n", x, exp);
_fmpz_vec_print(b, len), flint_printf("\n\n");
_fmpz_vec_print(c, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
_fmpz_vec_clear(c, len);
_fmpz_vec_clear(d, len);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,116 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009, 2010 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("scalar_divexact_fmpz....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b;
fmpz_t n;
slong len = n_randint(state, 100);
fmpz_init(n);
fmpz_randtest_not_zero(n, state, 100);
if (n_randint(state, 2))
fmpz_neg(n, n);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_scalar_mul_fmpz(a, a, len, n);
_fmpz_vec_scalar_divexact_fmpz(b, a, len, n);
_fmpz_vec_scalar_divexact_fmpz(a, a, len, n);
result = (_fmpz_vec_equal(a, b, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
fmpz_clear(n);
}
/* Check that a * n / n == a */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b;
fmpz_t n;
slong len = n_randint(state, 100);
fmpz_init(n);
fmpz_randtest_not_zero(n, state, 100);
if (n_randint(state, 2))
fmpz_neg(n, n);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_set(b, a, len);
_fmpz_vec_scalar_mul_fmpz(a, a, len, n);
_fmpz_vec_scalar_divexact_fmpz(a, a, len, n);
result = (_fmpz_vec_equal(a, b, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
fmpz_clear(n);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,110 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
#include "long_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("scalar_divexact_si....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b;
slong len = n_randint(state, 100);
slong n;
n = z_randtest_not_zero(state);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_scalar_mul_si(a, a, len, n);
_fmpz_vec_scalar_divexact_si(b, a, len, n);
_fmpz_vec_scalar_divexact_si(a, a, len, n);
result = (_fmpz_vec_equal(a, b, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
}
/* Check that a * n / n == a */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b;
slong len = n_randint(state, 100);
slong n;
n = z_randtest_not_zero(state);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_set(b, a, len);
_fmpz_vec_scalar_mul_si(a, a, len, n);
_fmpz_vec_scalar_divexact_si(a, a, len, n);
result = (_fmpz_vec_equal(a, b, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,105 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("scalar_divexact_ui....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b;
ulong n = n_randtest_not_zero(state);
slong len = n_randint(state, 100);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_scalar_mul_ui(a, a, len, n);
_fmpz_vec_scalar_divexact_ui(b, a, len, n);
_fmpz_vec_scalar_divexact_ui(a, a, len, n);
result = (_fmpz_vec_equal(a, b, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
}
/* Check that a * n / n == a */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b;
ulong n = n_randtest_not_zero(state);
slong len = n_randint(state, 100);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_set(b, a, len);
_fmpz_vec_scalar_mul_ui(a, a, len, n);
_fmpz_vec_scalar_divexact_ui(a, a, len, n);
result = (_fmpz_vec_equal(a, b, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,163 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009, 2010 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("scalar_fdiv_q_fmpz....");
fflush(stdout);
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b, *c;
fmpz_t n;
mpz_t d, e, f, m;
slong i;
slong len = n_randint(state, 100);
fmpz_init(n);
fmpz_randtest_not_zero(n, state, 100);
if (n_randint(state, 2))
fmpz_neg(n, n);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
c = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_set(b, a, len);
_fmpz_vec_scalar_fdiv_q_fmpz(c, a, len, n);
mpz_init(d);
mpz_init(e);
mpz_init(f);
mpz_init(m);
for (i = 0; i < len; i++)
{
fmpz_get_mpz(m, n);
fmpz_get_mpz(d, b + i);
mpz_fdiv_q(e, d, m);
fmpz_get_mpz(f, c + i);
result = (mpz_cmp(f, e) == 0);
if (!result)
{
flint_printf("FAIL:\n");
gmp_printf("d = %Zd, m = %Zd, e = %Zd, f = %Zd\n", d, m, e, f);
abort();
}
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
_fmpz_vec_clear(c, len);
fmpz_clear(n);
mpz_clear(d);
mpz_clear(e);
mpz_clear(f);
mpz_clear(m);
}
/* Test aliasing of a and c */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b;
fmpz_t n;
mpz_t d, e, f, m;
slong i;
slong len = n_randint(state, 100);
fmpz_init(n);
fmpz_randtest_not_zero(n, state, 100);
if (n_randint(state, 2))
fmpz_neg(n, n);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_set(b, a, len);
_fmpz_vec_scalar_fdiv_q_fmpz(a, a, len, n);
mpz_init(d);
mpz_init(e);
mpz_init(f);
mpz_init(m);
for (i = 0; i < len; i++)
{
fmpz_get_mpz(m, n);
fmpz_get_mpz(d, b + i);
mpz_fdiv_q(e, d, m);
fmpz_get_mpz(f, a + i);
result = (mpz_cmp(f, e) == 0);
if (!result)
{
flint_printf("FAIL:\n");
gmp_printf("d = %Zd, m = %Zd, e = %Zd, f = %Zd\n", d, m, e, f);
abort();
}
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
fmpz_clear(n);
mpz_clear(d);
mpz_clear(e);
mpz_clear(f);
mpz_clear(m);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,116 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2011 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("scalar_mod_fmpz....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz_t p;
fmpz *a, *b;
slong len = n_randint(state, 100);
fmpz_init(p);
fmpz_randtest_unsigned(p, state, 100);
fmpz_add_ui(p, p, 1);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_scalar_mod_fmpz(b, a, len, p);
_fmpz_vec_scalar_mod_fmpz(a, a, len, p);
result = (_fmpz_vec_equal(a, a, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
fmpz_clear(p);
}
/* Check the result is reduced */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz_t p;
fmpz *a, *b;
slong j, len = n_randint(state, 100);
fmpz_init(p);
fmpz_randtest_unsigned(p, state, 100);
fmpz_add_ui(p, p, 1);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_scalar_mod_fmpz(b, a, len, p);
result = 1;
for (j = 0; j < len; j++)
result &= (fmpz_sgn(b + j) >= 0 && fmpz_cmp(b + j, p) < 0);
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
fmpz_print(p), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
fmpz_clear(p);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,107 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009, 2010 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("scalar_mul_2exp....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b;
slong len = n_randint(state, 100);
ulong exp = n_randint(state, 200);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_scalar_mul_2exp(b, a, len, exp);
_fmpz_vec_scalar_mul_2exp(a, a, len, exp);
result = (_fmpz_vec_equal(a, b, len));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("exp = %wu\n", exp);
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
}
/* Check aliasing of (a*2^e1)*2^e2 equals a*2^(e1+e2) */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b;
slong len = n_randint(state, 100);
ulong e1 = n_randint(state, 200);
ulong e2 = n_randint(state, 200);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_scalar_mul_2exp(b, a, len, e1);
_fmpz_vec_scalar_mul_2exp(b, b, len, e2);
_fmpz_vec_scalar_mul_2exp(a, a, len, e1 + e2);
result = (_fmpz_vec_equal(a, b, len));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("e1 = %wu, e2 = %wu\n", e1, e2);
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,165 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009, 2010 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("scalar_mul_fmpz....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b;
fmpz_t n;
slong len = n_randint(state, 100);
fmpz_init(n);
fmpz_randtest(n, state, 100);
if (n_randint(state, 2))
fmpz_neg(n, n);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_scalar_mul_fmpz(b, a, len, n);
_fmpz_vec_scalar_mul_fmpz(a, a, len, n);
result = (_fmpz_vec_equal(a, b, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
fmpz_clear(n);
}
/* Check that n (a + b) == na + nb */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b, *lhs, *rhs;
fmpz_t n;
slong len = n_randint(state, 100);
fmpz_init(n);
fmpz_randtest(n, state, 100);
if (n_randint(state, 2))
fmpz_neg(n, n);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
lhs = _fmpz_vec_init(len);
rhs = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_randtest(b, state, len, 200);
_fmpz_vec_scalar_mul_fmpz(lhs, a, len, n);
_fmpz_vec_scalar_mul_fmpz(rhs, b, len, n);
_fmpz_vec_add(rhs, lhs, rhs, len);
_fmpz_vec_add(lhs, a, b, len);
_fmpz_vec_scalar_mul_fmpz(lhs, lhs, len, n);
result = (_fmpz_vec_equal(lhs, rhs, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
_fmpz_vec_print(lhs, len), flint_printf("\n\n");
_fmpz_vec_print(rhs, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
_fmpz_vec_clear(lhs, len);
_fmpz_vec_clear(rhs, len);
fmpz_clear(n);
}
/* Check that n2 * (n1 a) == (n1 * n2) a */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b;
fmpz_t n1, n2, n;
slong len = n_randint(state, 100);
fmpz_init(n1);
fmpz_init(n2);
fmpz_init(n);
fmpz_randtest(n1, state, 100);
fmpz_randtest(n2, state, 100);
if (n_randint(state, 2))
fmpz_neg(n1, n1);
if (n_randint(state, 2))
fmpz_neg(n2, n2);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_scalar_mul_fmpz(b, a, len, n1);
_fmpz_vec_scalar_mul_fmpz(b, b, len, n2);
fmpz_mul(n, n1, n2);
_fmpz_vec_scalar_mul_fmpz(a, a, len, n);
result = (_fmpz_vec_equal(a, b, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
fmpz_clear(n1);
fmpz_clear(n2);
fmpz_clear(n);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,111 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009, 2010 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
#include "long_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("scalar_mul_si....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b;
slong len = n_randint(state, 100);
slong n = z_randtest(state);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_scalar_mul_si(b, a, len, n);
_fmpz_vec_scalar_mul_si(a, a, len, n);
result = (_fmpz_vec_equal(a, b, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
}
/* Check agreement with _fmpz */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b;
slong len, n;
fmpz_t x;
len = n_randint(state, 100);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
n = z_randtest(state);
fmpz_init(x);
fmpz_set_si(x, n);
_fmpz_vec_scalar_mul_fmpz(b, a, len, x);
_fmpz_vec_scalar_mul_si(a, a, len, n);
result = (_fmpz_vec_equal(a, b, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
flint_printf("%li\n\n", n);
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
fmpz_clear(x);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,108 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009, 2010 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("scalar_mul_ui....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b;
slong len = n_randint(state, 100);
ulong n = n_randtest(state);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_scalar_mul_ui(b, a, len, n);
_fmpz_vec_scalar_mul_ui(a, a, len, n);
result = (_fmpz_vec_equal(a, b, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
}
/* Check agreement with _fmpz */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b;
slong len = n_randint(state, 100);
ulong n = n_randbits(state, FLINT_BITS);
fmpz_t x;
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
fmpz_init(x);
_fmpz_vec_randtest(a, state, len, 200);
fmpz_set_ui(x, n);
_fmpz_vec_scalar_mul_ui(b, a, len, n);
_fmpz_vec_scalar_mul_fmpz(a, a, len, x);
result = (_fmpz_vec_equal(a, b, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
fmpz_clear(x);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,137 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2011 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("scalar_smod_fmpz....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz_t p;
fmpz *a, *b;
slong len = n_randint(state, 100);
fmpz_init(p);
fmpz_randtest_unsigned(p, state, 100);
fmpz_add_ui(p, p, 1);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_scalar_smod_fmpz(b, a, len, p);
_fmpz_vec_scalar_smod_fmpz(a, a, len, p);
result = (_fmpz_vec_equal(a, a, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
fmpz_clear(p);
}
/* Check the result is reduced */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz_t p, lo, hi;
fmpz *a, *b;
slong j, len = n_randint(state, 100);
fmpz_init(p);
fmpz_init(lo);
fmpz_init(hi);
fmpz_randtest_unsigned(p, state, 100);
fmpz_add_ui(p, p, 1);
if (fmpz_cmp_ui(p, 2) > 0)
{
fmpz_fdiv_q_2exp(hi, p, 1);
fmpz_neg(lo, hi);
}
else if (fmpz_cmp_ui(p, 2) == 0)
{
fmpz_zero(lo);
fmpz_one(hi);
}
else
{
fmpz_zero(lo);
fmpz_zero(hi);
}
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_scalar_smod_fmpz(b, a, len, p);
result = 1;
for (j = 0; j < len; j++)
result &= (fmpz_cmp(lo, b + j) <= 0 && fmpz_cmp(b + j, hi) <= 0);
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
fmpz_print(p), flint_printf("\n\n");
fmpz_print(lo), flint_printf("\n\n");
fmpz_print(hi), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
fmpz_clear(p);
fmpz_clear(lo);
fmpz_clear(hi);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,124 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009, 2010 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("scalar_submul_fmpz....");
fflush(stdout);
/* Compare with fmpz_vec_scalar_submul_si */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b, *c;
slong len, n;
fmpz_t n1;
len = n_randint(state, 100);
n = (slong) n_randbits(state, FLINT_BITS - 1);
if (n_randint(state, 2))
n = -n;
fmpz_init(n1);
fmpz_set_si(n1, n);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
c = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_randtest(b, state, len, 200);
_fmpz_vec_set(c, b, len);
_fmpz_vec_scalar_submul_fmpz(b, a, len, n1);
_fmpz_vec_scalar_submul_si(c, a, len, n);
result = (_fmpz_vec_equal(c, b, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(c, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
abort();
}
fmpz_clear(n1);
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
_fmpz_vec_clear(c, len);
}
/* Compute a different way */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b, *c, *d;
slong len = n_randint(state, 100);
fmpz_t n1;
fmpz_init(n1);
fmpz_randtest(n1, state, 200);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
c = _fmpz_vec_init(len);
d = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_randtest(b, state, len, 200);
_fmpz_vec_set(c, b, len);
_fmpz_vec_scalar_submul_fmpz(b, a, len, n1);
_fmpz_vec_scalar_mul_fmpz(d, a, len, n1);
_fmpz_vec_sub(c, c, d, len);
result = (_fmpz_vec_equal(c, b, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(c, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
abort();
}
fmpz_clear(n1);
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
_fmpz_vec_clear(c, len);
_fmpz_vec_clear(d, len);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,88 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
#include "long_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("scalar_submul_si....");
fflush(stdout);
/* Compare with alternative method of computation */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b, *c, *d;
slong len = n_randint(state, 100), x;
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
c = _fmpz_vec_init(len);
d = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_randtest(b, state, len, 200);
_fmpz_vec_set(c, b, len);
x = z_randtest(state);
_fmpz_vec_scalar_submul_si(b, a, len, x);
_fmpz_vec_scalar_mul_si(d, a, len, x);
_fmpz_vec_sub(c, c, d, len);
result = (_fmpz_vec_equal(b, c, len));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("x = %wd\n", x);
_fmpz_vec_print(b, len), flint_printf("\n\n");
_fmpz_vec_print(c, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
_fmpz_vec_clear(c, len);
_fmpz_vec_clear(d, len);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,89 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
#include "long_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("scalar_submul_si_2exp....");
fflush(stdout);
/* Compare with alternative method of computation */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b, *c, *d;
slong len = n_randint(state, 100), x;
mp_bitcnt_t exp;
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
c = _fmpz_vec_init(len);
d = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_randtest(b, state, len, 200);
_fmpz_vec_set(c, b, len);
x = z_randtest(state);
exp = n_randint(state, 200);
_fmpz_vec_scalar_submul_si_2exp(b, a, len, x, exp);
_fmpz_vec_scalar_mul_2exp(d, a, len, exp);
_fmpz_vec_scalar_submul_si(c, d, len, x);
result = (_fmpz_vec_equal(b, c, len));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("x = %wd, exp = %wu\n", x, exp);
_fmpz_vec_print(b, len), flint_printf("\n\n");
_fmpz_vec_print(c, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
_fmpz_vec_clear(c, len);
_fmpz_vec_clear(d, len);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,124 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009, 2010 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("set/equal....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a;
slong len = n_randint(state, 100);
a = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_set(a, a, len);
result = (_fmpz_vec_equal(a, a, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
}
/* Compare copied vectors */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b;
slong len = n_randint(state, 100);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_set(b, a, len);
result = (_fmpz_vec_equal(a, b, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
}
/* Compare unequal vectors */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b;
slong len = n_randint(state, 100) + 1;
slong coeff;
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_set(b, a, len);
coeff = n_randint(state, len);
fmpz_add_ui(b + coeff, b + coeff, 1);
result = (!_fmpz_vec_equal(a, b, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,139 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009, 2010 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("sub....");
fflush(stdout);
/* Check aliasing of a and c */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b, *c;
slong len = n_randint(state, 100);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
c = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_randtest(b, state, len, 200);
_fmpz_vec_sub(c, a, b, len);
_fmpz_vec_sub(a, a, b, len);
result = (_fmpz_vec_equal(a, c, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(c, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
_fmpz_vec_clear(c, len);
}
/* Check aliasing of b and c */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b, *c;
slong len = n_randint(state, 100);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
c = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_randtest(b, state, len, 200);
_fmpz_vec_sub(c, a, b, len);
_fmpz_vec_sub(b, a, b, len);
result = (_fmpz_vec_equal(b, c, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
_fmpz_vec_print(c, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
_fmpz_vec_clear(c, len);
}
/* Check a + b - b = a */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b, *c, *d;
slong len = n_randint(state, 100);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
c = _fmpz_vec_init(len);
d = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_randtest(b, state, len, 200);
_fmpz_vec_add(c, a, b, len);
_fmpz_vec_sub(d, c, b, len);
result = (_fmpz_vec_equal(d, a, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(d, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
_fmpz_vec_clear(c, len);
_fmpz_vec_clear(d, len);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,88 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009, 2010 William Hart
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("sum....");
fflush(stdout);
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b;
fmpz_t x, y, z;
slong len1 = n_randint(state, 100);
slong len2 = n_randint(state, 100);
a = _fmpz_vec_init(len1 + len2);
b = a + len1;
_fmpz_vec_randtest(a, state, len1 + len2, 200);
fmpz_init(x);
fmpz_init(y);
fmpz_init(z);
_fmpz_vec_sum(x, a, len1);
_fmpz_vec_sum(y, b, len2);
fmpz_add(x, x, y);
_fmpz_vec_sum(z, a, len1 + len2);
result = (fmpz_equal(x, z));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len1), flint_printf("\n\n");
_fmpz_vec_print(b, len2), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len1 + len2);
fmpz_clear(x);
fmpz_clear(y);
fmpz_clear(z);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,79 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("swap....");
fflush(stdout);
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a, *b, *c;
slong len = n_randint(state, 100);
a = _fmpz_vec_init(len);
b = _fmpz_vec_init(len);
c = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_randtest(b, state, len, 200);
_fmpz_vec_set(c, b, len);
_fmpz_vec_swap(a, b, len);
result = (_fmpz_vec_equal(a, c, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
_fmpz_vec_print(b, len), flint_printf("\n\n");
_fmpz_vec_print(c, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
_fmpz_vec_clear(b, len);
_fmpz_vec_clear(c, len);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,72 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009, 2010 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("zero....");
fflush(stdout);
/* Check it's zero */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz *a;
slong len = n_randint(state, 100);
a = _fmpz_vec_init(len);
_fmpz_vec_randtest(a, state, len, 200);
_fmpz_vec_zero(a, len);
result = (_fmpz_vec_is_zero(a, len));
if (!result)
{
flint_printf("FAIL:\n");
_fmpz_vec_print(a, len), flint_printf("\n\n");
abort();
}
_fmpz_vec_clear(a, len);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

37
external/flint-2.4.3/fmpz_vec/zero.c vendored Normal file
View File

@@ -0,0 +1,37 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 William Hart
******************************************************************************/
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
void
_fmpz_vec_zero(fmpz * vec, slong len)
{
slong i;
for (i = 0; i < len; i++)
fmpz_zero(vec + i);
}