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

46
external/flint-2.4.3/nmod_vec/add.c vendored Normal file
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 <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "ulong_extras.h"
#include "nmod_vec.h"
void _nmod_vec_add(mp_ptr res, mp_srcptr vec1,
mp_srcptr vec2, slong len, nmod_t mod)
{
slong i;
if (mod.norm)
{
for (i = 0 ; i < len; i++)
res[i] = _nmod_add(vec1[i], vec2[i], mod);
} else
{
for (i = 0 ; i < len; i++)
res[i] = nmod_add(vec1[i], vec2[i], mod);
}
}

View File

@@ -0,0 +1,257 @@
/*=============================================================================
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
*******************************************************************************
mp_ptr _nmod_vec_init(slong len)
Returns a vector of the given length. The entries are not necessarily
zero.
void _nmod_vec_clear(mp_ptr vec)
Frees the memory used by the given vector.
*******************************************************************************
Modular reduction and arithmetic
*******************************************************************************
void nmod_init(nmod_t * mod, mp_limb_t n)
Initialises the given \code{nmod_t} structure for reduction modulo $n$
with a precomputed inverse.
NMOD_RED2(r, a_hi, a_lo, mod)
Macro to set $r$ to $a$ reduced modulo \code{mod.n}, where $a$
consists of two limbs \code{(a_hi, a_lo)}. The \code{mod} parameter
must be a valid \code{nmod_t} structure. It is assumed that \code{a_hi}
is already reduced modulo \code{mod.n}.
NMOD_RED(r, a, mod)
Macro to set $r$ to $a$ reduced modulo \code{mod.n}. The \code{mod}
parameter must be a valid \code{nmod_t} structure.
NMOD2_RED2(r, a_hi, a_lo, mod)
Macro to set $r$ to $a$ reduced modulo \code{mod.n}, where $a$
consists of two limbs \code{(a_hi, a_lo)}. The \code{mod} parameter
must be a valid \code{nmod_t} structure. No assumptions are made
about \code{a_hi}.
NMOD_RED3(r, a_hi, a_me, a_lo, mod)
Macro to set $r$ to $a$ reduced modulo \code{mod.n}, where $a$
consists of three limbs \code{(a_hi, a_me, a_lo)}. The \code{mod}
parameter must be a valid \code{nmod_t} structure. It is assumed
that \code{a_hi} is already reduced modulo \code{mod.n}.
NMOD_ADDMUL(r, a, b, mod)
Macro to set $r$ to $r + ab$ reduced modulo \code{mod.n}. The
\code{mod} parameter must be a valid \code{nmod_t} structure. It is
assumed that $r$, $a$, $b$ are already reduced modulo \code{mod.n}.
mp_limb_t _nmod_add(mp_limb_t a, mp_limb_t b, nmod_t mod)
Returns $a + b$ modulo \code{mod.n}. It is assumed that \code{mod} is
no more than \code{FLINT_BITS - 1} bits. It is assumed that $a$ and $b$
are already reduced modulo \code{mod.n}.
mp_limb_t nmod_add(mp_limb_t a, mp_limb_t b, nmod_t mod)
Returns $a + b$ modulo \code{mod.n}. No assumptions are made about
\code{mod.n}. It is assumed that $a$ and $b$ are already reduced
modulo \code{mod.n}.
mp_limb_t _nmod_sub(mp_limb_t a, mp_limb_t b, nmod_t mod)
Returns $a - b$ modulo \code{mod.n}. It is assumed that \code{mod}
is no more than \code{FLINT_BITS - 1} bits. It is assumed that
$a$ and $b$ are already reduced modulo \code{mod.n}.
mp_limb_t nmod_sub(mp_limb_t a, mp_limb_t b, nmod_t mod)
Returns $a - b$ modulo \code{mod.n}. No assumptions are made about
\code{mod.n}. It is assumed that $a$ and $b$ are already reduced
modulo \code{mod.n}.
mp_limb_t nmod_neg(mp_limb_t a, nmod_t mod)
Returns $-a$ modulo \code{mod.n}. It is assumed that $a$ is already
reduced modulo \code{mod.n}, but no assumptions are made about the
latter.
mp_limb_t nmod_mul(mp_limb_t a, mp_limb_t b, nmod_t mod)
Returns $ab$ modulo \code{mod.n}. No assumptions are made about
\code{mod.n}. It is assumed that $a$ and $b$ are already reduced
modulo \code{mod.n}.
mp_limb_t nmod_inv(mp_limb_t a, nmod_t mod)
Returns $a^{-1}$ modulo \code{mod.n}. The inverse is assumed to exist.
mp_limb_t nmod_div(mp_limb_t a, mp_limb_t b, nmod_t mod)
Returns $a^{-1}$ modulo \code{mod.n}. The inverse of $b$ is assumed to
exist. It is assumed that $a$ is already reduced modulo \code{mod.n}.
mp_limb_t nmod_pow_ui(mp_limb_t a, ulong e, nmod_t mod)
Returns $a^e$ modulo \code{mod.n}. No assumptions are made about
\code{mod.n}. It is assumed that $a$ is already reduced
modulo \code{mod.n}.
*******************************************************************************
Random functions
*******************************************************************************
void _nmod_vec_randtest(mp_ptr vec, flint_rand_t state, slong len, nmod_t mod)
Sets \code{vec} to a random vector of the given length with entries
reduced modulo \code{mod.n}.
*******************************************************************************
Basic manipulation and comparison
*******************************************************************************
void _nmod_vec_set(mp_ptr res, mp_srcptr vec, slong len)
Copies \code{len} entries from the vector \code{vec} to \code{res}.
void _nmod_vec_zero(mp_ptr vec, slong len)
Zeros the given vector of the given length.
void _nmod_vec_swap(mp_ptr a, mp_ptr b, slong length)
Swaps the vectors \code{a} and \code{b} of length $n$ by actually
swapping the entries.
void _nmod_vec_reduce(mp_ptr res, mp_srcptr vec, slong len, nmod_t mod)
Reduces the entries of \code{(vec, len)} modulo \code{mod.n} and set
\code{res} to the result.
mp_bitcnt_t _nmod_vec_max_bits(mp_srcptr vec, slong len)
Returns the maximum number of bits of any entry in the vector.
int _nmod_vec_equal(mp_srcptr vec, mp_srcptr vec2, slong len)
Returns~$1$ if \code{(vec, len)} is equal to \code{(vec2, len)},
otherwise returns~$0$.
*******************************************************************************
Arithmetic operations
*******************************************************************************
void _nmod_vec_add(mp_ptr res, mp_srcptr vec1,
mp_srcptr vec2, slong len, nmod_t mod)
Sets \code{(res, len)} to the sum of \code{(vec1, len)}
and \code{(vec2, len)}.
void _nmod_vec_sub(mp_ptr res, mp_srcptr vec1,
mp_srcptr vec2, slong len, nmod_t mod)
Sets \code{(res, len)} to the difference of \code{(vec1, len)}
and \code{(vec2, len)}.
void _nmod_vec_neg(mp_ptr res, mp_srcptr vec, slong len, nmod_t mod)
Sets \code{(res, len)} to the negation of \code{(vec, len)}.
void _nmod_vec_scalar_mul_nmod(mp_ptr res, mp_srcptr vec,
slong len, mp_limb_t c, nmod_t mod)
Sets \code{(res, len)} to \code{(vec, len)} multiplied by $c$.
void _nmod_vec_scalar_addmul_nmod(mp_ptr res, mp_srcptr vec,
slong len, mp_limb_t c, nmod_t mod)
Adds \code{(vec, len)} times $c$ to the vector \code{(res, len)}.
*******************************************************************************
Dot products
*******************************************************************************
int _nmod_vec_dot_bound_limbs(slong len, nmod_t mod)
Returns the number of limbs (0, 1, 2 or 3) needed to represent the
unreduced dot product of two vectors of length \code{len} having entries
modulo \code{mod.n}, assuming that \code{len} is nonnegative and that
\code{mod.n} is nonzero. The computed bound is tight. In other words,
this function returns the precise limb size of \code{len} times
\code{(mod.n - 1) ^ 2}.
macro NMOD_VEC_DOT(res, i, len, expr1, expr2, mod, nlimbs)
Effectively performs the computation
\begin{verbatim}
res = 0;
for (i = 0; i < len; i++)
res += (expr1) * (expr2);
\end{verbatim}
but with the arithmetic performed modulo \code{mod}.
The \code{nlimbs} parameter should be 0, 1, 2 or 3, specifying the
number of limbs needed to represent the unreduced result.
mp_limb_t _nmod_vec_dot(mp_srcptr vec1, mp_srcptr vec2,
slong len, nmod_t mod, int nlimbs)
Returns the dot product of (\code{vec1}, \code{len}) and
(\code{vec2}, \code{len}). The \code{nlimbs} parameter should be
0, 1, 2 or 3, specifying the number of limbs needed to represent the
unreduced result.
mp_limb_t
_nmod_vec_dot_ptr(mp_srcptr vec1, const mp_ptr * vec2, slong offset, slong len,
nmod_t mod, int nlimbs)
Returns the dot product of (\code{vec1}, \code{len}) and the values at
\code{vec2[i][offset]}. The \code{nlimbs} parameter should be
0, 1, 2 or 3, specifying the number of limbs needed to represent the
unreduced result.

39
external/flint-2.4.3/nmod_vec/dot.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) 2011 Fredrik Johansson
******************************************************************************/
#include <gmp.h>
#include <stdlib.h>
#include "flint.h"
#include "ulong_extras.h"
#include "nmod_vec.h"
mp_limb_t
_nmod_vec_dot(mp_srcptr vec1, mp_srcptr vec2, slong len, nmod_t mod, int nlimbs)
{
mp_limb_t res;
slong i;
NMOD_VEC_DOT(res, i, len, vec1[i], vec2[i], mod, nlimbs);
return res;
}

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) 2011 Fredrik Johansson
******************************************************************************/
#include <gmp.h>
#include <stdlib.h>
#include "flint.h"
#include "ulong_extras.h"
#include "nmod_vec.h"
int
_nmod_vec_dot_bound_limbs(slong len, nmod_t mod)
{
mp_limb_t t2, t1, t0, u1, u0;
umul_ppmm(t1, t0, mod.n - 1, mod.n - 1);
umul_ppmm(t2, t1, t1, len);
umul_ppmm(u1, u0, t0, len);
add_sssaaaaaa(t2, t1, t0, t2, t1, UWORD(0), UWORD(0), u1, u0);
if (t2 != 0) return 3;
if (t1 != 0) return 2;
return (t0 != 0);
}

40
external/flint-2.4.3/nmod_vec/dot_ptr.c vendored Normal file
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 <stdlib.h>
#include "flint.h"
#include "ulong_extras.h"
#include "nmod_vec.h"
mp_limb_t
_nmod_vec_dot_ptr(mp_srcptr vec1, const mp_ptr * vec2, slong offset,
slong len, nmod_t mod, int nlimbs)
{
mp_limb_t res;
slong i;
NMOD_VEC_DOT(res, i, len, vec1[i], vec2[i][offset], mod, nlimbs);
return res;
}

View File

@@ -0,0 +1,48 @@
/*=============================================================================
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 "nmod_vec.h"
mp_bitcnt_t _nmod_vec_max_bits(mp_srcptr vec, slong len)
{
mp_bitcnt_t bits = 0;
mp_limb_t mask = ~(mp_limb_t) 0;
slong i;
for (i = 0; i < len; i++)
{
if (vec[i] & mask)
{
bits = FLINT_BIT_COUNT(vec[i]);
if (bits == FLINT_BITS) break;
else mask = ~(mp_limb_t) 0 - ((UWORD(1) << bits) - UWORD(1));
}
}
return bits;
}

37
external/flint-2.4.3/nmod_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 <stdlib.h>
#include "flint.h"
#include "ulong_extras.h"
#include "nmod_vec.h"
void _nmod_vec_neg(mp_ptr res, mp_srcptr vec, slong len, nmod_t mod)
{
slong i;
for (i = 0 ; i < len; i++)
res[i] = nmod_neg(vec[i], mod);
}

View File

@@ -0,0 +1,128 @@
/*=============================================================================
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 2010 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "profiler.h"
#include "flint.h"
#include "ulong_extras.h"
#include "nmod_vec.h"
typedef struct
{
mp_bitcnt_t bits;
int type;
} info_t;
void sample(void * arg, ulong count)
{
mp_limb_t n, r = 0;
nmod_t mod;
info_t * info = (info_t *) arg;
mp_bitcnt_t bits = info->bits;
int type = info->type;
mp_size_t j;
slong i;
FLINT_TEST_INIT(state);
n = n_randbits(state, bits);
if (n == UWORD(0)) n++;
nmod_init(&mod, n);
mp_ptr vec1 = _nmod_vec_init(1000);
mp_ptr vec2 = _nmod_vec_init(1000);
mp_ptr res = _nmod_vec_init(1000);
for (j = 0; j < 1000; j++)
vec1[j] = n_randint(state, n);
for (j = 0; j < 1000; j++)
vec2[j] = n_randint(state, n);
switch (type)
{
case 1:
prof_start();
for (i = 0; i < count; i++)
{
_nmod_vec_add(res, vec1, vec2, 1000, mod);
}
prof_stop();
break;
case 2:
prof_start();
for (i = 0; i < count; i++)
{
_nmod_vec_sub(res, vec1, vec2, 1000, mod);
}
prof_stop();
break;
case 3:
prof_start();
for (i = 0; i < count; i++)
{
_nmod_vec_neg(res, vec1, 1000, mod);
}
prof_stop();
break;
}
flint_randclear(state);
_nmod_vec_clear(vec1);
_nmod_vec_clear(vec2);
}
int main(void)
{
double min1, min2, min3, max;
info_t info;
mp_bitcnt_t i;
for (i = 2; i <= FLINT_BITS; i++)
{
info.bits = i;
info.type = 1;
prof_repeat(&min1, &max, sample, (void *) &info);
info.type = 2;
prof_repeat(&min2, &max, sample, (void *) &info);
info.type = 3;
prof_repeat(&min3, &max, sample, (void *) &info);
flint_printf("bits %wd, add = %.1lf c/l, sub = %.1lf c/l, neg = %.1lf c/l\n",
i, (min1/(double)FLINT_CLOCK_SCALE_FACTOR)/1000,
(min2/(double)FLINT_CLOCK_SCALE_FACTOR)/1000,
(min3/(double)FLINT_CLOCK_SCALE_FACTOR)/1000
);
}
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 2010 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "profiler.h"
#include "flint.h"
#include "ulong_extras.h"
#include "nmod_vec.h"
typedef struct
{
mp_bitcnt_t bits;
} info_t;
void sample(void * arg, ulong count)
{
mp_limb_t n;
nmod_t mod;
info_t * info = (info_t *) arg;
mp_bitcnt_t bits = info->bits;
mp_ptr vec = _nmod_vec_init(1000);
mp_ptr vec2 = _nmod_vec_init(1000);
mp_size_t j;
slong i;
FLINT_TEST_INIT(state);
for (j = 0; j < 1000; j++)
vec[j] = n_randlimb(state);
prof_start();
for (i = 0; i < count; i++)
{
n = n_randbits(state, bits);
if (n == UWORD(0)) n++;
nmod_init(&mod, n);
_nmod_vec_reduce(vec2, vec, 1000, mod);
}
prof_stop();
flint_randclear(state);
_nmod_vec_clear(vec);
_nmod_vec_clear(vec2);
}
int main(void)
{
double min, max;
info_t info;
mp_bitcnt_t i;
for (i = 2; i <= FLINT_BITS; i++)
{
info.bits = i;
prof_repeat(&min, &max, sample, (void *) &info);
flint_printf("bits %wd, c/l = %.1lf\n",
i, (min/(double)FLINT_CLOCK_SCALE_FACTOR)/1000
);
}
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 2010 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "profiler.h"
#include "flint.h"
#include "ulong_extras.h"
#include "nmod_vec.h"
typedef struct
{
mp_bitcnt_t bits;
slong length;
} info_t;
void sample(void * arg, ulong count)
{
mp_limb_t n, c;
nmod_t mod;
info_t * info = (info_t *) arg;
mp_bitcnt_t bits = info->bits;
slong length = info->length;
slong i, j;
mp_ptr vec = _nmod_vec_init(length);
mp_ptr vec2 = _nmod_vec_init(length);
FLINT_TEST_INIT(state);
for (i = 0; i < count; i++)
{
n = n_randbits(state, bits);
if (n == UWORD(0)) n++;
c = n_randint(state, n);
for (j = 0; j < length; j++)
vec[j] = n_randint(state, n);
nmod_init(&mod, n);
prof_start();
for (j = 0; j < 30; j++)
_nmod_vec_scalar_mul_nmod(vec2, vec, length, c, mod);
prof_stop();
}
flint_randclear(state);
_nmod_vec_clear(vec);
_nmod_vec_clear(vec2);
}
int main(void)
{
double min1, min2, max;
info_t info;
mp_bitcnt_t i;
for (i = 2; i <= FLINT_BITS; i++)
{
info.bits = i;
info.length = 1024;
prof_repeat(&min1, &max, sample, (void *) &info);
info.length = 65536;
prof_repeat(&min2, &max, sample, (void *) &info);
flint_printf("bits %wd, length 128 %.1lf c/l, length 65536 %.1lf c/l\n",
i, (min1/(double)FLINT_CLOCK_SCALE_FACTOR)/(1024*30),
(min2/(double)FLINT_CLOCK_SCALE_FACTOR)/(65536*30)
);
}
return 0;
}

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
******************************************************************************/
#include <gmp.h>
#include <stdlib.h>
#include "flint.h"
#include "ulong_extras.h"
#include "nmod_vec.h"
void _nmod_vec_randtest(mp_ptr vec, flint_rand_t state, slong len, nmod_t mod)
{
slong i, sparseness;
if (n_randint(state, 2))
{
for (i = 0; i < len; i++)
vec[i] = n_randtest(state) % mod.n;
}
else
{
sparseness = 1 + n_randint(state, FLINT_MAX(2, len));
for (i = 0; i < len; i++)
{
if (n_randint(state, sparseness))
vec[i] = 0;
else
vec[i] = n_randtest(state) % mod.n;
}
}
}

37
external/flint-2.4.3/nmod_vec/reduce.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 <stdlib.h>
#include "flint.h"
#include "ulong_extras.h"
#include "nmod_vec.h"
void _nmod_vec_reduce(mp_ptr res, mp_srcptr vec, slong len, nmod_t mod)
{
slong i;
for (i = 0 ; i < len; i++)
NMOD_RED(res[i], vec[i], mod);
}

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 <stdlib.h>
#include "flint.h"
#include "ulong_extras.h"
#include "nmod_vec.h"
void _nmod_vec_scalar_addmul_nmod(mp_ptr res, mp_srcptr vec,
slong len, mp_limb_t c, nmod_t mod)
{
if (mod.norm >= FLINT_BITS/2) /* addmul will fit in a limb */
{
mpn_addmul_1(res, vec, len, c);
_nmod_vec_reduce(res, res, len, mod);
}
else /* products may take two limbs */
{
slong i;
for (i = 0; i < len; i++)
NMOD_ADDMUL(res[i], vec[i], c, mod); /* hi already reduced mod n */
}
}

View File

@@ -0,0 +1,49 @@
/*=============================================================================
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 <stdlib.h>
#include "flint.h"
#include "ulong_extras.h"
#include "nmod_vec.h"
void _nmod_vec_scalar_mul_nmod(mp_ptr res, mp_srcptr vec,
slong len, mp_limb_t c, nmod_t mod)
{
if (mod.norm >= FLINT_BITS/2) /* products will fit in a limb */
{
mpn_mul_1(res, vec, len, c);
_nmod_vec_reduce(res, res, len, mod);
} else /* products may take two limbs */
{
slong i;
for (i = 0; i < len; i++)
{
mp_limb_t hi, lo;
umul_ppmm(hi, lo, vec[i], c);
NMOD_RED2(res[i], hi, lo, mod); /* hi already reduced mod n */
}
}
}

45
external/flint-2.4.3/nmod_vec/sub.c vendored Normal file
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 <stdlib.h>
#include "flint.h"
#include "ulong_extras.h"
#include "nmod_vec.h"
void _nmod_vec_sub(mp_ptr res, mp_srcptr vec1,
mp_srcptr vec2, slong len, nmod_t mod)
{
slong i;
if (mod.norm)
{
for (i = 0 ; i < len; i++)
res[i] = _nmod_sub(vec1[i], vec2[i], mod);
} else
{
for (i = 0 ; i < len; i++)
res[i] = nmod_sub(vec1[i], vec2[i], mod);
}
}

View File

@@ -0,0 +1,112 @@
/*=============================================================================
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 "nmod_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("add/sub/neg....");
fflush(stdout);
/* Check (a + b) - b == a */
for (i = 0; i < 10000; i++)
{
slong len = n_randint(state, 100) + 1;
nmod_t mod;
mp_limb_t n = n_randtest_not_zero(state);
mp_ptr vec = _nmod_vec_init(len);
mp_ptr vec2 = _nmod_vec_init(len);
mp_ptr vec3 = _nmod_vec_init(len);
nmod_init(&mod, n);
_nmod_vec_randtest(vec, state, len, mod);
_nmod_vec_randtest(vec2, state, len, mod);
_nmod_vec_add(vec3, vec, vec2, len, mod);
_nmod_vec_sub(vec3, vec3, vec2, len, mod);
result = _nmod_vec_equal(vec, vec3, len);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("len = %wd, n = %wd\n", len, n);
abort();
}
_nmod_vec_clear(vec);
_nmod_vec_clear(vec2);
_nmod_vec_clear(vec3);
}
/* Check (a + -b) == a - b */
for (i = 0; i < 10000; i++)
{
slong len = n_randint(state, 100) + 1;
mp_limb_t n = n_randtest_not_zero(state);
nmod_t mod;
mp_ptr vec = _nmod_vec_init(len);
mp_ptr vec2 = _nmod_vec_init(len);
mp_ptr vec3 = _nmod_vec_init(len);
nmod_init(&mod, n);
_nmod_vec_randtest(vec, state, len, mod);
_nmod_vec_randtest(vec2, state, len, mod);
_nmod_vec_sub(vec3, vec, vec2, len, mod);
_nmod_vec_neg(vec2, vec2, len, mod);
_nmod_vec_add(vec, vec, vec2, len, mod);
result = _nmod_vec_equal(vec, vec3, len);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("len = %wd, n = %wd\n", len, n);
abort();
}
_nmod_vec_clear(vec);
_nmod_vec_clear(vec2);
_nmod_vec_clear(vec3);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,99 @@
/*=============================================================================
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 <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i;
FLINT_TEST_INIT(state);
flint_printf("dot....");
fflush(stdout);
for (i = 0; i < 10000; i++)
{
slong len;
nmod_t mod;
mp_limb_t m, res;
mp_ptr x, y;
int limbs1;
mpz_t s, t;
slong j;
len = n_randint(state, 1000) + 1;
m = n_randtest_not_zero(state);
nmod_init(&mod, m);
x = _nmod_vec_init(len);
y = _nmod_vec_init(len);
_nmod_vec_randtest(x, state, len, mod);
_nmod_vec_randtest(y, state, len, mod);
limbs1 = _nmod_vec_dot_bound_limbs(len, mod);
res = _nmod_vec_dot(x, y, len, mod, limbs1);
mpz_init(s);
mpz_init(t);
for (j = 0; j < len; j++)
{
flint_mpz_set_ui(t, x[j]);
flint_mpz_addmul_ui(s, t, y[j]);
}
flint_mpz_mod_ui(s, s, m);
if (flint_mpz_get_ui(s) != res)
{
flint_printf("FAIL:\n");
flint_printf("m = %wu\n", m);
flint_printf("len = %wd\n", len);
flint_printf("limbs1 = %d\n", limbs1);
abort();
}
mpz_clear(s);
mpz_clear(t);
_nmod_vec_clear(x);
_nmod_vec_clear(y);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

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) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i;
FLINT_TEST_INIT(state);
flint_printf("dot_bound_limbs....");
fflush(stdout);
for (i = 0; i < 1000000; i++)
{
slong len;
nmod_t mod;
mp_limb_t m;
int limbs1, limbs2;
mpz_t t;
len = n_randint(state, 10000) + 1;
m = n_randtest_not_zero(state);
nmod_init(&mod, m);
limbs1 = _nmod_vec_dot_bound_limbs(len, mod);
mpz_init2(t, 4*FLINT_BITS);
flint_mpz_set_ui(t, m-1);
mpz_mul(t, t, t);
flint_mpz_mul_ui(t, t, len);
limbs2 = mpz_size(t);
if (limbs1 != limbs2)
{
flint_printf("FAIL:\n");
flint_printf("m = %wu\n", m);
flint_printf("len = %wd\n", len);
flint_printf("limbs1 = %d\n", limbs1);
flint_printf("limbs2 = %d\n", limbs2);
gmp_printf("bound: %Zd\n", t);
abort();
}
mpz_clear(t);
}
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) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i;
FLINT_TEST_INIT(state);
flint_printf("dot_ptr....");
fflush(stdout);
for (i = 0; i < 10000; i++)
{
slong len;
nmod_t mod;
mp_limb_t m, res, res2;
mp_ptr x, y;
mp_ptr * z;
int limbs1;
slong j, offset;
len = n_randint(state, 1000) + 1;
m = n_randtest_not_zero(state);
offset = n_randint(state, 10);
nmod_init(&mod, m);
x = _nmod_vec_init(len);
y = _nmod_vec_init(len);
z = flint_malloc(sizeof(mp_ptr) * len);
_nmod_vec_randtest(x, state, len, mod);
_nmod_vec_randtest(y, state, len, mod);
for (j = 0; j < len; j++)
z[j] = &y[j] + offset;
limbs1 = _nmod_vec_dot_bound_limbs(len, mod);
res = _nmod_vec_dot_ptr(x, z, -offset, len, mod, limbs1);
res2 = _nmod_vec_dot(x, y, len, mod, limbs1);
if (res != res2)
{
flint_printf("FAIL:\n");
flint_printf("m = %wu\n", m);
flint_printf("len = %wd\n", len);
flint_printf("limbs1 = %d\n", limbs1);
abort();
}
_nmod_vec_clear(x);
_nmod_vec_clear(y);
flint_free(z);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,263 @@
/*=============================================================================
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) 2013 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i;
FLINT_TEST_INIT(state);
flint_printf("nmod....");
fflush(stdout);
/* nmod_add */
for (i = 0; i < 10000; i++)
{
nmod_t mod;
mp_limb_t m, a, b, c;
mpz_t x, y, z;
m = n_randtest_not_zero(state);
nmod_init(&mod, m);
a = n_randlimb(state) % m;
b = n_randlimb(state) % m;
c = nmod_add(a, b, mod);
mpz_init(x);
mpz_init(y);
mpz_init(z);
flint_mpz_set_ui(x, a);
flint_mpz_set_ui(y, b);
mpz_add(z, x, y);
flint_mpz_mod_ui(z, z, m);
if (flint_mpz_cmp_ui(z, c) != 0)
{
flint_printf("FAIL (add):\n");
flint_printf("m = %wu\n", m);
abort();
}
mpz_clear(x);
mpz_clear(y);
mpz_clear(z);
}
/* nmod_sub */
for (i = 0; i < 10000; i++)
{
nmod_t mod;
mp_limb_t m, a, b, c;
mpz_t x, y, z;
m = n_randtest_not_zero(state);
nmod_init(&mod, m);
a = n_randlimb(state) % m;
b = n_randlimb(state) % m;
c = nmod_sub(a, b, mod);
mpz_init(x);
mpz_init(y);
mpz_init(z);
flint_mpz_set_ui(x, a);
flint_mpz_set_ui(y, b);
mpz_sub(z, x, y);
flint_mpz_mod_ui(z, z, m);
if (flint_mpz_cmp_ui(z, c) != 0)
{
flint_printf("FAIL (sub):\n");
flint_printf("m = %wu\n", m);
abort();
}
mpz_clear(x);
mpz_clear(y);
mpz_clear(z);
}
/* nmod_mul */
for (i = 0; i < 10000; i++)
{
nmod_t mod;
mp_limb_t m, a, b, c;
mpz_t x, y, z;
m = n_randtest_not_zero(state);
nmod_init(&mod, m);
a = n_randlimb(state) % m;
b = n_randlimb(state) % m;
c = nmod_mul(a, b, mod);
mpz_init(x);
mpz_init(y);
mpz_init(z);
flint_mpz_set_ui(x, a);
flint_mpz_set_ui(y, b);
mpz_mul(z, x, y);
flint_mpz_mod_ui(z, z, m);
if (flint_mpz_cmp_ui(z, c) != 0)
{
flint_printf("FAIL (mul):\n");
flint_printf("m = %wu\n", m);
abort();
}
mpz_clear(x);
mpz_clear(y);
mpz_clear(z);
}
/* nmod_div */
for (i = 0; i < 10000; i++)
{
nmod_t mod;
mp_limb_t m, a, b, c;
mpz_t x, y, z;
m = n_randtest_prime(state, 0);
nmod_init(&mod, m);
a = n_randlimb(state) % m;
do { b = n_randlimb(state) % m; } while (b == 0);
c = nmod_div(a, b, mod);
mpz_init(x);
mpz_init(y);
mpz_init(z);
flint_mpz_set_ui(x, a);
flint_mpz_set_ui(y, b);
flint_mpz_set_ui(z, m);
mpz_invert(z, y, z);
mpz_mul(z, x, z);
flint_mpz_mod_ui(z, z, m);
if (flint_mpz_cmp_ui(z, c) != 0)
{
flint_printf("FAIL (div):\n");
flint_printf("m = %wu\n", m);
abort();
}
mpz_clear(x);
mpz_clear(y);
mpz_clear(z);
}
/* nmod_inv */
for (i = 0; i < 10000; i++)
{
nmod_t mod;
mp_limb_t m, b, c;
mpz_t y, z;
m = n_randtest_prime(state, 0);
nmod_init(&mod, m);
do { b = n_randlimb(state) % m; } while (b == 0);
c = nmod_inv(b, mod);
mpz_init(y);
mpz_init(z);
flint_mpz_set_ui(y, b);
flint_mpz_set_ui(z, m);
mpz_invert(z, y, z);
if (flint_mpz_cmp_ui(z, c) != 0)
{
flint_printf("FAIL (div):\n");
flint_printf("m = %wu\n", m);
abort();
}
mpz_clear(y);
mpz_clear(z);
}
/* nmod_pow_ui */
for (i = 0; i < 10000; i++)
{
nmod_t mod;
mp_limb_t m, b, c;
mpz_t y, z;
ulong exp;
m = n_randtest_prime(state, 0);
exp = n_randtest(state);
nmod_init(&mod, m);
b = n_randlimb(state) % m;
c = nmod_pow_ui(b, exp, mod);
mpz_init(y);
mpz_init(z);
flint_mpz_set_ui(y, b);
flint_mpz_set_ui(z, m);
flint_mpz_powm_ui(z, y, exp, z);
if (flint_mpz_cmp_ui(z, c) != 0)
{
flint_printf("FAIL (pow):\n");
flint_printf("m = %wu\n", m);
abort();
}
mpz_clear(y);
mpz_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
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("reduce....");
fflush(stdout);
for (i = 0; i < 10000; i++)
{
slong j, len = n_randint(state, 100) + 1;
mp_ptr vec = _nmod_vec_init(len);
mp_ptr vec2 = _nmod_vec_init(len);
mp_limb_t n = n_randtest_not_zero(state);
nmod_t mod;
nmod_init(&mod, n);
for (j = 0; j < len; j++)
{
vec[j] = n_randtest(state);
vec2[j] = vec[j];
}
_nmod_vec_reduce(vec, vec, len, mod);
for (j = 0; j < len; j++)
vec2[j] = n_mod2_preinv(vec2[j], mod.n, mod.ninv);
result = _nmod_vec_equal(vec, vec2, len);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("len = %wd, n = %wd\n", len, n);
abort();
}
_nmod_vec_clear(vec);
_nmod_vec_clear(vec2);
}
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
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("scalar_addmul_nmod....");
fflush(stdout);
/* Check (a + b*c) == a + (b*c) */
for (i = 0; i < 10000; i++)
{
slong len = n_randint(state, 100) + 1;
mp_limb_t n = n_randtest_not_zero(state);
mp_limb_t c = n_randint(state, n);
nmod_t mod;
mp_ptr vec = _nmod_vec_init(len);
mp_ptr vec2 = _nmod_vec_init(len);
mp_ptr vec3 = _nmod_vec_init(len);
nmod_init(&mod, n);
_nmod_vec_randtest(vec, state, len, mod);
_nmod_vec_randtest(vec2, state, len, mod);
flint_mpn_copyi(vec3, vec2, len);
_nmod_vec_scalar_mul_nmod(vec3, vec, len, c, mod);
_nmod_vec_add(vec3, vec3, vec2, len, mod);
_nmod_vec_scalar_addmul_nmod(vec2, vec, len, c, mod);
result = _nmod_vec_equal(vec2, vec3, len);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("len = %wd, n = %wd\n", len, n);
abort();
}
_nmod_vec_clear(vec);
_nmod_vec_clear(vec2);
_nmod_vec_clear(vec3);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

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) 2009 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("scalar_mul_nmod....");
fflush(stdout);
/* Check (a + b)*c == a*c + b*c */
for (i = 0; i < 10000; i++)
{
slong len = n_randint(state, 100) + 1;
mp_limb_t n = n_randtest_not_zero(state);
mp_limb_t c = n_randint(state, n);
nmod_t mod;
mp_ptr vec = _nmod_vec_init(len);
mp_ptr vec2 = _nmod_vec_init(len);
mp_ptr vec3 = _nmod_vec_init(len);
nmod_init(&mod, n);
_nmod_vec_randtest(vec, state, len, mod);
_nmod_vec_randtest(vec2, state, len, mod);
_nmod_vec_add(vec3, vec, vec2, len, mod);
_nmod_vec_scalar_mul_nmod(vec3, vec3, len, c, mod);
_nmod_vec_scalar_mul_nmod(vec, vec, len, c, mod);
_nmod_vec_scalar_mul_nmod(vec2, vec2, len, c, mod);
_nmod_vec_add(vec, vec, vec2, len, mod);
result = _nmod_vec_equal(vec, vec3, len);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("len = %wd, n = %wd\n", len, n);
abort();
}
_nmod_vec_clear(vec);
_nmod_vec_clear(vec2);
_nmod_vec_clear(vec3);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}