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

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) 2010 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.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++)
{
nmod_poly_t a, b, c;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(a, state, n_randint(state, 100));
nmod_poly_randtest(b, state, n_randint(state, 100));
nmod_poly_add(c, a, b);
nmod_poly_add(a, a, b);
result = (nmod_poly_equal(a, c));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(c), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Check aliasing of b and c */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(a, state, n_randint(state, 100));
nmod_poly_randtest(b, state, n_randint(state, 100));
nmod_poly_add(c, a, b);
nmod_poly_add(b, a, b);
result = (nmod_poly_equal(b, c));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(c), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,126 @@
/*=============================================================================
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) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result = 1;
FLINT_TEST_INIT(state);
flint_printf("asin_series....");
fflush(stdout);
/* Check asin(A) = atan(A/sqrt(1-A^2)) */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t A, B, asinA, atanB;
slong n;
mp_limb_t mod;
mod = n_randtest_prime(state, 0);
n = 1 + n_randtest(state) % 100;
n = FLINT_MIN(n, mod);
nmod_poly_init(A, mod);
nmod_poly_init(B, mod);
nmod_poly_init(asinA, mod);
nmod_poly_init(atanB, mod);
nmod_poly_randtest(A, state, n_randint(state, 100));
nmod_poly_set_coeff_ui(A, 0, UWORD(0));
nmod_poly_mullow(B, A, A, n);
nmod_poly_neg(B, B);
nmod_poly_set_coeff_ui(B, 0, UWORD(1));
nmod_poly_invsqrt_series(B, B, n);
nmod_poly_mullow(B, A, B, n);
nmod_poly_asin_series(asinA, A, n);
nmod_poly_atan_series(atanB, B, n);
result = nmod_poly_equal(asinA, atanB);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("n = %wd, mod = %wu\n", n, mod);
flint_printf("A: "); nmod_poly_print(A), flint_printf("\n\n");
flint_printf("B: "); nmod_poly_print(B), flint_printf("\n\n");
flint_printf("asin(A): "); nmod_poly_print(asinA), flint_printf("\n\n");
flint_printf("atan(B): "); nmod_poly_print(atanB), flint_printf("\n\n");
abort();
}
nmod_poly_clear(A);
nmod_poly_clear(B);
nmod_poly_clear(asinA);
nmod_poly_clear(atanB);
}
/* Check aliasing */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t A, B;
slong n;
mp_limb_t mod;
mod = n_randtest_prime(state, 0);
n = n_randtest(state) % 50;
n = FLINT_MIN(n, mod);
nmod_poly_init(A, mod);
nmod_poly_init(B, mod);
nmod_poly_randtest(A, state, n_randint(state, 50));
nmod_poly_set_coeff_ui(A, 0, UWORD(0));
nmod_poly_asin_series(B, A, n);
nmod_poly_asin_series(A, A, n);
result = nmod_poly_equal(A, B);
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(A), flint_printf("\n\n");
nmod_poly_print(B), flint_printf("\n\n");
abort();
}
nmod_poly_clear(A);
nmod_poly_clear(B);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,125 @@
/*=============================================================================
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) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result = 1;
FLINT_TEST_INIT(state);
flint_printf("asinh_series....");
fflush(stdout);
/* Check asinh(A) = atanh(A/sqrt(1+A^2)) */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t A, B, asinhA, atanhB;
slong n;
mp_limb_t mod;
mod = n_randtest_prime(state, 0);
n = 1 + n_randtest(state) % 100;
n = FLINT_MIN(n, mod);
nmod_poly_init(A, mod);
nmod_poly_init(B, mod);
nmod_poly_init(asinhA, mod);
nmod_poly_init(atanhB, mod);
nmod_poly_randtest(A, state, n_randint(state, 100));
nmod_poly_set_coeff_ui(A, 0, UWORD(0));
nmod_poly_mullow(B, A, A, n);
nmod_poly_set_coeff_ui(B, 0, UWORD(1));
nmod_poly_invsqrt_series(B, B, n);
nmod_poly_mullow(B, A, B, n);
nmod_poly_asinh_series(asinhA, A, n);
nmod_poly_atanh_series(atanhB, B, n);
result = nmod_poly_equal(asinhA, atanhB);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("n = %wd, mod = %wu\n", n, mod);
flint_printf("A: "); nmod_poly_print(A), flint_printf("\n\n");
flint_printf("B: "); nmod_poly_print(B), flint_printf("\n\n");
flint_printf("asinh(A): "); nmod_poly_print(asinhA), flint_printf("\n\n");
flint_printf("atanh(B): "); nmod_poly_print(atanhB), flint_printf("\n\n");
abort();
}
nmod_poly_clear(A);
nmod_poly_clear(B);
nmod_poly_clear(asinhA);
nmod_poly_clear(atanhB);
}
/* Check aliasing */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t A, B;
slong n;
mp_limb_t mod;
mod = n_randtest_prime(state, 0);
n = n_randtest(state) % 50;
n = FLINT_MIN(n, mod);
nmod_poly_init(A, mod);
nmod_poly_init(B, mod);
nmod_poly_randtest(A, state, n_randint(state, 50));
nmod_poly_set_coeff_ui(A, 0, UWORD(0));
nmod_poly_asinh_series(B, A, n);
nmod_poly_asinh_series(A, A, n);
result = nmod_poly_equal(A, B);
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(A), flint_printf("\n\n");
nmod_poly_print(B), flint_printf("\n\n");
abort();
}
nmod_poly_clear(A);
nmod_poly_clear(B);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,127 @@
/*=============================================================================
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) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result = 1;
FLINT_TEST_INIT(state);
flint_printf("atan_series....");
fflush(stdout);
/* Check 2*atan(A) = atan(2*A/(1-A^2)) */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t A, B, atanA, atanB;
slong n;
mp_limb_t mod;
mod = n_randtest_prime(state, 0);
n = 1 + n_randtest(state) % 100;
n = FLINT_MIN(n, mod);
nmod_poly_init(A, mod);
nmod_poly_init(B, mod);
nmod_poly_init(atanA, mod);
nmod_poly_init(atanB, mod);
nmod_poly_randtest(A, state, n_randint(state, 100));
nmod_poly_set_coeff_ui(A, 0, UWORD(0));
nmod_poly_mullow(B, A, A, n);
nmod_poly_neg(B, B);
nmod_poly_set_coeff_ui(B, 0, UWORD(1));
nmod_poly_div_series(B, A, B, n);
nmod_poly_add(B, B, B);
nmod_poly_atan_series(atanA, A, n);
nmod_poly_atan_series(atanB, B, n);
nmod_poly_add(atanA, atanA, atanA);
result = nmod_poly_equal(atanA, atanB);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("n = %wd, mod = %wu\n", n, mod);
flint_printf("A: "); nmod_poly_print(A), flint_printf("\n\n");
flint_printf("B: "); nmod_poly_print(B), flint_printf("\n\n");
flint_printf("2*atan(A): "); nmod_poly_print(atanA), flint_printf("\n\n");
flint_printf("atan(B): "); nmod_poly_print(atanB), flint_printf("\n\n");
abort();
}
nmod_poly_clear(A);
nmod_poly_clear(B);
nmod_poly_clear(atanA);
nmod_poly_clear(atanB);
}
/* Check aliasing */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t A, B;
slong n;
mp_limb_t mod;
mod = n_randtest_prime(state, 0);
n = n_randtest(state) % 50;
n = FLINT_MIN(n, mod);
nmod_poly_init(A, mod);
nmod_poly_init(B, mod);
nmod_poly_randtest(A, state, n_randint(state, 50));
nmod_poly_set_coeff_ui(A, 0, UWORD(0));
nmod_poly_atan_series(B, A, n);
nmod_poly_atan_series(A, A, n);
result = nmod_poly_equal(A, B);
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(A), flint_printf("\n\n");
nmod_poly_print(B), flint_printf("\n\n");
abort();
}
nmod_poly_clear(A);
nmod_poly_clear(B);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,126 @@
/*=============================================================================
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) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result = 1;
FLINT_TEST_INIT(state);
flint_printf("atanh_series....");
fflush(stdout);
/* Check 2*atanh(A) = atanh(2*A/(1+A^2)) */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t A, B, atanhA, atanhB;
slong n;
mp_limb_t mod;
mod = n_randtest_prime(state, 0);
n = 1 + n_randtest(state) % 100;
n = FLINT_MIN(n, mod);
nmod_poly_init(A, mod);
nmod_poly_init(B, mod);
nmod_poly_init(atanhA, mod);
nmod_poly_init(atanhB, mod);
nmod_poly_randtest(A, state, n_randint(state, 100));
nmod_poly_set_coeff_ui(A, 0, UWORD(0));
nmod_poly_mullow(B, A, A, n);
nmod_poly_set_coeff_ui(B, 0, UWORD(1));
nmod_poly_div_series(B, A, B, n);
nmod_poly_add(B, B, B);
nmod_poly_atanh_series(atanhA, A, n);
nmod_poly_atanh_series(atanhB, B, n);
nmod_poly_add(atanhA, atanhA, atanhA);
result = nmod_poly_equal(atanhA, atanhB);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("n = %wd, mod = %wu\n", n, mod);
flint_printf("A: "); nmod_poly_print(A), flint_printf("\n\n");
flint_printf("B: "); nmod_poly_print(B), flint_printf("\n\n");
flint_printf("2*atanh(A): "); nmod_poly_print(atanhA), flint_printf("\n\n");
flint_printf("atanh(B): "); nmod_poly_print(atanhB), flint_printf("\n\n");
abort();
}
nmod_poly_clear(A);
nmod_poly_clear(B);
nmod_poly_clear(atanhA);
nmod_poly_clear(atanhB);
}
/* Check aliasing */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t A, B;
slong n;
mp_limb_t mod;
mod = n_randtest_prime(state, 0);
n = n_randtest(state) % 50;
n = FLINT_MIN(n, mod);
nmod_poly_init(A, mod);
nmod_poly_init(B, mod);
nmod_poly_randtest(A, state, n_randint(state, 50));
nmod_poly_set_coeff_ui(A, 0, UWORD(0));
nmod_poly_atanh_series(B, A, n);
nmod_poly_atanh_series(A, A, n);
result = nmod_poly_equal(A, B);
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(A), flint_printf("\n\n");
nmod_poly_print(B), flint_printf("\n\n");
abort();
}
nmod_poly_clear(A);
nmod_poly_clear(B);
}
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) 2010 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
#include "fmpz.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("bit_pack/bit_unpack....");
fflush(stdout);
/* Check aliasing of a and c */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b;
mp_limb_t n;
ulong bits;
mp_ptr mpn;
do
{
n = n_randtest_not_zero(state);
} while (n == 1);
bits = 2 * FLINT_BIT_COUNT(n) + n_randint(state, FLINT_BITS);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
do
{
nmod_poly_randtest(a, state, n_randint(state, 100));
} while (a->length == 0);
mpn =
flint_malloc(sizeof(mp_limb_t) *
((bits * a->length - 1) / FLINT_BITS + 1));
_nmod_poly_bit_pack(mpn, a->coeffs, a->length, bits);
nmod_poly_fit_length(b, a->length);
_nmod_poly_bit_unpack(b->coeffs, a->length, mpn, bits, a->mod);
b->length = a->length;
result = (nmod_poly_equal(a, b));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
flint_free(mpn);
}
for (i = 0; i < 2000 * flint_test_multiplier(); i++)
{
fmpz_t f;
nmod_poly_t A, B;
slong b;
mp_limb_t n;
do
{
n = n_randtest_not_zero(state);
} while (n == 1);
fmpz_init(f);
nmod_poly_init(A, n);
nmod_poly_init(B, n);
nmod_poly_randtest(A, state, 1+n_randint(state,100));
b = FLINT_BIT_COUNT(n) + n_randint(state, FLINT_BITS);
nmod_poly_bit_pack(f, A, b);
nmod_poly_bit_unpack(B, f, b);
if (!nmod_poly_equal(A, B))
{
mpz_t zz;
flint_printf("FAIL:\n");
flint_printf("INPUT: ");
nmod_poly_print(A);
flint_printf("\n");
mpz_init(zz); fmpz_get_mpz(zz, f);
flint_printf("PACKED: ");
mpz_out_str(stdout, 2, zz);
flint_printf("\n");
flint_printf("OUTPUT: ");
nmod_poly_print(B);
flint_printf("\n\n");
abort();
}
fmpz_clear(f);
nmod_poly_clear(A);
nmod_poly_clear(B);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,183 @@
/*=============================================================================
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 <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result = 1;
FLINT_TEST_INIT(state);
flint_printf("compose....");
fflush(stdout);
/* Check (f(x-1))(x+1) == f */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, r, xp1, xm1;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(r, n);
nmod_poly_init(xm1, n);
nmod_poly_init(xp1, n);
nmod_poly_randtest(a, state, n_randint(state, 100));
nmod_poly_set_coeff_ui(xm1, 1, 1);
nmod_poly_set_coeff_ui(xm1, 0, n - 1);
nmod_poly_set_coeff_ui(xp1, 1, 1);
nmod_poly_set_coeff_ui(xp1, 0, 1);
nmod_poly_compose(r, a, xm1);
nmod_poly_compose(r, r, xp1);
result = nmod_poly_equal(a, r);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a->length = %wd, n = %wu\n", a->length, a->mod.n);
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(r);
nmod_poly_clear(xm1);
nmod_poly_clear(xp1);
}
/* Check a(c) + b(c) = (a + b)(c) */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, r1, r2;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_init(r1, n);
nmod_poly_init(r2, n);
nmod_poly_randtest(a, state, n_randint(state, 30));
nmod_poly_randtest(b, state, n_randint(state, 30));
nmod_poly_randtest(c, state, n_randint(state, 10));
nmod_poly_compose(r1, a, c);
nmod_poly_compose(r2, b, c);
nmod_poly_add(r1, r1, r2);
nmod_poly_add(a, a, b);
nmod_poly_compose(r2, a, c);
result = nmod_poly_equal(r1, r2);
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(r1), flint_printf("\n\n");
nmod_poly_print(r2), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(r1);
nmod_poly_clear(r2);
}
/* Compare aliasing */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, r1;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(r1, n);
nmod_poly_randtest(a, state, n_randint(state, 30));
nmod_poly_randtest(b, state, n_randint(state, 15));
nmod_poly_compose(r1, a, b);
nmod_poly_compose(a, a, b);
result = nmod_poly_equal(r1, a);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a->length = %wd, n = %wu\n", a->length, a->mod.n);
nmod_poly_print(r1), flint_printf("\n\n");
nmod_poly_print(a), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(r1);
}
/* Compare other aliasing */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, r1;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(r1, n);
nmod_poly_randtest(a, state, n_randint(state, 30));
nmod_poly_randtest(b, state, n_randint(state, 15));
nmod_poly_compose(r1, a, b);
nmod_poly_compose(b, a, b);
result = nmod_poly_equal(r1, b);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a->length = %wd, n = %wu\n", a->length, a->mod.n);
nmod_poly_print(r1), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(r1);
}
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) 2010 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result = 1;
FLINT_TEST_INIT(state);
flint_printf("compose_divconquer....");
fflush(stdout);
/* Compare aliasing */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, r1;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(r1, n);
nmod_poly_randtest(a, state, n_randint(state, 30));
nmod_poly_randtest(b, state, n_randint(state, 15));
nmod_poly_compose_divconquer(r1, a, b);
nmod_poly_compose_divconquer(a, a, b);
result = nmod_poly_equal(r1, a);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a->length = %wd, n = %wu\n", a->length, a->mod.n);
nmod_poly_print(r1), flint_printf("\n\n");
nmod_poly_print(a), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(r1);
}
/* Compare other aliasing */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, r1;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(r1, n);
nmod_poly_randtest(a, state, n_randint(state, 30));
nmod_poly_randtest(b, state, n_randint(state, 15));
nmod_poly_compose_divconquer(r1, a, b);
nmod_poly_compose_divconquer(b, a, b);
result = nmod_poly_equal(r1, b);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a->length = %wd, n = %wu\n", a->length, a->mod.n);
nmod_poly_print(r1), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(r1);
}
/* Compare with compose_horner */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, r1, r2;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(r1, n);
nmod_poly_init(r2, n);
nmod_poly_randtest(a, state, n_randint(state, 30));
nmod_poly_randtest(b, state, n_randint(state, 15));
nmod_poly_compose_divconquer(r1, a, b);
nmod_poly_compose_horner(r2, a, b);
result = nmod_poly_equal(r1, r2);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a->length = %wd, n = %wu\n", a->length, a->mod.n);
nmod_poly_print(r1), flint_printf("\n\n");
nmod_poly_print(r2), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(r1);
nmod_poly_clear(r2);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,123 @@
/*=============================================================================
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 <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result = 1;
FLINT_TEST_INIT(state);
flint_printf("compose_horner....");
fflush(stdout);
/* Check (f(x-1))(x+1) == f */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, r, xp1, xm1;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(r, n);
nmod_poly_init(xm1, n);
nmod_poly_init(xp1, n);
nmod_poly_randtest(a, state, n_randint(state, 100));
nmod_poly_set_coeff_ui(xm1, 1, 1);
nmod_poly_set_coeff_ui(xm1, 0, n - 1);
nmod_poly_set_coeff_ui(xp1, 1, 1);
nmod_poly_set_coeff_ui(xp1, 0, 1);
nmod_poly_compose_horner(r, a, xm1);
nmod_poly_compose_horner(r, r, xp1);
result = nmod_poly_equal(a, r);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a->length = %wd, n = %wu\n", a->length, a->mod.n);
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(r);
nmod_poly_clear(xm1);
nmod_poly_clear(xp1);
}
/* Check a(c) + b(c) = (a + b)(c) */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, r1, r2;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_init(r1, n);
nmod_poly_init(r2, n);
nmod_poly_randtest(a, state, n_randint(state, 30));
nmod_poly_randtest(b, state, n_randint(state, 30));
nmod_poly_randtest(c, state, n_randint(state, 10));
nmod_poly_compose_horner(r1, a, c);
nmod_poly_compose_horner(r2, b, c);
nmod_poly_add(r1, r1, r2);
nmod_poly_add(a, a, b);
nmod_poly_compose_horner(r2, a, c);
result = nmod_poly_equal(r1, r2);
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(r1), flint_printf("\n\n");
nmod_poly_print(r2), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(r1);
nmod_poly_clear(r2);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,185 @@
/*=============================================================================
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_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i;
FLINT_TEST_INIT(state);
flint_printf("compose_mod....");
fflush(stdout);
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, d, e;
mp_limb_t m = n_randtest_prime(state, 0);
nmod_poly_init(a, m);
nmod_poly_init(b, m);
nmod_poly_init(c, m);
nmod_poly_init(d, m);
nmod_poly_init(e, m);
nmod_poly_randtest(a, state, 1+n_randint(state, 20));
nmod_poly_randtest(b, state, 1+n_randint(state, 20));
nmod_poly_randtest_not_zero(c, state, 1+n_randint(state, 20));
nmod_poly_compose_mod(d, a, b, c);
nmod_poly_compose(e, a, b);
nmod_poly_rem(e, e, c);
if (!nmod_poly_equal(d, e))
{
flint_printf("FAIL (composition):\n");
nmod_poly_print(a); flint_printf("\n");
nmod_poly_print(b); flint_printf("\n");
nmod_poly_print(c); flint_printf("\n");
nmod_poly_print(d); flint_printf("\n");
nmod_poly_print(e); flint_printf("\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(d);
nmod_poly_clear(e);
}
/* Test aliasing of res and a */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, d;
mp_limb_t m = n_randtest_prime(state, 0);
nmod_poly_init(a, m);
nmod_poly_init(b, m);
nmod_poly_init(c, m);
nmod_poly_init(d, m);
nmod_poly_randtest(a, state, 1+n_randint(state, 20));
nmod_poly_randtest(b, state, 1+n_randint(state, 20));
nmod_poly_randtest_not_zero(c, state, 1+n_randint(state, 20));
nmod_poly_compose_mod(d, a, b, c);
nmod_poly_compose_mod(a, a, b, c);
if (!nmod_poly_equal(d, a))
{
flint_printf("FAIL (aliasing a):\n");
nmod_poly_print(a); flint_printf("\n");
nmod_poly_print(b); flint_printf("\n");
nmod_poly_print(c); flint_printf("\n");
nmod_poly_print(d); flint_printf("\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(d);
}
/* Test aliasing of res and b */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, d;
mp_limb_t m = n_randtest_prime(state, 0);
nmod_poly_init(a, m);
nmod_poly_init(b, m);
nmod_poly_init(c, m);
nmod_poly_init(d, m);
nmod_poly_randtest(a, state, 1+n_randint(state, 20));
nmod_poly_randtest(b, state, 1+n_randint(state, 20));
nmod_poly_randtest_not_zero(c, state, 1+n_randint(state, 20));
nmod_poly_compose_mod(d, a, b, c);
nmod_poly_compose_mod(b, a, b, c);
if (!nmod_poly_equal(d, b))
{
flint_printf("FAIL (aliasing b)\n");
nmod_poly_print(a); flint_printf("\n");
nmod_poly_print(b); flint_printf("\n");
nmod_poly_print(c); flint_printf("\n");
nmod_poly_print(d); flint_printf("\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(d);
}
/* Test aliasing of res and c */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, d;
mp_limb_t m = n_randtest_prime(state, 0);
nmod_poly_init(a, m);
nmod_poly_init(b, m);
nmod_poly_init(c, m);
nmod_poly_init(d, m);
nmod_poly_randtest(a, state, 1+n_randint(state, 20));
nmod_poly_randtest(b, state, 1+n_randint(state, 20));
nmod_poly_randtest_not_zero(c, state, 1+n_randint(state, 20));
nmod_poly_compose_mod(d, a, b, c);
nmod_poly_compose_mod(c, a, b, c);
if (!nmod_poly_equal(d, c))
{
flint_printf("FAIL (aliasing c)\n");
nmod_poly_print(a); flint_printf("\n");
nmod_poly_print(b); flint_printf("\n");
nmod_poly_print(c); flint_printf("\n");
nmod_poly_print(d); flint_printf("\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(d);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,189 @@
/*=============================================================================
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_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i;
FLINT_TEST_INIT(state);
flint_printf("compose_mod_brent_kung....");
fflush(stdout);
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, d, e;
mp_limb_t m = n_randtest_prime(state, 0);
nmod_poly_init(a, m);
nmod_poly_init(b, m);
nmod_poly_init(c, m);
nmod_poly_init(d, m);
nmod_poly_init(e, m);
nmod_poly_randtest(a, state, 1+n_randint(state, 20));
nmod_poly_randtest(b, state, 1+n_randint(state, 20));
nmod_poly_randtest_not_zero(c, state, 1+n_randint(state, 20));
nmod_poly_rem(a, a, c);
nmod_poly_compose_mod_brent_kung(d, a, b, c);
nmod_poly_compose(e, a, b);
nmod_poly_rem(e, e, c);
if (!nmod_poly_equal(d, e))
{
flint_printf("FAIL (composition):\n");
nmod_poly_print(a); flint_printf("\n");
nmod_poly_print(b); flint_printf("\n");
nmod_poly_print(c); flint_printf("\n");
nmod_poly_print(d); flint_printf("\n");
nmod_poly_print(e); flint_printf("\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(d);
nmod_poly_clear(e);
}
/* Test aliasing of res and a */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, d;
mp_limb_t m = n_randtest_prime(state, 0);
nmod_poly_init(a, m);
nmod_poly_init(b, m);
nmod_poly_init(c, m);
nmod_poly_init(d, m);
nmod_poly_randtest(a, state, 1+n_randint(state, 20));
nmod_poly_randtest(b, state, 1+n_randint(state, 20));
nmod_poly_randtest_not_zero(c, state, 1+n_randint(state, 20));
nmod_poly_rem(a, a, c);
nmod_poly_compose_mod_brent_kung(d, a, b, c);
nmod_poly_compose_mod_brent_kung(a, a, b, c);
if (!nmod_poly_equal(d, a))
{
flint_printf("FAIL (aliasing a):\n");
nmod_poly_print(a); flint_printf("\n");
nmod_poly_print(b); flint_printf("\n");
nmod_poly_print(c); flint_printf("\n");
nmod_poly_print(d); flint_printf("\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(d);
}
/* Test aliasing of res and b */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, d;
mp_limb_t m = n_randtest_prime(state, 0);
nmod_poly_init(a, m);
nmod_poly_init(b, m);
nmod_poly_init(c, m);
nmod_poly_init(d, m);
nmod_poly_randtest(a, state, 1+n_randint(state, 20));
nmod_poly_randtest(b, state, 1+n_randint(state, 20));
nmod_poly_randtest_not_zero(c, state, 1+n_randint(state, 20));
nmod_poly_rem(a, a, c);
nmod_poly_compose_mod_brent_kung(d, a, b, c);
nmod_poly_compose_mod_brent_kung(b, a, b, c);
if (!nmod_poly_equal(d, b))
{
flint_printf("FAIL (aliasing b)\n");
nmod_poly_print(a); flint_printf("\n");
nmod_poly_print(b); flint_printf("\n");
nmod_poly_print(c); flint_printf("\n");
nmod_poly_print(d); flint_printf("\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(d);
}
/* Test aliasing of res and c */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, d;
mp_limb_t m = n_randtest_prime(state, 0);
nmod_poly_init(a, m);
nmod_poly_init(b, m);
nmod_poly_init(c, m);
nmod_poly_init(d, m);
nmod_poly_randtest(a, state, 1+n_randint(state, 20));
nmod_poly_randtest(b, state, 1+n_randint(state, 20));
nmod_poly_randtest_not_zero(c, state, 1+n_randint(state, 20));
nmod_poly_rem(a, a, c);
nmod_poly_compose_mod_brent_kung(d, a, b, c);
nmod_poly_compose_mod_brent_kung(c, a, b, c);
if (!nmod_poly_equal(d, c))
{
flint_printf("FAIL (aliasing c)\n");
nmod_poly_print(a); flint_printf("\n");
nmod_poly_print(b); flint_printf("\n");
nmod_poly_print(c); flint_printf("\n");
nmod_poly_print(d); flint_printf("\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(d);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,235 @@
/*=============================================================================
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
Copyright (C) 2013 Martin Lee
******************************************************************************/
#undef ulong
#define ulong ulongxx/* interferes with system includes */
#include <stdlib.h>
#include <stdio.h>
#undef ulong
#include <gmp.h>
#define ulong mp_limb_t
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i;
FLINT_TEST_INIT(state);
flint_printf("compose_mod_brent_kung_precomp_preinv....");
fflush(stdout);
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, cinv, d, e;
nmod_mat_t B;
mp_limb_t m = n_randtest_prime(state, 0);
nmod_poly_init(a, m);
nmod_poly_init(b, m);
nmod_poly_init(c, m);
nmod_poly_init(cinv, m);
nmod_poly_init(d, m);
nmod_poly_init(e, m);
nmod_poly_randtest(a, state, 1+n_randint(state, 20));
nmod_poly_randtest(b, state, 1+n_randint(state, 20));
nmod_poly_randtest_not_zero(c, state, 1+n_randint(state, 20));
nmod_poly_rem(a, a, c);
nmod_poly_reverse(cinv, c, c->length);
nmod_poly_inv_series(cinv, cinv, c->length);
nmod_mat_init (B, n_sqrt (c->length-1)+1, c->length-1, m);
nmod_poly_precompute_matrix (B, b, c, cinv);
nmod_poly_compose_mod_brent_kung_precomp_preinv(d, a, B, c, cinv);
nmod_poly_compose(e, a, b);
nmod_poly_rem(e, e, c);
if (!nmod_poly_equal(d, e))
{
flint_printf("FAIL (composition):\n");
nmod_poly_print(a); flint_printf("\n");
nmod_poly_print(b); flint_printf("\n");
nmod_poly_print(c); flint_printf("\n");
nmod_poly_print(cinv); flint_printf("\n");
nmod_poly_print(d); flint_printf("\n");
nmod_poly_print(e); flint_printf("\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_mat_clear (B);
nmod_poly_clear(c);
nmod_poly_clear(cinv);
nmod_poly_clear(d);
nmod_poly_clear(e);
}
/* Test aliasing of res and a */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, cinv, d;
nmod_mat_t B;
mp_limb_t m = n_randtest_prime(state, 0);
nmod_poly_init(a, m);
nmod_poly_init(b, m);
nmod_poly_init(c, m);
nmod_poly_init(cinv, m);
nmod_poly_init(d, m);
nmod_poly_randtest(a, state, 1+n_randint(state, 20));
nmod_poly_randtest(b, state, 1+n_randint(state, 20));
nmod_poly_randtest_not_zero(c, state, 1+n_randint(state, 20));
nmod_poly_rem(a, a, c);
nmod_poly_reverse(cinv, c, c->length);
nmod_poly_inv_series(cinv, cinv, c->length);
nmod_mat_init (B, n_sqrt (c->length-1)+1, c->length-1, m);
nmod_poly_precompute_matrix (B, b, c, cinv);
nmod_poly_compose_mod_brent_kung_precomp_preinv(d, a, B, c, cinv);
nmod_poly_compose_mod_brent_kung_precomp_preinv(a, a, B, c, cinv);
if (!nmod_poly_equal(d, a))
{
flint_printf("FAIL (aliasing a):\n");
nmod_poly_print(a); flint_printf("\n");
nmod_poly_print(b); flint_printf("\n");
nmod_poly_print(c); flint_printf("\n");
nmod_poly_print(cinv); flint_printf("\n");
nmod_poly_print(d); flint_printf("\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_mat_clear (B);
nmod_poly_clear(c);
nmod_poly_clear(cinv);
nmod_poly_clear(d);
}
/* Test aliasing of res and c */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, cinv, d;
nmod_mat_t B;
mp_limb_t m = n_randtest_prime(state, 0);
nmod_poly_init(a, m);
nmod_poly_init(b, m);
nmod_poly_init(c, m);
nmod_poly_init(cinv, m);
nmod_poly_init(d, m);
nmod_poly_randtest(a, state, 1+n_randint(state, 20));
nmod_poly_randtest(b, state, 1+n_randint(state, 20));
nmod_poly_randtest_not_zero(c, state, 1+n_randint(state, 20));
nmod_poly_rem(a, a, c);
nmod_poly_reverse(cinv, c, c->length);
nmod_poly_inv_series(cinv, cinv, c->length);
nmod_mat_init (B, n_sqrt (c->length-1)+1, c->length-1, m);
nmod_poly_precompute_matrix (B, b, c, cinv);
nmod_poly_compose_mod_brent_kung_precomp_preinv(d, a, B, c, cinv);
nmod_poly_compose_mod_brent_kung_precomp_preinv(c, a, B, c, cinv);
if (!nmod_poly_equal(d, c))
{
flint_printf("FAIL (aliasing c)\n");
nmod_poly_print(a); flint_printf("\n");
nmod_poly_print(b); flint_printf("\n");
nmod_poly_print(c); flint_printf("\n");
nmod_poly_print(cinv); flint_printf("\n");
nmod_poly_print(d); flint_printf("\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_mat_clear (B);
nmod_poly_clear(c);
nmod_poly_clear(cinv);
nmod_poly_clear(d);
}
/* Test aliasing of res and cinv */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, cinv, d;
nmod_mat_t B;
mp_limb_t m = n_randtest_prime(state, 0);
nmod_poly_init(a, m);
nmod_poly_init(b, m);
nmod_poly_init(c, m);
nmod_poly_init(cinv, m);
nmod_poly_init(d, m);
nmod_poly_randtest(a, state, 1+n_randint(state, 20));
nmod_poly_randtest(b, state, 1+n_randint(state, 20));
nmod_poly_randtest_not_zero(c, state, 1+n_randint(state, 20));
nmod_poly_rem(a, a, c);
nmod_poly_reverse(cinv, c, c->length);
nmod_poly_inv_series(cinv, cinv, c->length);
nmod_mat_init (B, n_sqrt (c->length-1)+1, c->length-1, m);
nmod_poly_precompute_matrix (B, b, c, cinv);
nmod_poly_compose_mod_brent_kung_precomp_preinv(d, a, B, c, cinv);
nmod_poly_compose_mod_brent_kung_precomp_preinv(cinv, a, B, c, cinv);
if (!nmod_poly_equal(d, cinv))
{
flint_printf("FAIL (aliasing cinv)\n");
nmod_poly_print(a); flint_printf("\n");
nmod_poly_print(b); flint_printf("\n");
nmod_poly_print(c); flint_printf("\n");
nmod_poly_print(cinv); flint_printf("\n");
nmod_poly_print(d); flint_printf("\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_mat_clear (B);
nmod_poly_clear(c);
nmod_poly_clear(cinv);
nmod_poly_clear(d);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,259 @@
/*=============================================================================
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
Copyright (C) 2013 Martin Lee
******************************************************************************/
#undef ulong
#define ulong ulongxx/* interferes with system includes */
#include <stdlib.h>
#include <stdio.h>
#undef ulong
#include <gmp.h>
#define ulong mp_limb_t
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i;
FLINT_TEST_INIT(state);
flint_printf("compose_mod_brent_kung_preinv....");
fflush(stdout);
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, cinv, d, e;
mp_limb_t m = n_randtest_prime(state, 0);
nmod_poly_init(a, m);
nmod_poly_init(b, m);
nmod_poly_init(c, m);
nmod_poly_init(cinv, m);
nmod_poly_init(d, m);
nmod_poly_init(e, m);
nmod_poly_randtest(a, state, 1+n_randint(state, 20));
nmod_poly_randtest(b, state, 1+n_randint(state, 20));
nmod_poly_randtest_not_zero(c, state, 1+n_randint(state, 20));
nmod_poly_rem(a, a, c);
nmod_poly_reverse(cinv, c, c->length);
nmod_poly_inv_series(cinv, cinv, c->length);
nmod_poly_compose_mod_brent_kung_preinv(d, a, b, c, cinv);
nmod_poly_compose(e, a, b);
nmod_poly_rem(e, e, c);
if (!nmod_poly_equal(d, e))
{
flint_printf("FAIL (composition):\n");
nmod_poly_print(a); flint_printf("\n");
nmod_poly_print(b); flint_printf("\n");
nmod_poly_print(c); flint_printf("\n");
nmod_poly_print(cinv); flint_printf("\n");
nmod_poly_print(d); flint_printf("\n");
nmod_poly_print(e); flint_printf("\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(cinv);
nmod_poly_clear(d);
nmod_poly_clear(e);
}
/* Test aliasing of res and a */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, cinv, d;
mp_limb_t m = n_randtest_prime(state, 0);
nmod_poly_init(a, m);
nmod_poly_init(b, m);
nmod_poly_init(c, m);
nmod_poly_init(cinv, m);
nmod_poly_init(d, m);
nmod_poly_randtest(a, state, 1+n_randint(state, 20));
nmod_poly_randtest(b, state, 1+n_randint(state, 20));
nmod_poly_randtest_not_zero(c, state, 1+n_randint(state, 20));
nmod_poly_rem(a, a, c);
nmod_poly_reverse(cinv, c, c->length);
nmod_poly_inv_series(cinv, cinv, c->length);
nmod_poly_compose_mod_brent_kung_preinv(d, a, b, c, cinv);
nmod_poly_compose_mod_brent_kung_preinv(a, a, b, c, cinv);
if (!nmod_poly_equal(d, a))
{
flint_printf("FAIL (aliasing a):\n");
nmod_poly_print(a); flint_printf("\n");
nmod_poly_print(b); flint_printf("\n");
nmod_poly_print(c); flint_printf("\n");
nmod_poly_print(cinv); flint_printf("\n");
nmod_poly_print(d); flint_printf("\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(cinv);
nmod_poly_clear(d);
}
/* Test aliasing of res and b */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, cinv, d;
mp_limb_t m = n_randtest_prime(state, 0);
nmod_poly_init(a, m);
nmod_poly_init(b, m);
nmod_poly_init(c, m);
nmod_poly_init(cinv, m);
nmod_poly_init(d, m);
nmod_poly_randtest(a, state, 1+n_randint(state, 20));
nmod_poly_randtest(b, state, 1+n_randint(state, 20));
nmod_poly_randtest_not_zero(c, state, 1+n_randint(state, 20));
nmod_poly_rem(a, a, c);
nmod_poly_reverse(cinv, c, c->length);
nmod_poly_inv_series(cinv, cinv, c->length);
nmod_poly_compose_mod_brent_kung_preinv(d, a, b, c, cinv);
nmod_poly_compose_mod_brent_kung_preinv(b, a, b, c, cinv);
if (!nmod_poly_equal(d, b))
{
flint_printf("FAIL (aliasing b)\n");
nmod_poly_print(a); flint_printf("\n");
nmod_poly_print(b); flint_printf("\n");
nmod_poly_print(c); flint_printf("\n");
nmod_poly_print(cinv); flint_printf("\n");
nmod_poly_print(d); flint_printf("\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(cinv);
nmod_poly_clear(d);
}
/* Test aliasing of res and c */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, cinv, d;
mp_limb_t m = n_randtest_prime(state, 0);
nmod_poly_init(a, m);
nmod_poly_init(b, m);
nmod_poly_init(c, m);
nmod_poly_init(cinv, m);
nmod_poly_init(d, m);
nmod_poly_randtest(a, state, 1+n_randint(state, 20));
nmod_poly_randtest(b, state, 1+n_randint(state, 20));
nmod_poly_randtest_not_zero(c, state, 1+n_randint(state, 20));
nmod_poly_rem(a, a, c);
nmod_poly_reverse(cinv, c, c->length);
nmod_poly_inv_series(cinv, cinv, c->length);
nmod_poly_compose_mod_brent_kung_preinv(d, a, b, c, cinv);
nmod_poly_compose_mod_brent_kung_preinv(c, a, b, c, cinv);
if (!nmod_poly_equal(d, c))
{
flint_printf("FAIL (aliasing c)\n");
nmod_poly_print(a); flint_printf("\n");
nmod_poly_print(b); flint_printf("\n");
nmod_poly_print(c); flint_printf("\n");
nmod_poly_print(cinv); flint_printf("\n");
nmod_poly_print(d); flint_printf("\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(cinv);
nmod_poly_clear(d);
}
/* Test aliasing of res and cinv */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, cinv, d;
mp_limb_t m = n_randtest_prime(state, 0);
nmod_poly_init(a, m);
nmod_poly_init(b, m);
nmod_poly_init(c, m);
nmod_poly_init(cinv, m);
nmod_poly_init(d, m);
nmod_poly_randtest(a, state, 1+n_randint(state, 20));
nmod_poly_randtest(b, state, 1+n_randint(state, 20));
nmod_poly_randtest_not_zero(c, state, 1+n_randint(state, 20));
nmod_poly_rem(a, a, c);
nmod_poly_reverse(cinv, c, c->length);
nmod_poly_inv_series(cinv, cinv, c->length);
nmod_poly_compose_mod_brent_kung_preinv(d, a, b, c, cinv);
nmod_poly_compose_mod_brent_kung_preinv(cinv, a, b, c, cinv);
if (!nmod_poly_equal(d, cinv))
{
flint_printf("FAIL (aliasing cinv)\n");
nmod_poly_print(a); flint_printf("\n");
nmod_poly_print(b); flint_printf("\n");
nmod_poly_print(c); flint_printf("\n");
nmod_poly_print(cinv); flint_printf("\n");
nmod_poly_print(d); flint_printf("\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(cinv);
nmod_poly_clear(d);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,185 @@
/*=============================================================================
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_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i;
FLINT_TEST_INIT(state);
flint_printf("compose_mod_horner....");
fflush(stdout);
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, d, e;
mp_limb_t m = n_randtest_prime(state, 0);
nmod_poly_init(a, m);
nmod_poly_init(b, m);
nmod_poly_init(c, m);
nmod_poly_init(d, m);
nmod_poly_init(e, m);
nmod_poly_randtest(a, state, 1+n_randint(state, 20));
nmod_poly_randtest(b, state, 1+n_randint(state, 20));
nmod_poly_randtest_not_zero(c, state, 1+n_randint(state, 20));
nmod_poly_compose_mod_horner(d, a, b, c);
nmod_poly_compose(e, a, b);
nmod_poly_rem(e, e, c);
if (!nmod_poly_equal(d, e))
{
flint_printf("FAIL (composition):\n");
nmod_poly_print(a); flint_printf("\n");
nmod_poly_print(b); flint_printf("\n");
nmod_poly_print(c); flint_printf("\n");
nmod_poly_print(d); flint_printf("\n");
nmod_poly_print(e); flint_printf("\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(d);
nmod_poly_clear(e);
}
/* Test aliasing of res and a */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, d;
mp_limb_t m = n_randtest_prime(state, 0);
nmod_poly_init(a, m);
nmod_poly_init(b, m);
nmod_poly_init(c, m);
nmod_poly_init(d, m);
nmod_poly_randtest(a, state, 1+n_randint(state, 20));
nmod_poly_randtest(b, state, 1+n_randint(state, 20));
nmod_poly_randtest_not_zero(c, state, 1+n_randint(state, 20));
nmod_poly_compose_mod_horner(d, a, b, c);
nmod_poly_compose_mod_horner(a, a, b, c);
if (!nmod_poly_equal(d, a))
{
flint_printf("FAIL (aliasing a):\n");
nmod_poly_print(a); flint_printf("\n");
nmod_poly_print(b); flint_printf("\n");
nmod_poly_print(c); flint_printf("\n");
nmod_poly_print(d); flint_printf("\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(d);
}
/* Test aliasing of res and b */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, d;
mp_limb_t m = n_randtest_prime(state, 0);
nmod_poly_init(a, m);
nmod_poly_init(b, m);
nmod_poly_init(c, m);
nmod_poly_init(d, m);
nmod_poly_randtest(a, state, 1+n_randint(state, 20));
nmod_poly_randtest(b, state, 1+n_randint(state, 20));
nmod_poly_randtest_not_zero(c, state, 1+n_randint(state, 20));
nmod_poly_compose_mod_horner(d, a, b, c);
nmod_poly_compose_mod_horner(b, a, b, c);
if (!nmod_poly_equal(d, b))
{
flint_printf("FAIL (aliasing b)\n");
nmod_poly_print(a); flint_printf("\n");
nmod_poly_print(b); flint_printf("\n");
nmod_poly_print(c); flint_printf("\n");
nmod_poly_print(d); flint_printf("\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(d);
}
/* Test aliasing of res and c */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, d;
mp_limb_t m = n_randtest_prime(state, 0);
nmod_poly_init(a, m);
nmod_poly_init(b, m);
nmod_poly_init(c, m);
nmod_poly_init(d, m);
nmod_poly_randtest(a, state, 1+n_randint(state, 20));
nmod_poly_randtest(b, state, 1+n_randint(state, 20));
nmod_poly_randtest_not_zero(c, state, 1+n_randint(state, 20));
nmod_poly_compose_mod_horner(d, a, b, c);
nmod_poly_compose_mod_horner(c, a, b, c);
if (!nmod_poly_equal(d, c))
{
flint_printf("FAIL (aliasing c)\n");
nmod_poly_print(a); flint_printf("\n");
nmod_poly_print(b); flint_printf("\n");
nmod_poly_print(c); flint_printf("\n");
nmod_poly_print(d); flint_printf("\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(d);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,157 @@
/*=============================================================================
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 "nmod_vec.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("compose_series....");
fflush(stdout);
/* Check aliasing of the first argument */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
nmod_poly_t f, g, h;
mp_limb_t m;
slong n;
m = n_randtest_prime(state, 0);
nmod_poly_init(f, m);
nmod_poly_init(g, m);
nmod_poly_init(h, m);
nmod_poly_randtest(g, state, n_randint(state, 50));
nmod_poly_randtest(h, state, n_randint(state, 30));
nmod_poly_set_coeff_ui(h, 0, 0);
n = n_randint(state, 40);
nmod_poly_compose_series(f, g, h, n);
nmod_poly_compose_series(g, g, h, n);
result = (nmod_poly_equal(f, g));
if (!result)
{
flint_printf("FAIL (aliasing 1):\n");
nmod_poly_print(f), flint_printf("\n\n");
nmod_poly_print(g), flint_printf("\n\n");
abort();
}
nmod_poly_clear(f);
nmod_poly_clear(g);
nmod_poly_clear(h);
}
/* Check aliasing of the second argument */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
nmod_poly_t f, g, h;
mp_limb_t m;
slong n;
m = n_randtest_prime(state, 0);
nmod_poly_init(f, m);
nmod_poly_init(g, m);
nmod_poly_init(h, m);
nmod_poly_randtest(g, state, n_randint(state, 50));
nmod_poly_randtest(h, state, n_randint(state, 30));
nmod_poly_set_coeff_ui(h, 0, 0);
n = n_randint(state, 40);
nmod_poly_compose_series(f, g, h, n);
nmod_poly_compose_series(h, g, h, n);
result = (nmod_poly_equal(f, h));
if (!result)
{
flint_printf("FAIL (aliasing 2):\n");
nmod_poly_print(f), flint_printf("\n\n");
nmod_poly_print(h), flint_printf("\n\n");
abort();
}
nmod_poly_clear(f);
nmod_poly_clear(g);
nmod_poly_clear(h);
}
/* Compare with compose */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
nmod_poly_t f, g, h, s, t;
mp_limb_t m;
slong n;
m = n_randtest_prime(state, 0);
nmod_poly_init(f, m);
nmod_poly_init(g, m);
nmod_poly_init(h, m);
nmod_poly_init(s, m);
nmod_poly_init(t, m);
nmod_poly_randtest(g, state, n_randint(state, 50));
nmod_poly_randtest(h, state, n_randint(state, 30));
nmod_poly_set_coeff_ui(h, 0, 0);
n = n_randint(state, 40);
nmod_poly_compose(s, g, h);
nmod_poly_truncate(s, n);
nmod_poly_compose_series(f, g, h, n);
result = (nmod_poly_equal(f, s));
if (!result)
{
flint_printf("FAIL (comparison):\n");
flint_printf("n = %wd\n", n);
flint_printf("g = "), nmod_poly_print(g), flint_printf("\n\n");
flint_printf("h = "), nmod_poly_print(h), flint_printf("\n\n");
flint_printf("f = "), nmod_poly_print(f), flint_printf("\n\n");
flint_printf("s = "), nmod_poly_print(s), flint_printf("\n\n");
abort();
}
nmod_poly_clear(f);
nmod_poly_clear(g);
nmod_poly_clear(h);
nmod_poly_clear(s);
nmod_poly_clear(t);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,157 @@
/*=============================================================================
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 "nmod_vec.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("compose_series_brent_kung....");
fflush(stdout);
/* Check aliasing of the first argument */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
nmod_poly_t f, g, h;
mp_limb_t m;
slong n;
m = n_randtest_prime(state, 0);
nmod_poly_init(f, m);
nmod_poly_init(g, m);
nmod_poly_init(h, m);
nmod_poly_randtest(g, state, n_randint(state, 40));
nmod_poly_randtest(h, state, n_randint(state, 20));
nmod_poly_set_coeff_ui(h, 0, 0);
n = n_randint(state, 20);
nmod_poly_compose_series_brent_kung(f, g, h, n);
nmod_poly_compose_series_brent_kung(g, g, h, n);
result = (nmod_poly_equal(f, g));
if (!result)
{
flint_printf("FAIL (aliasing 1):\n");
nmod_poly_print(f), flint_printf("\n\n");
nmod_poly_print(g), flint_printf("\n\n");
abort();
}
nmod_poly_clear(f);
nmod_poly_clear(g);
nmod_poly_clear(h);
}
/* Check aliasing of the second argument */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
nmod_poly_t f, g, h;
mp_limb_t m;
slong n;
m = n_randtest_prime(state, 0);
nmod_poly_init(f, m);
nmod_poly_init(g, m);
nmod_poly_init(h, m);
nmod_poly_randtest(g, state, n_randint(state, 40));
nmod_poly_randtest(h, state, n_randint(state, 20));
nmod_poly_set_coeff_ui(h, 0, 0);
n = n_randint(state, 20);
nmod_poly_compose_series_brent_kung(f, g, h, n);
nmod_poly_compose_series_brent_kung(h, g, h, n);
result = (nmod_poly_equal(f, h));
if (!result)
{
flint_printf("FAIL (aliasing 2):\n");
nmod_poly_print(f), flint_printf("\n\n");
nmod_poly_print(h), flint_printf("\n\n");
abort();
}
nmod_poly_clear(f);
nmod_poly_clear(g);
nmod_poly_clear(h);
}
/* Compare with compose */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
nmod_poly_t f, g, h, s, t;
mp_limb_t m;
slong n;
m = n_randtest_prime(state, 0);
nmod_poly_init(f, m);
nmod_poly_init(g, m);
nmod_poly_init(h, m);
nmod_poly_init(s, m);
nmod_poly_init(t, m);
nmod_poly_randtest(g, state, n_randint(state, 40));
nmod_poly_randtest(h, state, n_randint(state, 20));
nmod_poly_set_coeff_ui(h, 0, 0);
n = n_randint(state, 20);
nmod_poly_compose(s, g, h);
nmod_poly_truncate(s, n);
nmod_poly_compose_series_brent_kung(f, g, h, n);
result = (nmod_poly_equal(f, s));
if (!result)
{
flint_printf("FAIL (comparison):\n");
flint_printf("n = %wd\n", n);
flint_printf("g = "), nmod_poly_print(g), flint_printf("\n\n");
flint_printf("h = "), nmod_poly_print(h), flint_printf("\n\n");
flint_printf("f = "), nmod_poly_print(f), flint_printf("\n\n");
flint_printf("s = "), nmod_poly_print(s), flint_printf("\n\n");
abort();
}
nmod_poly_clear(f);
nmod_poly_clear(g);
nmod_poly_clear(h);
nmod_poly_clear(s);
nmod_poly_clear(t);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,145 @@
/*=============================================================================
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) 2011 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result = 1;
FLINT_TEST_INIT(state);
flint_printf("compose_series_divconquer....");
fflush(stdout);
/* Aliasing */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
mp_limb_t n = n_randtest_not_zero(state);
slong N = n_randint(state, 50);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(a, state, n_randint(state, 30));
nmod_poly_randtest(b, state, n_randint(state, 15));
nmod_poly_compose_series_divconquer(c, a, b, N);
nmod_poly_compose_series_divconquer(a, a, b, N);
result = nmod_poly_equal(c, a);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a->length = %wd, n = %wu\n", a->length, a->mod.n);
nmod_poly_print(c), flint_printf("\n\n");
nmod_poly_print(a), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Aliasing */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
mp_limb_t n = n_randtest_not_zero(state);
slong N = n_randint(state, 50);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(a, state, n_randint(state, 30));
nmod_poly_randtest(b, state, n_randint(state, 15));
nmod_poly_compose_series_divconquer(c, a, b, N);
nmod_poly_compose_series_divconquer(b, a, b, N);
result = nmod_poly_equal(c, b);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a->length = %wd, n = %wu\n", a->length, a->mod.n);
nmod_poly_print(c), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Compare with compose */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, r1, r2;
mp_limb_t n = n_randtest_not_zero(state);
slong N = n_randint(state, 50);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(r1, n);
nmod_poly_init(r2, n);
nmod_poly_randtest(a, state, n_randint(state, 30));
nmod_poly_randtest(b, state, n_randint(state, 15));
nmod_poly_compose_series_divconquer(r1, a, b, N);
nmod_poly_compose(r2, a, b);
nmod_poly_truncate(r2, N);
result = nmod_poly_equal(r1, r2);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a->length = %wd, n = %wu\n", a->length, a->mod.n);
nmod_poly_print(r1), flint_printf("\n\n");
nmod_poly_print(r2), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(r1);
nmod_poly_clear(r2);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,157 @@
/*=============================================================================
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 "nmod_vec.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("compose_series_horner....");
fflush(stdout);
/* Check aliasing of the first argument */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
nmod_poly_t f, g, h;
mp_limb_t m;
slong n;
m = n_randtest_prime(state, 0);
nmod_poly_init(f, m);
nmod_poly_init(g, m);
nmod_poly_init(h, m);
nmod_poly_randtest(g, state, n_randint(state, 40));
nmod_poly_randtest(h, state, n_randint(state, 20));
nmod_poly_set_coeff_ui(h, 0, 0);
n = n_randint(state, 20);
nmod_poly_compose_series_horner(f, g, h, n);
nmod_poly_compose_series_horner(g, g, h, n);
result = (nmod_poly_equal(f, g));
if (!result)
{
flint_printf("FAIL (aliasing 1):\n");
nmod_poly_print(f), flint_printf("\n\n");
nmod_poly_print(g), flint_printf("\n\n");
abort();
}
nmod_poly_clear(f);
nmod_poly_clear(g);
nmod_poly_clear(h);
}
/* Check aliasing of the second argument */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
nmod_poly_t f, g, h;
mp_limb_t m;
slong n;
m = n_randtest_prime(state, 0);
nmod_poly_init(f, m);
nmod_poly_init(g, m);
nmod_poly_init(h, m);
nmod_poly_randtest(g, state, n_randint(state, 40));
nmod_poly_randtest(h, state, n_randint(state, 20));
nmod_poly_set_coeff_ui(h, 0, 0);
n = n_randint(state, 20);
nmod_poly_compose_series_horner(f, g, h, n);
nmod_poly_compose_series_horner(h, g, h, n);
result = (nmod_poly_equal(f, h));
if (!result)
{
flint_printf("FAIL (aliasing 2):\n");
nmod_poly_print(f), flint_printf("\n\n");
nmod_poly_print(h), flint_printf("\n\n");
abort();
}
nmod_poly_clear(f);
nmod_poly_clear(g);
nmod_poly_clear(h);
}
/* Compare with compose */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
nmod_poly_t f, g, h, s, t;
mp_limb_t m;
slong n;
m = n_randtest_prime(state, 0);
nmod_poly_init(f, m);
nmod_poly_init(g, m);
nmod_poly_init(h, m);
nmod_poly_init(s, m);
nmod_poly_init(t, m);
nmod_poly_randtest(g, state, n_randint(state, 40));
nmod_poly_randtest(h, state, n_randint(state, 20));
nmod_poly_set_coeff_ui(h, 0, 0);
n = n_randint(state, 20);
nmod_poly_compose(s, g, h);
nmod_poly_truncate(s, n);
nmod_poly_compose_series_horner(f, g, h, n);
result = (nmod_poly_equal(f, s));
if (!result)
{
flint_printf("FAIL (comparison):\n");
flint_printf("n = %wd\n", n);
flint_printf("g = "), nmod_poly_print(g), flint_printf("\n\n");
flint_printf("h = "), nmod_poly_print(h), flint_printf("\n\n");
flint_printf("f = "), nmod_poly_print(f), flint_printf("\n\n");
flint_printf("s = "), nmod_poly_print(s), flint_printf("\n\n");
abort();
}
nmod_poly_clear(f);
nmod_poly_clear(g);
nmod_poly_clear(h);
nmod_poly_clear(s);
nmod_poly_clear(t);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

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 (C) 2010 William Hart
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result = 1;
FLINT_TEST_INIT(state);
flint_printf("cos_series....");
fflush(stdout);
/* Check 1-cos(A)^2 = sin(A)^2 */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t A, cosA, sinA, B, C, one;
slong n;
mp_limb_t mod;
do { mod = n_randtest_prime(state, 0); } while (mod == 2);
n = 1 + n_randtest(state) % 100;
n = FLINT_MIN(n, mod);
nmod_poly_init(A, mod);
nmod_poly_init(cosA, mod);
nmod_poly_init(sinA, mod);
nmod_poly_init(B, mod);
nmod_poly_init(C, mod);
nmod_poly_init(one, mod);
nmod_poly_randtest(A, state, n_randint(state, 100));
nmod_poly_set_coeff_ui(A, 0, UWORD(0));
nmod_poly_cos_series(cosA, A, n);
nmod_poly_sin_series(sinA, A, n);
nmod_poly_mullow(B, cosA, cosA, n);
nmod_poly_set_coeff_ui(one, 0, UWORD(1));
nmod_poly_sub(B, one, B);
nmod_poly_mullow(C, sinA, sinA, n);
result = nmod_poly_equal(B, C);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("n = %wd, mod = %wu\n", n, mod);
flint_printf("A: "); nmod_poly_print(A), flint_printf("\n\n");
flint_printf("cos(A): "); nmod_poly_print(cosA), flint_printf("\n\n");
flint_printf("1-cos(A)^2: "); nmod_poly_print(B), flint_printf("\n\n");
flint_printf("sin(A)^2: "); nmod_poly_print(C), flint_printf("\n\n");
abort();
}
nmod_poly_clear(A);
nmod_poly_clear(cosA);
nmod_poly_clear(sinA);
nmod_poly_clear(B);
nmod_poly_clear(C);
nmod_poly_clear(one);
}
/* Check aliasing */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t A, B;
slong n;
mp_limb_t mod;
mod = n_randtest_prime(state, 0);
n = n_randtest(state) % 50;
n = FLINT_MIN(n, mod);
nmod_poly_init(A, mod);
nmod_poly_init(B, mod);
nmod_poly_randtest(A, state, n_randint(state, 50));
nmod_poly_set_coeff_ui(A, 0, UWORD(0));
nmod_poly_cos_series(B, A, n);
nmod_poly_cos_series(A, A, n);
result = nmod_poly_equal(A, B);
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(A), flint_printf("\n\n");
nmod_poly_print(B), flint_printf("\n\n");
abort();
}
nmod_poly_clear(A);
nmod_poly_clear(B);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

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 (C) 2010 William Hart
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result = 1;
FLINT_TEST_INIT(state);
flint_printf("cosh_series....");
fflush(stdout);
/* Check cosh(A)^2-1 = sinh(A)^2 */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t A, coshA, sinhA, B, C, one;
slong n;
mp_limb_t mod;
do { mod = n_randtest_prime(state, 0); } while (mod == 2);
n = 1 + n_randtest(state) % 100;
n = FLINT_MIN(n, mod);
nmod_poly_init(A, mod);
nmod_poly_init(coshA, mod);
nmod_poly_init(sinhA, mod);
nmod_poly_init(B, mod);
nmod_poly_init(C, mod);
nmod_poly_init(one, mod);
nmod_poly_randtest(A, state, n_randint(state, 100));
nmod_poly_set_coeff_ui(A, 0, UWORD(0));
nmod_poly_cosh_series(coshA, A, n);
nmod_poly_sinh_series(sinhA, A, n);
nmod_poly_mullow(B, coshA, coshA, n);
nmod_poly_set_coeff_ui(one, 0, UWORD(1));
nmod_poly_sub(B, B, one);
nmod_poly_mullow(C, sinhA, sinhA, n);
result = nmod_poly_equal(B, C);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("n = %wd, mod = %wu\n", n, mod);
flint_printf("A: "); nmod_poly_print(A), flint_printf("\n\n");
flint_printf("cosh(A): "); nmod_poly_print(coshA), flint_printf("\n\n");
flint_printf("cosh(A)^2-1: "); nmod_poly_print(B), flint_printf("\n\n");
flint_printf("sinh(A)^2: "); nmod_poly_print(C), flint_printf("\n\n");
abort();
}
nmod_poly_clear(A);
nmod_poly_clear(coshA);
nmod_poly_clear(sinhA);
nmod_poly_clear(B);
nmod_poly_clear(C);
nmod_poly_clear(one);
}
/* Check aliasing */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t A, B;
slong n;
mp_limb_t mod;
mod = n_randtest_prime(state, 0);
n = n_randtest(state) % 50;
n = FLINT_MIN(n, mod);
nmod_poly_init(A, mod);
nmod_poly_init(B, mod);
nmod_poly_randtest(A, state, n_randint(state, 50));
nmod_poly_set_coeff_ui(A, 0, UWORD(0));
nmod_poly_cosh_series(B, A, n);
nmod_poly_cosh_series(A, A, n);
result = nmod_poly_equal(A, B);
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(A), flint_printf("\n\n");
nmod_poly_print(B), flint_printf("\n\n");
abort();
}
nmod_poly_clear(A);
nmod_poly_clear(B);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,121 @@
/*=============================================================================
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 "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int iter;
FLINT_TEST_INIT(state);
flint_printf("deflate....");
fflush(stdout);
for (iter = 0; iter < 100 * flint_test_multiplier(); iter++)
{
nmod_poly_t poly1, poly2, poly3;
mp_limb_t modulus;
ulong infl1, infl, deflation;
modulus = n_randtest_prime(state, 0);
nmod_poly_init(poly1, modulus);
nmod_poly_init(poly2, modulus);
nmod_poly_init(poly3, modulus);
nmod_poly_randtest(poly1, state, n_randint(state, 15));
if (nmod_poly_length(poly1) <= 1)
{
if (nmod_poly_deflation(poly1) != nmod_poly_length(poly1))
{
flint_printf("FAIL: wrong deflation for constant polynomial\n");
abort();
}
nmod_poly_deflate(poly2, poly1, n_randint(state, 5) + 1);
if (!nmod_poly_equal(poly2, poly1))
{
flint_printf("FAIL: constant polynomial changed on deflation\n");
abort();
}
}
else
{
infl = n_randint(state, 13) + 1;
infl1 = nmod_poly_deflation(poly1);
nmod_poly_inflate(poly2, poly1, infl);
deflation = nmod_poly_deflation(poly2);
if (deflation != infl * infl1)
{
flint_printf("FAIL: deflation = %wu, inflation: %wu, %wu\n",
deflation, infl, infl1);
flint_printf("poly1:\n"); nmod_poly_print(poly1); flint_printf("\n\n");
flint_printf("poly2:\n"); nmod_poly_print(poly2); flint_printf("\n\n");
abort();
}
nmod_poly_deflate(poly3, poly2, infl);
if (!nmod_poly_equal(poly3, poly1))
{
flint_printf("FAIL: deflation = %wu, inflation: %wu, %wu\n",
deflation, infl, infl1);
flint_printf("Deflated polynomial not equal to input:\n");
flint_printf("poly1:\n"); nmod_poly_print(poly1); flint_printf("\n\n");
flint_printf("poly2:\n"); nmod_poly_print(poly2); flint_printf("\n\n");
flint_printf("poly3:\n"); nmod_poly_print(poly2); flint_printf("\n\n");
abort();
}
nmod_poly_deflate(poly2, poly2, infl);
if (!nmod_poly_equal(poly3, poly2))
{
flint_printf("FAIL: aliasing\n");
abort();
}
}
nmod_poly_clear(poly1);
nmod_poly_clear(poly2);
nmod_poly_clear(poly3);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,118 @@
/*=============================================================================
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 <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
#include "fmpz.h"
int
main(void)
{
int i, j, result = 1;
fmpz_t t;
FLINT_TEST_INIT(state);
flint_printf("derivative....");
fflush(stdout);
fmpz_init(t);
/* Check derivative by hand */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_randtest(a, state, n_randint(state, 100));
nmod_poly_derivative(b, a);
if (a->length <= 1)
result = (b->length == 0);
else
{
for (j = 1; j < a->length; j++)
{
fmpz_set_ui(t, nmod_poly_get_coeff_ui(a, j));
fmpz_mul_ui(t, t, j);
fmpz_mod_ui(t, t, n);
result &= (fmpz_get_ui(t) == nmod_poly_get_coeff_ui(b, j - 1));
}
}
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a->length = %wd, n = %wu\n", a->length, a->mod.n);
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
}
fmpz_clear(t);
/* Check aliasing */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_randtest(a, state, n_randint(state, 100));
nmod_poly_derivative(b, a);
nmod_poly_derivative(a, a);
result = nmod_poly_equal(a, b);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a->length = %wd, n = %wu\n", a->length, a->mod.n);
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,158 @@
/*=============================================================================
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 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("div....");
fflush(stdout);
/* Check result of div against divrem */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q, r, q2;
mp_limb_t n;
do n = n_randtest_not_zero(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
nmod_poly_init(q2, n);
nmod_poly_randtest(a, state, n_randint(state, 2000));
do nmod_poly_randtest(b, state, n_randint(state, 2000));
while (b->length == 0);
nmod_poly_divrem(q, r, a, b);
nmod_poly_div(q2, a, b);
result = (nmod_poly_equal(q, q2));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(q2), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
nmod_poly_clear(r);
nmod_poly_clear(q2);
}
/* Check aliasing of a and q */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_randtest(a, state, n_randint(state, 2000));
do nmod_poly_randtest(b, state, n_randint(state, 2000));
while (b->length == 0);
nmod_poly_div(q, a, b);
nmod_poly_div(a, a, b);
result = (nmod_poly_equal(a, q));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
}
/* Check aliasing of b and q */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_randtest(a, state, n_randint(state, 2000));
do nmod_poly_randtest(b, state, n_randint(state, 2000));
while (b->length == 0);
nmod_poly_div(q, a, b);
nmod_poly_div(b, a, b);
result = (nmod_poly_equal(b, q));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,168 @@
/*=============================================================================
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 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("div_basecase....");
fflush(stdout);
/* Check result of div against divrem */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q, r, q2;
mp_limb_t n;
do
{
n = n_randtest_not_zero(state);
} while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
nmod_poly_init(q2, n);
nmod_poly_randtest(a, state, n_randint(state, 200));
do nmod_poly_randtest(b, state, n_randint(state, 200));
while (b->length == 0);
nmod_poly_divrem_basecase(q, r, a, b);
nmod_poly_div_basecase(q2, a, b);
result = (nmod_poly_equal(q, q2));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(q2), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
nmod_poly_clear(r);
nmod_poly_clear(q2);
}
/* Check aliasing of a and q */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q;
mp_limb_t n;
do
{
n = n_randtest(state);
} while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_randtest(a, state, n_randint(state, 200));
do
{
nmod_poly_randtest(b, state, n_randint(state, 200));
} while (b->length == 0);
nmod_poly_div_basecase(q, a, b);
nmod_poly_div_basecase(a, a, b);
result = (nmod_poly_equal(a, q));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
}
/* Check aliasing of b and q */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q;
mp_limb_t n;
do
{
n = n_randtest(state);
} while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_randtest(a, state, n_randint(state, 200));
do
{
nmod_poly_randtest(b, state, n_randint(state, 200));
} while (b->length == 0);
nmod_poly_div_basecase(q, a, b);
nmod_poly_div_basecase(b, a, b);
result = (nmod_poly_equal(b, q));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,158 @@
/*=============================================================================
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 <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("div_divconquer....");
fflush(stdout);
/* Check result of div against divrem */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q, q2, r;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_init(q2, n);
nmod_poly_init(r, n);
nmod_poly_randtest(a, state, n_randint(state, 2000));
do nmod_poly_randtest(b, state, n_randint(state, 2000));
while (b->length == 0);
nmod_poly_divrem_divconquer(q, r, a, b);
nmod_poly_div_divconquer(q2, a, b);
result = (nmod_poly_equal(q, q2));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(q2), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
nmod_poly_clear(r);
nmod_poly_clear(q2);
}
/* Check aliasing of a and q */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_randtest(a, state, n_randint(state, 2000));
do nmod_poly_randtest(b, state, n_randint(state, 2000));
while (b->length == 0);
nmod_poly_div_divconquer(q, a, b);
nmod_poly_div_divconquer(a, a, b);
result = (nmod_poly_equal(a, q));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
}
/* Check aliasing of b and q */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_randtest(a, state, n_randint(state, 2000));
do nmod_poly_randtest(b, state, n_randint(state, 2000));
while (b->length == 0);
nmod_poly_div_divconquer(q, a, b);
nmod_poly_div_divconquer(b, a, b);
result = (nmod_poly_equal(b, q));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,158 @@
/*=============================================================================
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 <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("div_newton....");
fflush(stdout);
/* Check result of div against divrem */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q, q2, r;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_init(q2, n);
nmod_poly_init(r, n);
nmod_poly_randtest(a, state, n_randint(state, 2000));
do nmod_poly_randtest(b, state, n_randint(state, 2000));
while (b->length == 0);
nmod_poly_divrem_divconquer(q, r, a, b);
nmod_poly_div_newton(q2, a, b);
result = (nmod_poly_equal(q, q2));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(q2), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
nmod_poly_clear(r);
nmod_poly_clear(q2);
}
/* Check aliasing of a and q */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_randtest(a, state, n_randint(state, 2000));
do nmod_poly_randtest(b, state, n_randint(state, 2000));
while (b->length == 0);
nmod_poly_div_newton(q, a, b);
nmod_poly_div_newton(a, a, b);
result = (nmod_poly_equal(a, q));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
}
/* Check aliasing of b and q */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_randtest(a, state, n_randint(state, 2000));
do nmod_poly_randtest(b, state, n_randint(state, 2000));
while (b->length == 0);
nmod_poly_div_newton(q, a, b);
nmod_poly_div_newton(b, a, b);
result = (nmod_poly_equal(b, q));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,235 @@
/*=============================================================================
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) 2013 Martin Lee
******************************************************************************/
#undef ulong
#define ulong ulongxx/* interferes with system includes */
#include <stdlib.h>
#include <stdio.h>
#undef ulong
#include <gmp.h>
#define ulong mp_limb_t
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("div_newton_n_preinv....");
fflush(stdout);
/* Check result of divrem */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, binv, q, r, test;
mp_limb_t n;
do n = n_randtest_not_zero(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(binv, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
nmod_poly_init(test, n);
do
nmod_poly_randtest(b, state, n_randint(state, 200));
while (b->length <= 2);
nmod_poly_randtest(a, state, n_randint(state, 200));
if (a->length > 2*(b->length)-3)
nmod_poly_truncate (a, 2*(b->length)-3);
nmod_poly_reverse (binv, b, b->length);
nmod_poly_inv_series (binv, binv, b->length);
nmod_poly_div_newton_n_preinv(q, a, b, binv);
nmod_poly_divrem (test, r, a, b);
result = (nmod_poly_equal(q, test));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(test), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(binv);
nmod_poly_clear(q);
nmod_poly_clear(r);
nmod_poly_clear(test);
}
/* Check aliasing of a and q */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, binv, q;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(binv, n);
nmod_poly_init(q, n);
do
nmod_poly_randtest(b, state, n_randint(state, 200));
while (b->length <= 2);
nmod_poly_randtest(a, state, n_randint(state, 200));
if (a->length > 2*(b->length)-3)
nmod_poly_truncate (a, 2*(b->length)-3);
nmod_poly_reverse (binv, b, b->length);
nmod_poly_inv_series (binv, binv, b->length);
nmod_poly_div_newton_n_preinv(q, a, b, binv);
nmod_poly_div_newton_n_preinv(a, a, b, binv);
result = (nmod_poly_equal(a, q));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(binv);
nmod_poly_clear(q);
}
/* Check aliasing of b and q */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, binv, q;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(binv, n);
nmod_poly_init(q, n);
do
nmod_poly_randtest(b, state, n_randint(state, 200));
while (b->length <= 2);
nmod_poly_randtest(a, state, n_randint(state, 200));
if (a->length > 2*(b->length)-3)
nmod_poly_truncate (a, 2*(b->length)-3);
nmod_poly_reverse (binv, b, b->length);
nmod_poly_inv_series (binv, binv, b->length);
nmod_poly_div_newton_n_preinv(q, a, b, binv);
nmod_poly_div_newton_n_preinv(b, a, b, binv);
result = (nmod_poly_equal(b, q));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(binv);
nmod_poly_clear(q);
}
/* Check aliasing of binv and q */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, binv, q;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(binv, n);
nmod_poly_init(q, n);
do
nmod_poly_randtest(b, state, n_randint(state, 200));
while (b->length <= 2);
nmod_poly_randtest(a, state, n_randint(state, 200));
if (a->length > 2*(b->length)-3)
nmod_poly_truncate (a, 2*(b->length)-3);
nmod_poly_reverse (binv, b, b->length);
nmod_poly_inv_series (binv, binv, b->length);
nmod_poly_div_newton_n_preinv(q, a, b, binv);
nmod_poly_div_newton_n_preinv(binv, a, b, binv);
result = (nmod_poly_equal(binv, q));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(binv), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(binv);
nmod_poly_clear(q);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,133 @@
/*=============================================================================
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 "ulong_extras.h"
#include "nmod_vec.h"
#include "nmod_poly.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("div_root....");
fflush(stdout);
/* Compare with standard divrem */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t P, Q, D, DQ, DR;
mp_limb_t mod, r, rem;
slong n;
mod = n_randtest_prime(state, 0);
n = n_randint(state, 100);
r = n_randint(state, mod);
nmod_poly_init(P, mod);
nmod_poly_init(Q, mod);
nmod_poly_init(D, mod);
nmod_poly_init(DQ, mod);
nmod_poly_init(DR, mod);
nmod_poly_randtest(P, state, n);
rem = nmod_poly_div_root(Q, P, r);
nmod_poly_set_coeff_ui(D, 0, n_negmod(r, mod));
nmod_poly_set_coeff_ui(D, 1, UWORD(1));
nmod_poly_divrem(DQ, DR, P, D);
result = nmod_poly_equal(Q, DQ) &&
(rem == nmod_poly_get_coeff_ui(DR, 0));
if (!result)
{
flint_printf("FAIL!\n");
flint_printf("P:\n"); nmod_poly_print(P); flint_printf("\n\n");
flint_printf("Q:\n"); nmod_poly_print(Q); flint_printf("\n\n");
flint_printf("D:\n"); nmod_poly_print(D); flint_printf("\n\n");
flint_printf("DQ:\n"); nmod_poly_print(DQ); flint_printf("\n\n");
flint_printf("DR:\n"); nmod_poly_print(DR); flint_printf("\n\n");
abort();
}
nmod_poly_clear(P);
nmod_poly_clear(Q);
nmod_poly_clear(D);
nmod_poly_clear(DQ);
nmod_poly_clear(DR);
}
/* Check aliasing */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t P, Q1, Q2;
mp_limb_t mod, r, rem1, rem2;
slong n;
mod = n_randtest_prime(state, 0);
n = n_randint(state, 100);
r = n_randint(state, mod);
nmod_poly_init(P, mod);
nmod_poly_init(Q1, mod);
nmod_poly_init(Q2, mod);
nmod_poly_randtest(P, state, n);
nmod_poly_set(Q2, P);
rem1 = nmod_poly_div_root(Q1, P, r);
rem2 = nmod_poly_div_root(Q2, Q2, r);
result = nmod_poly_equal(Q1, Q2) && (rem1 == rem2);
if (!result)
{
flint_printf("FAIL (aliasing)!\n");
flint_printf("P:\n"); nmod_poly_print(P); flint_printf("\n\n");
flint_printf("Q1:\n"); nmod_poly_print(Q1); flint_printf("\n\n");
flint_printf("Q2:\n"); nmod_poly_print(Q2); flint_printf("\n\n");
abort();
}
nmod_poly_clear(P);
nmod_poly_clear(Q1);
nmod_poly_clear(Q2);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,168 @@
/*=============================================================================
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 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("div_series....");
fflush(stdout);
/* Check A/B * B = A */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t q, a, b, prod;
slong m;
mp_limb_t n;
do n = n_randtest_not_zero(state);
while (!n_is_probabprime(n));
nmod_poly_init(prod, n);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_randtest(a, state, n_randint(state, 2000));
do nmod_poly_randtest(b, state, n_randint(state, 2000));
while (b->length == 0 || b->coeffs[0] == 0);
m = n_randint(state, 2000) + 1;
nmod_poly_div_series(q, a, b, m);
nmod_poly_mullow(prod, q, b, m);
nmod_poly_truncate(a, m);
result = (nmod_poly_equal(a, prod));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(prod), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(q);
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(prod);
}
/* Check aliasing of q and a */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t q, a, b;
slong m;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(q, n);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_randtest(a, state, n_randint(state, 1000));
do nmod_poly_randtest(b, state, n_randint(state, 1000));
while (b->length == 0 || b->coeffs[0] == 0);
m = n_randint(state, 1000) + 1;
nmod_poly_div_series(q, a, b, m);
nmod_poly_div_series(a, a, b, m);
result = (nmod_poly_equal(q, a));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(a), flint_printf("\n\n");
flint_printf("n = %wd, m = %wd\n", n, m);
abort();
}
nmod_poly_clear(q);
nmod_poly_clear(a);
nmod_poly_clear(b);
}
/* Check aliasing of q and b */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t q, a, b;
slong m;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(q, n);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_randtest(a, state, n_randint(state, 1000));
do nmod_poly_randtest(b, state, n_randint(state, 1000));
while (b->length == 0 || b->coeffs[0] == 0);
m = n_randint(state, 1000) + 1;
nmod_poly_div_series(q, a, b, m);
nmod_poly_div_series(b, a, b, m);
result = (nmod_poly_equal(q, b));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
flint_printf("n = %wd, m = %wd\n", n, m);
abort();
}
nmod_poly_clear(q);
nmod_poly_clear(a);
nmod_poly_clear(b);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,327 @@
/*=============================================================================
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 <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("divrem....");
fflush(stdout);
/* Check result of divrem */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q, r, prod;
mp_limb_t n;
do n = n_randtest_not_zero(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
nmod_poly_init(prod, n);
nmod_poly_randtest(a, state, n_randint(state, 2000));
do nmod_poly_randtest(b, state, n_randint(state, 2000));
while (b->length == 0);
nmod_poly_divrem(q, r, a, b);
nmod_poly_mul(prod, q, b);
nmod_poly_add(prod, prod, r);
result = (nmod_poly_equal(a, prod));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(prod), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
nmod_poly_clear(r);
nmod_poly_clear(prod);
}
/* Check aliasing of a and q */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q, r;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
nmod_poly_randtest(a, state, n_randint(state, 2000));
do nmod_poly_randtest(b, state, n_randint(state, 2000));
while (b->length == 0);
nmod_poly_divrem(q, r, a, b);
nmod_poly_divrem(a, r, a, b);
result = (nmod_poly_equal(a, q));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
nmod_poly_clear(r);
}
/* Check aliasing of b and q */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q, r;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
nmod_poly_randtest(a, state, n_randint(state, 2000));
do nmod_poly_randtest(b, state, n_randint(state, 2000));
while (b->length == 0);
nmod_poly_divrem(q, r, a, b);
nmod_poly_divrem(b, r, a, b);
result = (nmod_poly_equal(b, q));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
nmod_poly_clear(r);
}
/* Check aliasing of a and r */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q, r;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
nmod_poly_randtest(a, state, n_randint(state, 2000));
do nmod_poly_randtest(b, state, n_randint(state, 2000));
while (b->length == 0);
nmod_poly_divrem(q, r, a, b);
nmod_poly_divrem(q, a, a, b);
result = (nmod_poly_equal(a, r));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
nmod_poly_clear(r);
}
/* Check aliasing of b and r */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q, r;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
nmod_poly_randtest(a, state, n_randint(state, 2000));
do nmod_poly_randtest(b, state, n_randint(state, 2000));
while (b->length == 0);
nmod_poly_divrem(q, r, a, b);
nmod_poly_divrem(q, b, a, b);
result = (nmod_poly_equal(b, r));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
nmod_poly_clear(r);
}
/* Check result of divrem_q0 */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q, r, prod;
mp_limb_t n = n_randprime(state, n_randint(state,FLINT_BITS-1)+2, 0);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
nmod_poly_init(prod, n);
do nmod_poly_randtest(a, state, n_randint(state, 400));
while (a->length < 1);
nmod_poly_randtest(b, state, a->length);
do b->coeffs[a->length - 1] = n_randint(state, n);
while (b->coeffs[a->length - 1] == 0);
b->length = a->length;
nmod_poly_divrem(q, r, a, b);
nmod_poly_mul(prod, q, b);
nmod_poly_add(prod, prod, r);
result = (nmod_poly_equal(a, prod) && r->length < b->length);
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(prod), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
nmod_poly_clear(r);
nmod_poly_clear(prod);
}
/* Check result of divrem_q1 */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q, r, prod;
mp_limb_t n = n_randprime(state, n_randint(state,FLINT_BITS-1)+2, 0);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
nmod_poly_init(prod, n);
do nmod_poly_randtest(a, state, n_randint(state, 1000));
while (a->length < 2);
nmod_poly_fit_length(b, a->length - 1);
flint_mpn_zero(b->coeffs, a->length - 1);
nmod_poly_randtest_not_zero(b, state, n_randint(state, 1000) + 1);
do b->coeffs[a->length - 2] = n_randint(state, n);
while (b->coeffs[a->length - 2] == 0);
b->length = a->length - 1;
nmod_poly_divrem(q, r, a, b);
nmod_poly_mul(prod, q, b);
nmod_poly_add(prod, prod, r);
result = (nmod_poly_equal(a, prod) && r->length < b->length);
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(prod), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
nmod_poly_clear(r);
nmod_poly_clear(prod);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,261 @@
/*=============================================================================
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 <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("divrem_basecase....");
fflush(stdout);
/* Check result of divrem */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q, r, prod;
mp_limb_t n;
do
{
n = n_randtest_not_zero(state);
} while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
nmod_poly_init(prod, n);
nmod_poly_randtest(a, state, n_randint(state, 200));
do
{
nmod_poly_randtest(b, state, n_randint(state, 200));
} while (b->length == 0);
nmod_poly_divrem_basecase(q, r, a, b);
nmod_poly_mul(prod, q, b);
nmod_poly_add(prod, prod, r);
result = (nmod_poly_equal(a, prod));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(prod), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
nmod_poly_clear(r);
nmod_poly_clear(prod);
}
/* Check aliasing of a and q */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q, r;
mp_limb_t n;
do
{
n = n_randtest(state);
} while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
nmod_poly_randtest(a, state, n_randint(state, 200));
do
{
nmod_poly_randtest(b, state, n_randint(state, 200));
} while (b->length == 0);
nmod_poly_divrem_basecase(q, r, a, b);
nmod_poly_divrem_basecase(a, r, a, b);
result = (nmod_poly_equal(a, q));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
nmod_poly_clear(r);
}
/* Check aliasing of b and q */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q, r;
mp_limb_t n;
do
{
n = n_randtest(state);
} while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
nmod_poly_randtest(a, state, n_randint(state, 200));
do
{
nmod_poly_randtest(b, state, n_randint(state, 200));
} while (b->length == 0);
nmod_poly_divrem_basecase(q, r, a, b);
nmod_poly_divrem_basecase(b, r, a, b);
result = (nmod_poly_equal(b, q));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
nmod_poly_clear(r);
}
/* Check aliasing of a and r */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q, r;
mp_limb_t n;
do
{
n = n_randtest(state);
} while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
nmod_poly_randtest(a, state, n_randint(state, 200));
do
{
nmod_poly_randtest(b, state, n_randint(state, 200));
} while (b->length == 0);
nmod_poly_divrem_basecase(q, r, a, b);
nmod_poly_divrem_basecase(q, a, a, b);
result = (nmod_poly_equal(a, r));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
nmod_poly_clear(r);
}
/* Check aliasing of b and r */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q, r;
mp_limb_t n;
do
{
n = n_randtest(state);
} while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
nmod_poly_randtest(a, state, n_randint(state, 200));
do
{
nmod_poly_randtest(b, state, n_randint(state, 200));
} while (b->length == 0);
nmod_poly_divrem_basecase(q, r, a, b);
nmod_poly_divrem_basecase(q, b, a, b);
result = (nmod_poly_equal(b, r));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
nmod_poly_clear(r);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,241 @@
/*=============================================================================
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 <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("divrem_divconquer....");
fflush(stdout);
/* Check result of divrem */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q, r, prod;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
nmod_poly_init(prod, n);
nmod_poly_randtest(a, state, n_randint(state, 2000));
do nmod_poly_randtest(b, state, n_randint(state, 2000));
while (b->length == 0);
nmod_poly_divrem_divconquer(q, r, a, b);
nmod_poly_mul(prod, q, b);
nmod_poly_add(prod, prod, r);
result = (nmod_poly_equal(a, prod));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(prod), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
nmod_poly_clear(r);
nmod_poly_clear(prod);
}
/* Check aliasing of a and q */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q, r;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
nmod_poly_randtest(a, state, n_randint(state, 2000));
do nmod_poly_randtest(b, state, n_randint(state, 2000));
while (b->length == 0);
nmod_poly_divrem_divconquer(q, r, a, b);
nmod_poly_divrem_divconquer(a, r, a, b);
result = (nmod_poly_equal(a, q));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
nmod_poly_clear(r);
}
/* Check aliasing of b and q */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q, r;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
nmod_poly_randtest(a, state, n_randint(state, 2000));
do nmod_poly_randtest(b, state, n_randint(state, 2000));
while (b->length == 0);
nmod_poly_divrem_divconquer(q, r, a, b);
nmod_poly_divrem_divconquer(b, r, a, b);
result = (nmod_poly_equal(b, q));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
nmod_poly_clear(r);
}
/* Check aliasing of a and r */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q, r;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
nmod_poly_randtest(a, state, n_randint(state, 2000));
do nmod_poly_randtest(b, state, n_randint(state, 2000));
while (b->length == 0);
nmod_poly_divrem_divconquer(q, r, a, b);
nmod_poly_divrem_divconquer(q, a, a, b);
result = (nmod_poly_equal(a, r));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
nmod_poly_clear(r);
}
/* Check aliasing of b and r */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q, r;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
nmod_poly_randtest(a, state, n_randint(state, 2000));
do nmod_poly_randtest(b, state, n_randint(state, 2000));
while (b->length == 0);
nmod_poly_divrem_divconquer(q, r, a, b);
nmod_poly_divrem_divconquer(q, b, a, b);
result = (nmod_poly_equal(b, r));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
nmod_poly_clear(r);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,241 @@
/*=============================================================================
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 <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("divrem_newton....");
fflush(stdout);
/* Check result of divrem */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q, r, prod;
mp_limb_t n;
do n = n_randtest_not_zero(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
nmod_poly_init(prod, n);
nmod_poly_randtest(a, state, n_randint(state, 200));
do nmod_poly_randtest(b, state, n_randint(state, 200));
while (b->length == 0);
nmod_poly_divrem_newton(q, r, a, b);
nmod_poly_mul(prod, q, b);
nmod_poly_add(prod, prod, r);
result = (nmod_poly_equal(a, prod));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(prod), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
nmod_poly_clear(r);
nmod_poly_clear(prod);
}
/* Check aliasing of a and q */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q, r;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
nmod_poly_randtest(a, state, n_randint(state, 200));
do nmod_poly_randtest(b, state, n_randint(state, 200));
while (b->length == 0);
nmod_poly_divrem_newton(q, r, a, b);
nmod_poly_divrem_newton(a, r, a, b);
result = (nmod_poly_equal(a, q));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
nmod_poly_clear(r);
}
/* Check aliasing of b and q */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q, r;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
nmod_poly_randtest(a, state, n_randint(state, 200));
do nmod_poly_randtest(b, state, n_randint(state, 200));
while (b->length == 0);
nmod_poly_divrem_newton(q, r, a, b);
nmod_poly_divrem_newton(b, r, a, b);
result = (nmod_poly_equal(b, q));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
nmod_poly_clear(r);
}
/* Check aliasing of a and r */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q, r;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
nmod_poly_randtest(a, state, n_randint(state, 200));
do nmod_poly_randtest(b, state, n_randint(state, 200));
while (b->length == 0);
nmod_poly_divrem_newton(q, r, a, b);
nmod_poly_divrem_newton(q, a, a, b);
result = (nmod_poly_equal(a, r));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
nmod_poly_clear(r);
}
/* Check aliasing of b and r */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q, r;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
nmod_poly_randtest(a, state, n_randint(state, 200));
do nmod_poly_randtest(b, state, n_randint(state, 200));
while (b->length == 0);
nmod_poly_divrem_newton(q, r, a, b);
nmod_poly_divrem_newton(q, b, a, b);
result = (nmod_poly_equal(b, r));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
nmod_poly_clear(r);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,385 @@
/*=============================================================================
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) 2013 Martin Lee
******************************************************************************/
#undef ulong
#define ulong ulongxx/* interferes with system includes */
#include <stdlib.h>
#include <stdio.h>
#undef ulong
#include <gmp.h>
#define ulong mp_limb_t
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("divrem_newton_n_preinv....");
fflush(stdout);
/* Check result of divrem */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, binv, q, r, test;
mp_limb_t n;
do n = n_randtest_not_zero(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(binv, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
nmod_poly_init(test, n);
do
nmod_poly_randtest(b, state, n_randint(state, 200));
while (b->length <= 2);
nmod_poly_randtest(a, state, n_randint(state, 200));
if (a->length > 2*(b->length)-3)
nmod_poly_truncate (a, 2*(b->length)-3);
nmod_poly_reverse (binv, b, b->length);
nmod_poly_inv_series (binv, binv, b->length);
nmod_poly_divrem_newton_n_preinv(q, r, a, b, binv);
nmod_poly_mul(test, q, b);
nmod_poly_add(test, test, r);
result = (nmod_poly_equal(a, test));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(test), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(binv);
nmod_poly_clear(q);
nmod_poly_clear(r);
nmod_poly_clear(test);
}
/* Check aliasing of a and q */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, binv, q, r;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(binv, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
do
nmod_poly_randtest(b, state, n_randint(state, 200));
while (b->length <= 2);
nmod_poly_randtest(a, state, n_randint(state, 200));
if (a->length > 2*(b->length)-3)
nmod_poly_truncate (a, 2*(b->length)-3);
nmod_poly_reverse (binv, b, b->length);
nmod_poly_inv_series (binv, binv, b->length);
nmod_poly_divrem_newton_n_preinv(q, r, a, b, binv);
nmod_poly_divrem_newton_n_preinv(a, r, a, b, binv);
result = (nmod_poly_equal(a, q));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(binv);
nmod_poly_clear(q);
nmod_poly_clear(r);
}
/* Check aliasing of b and q */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, binv, q, r;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(binv, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
do
nmod_poly_randtest(b, state, n_randint(state, 200));
while (b->length <= 2);
nmod_poly_randtest(a, state, n_randint(state, 200));
if (a->length > 2*(b->length)-3)
nmod_poly_truncate (a, 2*(b->length)-3);
nmod_poly_reverse (binv, b, b->length);
nmod_poly_inv_series (binv, binv, b->length);
nmod_poly_divrem_newton_n_preinv(q, r, a, b, binv);
nmod_poly_divrem_newton_n_preinv(b, r, a, b, binv);
result = (nmod_poly_equal(b, q));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(binv);
nmod_poly_clear(q);
nmod_poly_clear(r);
}
/* Check aliasing of binv and q */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, binv, q, r;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(binv, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
do
nmod_poly_randtest(b, state, n_randint(state, 200));
while (b->length <= 2);
nmod_poly_randtest(a, state, n_randint(state, 200));
if (a->length > 2*(b->length)-3)
nmod_poly_truncate (a, 2*(b->length)-3);
nmod_poly_reverse (binv, b, b->length);
nmod_poly_inv_series (binv, binv, b->length);
nmod_poly_divrem_newton_n_preinv(q, r, a, b, binv);
nmod_poly_divrem_newton_n_preinv(binv, r, a, b, binv);
result = (nmod_poly_equal(binv, q));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(binv), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(binv);
nmod_poly_clear(q);
nmod_poly_clear(r);
}
/* Check aliasing of a and r */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, binv, q, r;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(binv, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
do
nmod_poly_randtest(b, state, n_randint(state, 200));
while (b->length <= 2);
nmod_poly_randtest(a, state, n_randint(state, 200));
if (a->length > 2*(b->length)-3)
nmod_poly_truncate (a, 2*(b->length)-3);
nmod_poly_reverse (binv, b, b->length);
nmod_poly_inv_series (binv, binv, b->length);
nmod_poly_divrem_newton_n_preinv(q, r, a, b, binv);
nmod_poly_divrem_newton_n_preinv(q, a, a, b, binv);
result = (nmod_poly_equal(a, r));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(binv);
nmod_poly_clear(q);
nmod_poly_clear(r);
}
/* Check aliasing of b and r */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, binv, q, r;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(binv, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
do
nmod_poly_randtest(b, state, n_randint(state, 200));
while (b->length <= 2);
nmod_poly_randtest(a, state, n_randint(state, 200));
if (a->length > 2*(b->length)-3)
nmod_poly_truncate (a, 2*(b->length)-3);
nmod_poly_reverse (binv, b, b->length);
nmod_poly_inv_series (binv, binv, b->length);
nmod_poly_divrem_newton_n_preinv(q, r, a, b, binv);
nmod_poly_divrem_newton_n_preinv(q, b, a, b, binv);
result = (nmod_poly_equal(b, r));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(binv);
nmod_poly_clear(q);
nmod_poly_clear(r);
}
/* Check aliasing of binv and r */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, binv, q, r;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(binv, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
do
nmod_poly_randtest(b, state, n_randint(state, 200));
while (b->length <= 2);
nmod_poly_randtest(a, state, n_randint(state, 200));
if (a->length > 2*(b->length)-3)
nmod_poly_truncate (a, 2*(b->length)-3);
nmod_poly_reverse (binv, b, b->length);
nmod_poly_inv_series (binv, binv, b->length);
nmod_poly_divrem_newton_n_preinv(q, r, a, b, binv);
nmod_poly_divrem_newton_n_preinv(q, binv, a, b, binv);
result = (nmod_poly_equal(binv, r));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(binv), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(binv);
nmod_poly_clear(q);
nmod_poly_clear(r);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

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) 2010 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
#include "fmpz.h"
int
main(void)
{
int i, j, result = 1;
FLINT_TEST_INIT(state);
flint_printf("evaluate_nmod....");
fflush(stdout);
/* Check evaluation at 1 gives sum of coeffs */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a;
mp_limb_t n = n_randtest_not_zero(state);
mp_limb_t sum, eval;
nmod_poly_init(a, n);
nmod_poly_randtest(a, state, n_randint(state, 100));
eval = nmod_poly_evaluate_nmod(a, 1);
sum = 0;
for (j = 0; j < a->length; j++)
sum = n_addmod(sum, nmod_poly_get_coeff_ui(a, j), n);
result = (sum == eval);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a->length = %wd, n = %wu\n", a->length, a->mod.n);
flint_printf("sum = %wu, eval = %wu\n", sum, eval);
nmod_poly_print(a), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
}
/* Check a(c) + b(c) = (a + b)(c) */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b;
mp_limb_t n = n_randtest_not_zero(state);
mp_limb_t eval1, eval2, c;
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_randtest(a, state, n_randint(state, 100));
nmod_poly_randtest(b, state, n_randint(state, 100));
c = n_randint(state, n);
eval1 = nmod_poly_evaluate_nmod(a, c);
eval1 = n_addmod(eval1, nmod_poly_evaluate_nmod(b, c), n);
nmod_poly_add(a, a, b);
eval2 = nmod_poly_evaluate_nmod(a, c);
result = (eval1 == eval2);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("eval1 = %wu, eval2 = %wu\n", eval1, eval2);
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
}
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) 2010 William Hart
Copyright (C) 2011, 2012 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result = 1;
FLINT_TEST_INIT(state);
flint_printf("evaluate_nmod_vec_fast....");
fflush(stdout);
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t P, Q;
mp_ptr x, y, z;
mp_limb_t mod;
slong j, n, npoints;
mod = n_randtest_prime(state, 0);
npoints = n_randint(state, 100);
n = n_randint(state, 100);
nmod_poly_init(P, mod);
nmod_poly_init(Q, mod);
x = _nmod_vec_init(npoints);
y = _nmod_vec_init(npoints);
z = _nmod_vec_init(npoints);
nmod_poly_randtest(P, state, n);
for (j = 0; j < npoints; j++)
x[j] = n_randint(state, mod);
nmod_poly_evaluate_nmod_vec_iter(y, P, x, npoints);
nmod_poly_evaluate_nmod_vec_fast(z, P, x, npoints);
result = _nmod_vec_equal(y, z, npoints);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("mod=%wu, n=%wd, npoints=%wd\n\n", mod, n, npoints);
flint_printf("P: "); nmod_poly_print(P); flint_printf("\n\n");
abort();
}
nmod_poly_clear(P);
nmod_poly_clear(Q);
_nmod_vec_clear(x);
_nmod_vec_clear(y);
_nmod_vec_clear(z);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,147 @@
/*=============================================================================
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) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result = 1;
FLINT_TEST_INIT(state);
flint_printf("exp_series....");
fflush(stdout);
/* Check exp(A+B) = exp(A) * exp(B) */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t A, B, AB, expA, expB, expAB, S;
slong n;
slong N = 100;
mp_limb_t mod;
/* Make sure to workout the Newton code */
if (n_randint(state, 10) == 1)
N = 2000;
mod = n_randtest_prime(state, 0);
n = n_randtest(state) % N;
n = FLINT_MIN(n, mod);
nmod_poly_init(A, mod);
nmod_poly_init(B, mod);
nmod_poly_init(AB, mod);
nmod_poly_init(expA, mod);
nmod_poly_init(expB, mod);
nmod_poly_init(expAB, mod);
nmod_poly_init(S, mod);
nmod_poly_randtest(A, state, n_randint(state, N));
nmod_poly_set_coeff_ui(A, 0, UWORD(0));
nmod_poly_randtest(B, state, n_randint(state, N));
nmod_poly_set_coeff_ui(B, 0, UWORD(0));
/* Randomly generate a monomial */
if (n_randlimb(state) % 100 == 0)
{
nmod_poly_zero(A);
nmod_poly_set_coeff_ui(A, n_randlimb(state) % (n+5), \
n_randtest_not_zero(state) % mod);
nmod_poly_set_coeff_ui(A, 0, UWORD(0));
}
nmod_poly_exp_series(expA, A, n);
nmod_poly_exp_series(expB, B, n);
nmod_poly_add(AB, A, B);
nmod_poly_exp_series(expAB, AB, n);
nmod_poly_mullow(S, expA, expB, n);
result = nmod_poly_equal(S, expAB);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("n = %wd, mod = %wu\n", n, mod);
flint_printf("A: "); nmod_poly_print(A), flint_printf("\n\n");
flint_printf("B: "); nmod_poly_print(B), flint_printf("\n\n");
flint_printf("exp(A): "); nmod_poly_print(expA), flint_printf("\n\n");
flint_printf("exp(B): "); nmod_poly_print(expB), flint_printf("\n\n");
flint_printf("exp(A+B): "); nmod_poly_print(expAB), flint_printf("\n\n");
flint_printf("exp(A)*exp(B): "); nmod_poly_print(S), flint_printf("\n\n");
abort();
}
nmod_poly_clear(A);
nmod_poly_clear(B);
nmod_poly_clear(AB);
nmod_poly_clear(expA);
nmod_poly_clear(expB);
nmod_poly_clear(expAB);
nmod_poly_clear(S);
}
/* Check aliasing */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t A, B;
slong n;
mp_limb_t mod;
mod = n_randtest_prime(state, 0);
n = n_randtest(state) % 50;
n = FLINT_MIN(n, mod);
nmod_poly_init(A, mod);
nmod_poly_init(B, mod);
nmod_poly_randtest(A, state, n_randint(state, 50));
nmod_poly_set_coeff_ui(A, 0, UWORD(0));
nmod_poly_exp_series(B, A, n);
nmod_poly_exp_series(A, A, n);
result = nmod_poly_equal(A, B);
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(A), flint_printf("\n\n");
nmod_poly_print(B), flint_printf("\n\n");
abort();
}
nmod_poly_clear(A);
nmod_poly_clear(B);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,141 @@
/*=============================================================================
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) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result = 1;
FLINT_TEST_INIT(state);
flint_printf("exp_series_basecase....");
fflush(stdout);
/* Check exp(A+B) = exp(A) * exp(B) */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t A, B, AB, expA, expB, expAB, S;
slong n;
mp_limb_t mod;
mod = n_randtest_prime(state, 0);
n = n_randtest(state) % 100;
n = FLINT_MIN(n, mod);
nmod_poly_init(A, mod);
nmod_poly_init(B, mod);
nmod_poly_init(AB, mod);
nmod_poly_init(expA, mod);
nmod_poly_init(expB, mod);
nmod_poly_init(expAB, mod);
nmod_poly_init(S, mod);
nmod_poly_randtest(A, state, n_randint(state, 100));
nmod_poly_set_coeff_ui(A, 0, UWORD(0));
nmod_poly_randtest(B, state, n_randint(state, 100));
nmod_poly_set_coeff_ui(B, 0, UWORD(0));
if (n_randlimb(state) % 100 == 0)
{
nmod_poly_zero(A);
nmod_poly_set_coeff_ui(A, n_randlimb(state) % (n+5), \
n_randtest_not_zero(state) % mod);
nmod_poly_set_coeff_ui(A, 0, UWORD(0));
}
nmod_poly_exp_series_basecase(expA, A, n);
nmod_poly_exp_series_basecase(expB, B, n);
nmod_poly_add(AB, A, B);
nmod_poly_exp_series(expAB, AB, n);
nmod_poly_mullow(S, expA, expB, n);
result = nmod_poly_equal(S, expAB);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("n = %wd, mod = %wu\n", n, mod);
flint_printf("A: "); nmod_poly_print(A), flint_printf("\n\n");
flint_printf("B: "); nmod_poly_print(B), flint_printf("\n\n");
flint_printf("exp(A): "); nmod_poly_print(expA), flint_printf("\n\n");
flint_printf("exp(B): "); nmod_poly_print(expB), flint_printf("\n\n");
flint_printf("exp(A+B): "); nmod_poly_print(expAB), flint_printf("\n\n");
flint_printf("exp(A)*exp(B): "); nmod_poly_print(S), flint_printf("\n\n");
abort();
}
nmod_poly_clear(A);
nmod_poly_clear(B);
nmod_poly_clear(AB);
nmod_poly_clear(expA);
nmod_poly_clear(expB);
nmod_poly_clear(expAB);
nmod_poly_clear(S);
}
/* Check aliasing */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t A, B;
slong n;
mp_limb_t mod;
mod = n_randtest_prime(state, 0);
n = n_randtest(state) % 50;
n = FLINT_MIN(n, mod);
nmod_poly_init(A, mod);
nmod_poly_init(B, mod);
nmod_poly_randtest(A, state, n_randint(state, 50));
nmod_poly_set_coeff_ui(A, 0, UWORD(0));
nmod_poly_exp_series_basecase(B, A, n);
nmod_poly_exp_series_basecase(A, A, n);
result = nmod_poly_equal(A, B);
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(A), flint_printf("\n\n");
nmod_poly_print(B), flint_printf("\n\n");
abort();
}
nmod_poly_clear(A);
nmod_poly_clear(B);
}
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) 2010 William Hart
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result = 1;
FLINT_TEST_INIT(state);
flint_printf("exp_series_monomial_ui....");
fflush(stdout);
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t A, expA, res;
slong n;
mp_limb_t mod;
ulong power;
mp_limb_t coeff;
mod = n_randtest_prime(state, 0);
n = n_randtest(state) % 100;
n = FLINT_MIN(n, mod);
nmod_poly_init(A, mod);
nmod_poly_init(expA, mod);
nmod_poly_init(res, mod);
coeff = n_randlimb(state) % mod;
power = 1 + n_randint(state, 2*n + 1);
nmod_poly_set_coeff_ui(A, power, coeff);
nmod_poly_exp_series(expA, A, n);
nmod_poly_exp_series_monomial_ui(res, coeff, power, n);
result = nmod_poly_equal(expA, res);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("n = %wd, mod = %wu\n", n, mod);
flint_printf("power = %wu, coeff = %wu\n", power, coeff);
flint_printf("A: "); nmod_poly_print(A), flint_printf("\n\n");
flint_printf("exp(A): "); nmod_poly_print(expA), flint_printf("\n\n");
flint_printf("res: "); nmod_poly_print(res), flint_printf("\n\n");
abort();
}
nmod_poly_clear(A);
nmod_poly_clear(expA);
nmod_poly_clear(res);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,106 @@
/*=============================================================================
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 <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
#if !defined (__WIN32) && !defined (__CYGWIN__)
int
main(void)
{
int i, result, r1;
FLINT_TEST_INIT(state);
flint_printf("fread_print....");
fflush(stdout);
/* Check reading and writing to a file */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b;
mp_limb_t n = n_randtest_not_zero(state);
FILE * f = fopen("nmod_poly_test", "w+");
if (!f)
{
flint_printf("Error: unable to open file for writing.\n");
abort();
}
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_randtest(a, state, n_randint(state, 100));
nmod_poly_fprint(f, a);
fflush(f);
fclose(f);
f = fopen("nmod_poly_test", "r");
r1 = nmod_poly_fread(f, b);
result = (r1 && nmod_poly_equal(a, b));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("r1 = %d, n = %wu\n", r1, a->mod.n);
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
fclose(f);
remove("nmod_poly_test");
abort();
}
fclose(f);
if (remove("nmod_poly_test"))
{
flint_printf("Error, unable to delete file nmod_poly_test\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}
#else
int main(void)
{
flint_printf("print/ read....");
fflush(stdout);
flint_printf("SKIPPED\n");
return EXIT_SUCCESS;
}
#endif

View File

@@ -0,0 +1,167 @@
/*=============================================================================
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 William Hart
Copyright (C) 2012 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("gcd....");
fflush(stdout);
/*
Find coprime polys, multiply by another poly
and check the GCD is that poly
*/
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, g;
mp_limb_t n;
do n = n_randtest_not_zero(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_init(g, n);
do {
nmod_poly_randtest(a, state, n_randint(state, 1000));
nmod_poly_randtest(b, state, n_randint(state, 1000));
nmod_poly_gcd_euclidean(g, a, b);
} while (g->length != 1);
do {
nmod_poly_randtest(c, state, n_randint(state, 1000));
} while (c->length < 2);
nmod_poly_make_monic(c, c);
nmod_poly_mul(a, a, c);
nmod_poly_mul(b, b, c);
nmod_poly_gcd_euclidean(g, a, b);
result = (nmod_poly_equal(g, c));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(c), flint_printf("\n\n");
nmod_poly_print(g), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(g);
}
/* Check aliasing of a and g */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, g;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(g, n);
nmod_poly_randtest(a, state, n_randint(state, 1000));
nmod_poly_randtest(b, state, n_randint(state, 1000));
nmod_poly_gcd_euclidean(g, a, b);
nmod_poly_gcd_euclidean(a, a, b);
result = (nmod_poly_equal(a, g));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(g), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(g);
}
/* Check aliasing of b and g */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, g;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(g, n);
nmod_poly_randtest(a, state, n_randint(state, 1000));
nmod_poly_randtest(b, state, n_randint(state, 1000));
nmod_poly_gcd_euclidean(g, a, b);
nmod_poly_gcd_euclidean(b, a, b);
result = (nmod_poly_equal(b, g));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(g), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(g);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,166 @@
/*=============================================================================
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 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("gcd_euclidean....");
fflush(stdout);
/*
Find coprime polys, multiply by another poly
and check the GCD is that poly
*/
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, g;
mp_limb_t n;
do n = n_randtest_not_zero(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_init(g, n);
do {
nmod_poly_randtest(a, state, n_randint(state, 200));
nmod_poly_randtest(b, state, n_randint(state, 200));
nmod_poly_gcd_euclidean(g, a, b);
} while (g->length != 1);
do {
nmod_poly_randtest(c, state, n_randint(state, 200));
} while (c->length < 2);
nmod_poly_make_monic(c, c);
nmod_poly_mul(a, a, c);
nmod_poly_mul(b, b, c);
nmod_poly_gcd_euclidean(g, a, b);
result = (nmod_poly_equal(g, c));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(c), flint_printf("\n\n");
nmod_poly_print(g), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(g);
}
/* Check aliasing of a and g */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, g;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(g, n);
nmod_poly_randtest(a, state, n_randint(state, 200));
nmod_poly_randtest(b, state, n_randint(state, 200));
nmod_poly_gcd_euclidean(g, a, b);
nmod_poly_gcd_euclidean(a, a, b);
result = (nmod_poly_equal(a, g));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(g), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(g);
}
/* Check aliasing of b and g */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, g;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(g, n);
nmod_poly_randtest(a, state, n_randint(state, 200));
nmod_poly_randtest(b, state, n_randint(state, 200));
nmod_poly_gcd_euclidean(g, a, b);
nmod_poly_gcd_euclidean(b, a, b);
result = (nmod_poly_equal(b, g));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(g), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(g);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,168 @@
/*=============================================================================
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 William Hart
Copyright (C) 2011 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("gcd_hgcd....");
fflush(stdout);
/*
Find coprime polys, multiply by another poly
and check the GCD is that poly
*/
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, g;
mp_limb_t n;
do n = n_randtest_not_zero(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_init(g, n);
do {
nmod_poly_randtest(a, state, n_randint(state, 1000));
nmod_poly_randtest(b, state, n_randint(state, 1000));
nmod_poly_gcd_hgcd(g, a, b);
} while (g->length != 1);
do {
nmod_poly_randtest(c, state, n_randint(state, 1000));
} while (c->length < 2);
nmod_poly_make_monic(c, c);
nmod_poly_mul(a, a, c);
nmod_poly_mul(b, b, c);
nmod_poly_gcd_hgcd(g, a, b);
result = (nmod_poly_equal(g, c));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(c), flint_printf("\n\n");
nmod_poly_print(g), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(g);
}
/* Check aliasing of a and g */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, g;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(g, n);
nmod_poly_randtest(a, state, n_randint(state, 1000));
nmod_poly_randtest(b, state, n_randint(state, 1000));
nmod_poly_gcd_hgcd(g, a, b);
nmod_poly_gcd_hgcd(a, a, b);
result = (nmod_poly_equal(a, g));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(g), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(g);
}
/* Check aliasing of b and g */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, g;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(g, n);
nmod_poly_randtest(a, state, n_randint(state, 1000));
nmod_poly_randtest(b, state, n_randint(state, 1000));
nmod_poly_gcd_hgcd(g, a, b);
nmod_poly_gcd_hgcd(b, a, b);
result = (nmod_poly_equal(b, g));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(g), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(g);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,154 @@
/*=============================================================================
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 Mike Hansen
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
printf("gcdinv....");
fflush(stdout);
/* Generic case, most likely co-prime arguments ******************************/
/* Compare with result from XGCD */
for (i = 0; i < 1000; i++)
{
mp_limb_t p;
nmod_poly_t a, b, d, g, s, t, u;
p = n_randtest_prime(state, 0);
nmod_poly_init(a, p);
nmod_poly_init(b, p);
nmod_poly_init(d, p);
nmod_poly_init(g, p);
nmod_poly_init(s, p);
nmod_poly_init(t, p);
nmod_poly_init(u, p);
nmod_poly_randtest(a, state, n_randint(state, 100));
do
nmod_poly_randtest(b, state, n_randint(state, 100));
while (b->length < 2);
nmod_poly_gcdinv(d, u, a, b);
nmod_poly_xgcd(g, s, t, a, b);
result = ((nmod_poly_equal(d, g) && nmod_poly_equal(u, s))
|| (nmod_poly_is_zero(d)));
if (!result)
{
printf("FAIL:\n");
printf("a = "), nmod_poly_print(a), printf("\n\n");
printf("b = "), nmod_poly_print(b), printf("\n\n");
printf("d = "), nmod_poly_print(d), printf("\n\n");
printf("g = "), nmod_poly_print(g), printf("\n\n");
printf("s = "), nmod_poly_print(s), printf("\n\n");
printf("t = "), nmod_poly_print(t), printf("\n\n");
printf("u = "), nmod_poly_print(u), printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(d);
nmod_poly_clear(g);
nmod_poly_clear(s);
nmod_poly_clear(t);
nmod_poly_clear(u);
}
/* Special case, arguments share a factor ********************************/
/* Compare with result from XGCD */
for (i = 0; i < 1000; i++)
{
mp_limb_t p;
nmod_poly_t a, b, d, f, g, s, t, u;
p = n_randtest_prime(state, 0);
nmod_poly_init(a, p);
nmod_poly_init(b, p);
nmod_poly_init(d, p);
nmod_poly_init(f, p);
nmod_poly_init(g, p);
nmod_poly_init(s, p);
nmod_poly_init(t, p);
nmod_poly_init(u, p);
nmod_poly_randtest(a, state, n_randint(state, 100));
do
nmod_poly_randtest(b, state, n_randint(state, 100));
while (b->length < 2);
nmod_poly_randtest_not_zero(f, state, n_randint(state, 20) + 1);
nmod_poly_mul(a, f, a);
nmod_poly_mul(b, f, b);
nmod_poly_gcdinv(d, u, a, b);
nmod_poly_xgcd(g, s, t, a, b);
result = ((nmod_poly_equal(d, g) && nmod_poly_equal(u, s))
|| (nmod_poly_is_zero(d)));
if (!result)
{
printf("FAIL:\n");
printf("a = "), nmod_poly_print(a), printf("\n\n");
printf("b = "), nmod_poly_print(b), printf("\n\n");
printf("d = "), nmod_poly_print(d), printf("\n\n");
printf("f = "), nmod_poly_print(f), printf("\n\n");
printf("g = "), nmod_poly_print(g), printf("\n\n");
printf("s = "), nmod_poly_print(s), printf("\n\n");
printf("t = "), nmod_poly_print(t), printf("\n\n");
printf("u = "), nmod_poly_print(u), printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(d);
nmod_poly_clear(f);
nmod_poly_clear(g);
nmod_poly_clear(s);
nmod_poly_clear(t);
nmod_poly_clear(u);
}
FLINT_TEST_CLEANUP(state);
printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,75 @@
/*=============================================================================
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 <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong j;
FLINT_TEST_INIT(state);
flint_printf("get/set_coeff_ui....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a;
mp_limb_t n = n_randtest_not_zero(state);
mp_limb_t c1 = n_randtest(state), c2;
j = n_randint(state, 100);
nmod_poly_init(a, n);
nmod_poly_randtest(a, state, n_randint(state, 100));
nmod_poly_set_coeff_ui(a, j, c1);
c2 = nmod_poly_get_coeff_ui(a, j);
result = (c2 == c1 % n);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("j = %wu, c1 = %wu, c2 = %wu, n = %wu\n", j, c1, c2, a->mod.n);
nmod_poly_print(a), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,77 @@
/*=============================================================================
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 <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result, r1;
FLINT_TEST_INIT(state);
flint_printf("get/set_str....");
fflush(stdout);
/* Check to and from string */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b;
mp_limb_t n = n_randtest_not_zero(state);
char * str;
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_randtest(a, state, n_randint(state, 100));
str = nmod_poly_get_str(a);
r1 = nmod_poly_set_str(b, str);
result = (r1 && nmod_poly_equal(a, b));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("r1 = %d, n = %wu\n", r1, a->mod.n);
flint_printf("%s\n", str);
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
abort();
}
flint_free(str);
nmod_poly_clear(a);
nmod_poly_clear(b);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,164 @@
/*=============================================================================
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 William Hart
Copyright (C) 2011 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
#include "mpn_extras.h"
#define __mul(C, lenC, A, lenA, B, lenB) \
do { \
if ((lenA) != 0 && (lenB) != 0) \
{ \
if ((lenA) >= (lenB)) \
_nmod_poly_mul((C), (A), (lenA), (B), (lenB), mod); \
else \
_nmod_poly_mul((C), (B), (lenB), (A), (lenA), mod); \
(lenC) = (lenA) + (lenB) - 1; \
} \
else \
{ \
(lenC) = 0; \
} \
} while (0)
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("hgcd....");
fflush(stdout);
/*
Find coprime polys, multiply by another poly
and check the GCD is that poly
*/
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, d, c1, d1, s, t;
mp_ptr M[4];
slong lenM[4];
slong sgnM;
mp_limb_t n = n_randprime(state, FLINT_BITS, 0);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_init(d, n);
nmod_poly_init(c1, n);
nmod_poly_init(d1, n);
nmod_poly_init(s, n);
nmod_poly_init(t, n);
do {
nmod_poly_randtest_not_zero(a, state, n_randint(state, 800) + 1);
nmod_poly_randtest_not_zero(b, state, n_randint(state, 800) + 1);
} while (a->length == b->length);
if (a->length < b->length)
nmod_poly_swap(a, b);
M[0] = _nmod_vec_init(a->length);
M[1] = _nmod_vec_init(a->length);
M[2] = _nmod_vec_init(a->length);
M[3] = _nmod_vec_init(a->length);
nmod_poly_fit_length(c, a->length);
nmod_poly_fit_length(d, b->length);
sgnM = _nmod_poly_hgcd(M, lenM,
c->coeffs, &(c->length), d->coeffs, &(d->length),
a->coeffs, a->length, b->coeffs, b->length, a->mod);
nmod_poly_fit_length(s, 2 * a->length);
nmod_poly_fit_length(t, 2 * a->length);
/* [c1,d1] := sgnM * M^{-1} [a,b] */
{
const nmod_t mod = a->mod;
MPN_SWAP(M[0], lenM[0], M[3], lenM[3]);
_nmod_vec_neg(M[1], M[1], lenM[1], mod);
_nmod_vec_neg(M[2], M[2], lenM[2], mod);
__mul(s->coeffs, s->length, M[0], lenM[0], a->coeffs, a->length);
__mul(t->coeffs, t->length, M[1], lenM[1], b->coeffs, b->length);
nmod_poly_add(c1, s, t);
__mul(s->coeffs, s->length, M[2], lenM[2], a->coeffs, a->length);
__mul(t->coeffs, t->length, M[3], lenM[3], b->coeffs, b->length);
nmod_poly_add(d1, s, t);
}
if (sgnM < 0)
{
nmod_poly_neg(c1, c1);
nmod_poly_neg(d1, d1);
}
result = (nmod_poly_equal(c, c1) && nmod_poly_equal(d, d1));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a = "), nmod_poly_print(a), flint_printf("\n\n");
flint_printf("b = "), nmod_poly_print(b), flint_printf("\n\n");
flint_printf("c = "), nmod_poly_print(c), flint_printf("\n\n");
flint_printf("d = "), nmod_poly_print(d), flint_printf("\n\n");
flint_printf("c1 = "), nmod_poly_print(c1), flint_printf("\n\n");
flint_printf("d1 = "), nmod_poly_print(d1), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(d);
nmod_poly_clear(c1);
nmod_poly_clear(d1);
nmod_poly_clear(s);
nmod_poly_clear(t);
_nmod_vec_clear(M[0]);
_nmod_vec_clear(M[1]);
_nmod_vec_clear(M[2]);
_nmod_vec_clear(M[3]);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}
#undef __mul

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) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_vec.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int iter;
FLINT_TEST_INIT(state);
flint_printf("inflate....");
fflush(stdout);
for (iter = 0; iter < 100 * flint_test_multiplier(); iter++)
{
nmod_poly_t poly1, poly2, poly3, xp;
mp_limb_t modulus;
ulong inflation;
modulus = n_randtest_prime(state, 0);
nmod_poly_init(poly1, modulus);
nmod_poly_init(poly2, modulus);
nmod_poly_init(poly3, modulus);
nmod_poly_init(xp, modulus);
nmod_poly_randtest(poly1, state, n_randint(state, 20));
inflation = n_randint(state, 10);
nmod_poly_inflate(poly2, poly1, inflation);
nmod_poly_set_coeff_ui(xp, inflation, 1);
nmod_poly_compose(poly3, poly1, xp);
if (!nmod_poly_equal(poly2, poly3))
{
flint_printf("FAIL: not equal to compose (inflation = %wu)\n", inflation);
flint_printf("poly1:\n"); nmod_poly_print(poly1); flint_printf("\n\n");
flint_printf("poly2:\n"); nmod_poly_print(poly2); flint_printf("\n\n");
flint_printf("poly3:\n"); nmod_poly_print(poly3); flint_printf("\n\n");
abort();
}
nmod_poly_inflate(poly1, poly1, inflation);
if (!nmod_poly_equal(poly1, poly2))
{
flint_printf("FAIL: aliasing (inflation = %wu)\n", inflation);
flint_printf("poly1:\n"); nmod_poly_print(poly1); flint_printf("\n\n");
flint_printf("poly2:\n"); nmod_poly_print(poly2); flint_printf("\n\n");
abort();
}
nmod_poly_clear(poly1);
nmod_poly_clear(poly2);
nmod_poly_clear(poly3);
nmod_poly_clear(xp);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,77 @@
/*=============================================================================
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 <stdio.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i;
FLINT_TEST_INIT(state);
flint_printf("init/init2/realloc/clear....");
fflush(stdout);
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init2(a, n, n_randint(state, 100));
nmod_poly_clear(a);
}
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init2(a, n, n_randint(state, 100));
nmod_poly_realloc(a, n_randint(state, 100));
nmod_poly_realloc(a, n_randint(state, 100));
nmod_poly_clear(a);
}
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_randtest(a, state, n_randint(state, 100));
nmod_poly_clear(a);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,114 @@
/*=============================================================================
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) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
#include "fmpz.h"
int
main(void)
{
int i, result = 1;
FLINT_TEST_INIT(state);
flint_printf("integral....");
fflush(stdout);
/* Check with derivative */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
ulong len;
mp_limb_t c0;
mp_limb_t n = n_randtest_prime(state, 0);
len = n_randint(state, 100);
len = FLINT_MIN(len, n - 1);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(a, state, len);
nmod_poly_integral(b, a);
c0 = nmod_poly_get_coeff_ui(b, 0);
nmod_poly_derivative(c, b);
result = (c0 == UWORD(0)) && nmod_poly_equal(a, c);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a->length = %wd, n = %wu\n", a->length, a->mod.n);
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(c), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Check aliasing */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b;
mp_limb_t n = n_randtest_prime(state, 0);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_randtest(a, state, n_randint(state, 100));
nmod_poly_integral(b, a);
nmod_poly_integral(a, a);
result = nmod_poly_equal(a, b);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a->length = %wd, n = %wu\n", a->length, a->mod.n);
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
}
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) 2010 William Hart
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result = 1;
FLINT_TEST_INIT(state);
flint_printf("interpolate_nmod_vec....");
fflush(stdout);
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t P, Q;
mp_ptr x, y;
mp_limb_t mod;
slong j, n, npoints;
mod = n_randtest_prime(state, 0);
npoints = n_randint(state, FLINT_MIN(100, mod));
n = n_randint(state, npoints + 1);
nmod_poly_init(P, mod);
nmod_poly_init(Q, mod);
x = _nmod_vec_init(npoints);
y = _nmod_vec_init(npoints);
nmod_poly_randtest(P, state, n);
for (j = 0; j < npoints; j++)
x[j] = j;
nmod_poly_evaluate_nmod_vec(y, P, x, npoints);
nmod_poly_interpolate_nmod_vec(Q, x, y, npoints);
result = nmod_poly_equal(P, Q);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("mod=%wu, n=%wd, npoints=%wd\n\n", mod, n, npoints);
nmod_poly_print(P), flint_printf("\n\n");
nmod_poly_print(Q), flint_printf("\n\n");
abort();
}
nmod_poly_clear(P);
nmod_poly_clear(Q);
_nmod_vec_clear(x);
_nmod_vec_clear(y);
}
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) 2010 William Hart
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
#include "fmpz.h"
int
main(void)
{
int i, result = 1;
FLINT_TEST_INIT(state);
flint_printf("interpolate_nmod_vec_barycentric....");
fflush(stdout);
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t P, Q;
mp_ptr x, y;
mp_limb_t mod;
slong j, n, npoints;
mod = n_randtest_prime(state, 0);
npoints = n_randint(state, FLINT_MIN(100, mod));
n = n_randint(state, npoints + 1);
nmod_poly_init(P, mod);
nmod_poly_init(Q, mod);
x = _nmod_vec_init(npoints);
y = _nmod_vec_init(npoints);
nmod_poly_randtest(P, state, n);
for (j = 0; j < npoints; j++)
x[j] = j;
nmod_poly_evaluate_nmod_vec(y, P, x, npoints);
nmod_poly_interpolate_nmod_vec_barycentric(Q, x, y, npoints);
result = nmod_poly_equal(P, Q);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("mod=%wu, n=%wd, npoints=%wd\n\n", mod, n, npoints);
nmod_poly_print(P), flint_printf("\n\n");
nmod_poly_print(Q), flint_printf("\n\n");
abort();
}
nmod_poly_clear(P);
nmod_poly_clear(Q);
_nmod_vec_clear(x);
_nmod_vec_clear(y);
}
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) 2010 William Hart
Copyright (C) 2011, 2012 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result = 1;
FLINT_TEST_INIT(state);
flint_printf("interpolate_nmod_vec_fast....");
fflush(stdout);
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t P, Q;
mp_ptr x, y;
mp_limb_t mod;
slong j, n, npoints;
mod = n_randtest_prime(state, 0);
npoints = n_randint(state, FLINT_MIN(100, mod));
n = n_randint(state, npoints + 1);
nmod_poly_init(P, mod);
nmod_poly_init(Q, mod);
x = _nmod_vec_init(npoints);
y = _nmod_vec_init(npoints);
nmod_poly_randtest(P, state, n);
for (j = 0; j < npoints; j++)
x[j] = j;
nmod_poly_evaluate_nmod_vec_fast(y, P, x, npoints);
nmod_poly_interpolate_nmod_vec_fast(Q, x, y, npoints);
result = nmod_poly_equal(P, Q);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("mod=%wu, n=%wd, npoints=%wd\n\n", mod, n, npoints);
nmod_poly_print(P), flint_printf("\n\n");
nmod_poly_print(Q), flint_printf("\n\n");
abort();
}
nmod_poly_clear(P);
nmod_poly_clear(Q);
_nmod_vec_clear(x);
_nmod_vec_clear(y);
}
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) 2010 William Hart
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
#include "fmpz.h"
int
main(void)
{
int i, result = 1;
FLINT_TEST_INIT(state);
flint_printf("interpolate_nmod_vec_newton....");
fflush(stdout);
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t P, Q;
mp_ptr x, y;
mp_limb_t mod;
slong j, n, npoints;
mod = n_randtest_prime(state, 0);
npoints = n_randint(state, FLINT_MIN(100, mod));
n = n_randint(state, npoints + 1);
nmod_poly_init(P, mod);
nmod_poly_init(Q, mod);
x = _nmod_vec_init(npoints);
y = _nmod_vec_init(npoints);
nmod_poly_randtest(P, state, n);
for (j = 0; j < npoints; j++)
x[j] = j;
nmod_poly_evaluate_nmod_vec(y, P, x, npoints);
nmod_poly_interpolate_nmod_vec_newton(Q, x, y, npoints);
result = nmod_poly_equal(P, Q);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("mod=%wu, n=%wd, npoints=%wd\n\n", mod, n, npoints);
nmod_poly_print(P), flint_printf("\n\n");
nmod_poly_print(Q), flint_printf("\n\n");
abort();
}
nmod_poly_clear(P);
nmod_poly_clear(Q);
_nmod_vec_clear(x);
_nmod_vec_clear(y);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,122 @@
/*=============================================================================
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 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("inv_series_basecase....");
fflush(stdout);
/* Check Q * Qinv = 1 mod x^n */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t q, qinv, prod;
slong m;
mp_limb_t n;
do n = n_randtest_not_zero(state);
while (!n_is_probabprime(n));
nmod_poly_init(prod, n);
nmod_poly_init(qinv, n);
nmod_poly_init(q, n);
do nmod_poly_randtest(q, state, n_randint(state, 2000));
while (q->length == 0 || q->coeffs[0] == 0);
m = n_randint(state, q->length) + 1;
nmod_poly_inv_series_basecase(qinv, q, m);
nmod_poly_mul(prod, q, qinv);
nmod_poly_truncate(prod, m);
result = (prod->length == 1 && prod->coeffs[0] == 1);
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(qinv), flint_printf("\n\n");
nmod_poly_print(prod), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(q);
nmod_poly_clear(qinv);
nmod_poly_clear(prod);
}
/* Check aliasing of q and qinv */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t q, qinv;
slong m;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(q, n);
nmod_poly_init(qinv, n);
do nmod_poly_randtest(q, state, n_randint(state, 1000));
while (q->length == 0 || q->coeffs[0] == 0);
m = n_randint(state, q->length) + 1;
nmod_poly_inv_series_basecase(qinv, q, m);
nmod_poly_inv_series_basecase(q, q, m);
result = (nmod_poly_equal(q, qinv));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(qinv), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
flint_printf("n = %wd, m = %wd\n", n, m);
abort();
}
nmod_poly_clear(q);
nmod_poly_clear(qinv);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,122 @@
/*=============================================================================
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 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("inv_series_newton....");
fflush(stdout);
/* Check Q * Qinv = 1 mod x^n */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t q, qinv, prod;
slong m;
mp_limb_t n;
do n = n_randtest_not_zero(state);
while (!n_is_probabprime(n));
nmod_poly_init(prod, n);
nmod_poly_init(qinv, n);
nmod_poly_init(q, n);
do nmod_poly_randtest(q, state, n_randint(state, 2000));
while (q->length == 0 || q->coeffs[0] == 0);
m = n_randint(state, q->length) + 1;
nmod_poly_inv_series_newton(qinv, q, m);
nmod_poly_mul(prod, q, qinv);
nmod_poly_truncate(prod, m);
result = (prod->length == 1 && prod->coeffs[0] == 1);
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(qinv), flint_printf("\n\n");
nmod_poly_print(prod), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(q);
nmod_poly_clear(qinv);
nmod_poly_clear(prod);
}
/* Check aliasing of q and qinv */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t q, qinv;
slong m;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(q, n);
nmod_poly_init(qinv, n);
do nmod_poly_randtest(q, state, n_randint(state, 1000));
while (q->length == 0 || q->coeffs[0] == 0);
m = n_randint(state, q->length) + 1;
nmod_poly_inv_series_newton(qinv, q, m);
nmod_poly_inv_series_newton(q, q, m);
result = (nmod_poly_equal(q, qinv));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(qinv), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
flint_printf("n = %wd, m = %wd\n", n, m);
abort();
}
nmod_poly_clear(q);
nmod_poly_clear(qinv);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,221 @@
/*=============================================================================
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 Mike Hansen
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
printf("invmod....");
fflush(stdout);
/* Test aliasing *************************************************************/
/* Aliasing c and a */
for (i = 0; i < 500; i++)
{
mp_limb_t p;
nmod_poly_t a, b, c;
int ans1, ans2;
p = n_randtest_prime(state, 0);
nmod_poly_init(a, p);
nmod_poly_init(b, p);
nmod_poly_init(c, p);
do
nmod_poly_randtest(b, state, n_randint(state, 100));
while (b->length < 3);
nmod_poly_randtest(a, state, n_randint(state, 100));
ans1 = nmod_poly_invmod(c, a, b);
ans2 = nmod_poly_invmod(a, a, b);
result = (ans1 == ans2 && nmod_poly_equal(a, c));
if (!result)
{
printf("FAIL (alias a and c):\n");
nmod_poly_print(a), printf("\n\n");
nmod_poly_print(b), printf("\n\n");
nmod_poly_print(c), printf("\n\n");
printf("ans1 = %d\n\n", ans1);
printf("ans2 = %d\n\n", ans2);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Aliasing c and b */
for (i = 0; i < 500; i++)
{
mp_limb_t p;
nmod_poly_t a, b, c;
int ans1, ans2;
p = n_randtest_prime(state, 0);
nmod_poly_init(a, p);
nmod_poly_init(b, p);
nmod_poly_init(c, p);
do
nmod_poly_randtest(b, state, n_randint(state, 100));
while (b->length < 3);
nmod_poly_randtest(a, state, n_randint(state, 100));
ans1 = nmod_poly_invmod(c, a, b);
ans2 = nmod_poly_invmod(b, a, b);
result = ((ans1 == ans2) && nmod_poly_equal(b, c));
if (!result)
{
printf("FAIL (alias b and c):\n");
nmod_poly_print(a), printf("\n\n");
nmod_poly_print(b), printf("\n\n");
nmod_poly_print(c), printf("\n\n");
printf("ans1 = %d\n\n", ans1);
printf("ans2 = %d\n\n", ans2);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Compare with result from XGCD */
for (i = 0; i < 1000; i++)
{
mp_limb_t p;
nmod_poly_t a, b, g, s, t, u;
int ans;
p = n_randtest_prime(state, 0);
nmod_poly_init(a, p);
nmod_poly_init(b, p);
nmod_poly_init(g, p);
nmod_poly_init(s, p);
nmod_poly_init(t, p);
nmod_poly_init(u, p);
do
nmod_poly_randtest(b, state, n_randint(state, 100));
while (b->length < 3);
nmod_poly_randtest(a, state, n_randint(state, 100));
ans = nmod_poly_invmod(u, a, b);
nmod_poly_xgcd(g, s, t, a, b);
result = (((ans) && g->length == 1
&& g->coeffs[0] == WORD(1) && nmod_poly_equal(s, u))
|| (!(ans) && g->length > 1));
if (!result)
{
printf("FAIL:\n");
nmod_poly_print(a), printf("\n\n");
nmod_poly_print(b), printf("\n\n");
nmod_poly_print(g), printf("\n\n");
nmod_poly_print(s), printf("\n\n");
nmod_poly_print(t), printf("\n\n");
nmod_poly_print(u), printf("\n\n");
printf("ans = %d\n\n", ans);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(g);
nmod_poly_clear(s);
nmod_poly_clear(t);
nmod_poly_clear(u);
}
/* Special case, arguments share a factor ********************************/
/* Check correctness */
for (i = 0; i < 1000; i++)
{
mp_limb_t p;
nmod_poly_t a, b, f, u;
int ans;
p = n_randtest_prime(state, 0);
nmod_poly_init(a, p);
nmod_poly_init(b, p);
nmod_poly_init(f, p);
nmod_poly_init(u, p);
do
nmod_poly_randtest(b, state, n_randint(state, 100));
while (b->length < 2);
nmod_poly_randtest(a, state, n_randint(state, 100));
do
nmod_poly_randtest_not_zero(f, state, n_randint(state, 20) + 1);
while (f->length < 2);
nmod_poly_mul(a, f, a);
nmod_poly_mul(b, f, b);
ans = nmod_poly_invmod(u, a, b);
result = (!ans);
if (!result)
{
printf("FAIL:\n");
nmod_poly_print(a), printf("\n\n");
nmod_poly_print(b), printf("\n\n");
nmod_poly_print(f), printf("\n\n");
nmod_poly_print(u), printf("\n\n");
printf("ans = %d\n\n", ans);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(f);
nmod_poly_clear(u);
}
FLINT_TEST_CLEANUP(state);
printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,125 @@
/*=============================================================================
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 William Hart
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("invsqrt_series....");
fflush(stdout);
/* Check 1/g^2 = h mod x^m */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t h, g, r;
slong m;
mp_limb_t n;
do n = n_randtest_prime(state, 0);
while (n == UWORD(2));
nmod_poly_init(h, n);
nmod_poly_init(g, n);
nmod_poly_init(r, n);
do nmod_poly_randtest(h, state, n_randint(state, 1000));
while (h->length == 0);
nmod_poly_set_coeff_ui(h, 0, UWORD(1));
m = n_randint(state, h->length) + 1;
nmod_poly_invsqrt_series(g, h, m);
nmod_poly_mullow(r, g, g, m);
nmod_poly_inv_series(r, r, m);
nmod_poly_truncate(h, m);
result = (nmod_poly_equal(r, h));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(h), flint_printf("\n\n");
nmod_poly_print(g), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(h);
nmod_poly_clear(g);
nmod_poly_clear(r);
}
/* Check aliasing of h and g */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t g, h;
slong m;
mp_limb_t n;
do n = n_randtest_prime(state, 0);
while (n == UWORD(2));
nmod_poly_init(h, n);
nmod_poly_init(g, n);
do nmod_poly_randtest(h, state, n_randint(state, 500));
while (h->length == 0);
nmod_poly_set_coeff_ui(h, 0, UWORD(1));
m = n_randint(state, h->length) + 1;
nmod_poly_invsqrt_series(g, h, m);
nmod_poly_invsqrt_series(h, h, m);
result = (nmod_poly_equal(g, h));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(h), flint_printf("\n\n");
nmod_poly_print(g), flint_printf("\n\n");
flint_printf("n = %wd, m = %wd\n", n, m);
abort();
}
nmod_poly_clear(g);
nmod_poly_clear(h);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,141 @@
/*=============================================================================
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) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result = 1;
FLINT_TEST_INIT(state);
flint_printf("log_series....");
fflush(stdout);
/* Check log(AB) = log(A) + log(B) */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t A, B, AB, logA, logB, logAB, S;
slong n;
mp_limb_t mod;
mod = n_randtest_prime(state, 0);
n = n_randtest(state) % 100;
n = FLINT_MIN(n, mod);
nmod_poly_init(A, mod);
nmod_poly_init(B, mod);
nmod_poly_init(AB, mod);
nmod_poly_init(logA, mod);
nmod_poly_init(logB, mod);
nmod_poly_init(logAB, mod);
nmod_poly_init(S, mod);
nmod_poly_randtest(A, state, n_randint(state, 100));
nmod_poly_set_coeff_ui(A, 0, UWORD(1));
nmod_poly_randtest(B, state, n_randint(state, 100));
nmod_poly_set_coeff_ui(B, 0, UWORD(1));
if (n_randlimb(state) % 100 == 0)
{
nmod_poly_zero(A);
nmod_poly_set_coeff_ui(A, n_randlimb(state) % (n+5), \
n_randtest_not_zero(state) % mod);
nmod_poly_set_coeff_ui(A, 0, UWORD(1));
}
nmod_poly_log_series(logA, A, n);
nmod_poly_log_series(logB, B, n);
nmod_poly_mul(AB, A, B);
nmod_poly_log_series(logAB, AB, n);
nmod_poly_add(S, logA, logB);
result = nmod_poly_equal(S, logAB);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("n = %wd, mod = %wu\n", n, mod);
flint_printf("A: "); nmod_poly_print(A), flint_printf("\n\n");
flint_printf("B: "); nmod_poly_print(B), flint_printf("\n\n");
flint_printf("log(A): "); nmod_poly_print(logA), flint_printf("\n\n");
flint_printf("log(B): "); nmod_poly_print(logB), flint_printf("\n\n");
flint_printf("log(AB): "); nmod_poly_print(logAB), flint_printf("\n\n");
flint_printf("log(A)+log(B): "); nmod_poly_print(S), flint_printf("\n\n");
abort();
}
nmod_poly_clear(A);
nmod_poly_clear(B);
nmod_poly_clear(AB);
nmod_poly_clear(logA);
nmod_poly_clear(logB);
nmod_poly_clear(logAB);
nmod_poly_clear(S);
}
/* Check aliasing */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t A, B;
slong n;
mp_limb_t mod;
mod = n_randtest_prime(state, 0);
n = n_randtest(state) % 50;
n = FLINT_MIN(n, mod);
nmod_poly_init(A, mod);
nmod_poly_init(B, mod);
nmod_poly_randtest(A, state, n_randint(state, 50));
nmod_poly_set_coeff_ui(A, 0, UWORD(1));
nmod_poly_log_series(B, A, n);
nmod_poly_log_series(A, A, n);
result = nmod_poly_equal(A, B);
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(A), flint_printf("\n\n");
nmod_poly_print(B), flint_printf("\n\n");
abort();
}
nmod_poly_clear(A);
nmod_poly_clear(B);
}
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) 2010 William Hart
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result = 1;
FLINT_TEST_INIT(state);
flint_printf("log_series_monomial_ui....");
fflush(stdout);
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t A, logA, res;
slong n;
mp_limb_t mod;
ulong power;
mp_limb_t coeff;
mod = n_randtest_prime(state, 0);
n = n_randtest(state) % 100;
n = FLINT_MIN(n, mod);
nmod_poly_init(A, mod);
nmod_poly_init(logA, mod);
nmod_poly_init(res, mod);
coeff = n_randlimb(state) % mod;
power = 1 + n_randint(state, 2*n + 1);
nmod_poly_set_coeff_ui(A, 0, UWORD(1));
nmod_poly_set_coeff_ui(A, power, coeff);
nmod_poly_log_series(logA, A, n);
nmod_poly_log_series_monomial_ui(res, coeff, power, n);
result = nmod_poly_equal(logA, res);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("n = %wd, mod = %wu\n", n, mod);
flint_printf("power = %wu, coeff = %wu\n", power, coeff);
flint_printf("A: "); nmod_poly_print(A), flint_printf("\n\n");
flint_printf("log(A): "); nmod_poly_print(logA), flint_printf("\n\n");
flint_printf("res: "); nmod_poly_print(res), flint_printf("\n\n");
abort();
}
nmod_poly_clear(A);
nmod_poly_clear(logA);
nmod_poly_clear(res);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,106 @@
/*=============================================================================
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 <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("make_monic....");
fflush(stdout);
/* Check new leading coeff = gcd old leading coeff and modulus */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b;
mp_limb_t n = n_randtest_not_zero(state);
mp_limb_t l;
nmod_poly_init(a, n);
nmod_poly_init(b, n);
if (n == 1) continue;
do { nmod_poly_randtest(a, state, n_randint(state, 100) + 1); } while (a->length == 0);
nmod_poly_make_monic(b, a);
l = n_gcd(a->mod.n, a->coeffs[a->length - 1]);
result = (l == b->coeffs[b->length - 1]);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("l = %wu, a->lead = %wd, n = %wu\n",
l, a->coeffs[a->length - 1], a->mod.n);
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
}
/* test aliasing */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a;
mp_limb_t n = n_randtest_not_zero(state);
mp_limb_t l;
nmod_poly_init(a, n);
if (n == 1) continue;
do { nmod_poly_randtest(a, state, n_randint(state, 100) + 1); } while (a->length == 0);
l = n_gcd(a->mod.n, a->coeffs[a->length - 1]);
nmod_poly_make_monic(a, a);
result = (l == a->coeffs[a->length - 1]);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("l = %wu, a->lead = %wd, n = %wu\n",
l, a->coeffs[a->length - 1], a->mod.n);
nmod_poly_print(a), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,147 @@
/*=============================================================================
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 "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("mul....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(b, state, n_randint(state, 50));
nmod_poly_randtest(c, state, n_randint(state, 50));
nmod_poly_mul(a, b, c);
nmod_poly_mul(b, b, c);
result = (nmod_poly_equal(a, b));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Check aliasing of a and c */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(b, state, n_randint(state, 50));
nmod_poly_randtest(c, state, n_randint(state, 50));
nmod_poly_mul(a, b, c);
nmod_poly_mul(c, b, c);
result = (nmod_poly_equal(a, c));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(c), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Check (b*c)+(b*d) = b*(c+d) */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
nmod_poly_t a1, a2, b, c, d;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a1, n);
nmod_poly_init(a2, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_init(d, n);
nmod_poly_randtest(b, state, n_randint(state, 100));
nmod_poly_randtest(c, state, n_randint(state, 100));
nmod_poly_randtest(d, state, n_randint(state, 100));
nmod_poly_mul(a1, b, c);
nmod_poly_mul(a2, b, d);
nmod_poly_add(a1, a1, a2);
nmod_poly_add(c, c, d);
nmod_poly_mul(a2, b, c);
result = (nmod_poly_equal(a1, a2));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a1), flint_printf("\n\n");
nmod_poly_print(a2), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a1);
nmod_poly_clear(a2);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(d);
}
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) 2010 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_vec.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("mul_KS....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(b, state, n_randint(state, 50));
nmod_poly_randtest(c, state, n_randint(state, 50));
nmod_poly_mul_KS(a, b, c, 0);
nmod_poly_mul_KS(b, b, c, 0);
result = (nmod_poly_equal(a, b));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Check aliasing of a and c */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(b, state, n_randint(state, 50));
nmod_poly_randtest(c, state, n_randint(state, 50));
nmod_poly_mul_KS(a, b, c, 0);
nmod_poly_mul_KS(c, b, c, 0);
result = (nmod_poly_equal(a, c));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(c), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Compare with mul_classical */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
nmod_poly_t a1, a2, b, c;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a1, n);
nmod_poly_init(a2, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(b, state, n_randint(state, 50));
nmod_poly_randtest(c, state, n_randint(state, 50));
nmod_poly_mul_classical(a1, b, c);
nmod_poly_mul_KS(a2, b, c, 0);
result = (nmod_poly_equal(a1, a2));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a1), flint_printf("\n\n");
nmod_poly_print(a2), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a1);
nmod_poly_clear(a2);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,170 @@
/*=============================================================================
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 <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_vec.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
#pragma GCC diagnostic ignored "-Woverlength-strings"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("mul_KS2....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(b, state, n_randint(state, 50));
nmod_poly_randtest(c, state, n_randint(state, 50));
nmod_poly_mul_KS2(a, b, c);
nmod_poly_mul_KS2(b, b, c);
result = (nmod_poly_equal(a, b));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Check aliasing of a and c */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(b, state, n_randint(state, 50));
nmod_poly_randtest(c, state, n_randint(state, 50));
nmod_poly_mul_KS2(a, b, c);
nmod_poly_mul_KS2(c, b, c);
result = (nmod_poly_equal(a, c));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(c), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Compare with mul_classical */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
nmod_poly_t a1, a2, b, c;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a1, n);
nmod_poly_init(a2, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(b, state, n_randint(state, 50));
nmod_poly_randtest(c, state, n_randint(state, 50));
nmod_poly_mul_classical(a1, b, c);
nmod_poly_mul_KS2(a2, b, c);
result = (nmod_poly_equal(a1, a2));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a1), flint_printf("\n\n");
nmod_poly_print(a2), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a1);
nmod_poly_clear(a2);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Test bug */
#if FLINT64
{
nmod_poly_t a, b, c, d;
mp_limb_t mod = UWORD(2289285083314003039);
nmod_poly_init(a, mod);
nmod_poly_init(b, mod);
nmod_poly_init(c, mod);
nmod_poly_init(d, mod);
nmod_poly_set_str(a, "33 1904046980750977501 45214318121847844 54776012950656710 1873599154826904295 870135259339956207 1979537227904177235 1077518167660740425 1914467488553877071 590032441505981152 615648453231634975 1569207985886566133 787136232386763586 263398180027397052 1072218041043012468 1506848477788670239 1400920451698857943 1647489479045838018 916805681536849287 418919486780459023 1905019227786610376 521214770020411309 1686949157600795332 1694792566051380615 859359964104912916 379633023194464188 1707896212900599917 2116886930226258819 1784312697572836983 1657809908840472396 187671865737908075 24295635882237532 1236324514297047805 1");
nmod_poly_set_str(b, "33 1248232897348310716 2007649684622883320 1745423566053694824 377131386390909586 510000530211074748 2252357745328136405 121845726568848648 1776552397423576952 1087867787512095029 1542258909416820365 333466255708033066 1369137418799234940 1019757368632255267 1708944472854199555 424720899313432606 1832061349660947209 1680133579237359807 1011480105427615896 469487889066997171 250011917413341143 1528554661920601095 1534412092525363608 1513772824610977843 1546061195142719878 2202390411223099645 1876123527101934779 777483746883723994 1298099847659446396 1845415258502877349 82593368833294076 7103430832858844 1414221645839662896 1");
nmod_poly_mul_classical(c, a, b);
nmod_poly_mul_KS2(d, a, b);
if (!nmod_poly_equal(c, d))
{
flint_printf("FAIL: NMOD_RED2 bug!\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(d);
}
#endif
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,170 @@
/*=============================================================================
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 <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_vec.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
#pragma GCC diagnostic ignored "-Woverlength-strings"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("mul_KS4....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(b, state, n_randint(state, 50));
nmod_poly_randtest(c, state, n_randint(state, 50));
nmod_poly_mul_KS4(a, b, c);
nmod_poly_mul_KS4(b, b, c);
result = (nmod_poly_equal(a, b));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Check aliasing of a and c */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(b, state, n_randint(state, 50));
nmod_poly_randtest(c, state, n_randint(state, 50));
nmod_poly_mul_KS4(a, b, c);
nmod_poly_mul_KS4(c, b, c);
result = (nmod_poly_equal(a, c));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(c), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Compare with mul_classical */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
nmod_poly_t a1, a2, b, c;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a1, n);
nmod_poly_init(a2, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(b, state, n_randint(state, 50));
nmod_poly_randtest(c, state, n_randint(state, 50));
nmod_poly_mul_classical(a1, b, c);
nmod_poly_mul_KS4(a2, b, c);
result = (nmod_poly_equal(a1, a2));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a1), flint_printf("\n\n");
nmod_poly_print(a2), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a1);
nmod_poly_clear(a2);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Test bug */
#if FLINT64
{
nmod_poly_t a, b, c, d;
mp_limb_t mod = UWORD(2289285083314003039);
nmod_poly_init(a, mod);
nmod_poly_init(b, mod);
nmod_poly_init(c, mod);
nmod_poly_init(d, mod);
nmod_poly_set_str(a, "33 1904046980750977501 45214318121847844 54776012950656710 1873599154826904295 870135259339956207 1979537227904177235 1077518167660740425 1914467488553877071 590032441505981152 615648453231634975 1569207985886566133 787136232386763586 263398180027397052 1072218041043012468 1506848477788670239 1400920451698857943 1647489479045838018 916805681536849287 418919486780459023 1905019227786610376 521214770020411309 1686949157600795332 1694792566051380615 859359964104912916 379633023194464188 1707896212900599917 2116886930226258819 1784312697572836983 1657809908840472396 187671865737908075 24295635882237532 1236324514297047805 1");
nmod_poly_set_str(b, "33 1248232897348310716 2007649684622883320 1745423566053694824 377131386390909586 510000530211074748 2252357745328136405 121845726568848648 1776552397423576952 1087867787512095029 1542258909416820365 333466255708033066 1369137418799234940 1019757368632255267 1708944472854199555 424720899313432606 1832061349660947209 1680133579237359807 1011480105427615896 469487889066997171 250011917413341143 1528554661920601095 1534412092525363608 1513772824610977843 1546061195142719878 2202390411223099645 1876123527101934779 777483746883723994 1298099847659446396 1845415258502877349 82593368833294076 7103430832858844 1414221645839662896 1");
nmod_poly_mul_classical(c, a, b);
nmod_poly_mul_KS4(d, a, b);
if (!nmod_poly_equal(c, d))
{
flint_printf("FAIL: NMOD_RED2 bug!\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(d);
}
#endif
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,147 @@
/*=============================================================================
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 <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_vec.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("mul_classical....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(b, state, n_randint(state, 50));
nmod_poly_randtest(c, state, n_randint(state, 50));
nmod_poly_mul_classical(a, b, c);
nmod_poly_mul_classical(b, b, c);
result = (nmod_poly_equal(a, b));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Check aliasing of a and c */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(b, state, n_randint(state, 50));
nmod_poly_randtest(c, state, n_randint(state, 50));
nmod_poly_mul_classical(a, b, c);
nmod_poly_mul_classical(c, b, c);
result = (nmod_poly_equal(a, c));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(c), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Check (b*c)+(b*d) = b*(c+d) */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
nmod_poly_t a1, a2, b, c, d;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a1, n);
nmod_poly_init(a2, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_init(d, n);
nmod_poly_randtest(b, state, n_randint(state, 50));
nmod_poly_randtest(c, state, n_randint(state, 50));
nmod_poly_randtest(d, state, n_randint(state, 50));
nmod_poly_mul_classical(a1, b, c);
nmod_poly_mul_classical(a2, b, d);
nmod_poly_add(a1, a1, a2);
nmod_poly_add(c, c, d);
nmod_poly_mul_classical(a2, b, c);
result = (nmod_poly_equal(a1, a2));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a1), flint_printf("\n\n");
nmod_poly_print(a2), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a1);
nmod_poly_clear(a2);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(d);
}
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 "nmod_vec.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("mulhigh....");
fflush(stdout);
/* Compare with left truncated product of a and b */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
slong j, n;
mp_limb_t m = n_randtest_not_zero(state);
nmod_poly_init(a, m);
nmod_poly_init(b, m);
nmod_poly_init(c, m);
n = n_randint(state, 50);
nmod_poly_randtest(b, state, n);
nmod_poly_randtest(c, state, n);
nmod_poly_mulhigh(a, b, c, n);
nmod_poly_mul(b, b, c);
for (j = 0; j < n; j++)
{
if (j < a->length)
a->coeffs[j] = 0;
if (j < b->length)
b->coeffs[j] = 0;
}
_nmod_poly_normalise(a);
_nmod_poly_normalise(b);
result = (nmod_poly_equal(a, b));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,176 @@
/*=============================================================================
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 <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_vec.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("mulhigh_classical....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
slong j, start;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(b, state, n_randint(state, 50));
nmod_poly_randtest(c, state, n_randint(state, 50));
start = n_randint(state, 50);
nmod_poly_mulhigh_classical(a, b, c, start);
nmod_poly_mulhigh_classical(b, b, c, start);
for (j = 0; j < start; j++)
{
if (j < a->length)
a->coeffs[j] = 0;
if (j < b->length)
b->coeffs[j] = 0;
}
_nmod_poly_normalise(a);
_nmod_poly_normalise(b);
result = (nmod_poly_equal(a, b));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Check aliasing of a and c */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
slong j, start;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(b, state, n_randint(state, 50));
nmod_poly_randtest(c, state, n_randint(state, 50));
start = n_randint(state, 50);
nmod_poly_mulhigh_classical(a, b, c, start);
nmod_poly_mulhigh_classical(c, b, c, start);
for (j = 0; j < start; j++)
{
if (j < a->length)
a->coeffs[j] = 0;
if (j < c->length)
c->coeffs[j] = 0;
}
_nmod_poly_normalise(a);
_nmod_poly_normalise(c);
result = (nmod_poly_equal(a, c));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(c), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Compare with mul_basecase */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, d;
slong j, start;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_init(d, n);
nmod_poly_randtest(b, state, n_randint(state, 50));
nmod_poly_randtest(c, state, n_randint(state, 50));
start = n_randint(state, 50);
nmod_poly_mul_classical(a, b, c);
nmod_poly_mulhigh_classical(d, b, c, start);
for (j = 0; j < start; j++)
{
if (j < a->length)
a->coeffs[j] = 0;
if (j < d->length)
d->coeffs[j] = 0;
}
_nmod_poly_normalise(a);
_nmod_poly_normalise(d);
result = (nmod_poly_equal(a, d));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(c), flint_printf("\n\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(d), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(d);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,80 @@
/*=============================================================================
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 "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("mullow....");
fflush(stdout);
/* Compare with truncated product of a and b */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
slong trunc;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
trunc = n_randint(state, 50);
nmod_poly_randtest(b, state, trunc);
nmod_poly_randtest(c, state, trunc);
nmod_poly_mullow(a, b, c, trunc);
nmod_poly_mul(b, b, c);
nmod_poly_truncate(b, trunc);
result = (nmod_poly_equal(a, b));
if (!result)
{
flint_printf(":\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,149 @@
/*=============================================================================
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 <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_vec.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("mullow_KS....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
mp_limb_t n = n_randtest_not_zero(state);
slong trunc = 0;
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(b, state, n_randint(state, 50));
nmod_poly_randtest(c, state, n_randint(state, 50));
if (b->length > 0 && c->length > 0)
trunc = n_randint(state, b->length + c->length);
nmod_poly_mullow_KS(a, b, c, 0, trunc);
nmod_poly_mullow_KS(b, b, c, 0, trunc);
result = (nmod_poly_equal(a, b));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Check aliasing of a and c */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
mp_limb_t n = n_randtest_not_zero(state);
slong trunc = 0;
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(b, state, n_randint(state, 50));
nmod_poly_randtest(c, state, n_randint(state, 50));
if (b->length > 0 && c->length > 0)
trunc = n_randint(state, b->length + c->length);
nmod_poly_mullow_KS(a, b, c, 0, trunc);
nmod_poly_mullow_KS(c, b, c, 0, trunc);
result = (nmod_poly_equal(a, c));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(c), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Compare with mul_classical */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
nmod_poly_t a1, a2, b, c;
mp_limb_t n = n_randtest_not_zero(state);
slong trunc = 0;
nmod_poly_init(a1, n);
nmod_poly_init(a2, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(b, state, n_randint(state, 50));
nmod_poly_randtest(c, state, n_randint(state, 50));
if (b->length > 0 && c->length > 0)
trunc = n_randint(state, b->length + c->length);
nmod_poly_mullow_classical(a1, b, c, trunc);
nmod_poly_mullow_KS(a2, b, c, 0, trunc);
result = (nmod_poly_equal(a1, a2));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a1), flint_printf("\n\n");
nmod_poly_print(a2), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a1);
nmod_poly_clear(a2);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,159 @@
/*=============================================================================
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 <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_vec.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("mullow_classical....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
slong len, trunc;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(b, state, n_randint(state, 50));
nmod_poly_randtest(c, state, n_randint(state, 50));
len = b->length + c->length - 1;
if (len <= 0)
trunc = 0;
else
trunc = n_randint(state, b->length + c->length);
nmod_poly_mullow_classical(a, b, c, trunc);
nmod_poly_mullow_classical(b, b, c, trunc);
result = (nmod_poly_equal(a, b));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Check aliasing of a and c */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
slong len, trunc;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(b, state, n_randint(state, 50));
nmod_poly_randtest(c, state, n_randint(state, 50));
len = b->length + c->length - 1;
if (len <= 0)
trunc = 0;
else
trunc = n_randint(state, b->length + c->length - 1);
nmod_poly_mullow_classical(a, b, c, trunc);
nmod_poly_mullow_classical(c, b, c, trunc);
result = (nmod_poly_equal(a, c));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(c), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Compare with mul_basecase */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, d;
slong len, trunc;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_init(d, n);
nmod_poly_randtest(b, state, n_randint(state, 50));
nmod_poly_randtest(c, state, n_randint(state, 50));
len = b->length + c->length - 1;
if (len <= 0)
trunc = 0;
else
trunc = n_randint(state, b->length + c->length - 1);
nmod_poly_mul_classical(a, b, c);
nmod_poly_truncate(a, trunc);
nmod_poly_mullow_classical(d, b, c, trunc);
result = (nmod_poly_equal(a, d));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(d), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(d);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,213 @@
/*=============================================================================
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 "nmod_vec.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("mulmod....");
fflush(stdout);
/* Aliasing res and a */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, res, t, f;
mp_limb_t n = n_randtest_prime(state, 0);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(f, n);
nmod_poly_init(res, n);
nmod_poly_init(t, n);
nmod_poly_randtest(a, state, n_randint(state, 50));
nmod_poly_randtest(b, state, n_randint(state, 50));
do {
nmod_poly_randtest(f, state, n_randint(state, 50));
} while (nmod_poly_is_zero(f));
nmod_poly_mulmod(res, a, b, f);
nmod_poly_mulmod(a, a, b, f);
result = (nmod_poly_equal(res, a));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a:\n"); nmod_poly_print(a), flint_printf("\n\n");
flint_printf("b:\n"); nmod_poly_print(b), flint_printf("\n\n");
flint_printf("f:\n"); nmod_poly_print(f), flint_printf("\n\n");
flint_printf("res1:\n"); nmod_poly_print(res), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(f);
nmod_poly_clear(res);
nmod_poly_clear(t);
}
/* Aliasing res and b */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, res, t, f;
mp_limb_t n = n_randtest_prime(state, 0);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(f, n);
nmod_poly_init(res, n);
nmod_poly_init(t, n);
nmod_poly_randtest(a, state, n_randint(state, 50));
nmod_poly_randtest(b, state, n_randint(state, 50));
do {
nmod_poly_randtest(f, state, n_randint(state, 50));
} while (nmod_poly_is_zero(f));
nmod_poly_mulmod(res, a, b, f);
nmod_poly_mulmod(b, a, b, f);
result = (nmod_poly_equal(res, b));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a:\n"); nmod_poly_print(a), flint_printf("\n\n");
flint_printf("b:\n"); nmod_poly_print(b), flint_printf("\n\n");
flint_printf("f:\n"); nmod_poly_print(f), flint_printf("\n\n");
flint_printf("res1:\n"); nmod_poly_print(res), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(f);
nmod_poly_clear(res);
nmod_poly_clear(t);
}
/* Aliasing res and f */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, res, t, f;
mp_limb_t n = n_randtest_prime(state, 0);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(f, n);
nmod_poly_init(res, n);
nmod_poly_init(t, n);
nmod_poly_randtest(a, state, n_randint(state, 50));
nmod_poly_randtest(b, state, n_randint(state, 50));
do {
nmod_poly_randtest(f, state, n_randint(state, 50));
} while (nmod_poly_is_zero(f));
nmod_poly_mulmod(res, a, b, f);
nmod_poly_mulmod(f, a, b, f);
result = (nmod_poly_equal(res, f));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a:\n"); nmod_poly_print(a), flint_printf("\n\n");
flint_printf("b:\n"); nmod_poly_print(b), flint_printf("\n\n");
flint_printf("f:\n"); nmod_poly_print(f), flint_printf("\n\n");
flint_printf("res1:\n"); nmod_poly_print(res), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(f);
nmod_poly_clear(res);
nmod_poly_clear(t);
}
/* No aliasing */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, res1, res2, t, f;
mp_limb_t n = n_randtest_prime(state, 0);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(f, n);
nmod_poly_init(res1, n);
nmod_poly_init(res2, n);
nmod_poly_init(t, n);
nmod_poly_randtest(a, state, n_randint(state, 50));
nmod_poly_randtest(b, state, n_randint(state, 50));
do {
nmod_poly_randtest(f, state, n_randint(state, 50));
} while (nmod_poly_is_zero(f));
nmod_poly_mulmod(res1, a, b, f);
nmod_poly_mul(res2, a, b);
nmod_poly_divrem(t, res2, res2, f);
result = (nmod_poly_equal(res1, res2));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a:\n"); nmod_poly_print(a), flint_printf("\n\n");
flint_printf("b:\n"); nmod_poly_print(b), flint_printf("\n\n");
flint_printf("f:\n"); nmod_poly_print(f), flint_printf("\n\n");
flint_printf("res1:\n"); nmod_poly_print(res1), flint_printf("\n\n");
flint_printf("res2:\n"); nmod_poly_print(res2), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(f);
nmod_poly_clear(res1);
nmod_poly_clear(res2);
nmod_poly_clear(t);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,301 @@
/*=============================================================================
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
Copyright (C) 2013 Martin Lee
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_vec.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("mulmod_preinv....");
fflush(stdout);
/* Aliasing res and a */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, res, t, f, finv;
mp_limb_t n = n_randtest_prime(state, 0);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(f, n);
nmod_poly_init(finv, n);
nmod_poly_init(res, n);
nmod_poly_init(t, n);
nmod_poly_randtest(a, state, n_randint(state, 50));
nmod_poly_randtest(b, state, n_randint(state, 50));
do {
nmod_poly_randtest(f, state, n_randint(state, 50));
} while (nmod_poly_is_zero(f));
if (a->length >= f->length)
nmod_poly_rem (a, a, f);
if (b->length >= f->length)
nmod_poly_rem (b, b, f);
nmod_poly_reverse(finv, f, f->length);
nmod_poly_inv_series(finv, finv, f->length);
nmod_poly_mulmod_preinv(res, a, b, f, finv);
nmod_poly_mulmod_preinv(a, a, b, f, finv);
result = (nmod_poly_equal(res, a));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a:\n"); nmod_poly_print(a), flint_printf("\n\n");
flint_printf("b:\n"); nmod_poly_print(b), flint_printf("\n\n");
flint_printf("f:\n"); nmod_poly_print(f), flint_printf("\n\n");
flint_printf("res1:\n"); nmod_poly_print(res), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(f);
nmod_poly_clear(finv);
nmod_poly_clear(res);
nmod_poly_clear(t);
}
/* Aliasing res and b */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, res, t, f, finv;
mp_limb_t n = n_randtest_prime(state, 0);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(f, n);
nmod_poly_init(finv, n);
nmod_poly_init(res, n);
nmod_poly_init(t, n);
nmod_poly_randtest(a, state, n_randint(state, 50));
nmod_poly_randtest(b, state, n_randint(state, 50));
do {
nmod_poly_randtest(f, state, n_randint(state, 50));
} while (nmod_poly_is_zero(f));
if (a->length >= f->length)
nmod_poly_rem (a, a, f);
if (b->length >= f->length)
nmod_poly_rem (b, b, f);
nmod_poly_reverse(finv, f, f->length);
nmod_poly_inv_series(finv, finv, f->length);
nmod_poly_mulmod_preinv(res, a, b, f, finv);
nmod_poly_mulmod_preinv(b, a, b, f, finv);
result = (nmod_poly_equal(res, b));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a:\n"); nmod_poly_print(a), flint_printf("\n\n");
flint_printf("b:\n"); nmod_poly_print(b), flint_printf("\n\n");
flint_printf("f:\n"); nmod_poly_print(f), flint_printf("\n\n");
flint_printf("res1:\n"); nmod_poly_print(res), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(f);
nmod_poly_clear(finv);
nmod_poly_clear(res);
nmod_poly_clear(t);
}
/* Aliasing res and f */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, res, t, f, finv;
mp_limb_t n = n_randtest_prime(state, 0);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(f, n);
nmod_poly_init(finv, n);
nmod_poly_init(res, n);
nmod_poly_init(t, n);
nmod_poly_randtest(a, state, n_randint(state, 50));
nmod_poly_randtest(b, state, n_randint(state, 50));
do {
nmod_poly_randtest(f, state, n_randint(state, 50));
} while (nmod_poly_is_zero(f));
if (a->length >= f->length)
nmod_poly_rem (a, a, f);
if (b->length >= f->length)
nmod_poly_rem (b, b, f);
nmod_poly_reverse(finv, f, f->length);
nmod_poly_inv_series(finv, finv, f->length);
nmod_poly_mulmod_preinv(res, a, b, f, finv);
nmod_poly_mulmod_preinv(f, a, b, f, finv);
result = (nmod_poly_equal(res, f));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a:\n"); nmod_poly_print(a), flint_printf("\n\n");
flint_printf("b:\n"); nmod_poly_print(b), flint_printf("\n\n");
flint_printf("f:\n"); nmod_poly_print(f), flint_printf("\n\n");
flint_printf("res1:\n"); nmod_poly_print(res), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(f);
nmod_poly_clear(finv);
nmod_poly_clear(res);
nmod_poly_clear(t);
}
/* Aliasing res and finv */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, res, t, f, finv;
mp_limb_t n = n_randtest_prime(state, 0);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(f, n);
nmod_poly_init(finv, n);
nmod_poly_init(res, n);
nmod_poly_init(t, n);
nmod_poly_randtest(a, state, n_randint(state, 50));
nmod_poly_randtest(b, state, n_randint(state, 50));
do {
nmod_poly_randtest(f, state, n_randint(state, 50));
} while (nmod_poly_is_zero(f));
if (a->length >= f->length)
nmod_poly_rem (a, a, f);
if (b->length >= f->length)
nmod_poly_rem (b, b, f);
nmod_poly_reverse(finv, f, f->length);
nmod_poly_inv_series(finv, finv, f->length);
nmod_poly_mulmod_preinv(res, a, b, f, finv);
nmod_poly_mulmod_preinv(finv, a, b, f, finv);
result = (nmod_poly_equal(res, finv));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a:\n"); nmod_poly_print(a), flint_printf("\n\n");
flint_printf("b:\n"); nmod_poly_print(b), flint_printf("\n\n");
flint_printf("f:\n"); nmod_poly_print(f), flint_printf("\n\n");
flint_printf("finv:\n"); nmod_poly_print(finv), flint_printf("\n\n");
flint_printf("res1:\n"); nmod_poly_print(res), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(f);
nmod_poly_clear(finv);
nmod_poly_clear(res);
nmod_poly_clear(t);
}
/* No aliasing */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, res1, res2, t, f, finv;
mp_limb_t n = n_randtest_prime(state, 0);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(f, n);
nmod_poly_init(finv, n);
nmod_poly_init(res1, n);
nmod_poly_init(res2, n);
nmod_poly_init(t, n);
nmod_poly_randtest(a, state, n_randint(state, 50));
nmod_poly_randtest(b, state, n_randint(state, 50));
do {
nmod_poly_randtest(f, state, n_randint(state, 50));
} while (nmod_poly_is_zero(f));
if (a->length >= f->length)
nmod_poly_rem (a, a, f);
if (b->length >= f->length)
nmod_poly_rem (b, b, f);
nmod_poly_reverse(finv, f, f->length);
nmod_poly_inv_series(finv, finv, f->length);
nmod_poly_mulmod_preinv(res1, a, b, f, finv);
nmod_poly_mul(res2, a, b);
nmod_poly_divrem(t, res2, res2, f);
result = (nmod_poly_equal(res1, res2));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a:\n"); nmod_poly_print(a), flint_printf("\n\n");
flint_printf("b:\n"); nmod_poly_print(b), flint_printf("\n\n");
flint_printf("f:\n"); nmod_poly_print(f), flint_printf("\n\n");
flint_printf("res1:\n"); nmod_poly_print(res1), flint_printf("\n\n");
flint_printf("res2:\n"); nmod_poly_print(res2), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(f);
nmod_poly_clear(finv);
nmod_poly_clear(res1);
nmod_poly_clear(res2);
nmod_poly_clear(t);
}
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) 2010 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("neg....");
fflush(stdout);
/* Check neg neg a == a */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_randtest(a, state, n_randint(state, 100));
nmod_poly_neg(b, a);
nmod_poly_neg(b, b);
result = (nmod_poly_equal(a, b));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a->length = %wd, n = %wu\n", a->length, a->mod.n);
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,117 @@
/*=============================================================================
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 <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, j, result;
FLINT_TEST_INIT(state);
flint_printf("pow....");
fflush(stdout);
/* Check powering against naive method */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
mp_limb_t n = n_randtest_not_zero(state);
slong e;
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(a, state, n_randint(state, 30));
e = n_randint(state, 20);
nmod_poly_pow(b, a, e);
nmod_poly_set_coeff_ui(c, 0, 1);
for (j = 0; j < e; j++)
nmod_poly_mul(c, c, a);
result = (nmod_poly_equal(b, c)
|| (a->length == 0 && e == 0 && c->length == 1 && c->coeffs[0] == 1));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a->length = %wd, n = %wu, exp = %wd\n", a->length, a->mod.n, e);
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(c), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Check aliasing */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
mp_limb_t n = n_randtest_not_zero(state);
slong e;
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(a, state, n_randint(state, 30));
e = n_randint(state, 20);
nmod_poly_pow(b, a, e);
nmod_poly_set(c, a);
nmod_poly_pow(c, c, e);
result = (nmod_poly_equal(b, c));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a->length = %wd, n = %wu, exp = %wd\n", a->length, a->mod.n, e);
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(c), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,117 @@
/*=============================================================================
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 <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, j, result;
FLINT_TEST_INIT(state);
flint_printf("pow_binexp....");
fflush(stdout);
/* Check powering against naive method */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
mp_limb_t n = n_randtest_not_zero(state);
slong e;
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(a, state, n_randint(state, 30));
e = n_randint(state, 20);
nmod_poly_pow_binexp(b, a, e);
nmod_poly_set_coeff_ui(c, 0, 1);
for (j = 0; j < e; j++)
nmod_poly_mul(c, c, a);
result = (nmod_poly_equal(b, c)
|| (a->length == 0 && e == 0 && c->length == 1 && c->coeffs[0] == 1));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a->length = %wd, n = %wu, exp = %wd\n", a->length, a->mod.n, e);
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(c), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Check aliasing */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
mp_limb_t n = n_randtest_not_zero(state);
slong e;
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(a, state, n_randint(state, 30));
e = n_randint(state, 20);
nmod_poly_pow_binexp(b, a, e);
nmod_poly_set(c, a);
nmod_poly_pow_binexp(c, c, e);
result = (nmod_poly_equal(b, c));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a->length = %wd, n = %wu, exp = %wd\n", a->length, a->mod.n, e);
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(c), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,120 @@
/*=============================================================================
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 <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("pow_trunc....");
fflush(stdout);
/* Check powering against naive method */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
mp_limb_t n = n_randtest_not_zero(state);
slong e, trunc;
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(a, state, n_randint(state, 30));
e = n_randint(state, 20);
trunc = n_randint(state, 30);
nmod_poly_pow_trunc(b, a, e, trunc);
nmod_poly_pow(c, a, e);
nmod_poly_truncate(c, trunc);
result = (nmod_poly_equal(b, c)
|| (a->length == 0 && e == 0 && c->length == 1 && c->coeffs[0] == 1));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a->length = %wd, n = %wu, exp = %wd, trunc = %wd\n",
a->length, a->mod.n, e, trunc);
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(c), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Check aliasing */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
mp_limb_t n = n_randtest_not_zero(state);
slong e, trunc;
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(a, state, n_randint(state, 30));
e = n_randint(state, 20);
trunc = n_randint(state, 30);
nmod_poly_pow_trunc(b, a, e, trunc);
nmod_poly_set(c, a);
nmod_poly_pow_trunc(c, c, e, trunc);
result = (nmod_poly_equal(b, c));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a->length = %wd, n = %wu, exp = %wd, trunc = %wd\n",
a->length, a->mod.n, e, trunc);
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(c), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,120 @@
/*=============================================================================
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 <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("pow_trunc_binexp....");
fflush(stdout);
/* Check powering against naive method */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
mp_limb_t n = n_randtest_not_zero(state);
slong e, trunc;
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(a, state, n_randint(state, 30));
e = n_randint(state, 20);
trunc = n_randint(state, 30);
nmod_poly_pow_trunc_binexp(b, a, e, trunc);
nmod_poly_pow(c, a, e);
nmod_poly_truncate(c, trunc);
result = (nmod_poly_equal(b, c)
|| (a->length == 0 && e == 0 && c->length == 1 && c->coeffs[0] == 1));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a->length = %wd, n = %wu, exp = %wd, trunc = %wd\n",
a->length, a->mod.n, e, trunc);
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(c), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Check aliasing */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
mp_limb_t n = n_randtest_not_zero(state);
slong e, trunc;
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(a, state, n_randint(state, 30));
e = n_randint(state, 20);
trunc = n_randint(state, 30);
nmod_poly_pow_trunc_binexp(b, a, e, trunc);
nmod_poly_set(c, a);
nmod_poly_pow_trunc_binexp(c, c, e, trunc);
result = (nmod_poly_equal(b, c));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a->length = %wd, n = %wu, exp = %wd, trunc = %wd\n",
a->length, a->mod.n, e, trunc);
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(c), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,178 @@
/*=============================================================================
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 "nmod_vec.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("powmod_mpz_binexp....");
fflush(stdout);
/* Aliasing of res and a */
for (i = 0; i < 25 * flint_test_multiplier(); i++)
{
nmod_poly_t a, res1, t, f;
mp_limb_t n;
ulong exp;
mpz_t expz;
n = n_randtest_prime(state, 0);
exp = n_randlimb(state);
flint_mpz_init_set_ui(expz, exp);
nmod_poly_init(a, n);
nmod_poly_init(f, n);
nmod_poly_init(res1, n);
nmod_poly_init(t, n);
nmod_poly_randtest(a, state, n_randint(state, 50));
do {
nmod_poly_randtest(f, state, n_randint(state, 50));
} while (nmod_poly_is_zero(f));
nmod_poly_powmod_mpz_binexp(res1, a, expz, f);
nmod_poly_powmod_mpz_binexp(a, a, expz, f);
result = (nmod_poly_equal(res1, a));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a:\n"); nmod_poly_print(a), flint_printf("\n\n");
flint_printf("f:\n"); nmod_poly_print(f), flint_printf("\n\n");
flint_printf("res1:\n"); nmod_poly_print(res1), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(f);
nmod_poly_clear(res1);
nmod_poly_clear(t);
mpz_clear(expz);
}
/* Aliasing of res and f */
for (i = 0; i < 25 * flint_test_multiplier(); i++)
{
nmod_poly_t a, res1, t, f;
mp_limb_t n;
ulong exp;
mpz_t expz;
n = n_randtest_prime(state, 0);
exp = n_randlimb(state);
flint_mpz_init_set_ui(expz, exp);
nmod_poly_init(a, n);
nmod_poly_init(f, n);
nmod_poly_init(res1, n);
nmod_poly_init(t, n);
nmod_poly_randtest(a, state, n_randint(state, 50));
do {
nmod_poly_randtest(f, state, n_randint(state, 50));
} while (nmod_poly_is_zero(f));
nmod_poly_powmod_mpz_binexp(res1, a, expz, f);
nmod_poly_powmod_mpz_binexp(f, a, expz, f);
result = (nmod_poly_equal(res1, f));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a:\n"); nmod_poly_print(a), flint_printf("\n\n");
flint_printf("f:\n"); nmod_poly_print(f), flint_printf("\n\n");
flint_printf("res1:\n"); nmod_poly_print(res1), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(f);
nmod_poly_clear(res1);
nmod_poly_clear(t);
mpz_clear(expz);
}
/* No aliasing */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
nmod_poly_t a, res1, res2, t, f;
mp_limb_t n;
ulong exp;
mpz_t expz;
n = n_randtest_prime(state, 0);
exp = n_randlimb(state);
nmod_poly_init(a, n);
nmod_poly_init(f, n);
nmod_poly_init(res1, n);
nmod_poly_init(res2, n);
nmod_poly_init(t, n);
nmod_poly_randtest(a, state, n_randint(state, 50));
do {
nmod_poly_randtest(f, state, n_randint(state, 50));
} while (nmod_poly_is_zero(f));
flint_mpz_init_set_ui(expz, exp);
nmod_poly_powmod_mpz_binexp(res1, a, expz, f);
nmod_poly_powmod_ui_binexp(res2, a, exp, f);
result = (nmod_poly_equal(res1, res2));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a:\n"); nmod_poly_print(a), flint_printf("\n\n");
flint_printf("f:\n"); nmod_poly_print(f), flint_printf("\n\n");
flint_printf("res1:\n"); nmod_poly_print(res1), flint_printf("\n\n");
flint_printf("res2:\n"); nmod_poly_print(res2), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(f);
nmod_poly_clear(res1);
nmod_poly_clear(res2);
nmod_poly_clear(t);
mpz_clear(expz);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,251 @@
/*=============================================================================
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
Copyright (C) 2013 Martin Lee
******************************************************************************/
#undef ulong
#define ulong ulongxx/* interferes with system includes */
#include <stdlib.h>
#include <stdio.h>
#undef ulong
#include <gmp.h>
#define ulong mp_limb_t
#include "flint.h"
#include "nmod_vec.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("powmod_mpz_binexp_preinv....");
fflush(stdout);
/* Aliasing of res and a */
for (i = 0; i < 25 * flint_test_multiplier(); i++)
{
nmod_poly_t a, res1, t, f, finv;
mp_limb_t n;
ulong exp;
mpz_t expz;
n = n_randtest_prime(state, 0);
exp = n_randlimb(state);
flint_mpz_init_set_ui(expz, exp);
nmod_poly_init(a, n);
nmod_poly_init(f, n);
nmod_poly_init(finv, n);
nmod_poly_init(res1, n);
nmod_poly_init(t, n);
nmod_poly_randtest(a, state, n_randint(state, 50));
do {
nmod_poly_randtest(f, state, n_randint(state, 50));
} while (nmod_poly_is_zero(f));
nmod_poly_reverse(finv, f, f->length);
nmod_poly_inv_series(finv, finv, f->length);
nmod_poly_powmod_mpz_binexp_preinv(res1, a, expz, f, finv);
nmod_poly_powmod_mpz_binexp_preinv(a, a, expz, f, finv);
result = (nmod_poly_equal(res1, a));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a:\n"); nmod_poly_print(a), flint_printf("\n\n");
flint_printf("f:\n"); nmod_poly_print(f), flint_printf("\n\n");
flint_printf("res1:\n"); nmod_poly_print(res1), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(f);
nmod_poly_clear(finv);
nmod_poly_clear(res1);
nmod_poly_clear(t);
mpz_clear(expz);
}
/* Aliasing of res and f */
for (i = 0; i < 25 * flint_test_multiplier(); i++)
{
nmod_poly_t a, res1, t, f, finv;
mp_limb_t n;
ulong exp;
mpz_t expz;
n = n_randtest_prime(state, 0);
exp = n_randlimb(state);
flint_mpz_init_set_ui(expz, exp);
nmod_poly_init(a, n);
nmod_poly_init(f, n);
nmod_poly_init(finv, n);
nmod_poly_init(res1, n);
nmod_poly_init(t, n);
nmod_poly_randtest(a, state, n_randint(state, 50));
do {
nmod_poly_randtest(f, state, n_randint(state, 50));
} while (nmod_poly_is_zero(f));
nmod_poly_reverse(finv, f, f->length);
nmod_poly_inv_series(finv, finv, f->length);
nmod_poly_powmod_mpz_binexp_preinv(res1, a, expz, f, finv);
nmod_poly_powmod_mpz_binexp_preinv(f, a, expz, f, finv);
result = (nmod_poly_equal(res1, f));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a:\n"); nmod_poly_print(a), flint_printf("\n\n");
flint_printf("f:\n"); nmod_poly_print(f), flint_printf("\n\n");
flint_printf("res1:\n"); nmod_poly_print(res1), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(f);
nmod_poly_clear(finv);
nmod_poly_clear(res1);
nmod_poly_clear(t);
mpz_clear(expz);
}
/* Aliasing of res and finv */
for (i = 0; i < 25 * flint_test_multiplier(); i++)
{
nmod_poly_t a, res1, t, f, finv;
mp_limb_t n;
ulong exp;
mpz_t expz;
n = n_randtest_prime(state, 0);
exp = n_randlimb(state);
flint_mpz_init_set_ui(expz, exp);
nmod_poly_init(a, n);
nmod_poly_init(f, n);
nmod_poly_init(finv, n);
nmod_poly_init(res1, n);
nmod_poly_init(t, n);
nmod_poly_randtest(a, state, n_randint(state, 50));
do {
nmod_poly_randtest(f, state, n_randint(state, 50));
} while (nmod_poly_is_zero(f));
nmod_poly_reverse(finv, f, f->length);
nmod_poly_inv_series(finv, finv, f->length);
nmod_poly_powmod_mpz_binexp_preinv(res1, a, expz, f, finv);
nmod_poly_powmod_mpz_binexp_preinv(finv, a, expz, f, finv);
result = (nmod_poly_equal(res1, finv));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a:\n"); nmod_poly_print(a), flint_printf("\n\n");
flint_printf("f:\n"); nmod_poly_print(f), flint_printf("\n\n");
flint_printf("res1:\n"); nmod_poly_print(res1), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(f);
nmod_poly_clear(finv);
nmod_poly_clear(res1);
nmod_poly_clear(t);
mpz_clear(expz);
}
/* No aliasing */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
nmod_poly_t a, res1, res2, t, f, finv;
mp_limb_t n;
ulong exp;
mpz_t expz;
n = n_randtest_prime(state, 0);
exp = n_randlimb(state);
nmod_poly_init(a, n);
nmod_poly_init(f, n);
nmod_poly_init(finv, n);
nmod_poly_init(res1, n);
nmod_poly_init(res2, n);
nmod_poly_init(t, n);
nmod_poly_randtest(a, state, n_randint(state, 50));
do {
nmod_poly_randtest(f, state, n_randint(state, 50));
} while (nmod_poly_is_zero(f));
flint_mpz_init_set_ui(expz, exp);
nmod_poly_reverse(finv, f, f->length);
nmod_poly_inv_series(finv, finv, f->length);
nmod_poly_powmod_mpz_binexp_preinv(res1, a, expz, f, finv);
nmod_poly_powmod_ui_binexp_preinv(res2, a, exp, f, finv);
result = (nmod_poly_equal(res1, res2));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a:\n"); nmod_poly_print(a), flint_printf("\n\n");
flint_printf("f:\n"); nmod_poly_print(f), flint_printf("\n\n");
flint_printf("res1:\n"); nmod_poly_print(res1), flint_printf("\n\n");
flint_printf("res2:\n"); nmod_poly_print(res2), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(f);
nmod_poly_clear(finv);
nmod_poly_clear(res1);
nmod_poly_clear(res2);
nmod_poly_clear(t);
mpz_clear(expz);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,177 @@
/*=============================================================================
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 "nmod_vec.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("powmod_ui_binexp....");
fflush(stdout);
/* Aliasing of res and a */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
nmod_poly_t a, res1, t, f;
mp_limb_t n;
ulong exp;
n = n_randtest_prime(state, 0);
exp = n_randlimb(state) % 32;
nmod_poly_init(a, n);
nmod_poly_init(f, n);
nmod_poly_init(res1, n);
nmod_poly_init(t, n);
nmod_poly_randtest(a, state, n_randint(state, 50));
do {
nmod_poly_randtest(f, state, n_randint(state, 50));
} while (nmod_poly_is_zero(f));
nmod_poly_powmod_ui_binexp(res1, a, exp, f);
nmod_poly_powmod_ui_binexp(a, a, exp, f);
result = (nmod_poly_equal(res1, a));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("exp: %wu\n\n", exp);
flint_printf("a:\n"); nmod_poly_print(a), flint_printf("\n\n");
flint_printf("f:\n"); nmod_poly_print(f), flint_printf("\n\n");
flint_printf("res1:\n"); nmod_poly_print(res1), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(f);
nmod_poly_clear(res1);
nmod_poly_clear(t);
}
/* Aliasing of res and f */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
nmod_poly_t a, res1, t, f;
mp_limb_t n;
ulong exp;
n = n_randtest_prime(state, 0);
exp = n_randlimb(state) % 32;
nmod_poly_init(a, n);
nmod_poly_init(f, n);
nmod_poly_init(res1, n);
nmod_poly_init(t, n);
nmod_poly_randtest(a, state, n_randint(state, 50));
do {
nmod_poly_randtest(f, state, n_randint(state, 50));
} while (nmod_poly_is_zero(f));
nmod_poly_powmod_ui_binexp(res1, a, exp, f);
nmod_poly_powmod_ui_binexp(f, a, exp, f);
result = (nmod_poly_equal(res1, f));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("exp: %wu\n\n", exp);
flint_printf("a:\n"); nmod_poly_print(a), flint_printf("\n\n");
flint_printf("f:\n"); nmod_poly_print(f), flint_printf("\n\n");
flint_printf("res1:\n"); nmod_poly_print(res1), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(f);
nmod_poly_clear(res1);
nmod_poly_clear(t);
}
/* No aliasing */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, res1, res2, t, f;
mp_limb_t n;
ulong exp;
int j;
n = n_randtest_prime(state, 0);
exp = n_randlimb(state) % 32;
nmod_poly_init(a, n);
nmod_poly_init(f, n);
nmod_poly_init(res1, n);
nmod_poly_init(res2, n);
nmod_poly_init(t, n);
nmod_poly_randtest(a, state, n_randint(state, 50));
do {
nmod_poly_randtest(f, state, n_randint(state, 50));
} while (nmod_poly_is_zero(f));
nmod_poly_powmod_ui_binexp(res1, a, exp, f);
nmod_poly_zero(res2);
nmod_poly_set_coeff_ui(res2, 0, 1);
for (j = 1; j <= exp; j++)
nmod_poly_mulmod(res2, res2, a, f);
result = (nmod_poly_equal(res1, res2));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("exp: %wu\n\n", exp);
flint_printf("a:\n"); nmod_poly_print(a), flint_printf("\n\n");
flint_printf("f:\n"); nmod_poly_print(f), flint_printf("\n\n");
flint_printf("res1:\n"); nmod_poly_print(res1), flint_printf("\n\n");
flint_printf("res2:\n"); nmod_poly_print(res2), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(f);
nmod_poly_clear(res1);
nmod_poly_clear(res2);
nmod_poly_clear(t);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,248 @@
/*=============================================================================
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
Copyright (C) 2013 Martin Lee
******************************************************************************/
#undef ulong
#define ulong ulongxx/* interferes with system includes */
#include <stdlib.h>
#include <stdio.h>
#undef ulong
#include <gmp.h>
#define ulong mp_limb_t
#include "flint.h"
#include "nmod_vec.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("powmod_ui_binexp_preinv....");
fflush(stdout);
/* Aliasing of res and a */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
nmod_poly_t a, res1, t, f, finv;
mp_limb_t n;
ulong exp;
n = n_randtest_prime(state, 0);
exp = n_randlimb(state) % 32;
nmod_poly_init(a, n);
nmod_poly_init(f, n);
nmod_poly_init(finv, n);
nmod_poly_init(res1, n);
nmod_poly_init(t, n);
nmod_poly_randtest(a, state, n_randint(state, 50));
do {
nmod_poly_randtest(f, state, n_randint(state, 50));
} while (nmod_poly_is_zero(f));
nmod_poly_reverse(finv, f, f->length);
nmod_poly_inv_series(finv, finv, f->length);
nmod_poly_powmod_ui_binexp_preinv(res1, a, exp, f, finv);
nmod_poly_powmod_ui_binexp_preinv(a, a, exp, f, finv);
result = (nmod_poly_equal(res1, a));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("exp: %wu\n\n", exp);
flint_printf("a:\n"); nmod_poly_print(a), flint_printf("\n\n");
flint_printf("f:\n"); nmod_poly_print(f), flint_printf("\n\n");
flint_printf("res1:\n"); nmod_poly_print(res1), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(f);
nmod_poly_clear(finv);
nmod_poly_clear(res1);
nmod_poly_clear(t);
}
/* Aliasing of res and f */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
nmod_poly_t a, res1, t, f, finv;
mp_limb_t n;
ulong exp;
n = n_randtest_prime(state, 0);
exp = n_randlimb(state) % 32;
nmod_poly_init(a, n);
nmod_poly_init(f, n);
nmod_poly_init(finv, n);
nmod_poly_init(res1, n);
nmod_poly_init(t, n);
nmod_poly_randtest(a, state, n_randint(state, 50));
do {
nmod_poly_randtest(f, state, n_randint(state, 50));
} while (nmod_poly_is_zero(f));
nmod_poly_reverse(finv, f, f->length);
nmod_poly_inv_series(finv, finv, f->length);
nmod_poly_powmod_ui_binexp_preinv(res1, a, exp, f, finv);
nmod_poly_powmod_ui_binexp_preinv(f, a, exp, f, finv);
result = (nmod_poly_equal(res1, f));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("exp: %wu\n\n", exp);
flint_printf("a:\n"); nmod_poly_print(a), flint_printf("\n\n");
flint_printf("f:\n"); nmod_poly_print(f), flint_printf("\n\n");
flint_printf("res1:\n"); nmod_poly_print(res1), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(f);
nmod_poly_clear(finv);
nmod_poly_clear(res1);
nmod_poly_clear(t);
}
/* Aliasing of res and finv */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
nmod_poly_t a, res1, t, f, finv;
mp_limb_t n;
ulong exp;
n = n_randtest_prime(state, 0);
exp = n_randlimb(state) % 32;
nmod_poly_init(a, n);
nmod_poly_init(f, n);
nmod_poly_init(finv, n);
nmod_poly_init(res1, n);
nmod_poly_init(t, n);
nmod_poly_randtest(a, state, n_randint(state, 50));
do {
nmod_poly_randtest(f, state, n_randint(state, 50));
} while (nmod_poly_is_zero(f));
nmod_poly_reverse(finv, f, f->length);
nmod_poly_inv_series(finv, finv, f->length);
nmod_poly_powmod_ui_binexp_preinv(res1, a, exp, f, finv);
nmod_poly_powmod_ui_binexp_preinv(finv, a, exp, f, finv);
result = (nmod_poly_equal(res1, finv));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("exp: %wu\n\n", exp);
flint_printf("a:\n"); nmod_poly_print(a), flint_printf("\n\n");
flint_printf("f:\n"); nmod_poly_print(f), flint_printf("\n\n");
flint_printf("finv:\n"); nmod_poly_print(finv), flint_printf("\n\n");
flint_printf("res1:\n"); nmod_poly_print(res1), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(f);
nmod_poly_clear(finv);
nmod_poly_clear(res1);
nmod_poly_clear(t);
}
/* No aliasing */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, res1, res2, t, f, finv;
mp_limb_t n;
ulong exp;
int j;
n = n_randtest_prime(state, 0);
exp = n_randlimb(state) % 32;
nmod_poly_init(a, n);
nmod_poly_init(f, n);
nmod_poly_init(finv, n);
nmod_poly_init(res1, n);
nmod_poly_init(res2, n);
nmod_poly_init(t, n);
nmod_poly_randtest(a, state, n_randint(state, 50));
do {
nmod_poly_randtest(f, state, n_randint(state, 50));
} while (nmod_poly_is_zero(f));
nmod_poly_reverse(finv, f, f->length);
nmod_poly_inv_series(finv, finv, f->length);
nmod_poly_powmod_ui_binexp_preinv(res1, a, exp, f, finv);
nmod_poly_zero(res2);
nmod_poly_set_coeff_ui(res2, 0, 1);
for (j = 1; j <= exp; j++)
nmod_poly_mulmod(res2, res2, a, f);
result = (nmod_poly_equal(res1, res2));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("exp: %wu\n\n", exp);
flint_printf("a:\n"); nmod_poly_print(a), flint_printf("\n\n");
flint_printf("f:\n"); nmod_poly_print(f), flint_printf("\n\n");
flint_printf("res1:\n"); nmod_poly_print(res1), flint_printf("\n\n");
flint_printf("res2:\n"); nmod_poly_print(res2), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(f);
nmod_poly_clear(finv);
nmod_poly_clear(res1);
nmod_poly_clear(res2);
nmod_poly_clear(t);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,192 @@
/*=============================================================================
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
Copyright (C) 2013 Martin Lee
******************************************************************************/
#undef ulong
#define ulong ulongxx/* interferes with system includes */
#include <stdlib.h>
#include <stdio.h>
#undef ulong
#include <gmp.h>
#define ulong mp_limb_t
#include "flint.h"
#include "nmod_vec.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("powmod_x_ui_preinv....");
fflush(stdout);
/* No aliasing */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, res1, res2, t, f, finv;
mp_limb_t n;
ulong exp;
n = n_randtest_prime(state, 0);
exp = n_randlimb(state) % 32;
nmod_poly_init(f, n);
nmod_poly_init(finv, n);
nmod_poly_init(res1, n);
nmod_poly_init(res2, n);
nmod_poly_init(t, n);
do {
nmod_poly_randtest(f, state, n_randint(state, 50));
} while (nmod_poly_is_zero(f));
nmod_poly_reverse(finv, f, f->length);
nmod_poly_inv_series(finv, finv, f->length);
nmod_poly_init2 (a, n, f->length-1);
nmod_poly_set_coeff_ui (a, 1, 1);
nmod_poly_powmod_x_ui_preinv(res1, exp, f, finv);
nmod_poly_powmod_ui_binexp_preinv (res2, a, exp, f, finv);
result = (nmod_poly_equal(res1, res2));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("exp: %wu\n\n", exp);
flint_printf("a:\n"); nmod_poly_print(a), flint_printf("\n\n");
flint_printf("f:\n"); nmod_poly_print(f), flint_printf("\n\n");
flint_printf("res1:\n"); nmod_poly_print(res1), flint_printf("\n\n");
flint_printf("res2:\n"); nmod_poly_print(res2), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(f);
nmod_poly_clear(finv);
nmod_poly_clear(res1);
nmod_poly_clear(res2);
nmod_poly_clear(t);
}
/* Aliasing of res and f */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
nmod_poly_t res1, t, f, finv;
mp_limb_t n;
ulong exp;
n = n_randtest_prime(state, 0);
exp = n_randlimb(state) % 32;
nmod_poly_init(f, n);
nmod_poly_init(finv, n);
nmod_poly_init(res1, n);
nmod_poly_init(t, n);
do {
nmod_poly_randtest(f, state, n_randint(state, 50));
} while (nmod_poly_is_zero(f));
nmod_poly_reverse(finv, f, f->length);
nmod_poly_inv_series(finv, finv, f->length);
nmod_poly_powmod_x_ui_preinv(res1, exp, f, finv);
nmod_poly_powmod_x_ui_preinv(f, exp, f, finv);
result = (nmod_poly_equal(res1, f));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("exp: %wu\n\n", exp);
flint_printf("f:\n"); nmod_poly_print(f), flint_printf("\n\n");
flint_printf("res1:\n"); nmod_poly_print(res1), flint_printf("\n\n");
abort();
}
nmod_poly_clear(f);
nmod_poly_clear(finv);
nmod_poly_clear(res1);
nmod_poly_clear(t);
}
/* Aliasing of res and finv */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
nmod_poly_t res1, t, f, finv;
mp_limb_t n;
ulong exp;
n = n_randtest_prime(state, 0);
exp = n_randlimb(state) % 32;
nmod_poly_init(f, n);
nmod_poly_init(finv, n);
nmod_poly_init(res1, n);
nmod_poly_init(t, n);
do {
nmod_poly_randtest(f, state, n_randint(state, 50));
} while (nmod_poly_is_zero(f));
nmod_poly_reverse(finv, f, f->length);
nmod_poly_inv_series(finv, finv, f->length);
nmod_poly_powmod_x_ui_preinv(res1, exp, f, finv);
nmod_poly_powmod_x_ui_preinv(finv, exp, f, finv);
result = (nmod_poly_equal(res1, finv));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("exp: %wu\n\n", exp);
flint_printf("f:\n"); nmod_poly_print(f), flint_printf("\n\n");
flint_printf("finv:\n"); nmod_poly_print(finv), flint_printf("\n\n");
flint_printf("res1:\n"); nmod_poly_print(res1), flint_printf("\n\n");
abort();
}
nmod_poly_clear(f);
nmod_poly_clear(finv);
nmod_poly_clear(res1);
nmod_poly_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 "ulong_extras.h"
#include "nmod_vec.h"
#include "nmod_poly.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("product_roots_nmod_vec....");
fflush(stdout);
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t P, Q, tmp;
mp_ptr x;
mp_limb_t mod;
slong j, n;
n = n_randint(state, 100);
mod = n_randtest_prime(state, 0);
nmod_poly_init(P, mod);
nmod_poly_init(Q, mod);
nmod_poly_init(tmp, mod);
x = _nmod_vec_init(n);
_nmod_vec_randtest(x, state, n, P->mod);
nmod_poly_product_roots_nmod_vec(P, x, n);
nmod_poly_set_coeff_ui(Q, 0, UWORD(1));
for (j = 0; j < n; j++)
{
nmod_poly_zero(tmp);
nmod_poly_set_coeff_ui(tmp, 1, UWORD(1));
nmod_poly_set_coeff_ui(tmp, 0, n_negmod(x[j], mod));
nmod_poly_mul(Q, Q, tmp);
}
result = (nmod_poly_equal(P, Q));
if (!result)
{
flint_printf("FAIL (P != Q):\n");
nmod_poly_print(P), flint_printf("\n\n");
nmod_poly_print(Q), flint_printf("\n\n");
abort();
}
nmod_poly_clear(P);
nmod_poly_clear(Q);
nmod_poly_clear(tmp);
_nmod_vec_clear(x);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,203 @@
/*=============================================================================
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 <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("rem....");
fflush(stdout);
/* Check result of rem */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q, r, prod;
mp_limb_t n;
do n = n_randtest_not_zero(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q, n);
nmod_poly_init(r, n);
nmod_poly_init(prod, n);
nmod_poly_randtest(a, state, n_randint(state, 2000));
do nmod_poly_randtest(b, state, n_randint(state, 2000));
while (b->length == 0);
nmod_poly_div(q, a, b);
nmod_poly_rem(r, a, b);
nmod_poly_mul(prod, q, b);
nmod_poly_add(prod, prod, r);
result = (nmod_poly_equal(a, prod));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(prod), flint_printf("\n\n");
nmod_poly_print(q), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q);
nmod_poly_clear(r);
nmod_poly_clear(prod);
}
/* Check aliasing of a and r */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, r;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(r, n);
nmod_poly_randtest(a, state, n_randint(state, 2000));
do nmod_poly_randtest(b, state, n_randint(state, 2000));
while (b->length == 0);
nmod_poly_rem(r, a, b);
nmod_poly_rem(a, a, b);
result = (nmod_poly_equal(a, r));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(r);
}
/* Check aliasing of b and r */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, r;
mp_limb_t n;
do n = n_randtest(state);
while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(r, n);
nmod_poly_randtest(a, state, n_randint(state, 2000));
do nmod_poly_randtest(b, state, n_randint(state, 2000));
while (b->length == 0);
nmod_poly_rem(r, a, b);
nmod_poly_rem(b, a, b);
result = (nmod_poly_equal(b, r));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(r);
}
/* Check result of rem_q1 */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q0, r0, r;
mp_limb_t n = n_randprime(state, n_randint(state,FLINT_BITS-1)+2, 0);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q0, n);
nmod_poly_init(r0, n);
nmod_poly_init(r, n);
do nmod_poly_randtest(a, state, n_randint(state, 1000));
while (a->length < 2);
nmod_poly_fit_length(b, a->length - 1);
flint_mpn_zero(b->coeffs, a->length - 1);
nmod_poly_randtest_not_zero(b, state, n_randint(state, 1000) + 1);
do b->coeffs[a->length - 2] = n_randint(state, n);
while (b->coeffs[a->length - 2] == 0);
b->length = a->length - 1;
nmod_poly_divrem(q0, r0, a, b);
nmod_poly_rem(r, a, b);
result = (nmod_poly_equal(r0, r));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q0), flint_printf("\n\n");
nmod_poly_print(r0), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q0);
nmod_poly_clear(r0);
nmod_poly_clear(r);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,173 @@
/*=============================================================================
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) 2011 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("rem_basecase....");
fflush(stdout);
/* Check result of divrem */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, q0, r0, r;
mp_limb_t n;
do
{
n = n_randtest_not_zero(state);
} while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(q0, n);
nmod_poly_init(r0, n);
nmod_poly_init(r, n);
nmod_poly_randtest(a, state, n_randint(state, 200));
do
{
nmod_poly_randtest(b, state, n_randint(state, 200));
} while (b->length == 0);
nmod_poly_divrem_basecase(q0, r0, a, b);
nmod_poly_rem_basecase(r, a, b);
result = (nmod_poly_equal(r0, r));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(q0), flint_printf("\n\n");
nmod_poly_print(r0), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(q0);
nmod_poly_clear(r0);
nmod_poly_clear(r);
}
/* Check aliasing of a and r */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, r;
mp_limb_t n;
do
{
n = n_randtest(state);
} while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(r, n);
nmod_poly_randtest(a, state, n_randint(state, 200));
do
{
nmod_poly_randtest(b, state, n_randint(state, 200));
} while (b->length == 0);
nmod_poly_rem_basecase(r, a, b);
nmod_poly_rem_basecase(a, a, b);
result = (nmod_poly_equal(a, r));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(r);
}
/* Check aliasing of b and r */
for (i = 0; i < 500 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, r;
mp_limb_t n;
do
{
n = n_randtest(state);
} while (!n_is_probabprime(n));
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(r, n);
nmod_poly_randtest(a, state, n_randint(state, 200));
do
{
nmod_poly_randtest(b, state, n_randint(state, 200));
} while (b->length == 0);
nmod_poly_rem_basecase(r, a, b);
nmod_poly_rem_basecase(b, a, b);
result = (nmod_poly_equal(b, r));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(r);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

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 (C) 2011 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("resultant....");
fflush(stdout);
/* Check res(f, g) == (-1)^(deg f deg g) res(g, f) */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t f, g;
mp_limb_t x, y;
mp_limb_t n;
do n = n_randtest_not_zero(state);
while (!n_is_probabprime(n));
nmod_poly_init(f, n);
nmod_poly_init(g, n);
nmod_poly_randtest(f, state, n_randint(state, 200));
nmod_poly_randtest(g, state, n_randint(state, 200));
x = nmod_poly_resultant(f, g);
y = nmod_poly_resultant(g, f);
if ((nmod_poly_degree(f) * nmod_poly_degree(g)) % 2)
y = nmod_neg(y, f->mod);
result = (x == y);
if (!result)
{
flint_printf("FAIL (res(f, g) == (-1)^(deg f deg g) res(g, f)):\n");
nmod_poly_print(f), flint_printf("\n\n");
nmod_poly_print(g), flint_printf("\n\n");
flint_printf("x = %wu\n", x);
flint_printf("y = %wu\n", y);
flint_printf("n = %wu\n", n);
abort();
}
nmod_poly_clear(f);
nmod_poly_clear(g);
}
/* Check res(f h, g) == res(f, g) res(h, g) */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
nmod_poly_t f, g, h;
mp_limb_t x, y, z;
mp_limb_t n;
do n = n_randtest_not_zero(state);
while (!n_is_probabprime(n));
nmod_poly_init(f, n);
nmod_poly_init(g, n);
nmod_poly_init(h, n);
nmod_poly_randtest(f, state, n_randint(state, 200));
nmod_poly_randtest(g, state, n_randint(state, 200));
nmod_poly_randtest(h, state, n_randint(state, 200));
y = nmod_poly_resultant(f, g);
z = nmod_poly_resultant(h, g);
y = nmod_mul(y, z, f->mod);
nmod_poly_mul(f, f, h);
x = nmod_poly_resultant(f, g);
result = (x == y);
if (!result)
{
flint_printf("FAIL (res(f h, g) == res(f, g) res(h, g)):\n");
nmod_poly_print(f), flint_printf("\n\n");
nmod_poly_print(g), flint_printf("\n\n");
nmod_poly_print(h), flint_printf("\n\n");
flint_printf("x = %wu\n", x);
flint_printf("y = %wu\n", y);
flint_printf("z = %wd\n", z);
flint_printf("n = %wu\n", n);
abort();
}
nmod_poly_clear(f);
nmod_poly_clear(g);
nmod_poly_clear(h);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

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 (C) 2011 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("resultant_euclidean....");
fflush(stdout);
/* Check res(f, g) == (-1)^(deg f deg g) res(g, f) */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t f, g;
mp_limb_t x, y;
mp_limb_t n;
do n = n_randtest_not_zero(state);
while (!n_is_probabprime(n));
nmod_poly_init(f, n);
nmod_poly_init(g, n);
nmod_poly_randtest(f, state, n_randint(state, 200));
nmod_poly_randtest(g, state, n_randint(state, 200));
x = nmod_poly_resultant_euclidean(f, g);
y = nmod_poly_resultant_euclidean(g, f);
if ((nmod_poly_degree(f) * nmod_poly_degree(g)) % 2)
y = nmod_neg(y, f->mod);
result = (x == y);
if (!result)
{
flint_printf("FAIL (res(f, g) == (-1)^(deg f deg g) res(g, f)):\n");
nmod_poly_print(f), flint_printf("\n\n");
nmod_poly_print(g), flint_printf("\n\n");
flint_printf("x = %wu\n", x);
flint_printf("y = %wu\n", y);
flint_printf("n = %wu\n", n);
abort();
}
nmod_poly_clear(f);
nmod_poly_clear(g);
}
/* Check res(f h, g) == res(f, g) res(h, g) */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
nmod_poly_t f, g, h;
mp_limb_t x, y, z;
mp_limb_t n;
do n = n_randtest_not_zero(state);
while (!n_is_probabprime(n));
nmod_poly_init(f, n);
nmod_poly_init(g, n);
nmod_poly_init(h, n);
nmod_poly_randtest(f, state, n_randint(state, 200));
nmod_poly_randtest(g, state, n_randint(state, 200));
nmod_poly_randtest(h, state, n_randint(state, 200));
y = nmod_poly_resultant_euclidean(f, g);
z = nmod_poly_resultant_euclidean(h, g);
y = nmod_mul(y, z, f->mod);
nmod_poly_mul(f, f, h);
x = nmod_poly_resultant_euclidean(f, g);
result = (x == y);
if (!result)
{
flint_printf("FAIL (res(f h, g) == res(f, g) res(h, g)):\n");
nmod_poly_print(f), flint_printf("\n\n");
nmod_poly_print(g), flint_printf("\n\n");
nmod_poly_print(h), flint_printf("\n\n");
flint_printf("x = %wu\n", x);
flint_printf("y = %wu\n", y);
flint_printf("z = %wd\n", z);
flint_printf("n = %wu\n", n);
abort();
}
nmod_poly_clear(f);
nmod_poly_clear(g);
nmod_poly_clear(h);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,106 @@
/*=============================================================================
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 <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("reverse....");
fflush(stdout);
/* Check rev rev a == a */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b;
mp_limb_t n = n_randtest_not_zero(state);
slong len;
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_randtest(a, state, n_randint(state, 100));
len = nmod_poly_length(a);
nmod_poly_reverse(b, a, len);
nmod_poly_reverse(b, b, len);
result = (nmod_poly_equal(a, b));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("len = %wd, n = %wu\n", len, a->mod.n);
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
}
/* check reversal for m > a->len */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b;
mp_limb_t n = n_randtest_not_zero(state);
slong m = n_randint(state, 100) + 1;
slong len = n_randint(state, m);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_randtest(a, state, len);
nmod_poly_reverse(b, a, m);
nmod_poly_reverse(b, b, m);
result = (nmod_poly_equal(a, b));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("len = %wd, m = %wd, n = %wu\n", a->length, m, a->mod.n);
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,123 @@
/*=============================================================================
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 "nmod_vec.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("revert_series....");
fflush(stdout);
/* Check aliasing */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
nmod_poly_t f, g;
mp_limb_t m;
slong n;
m = n_randtest_prime(state, 0);
nmod_poly_init(f, m);
nmod_poly_init(g, m);
do {
nmod_poly_randtest(g, state, n_randint(state, 100));
} while (nmod_poly_get_coeff_ui(g, 1) == 0);
nmod_poly_set_coeff_ui(g, 0, 0);
do {
n = n_randint(state, 100);
} while (n >= m);
nmod_poly_revert_series(f, g, n);
nmod_poly_revert_series(g, g, n);
result = (nmod_poly_equal(f, g));
if (!result)
{
flint_printf("FAIL (aliasing):\n");
nmod_poly_print(f), flint_printf("\n\n");
nmod_poly_print(g), flint_printf("\n\n");
abort();
}
nmod_poly_clear(f);
nmod_poly_clear(g);
}
/* Check f(f^(-1)) = id */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t f, g, h;
mp_limb_t m;
slong n;
m = n_randtest_prime(state, 0);
nmod_poly_init(f, m);
nmod_poly_init(g, m);
nmod_poly_init(h, m);
do {
nmod_poly_randtest(g, state, n_randint(state, 100));
} while (nmod_poly_get_coeff_ui(g, 1) == 0);
nmod_poly_set_coeff_ui(g, 0, 0);
do {
n = n_randint(state, 100);
} while (n >= m);
nmod_poly_revert_series(f, g, n);
nmod_poly_compose_series(h, g, f, n);
result = ((n <= 1 && nmod_poly_is_zero(h)) ||
(h->length == 2 && h->coeffs[0] == 0 && h->coeffs[1] == 1));
if (!result)
{
flint_printf("FAIL (comparison):\n");
nmod_poly_print(g), flint_printf("\n\n");
nmod_poly_print(f), flint_printf("\n\n");
nmod_poly_print(h), flint_printf("\n\n");
abort();
}
nmod_poly_clear(f);
nmod_poly_clear(g);
nmod_poly_clear(h);
}
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 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 "nmod_vec.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("revert_series_lagrange....");
fflush(stdout);
/* Check aliasing */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
nmod_poly_t f, g;
mp_limb_t m;
slong n;
m = n_randtest_prime(state, 0);
nmod_poly_init(f, m);
nmod_poly_init(g, m);
do {
nmod_poly_randtest(g, state, n_randint(state, 100));
} while (nmod_poly_get_coeff_ui(g, 1) == 0);
nmod_poly_set_coeff_ui(g, 0, 0);
do {
n = n_randint(state, 100);
} while (n >= m);
nmod_poly_revert_series_lagrange(f, g, n);
nmod_poly_revert_series_lagrange(g, g, n);
result = (nmod_poly_equal(f, g));
if (!result)
{
flint_printf("FAIL (aliasing):\n");
nmod_poly_print(f), flint_printf("\n\n");
nmod_poly_print(g), flint_printf("\n\n");
abort();
}
nmod_poly_clear(f);
nmod_poly_clear(g);
}
/* Check f(f^(-1)) = id */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t f, g, h;
mp_limb_t m;
slong n;
m = n_randtest_prime(state, 0);
nmod_poly_init(f, m);
nmod_poly_init(g, m);
nmod_poly_init(h, m);
do {
nmod_poly_randtest(g, state, n_randint(state, 100));
} while (nmod_poly_get_coeff_ui(g, 1) == 0);
nmod_poly_set_coeff_ui(g, 0, 0);
do {
n = n_randint(state, 100);
} while (n >= m);
nmod_poly_revert_series_lagrange(f, g, n);
nmod_poly_compose_series(h, g, f, n);
result = ((n <= 1 && nmod_poly_is_zero(h)) ||
(h->length == 2 && h->coeffs[0] == 0 && h->coeffs[1] == 1));
if (!result)
{
flint_printf("FAIL (comparison):\n");
nmod_poly_print(g), flint_printf("\n\n");
nmod_poly_print(f), flint_printf("\n\n");
nmod_poly_print(h), flint_printf("\n\n");
abort();
}
nmod_poly_clear(f);
nmod_poly_clear(g);
nmod_poly_clear(h);
}
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 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 "nmod_vec.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("revert_series_lagrange_fast....");
fflush(stdout);
/* Check aliasing */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
nmod_poly_t f, g;
mp_limb_t m;
slong n;
m = n_randtest_prime(state, 0);
nmod_poly_init(f, m);
nmod_poly_init(g, m);
do {
nmod_poly_randtest(g, state, n_randint(state, 100));
} while (nmod_poly_get_coeff_ui(g, 1) == 0);
nmod_poly_set_coeff_ui(g, 0, 0);
do {
n = n_randint(state, 100);
} while (n >= m);
nmod_poly_revert_series_lagrange_fast(f, g, n);
nmod_poly_revert_series_lagrange_fast(g, g, n);
result = (nmod_poly_equal(f, g));
if (!result)
{
flint_printf("FAIL (aliasing):\n");
nmod_poly_print(f), flint_printf("\n\n");
nmod_poly_print(g), flint_printf("\n\n");
abort();
}
nmod_poly_clear(f);
nmod_poly_clear(g);
}
/* Check f(f^(-1)) = id */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t f, g, h;
mp_limb_t m;
slong n;
m = n_randtest_prime(state, 0);
nmod_poly_init(f, m);
nmod_poly_init(g, m);
nmod_poly_init(h, m);
do {
nmod_poly_randtest(g, state, n_randint(state, 100));
} while (nmod_poly_get_coeff_ui(g, 1) == 0);
nmod_poly_set_coeff_ui(g, 0, 0);
do {
n = n_randint(state, 100);
} while (n >= m);
nmod_poly_revert_series_lagrange_fast(f, g, n);
nmod_poly_compose_series(h, g, f, n);
result = ((n <= 1 && nmod_poly_is_zero(h)) ||
(h->length == 2 && h->coeffs[0] == 0 && h->coeffs[1] == 1));
if (!result)
{
flint_printf("FAIL (comparison):\n");
nmod_poly_print(g), flint_printf("\n\n");
nmod_poly_print(f), flint_printf("\n\n");
nmod_poly_print(h), flint_printf("\n\n");
abort();
}
nmod_poly_clear(f);
nmod_poly_clear(g);
nmod_poly_clear(h);
}
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 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 "nmod_vec.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("revert_series_newton....");
fflush(stdout);
/* Check aliasing */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
nmod_poly_t f, g;
mp_limb_t m;
slong n;
m = n_randtest_prime(state, 0);
nmod_poly_init(f, m);
nmod_poly_init(g, m);
do {
nmod_poly_randtest(g, state, n_randint(state, 100));
} while (nmod_poly_get_coeff_ui(g, 1) == 0);
nmod_poly_set_coeff_ui(g, 0, 0);
do {
n = n_randint(state, 100);
} while (n >= m);
nmod_poly_revert_series_newton(f, g, n);
nmod_poly_revert_series_newton(g, g, n);
result = (nmod_poly_equal(f, g));
if (!result)
{
flint_printf("FAIL (aliasing):\n");
nmod_poly_print(f), flint_printf("\n\n");
nmod_poly_print(g), flint_printf("\n\n");
abort();
}
nmod_poly_clear(f);
nmod_poly_clear(g);
}
/* Check f(f^(-1)) = id */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t f, g, h;
mp_limb_t m;
slong n;
m = n_randtest_prime(state, 0);
nmod_poly_init(f, m);
nmod_poly_init(g, m);
nmod_poly_init(h, m);
do {
nmod_poly_randtest(g, state, n_randint(state, 100));
} while (nmod_poly_get_coeff_ui(g, 1) == 0);
nmod_poly_set_coeff_ui(g, 0, 0);
do {
n = n_randint(state, 100);
} while (n >= m);
nmod_poly_revert_series_newton(f, g, n);
nmod_poly_compose_series(h, g, f, n);
result = ((n <= 1 && nmod_poly_is_zero(h)) ||
(h->length == 2 && h->coeffs[0] == 0 && h->coeffs[1] == 1));
if (!result)
{
flint_printf("FAIL (comparison):\n");
nmod_poly_print(g), flint_printf("\n\n");
nmod_poly_print(f), flint_printf("\n\n");
nmod_poly_print(h), flint_printf("\n\n");
abort();
}
nmod_poly_clear(f);
nmod_poly_clear(g);
nmod_poly_clear(h);
}
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 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("scalar_mul_nmod....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b;
mp_limb_t n = n_randtest_not_zero(state);
mp_limb_t c = n_randint(state, n);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_randtest(a, state, n_randint(state, 100));
nmod_poly_scalar_mul_nmod(b, a, c);
nmod_poly_scalar_mul_nmod(a, a, c);
result = (nmod_poly_equal(a, b));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
}
/* Check (a + b)*c = a*c + b*c */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, d1, d2;
mp_limb_t n = n_randtest_not_zero(state);
mp_limb_t c = n_randint(state, n);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(d1, n);
nmod_poly_init(d2, n);
nmod_poly_randtest(a, state, n_randint(state, 100));
nmod_poly_randtest(b, state, n_randint(state, 100));
nmod_poly_add(d1, a, b);
nmod_poly_scalar_mul_nmod(d1, d1, c);
nmod_poly_scalar_mul_nmod(d2, a, c);
nmod_poly_scalar_mul_nmod(b, b, c);
nmod_poly_add(d2, d2, b);
result = (nmod_poly_equal(d1, d2));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(d1), flint_printf("\n\n");
nmod_poly_print(d2), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(d1);
nmod_poly_clear(d2);
}
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) 2010 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("shift_left_right....");
fflush(stdout);
/* Check a << shift >> shift == a */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b;
mp_limb_t n = n_randtest_not_zero(state);
slong shift = n_randint(state, 100);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_randtest(a, state, n_randint(state, 100));
nmod_poly_shift_left(b, a, shift);
nmod_poly_shift_right(b, b, shift);
result = (nmod_poly_equal(a, b));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("shift = %wd, a->length = %wd, n = %wu\n",
shift, a->length, a->mod.n);
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
}
/* Check a << shift >> shift == a aliasing the other way */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
mp_limb_t n = n_randtest_not_zero(state);
slong shift = n_randint(state, 100);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(c, state, n_randint(state, 100));
nmod_poly_set(a, c);
nmod_poly_shift_left(c, c, shift);
nmod_poly_shift_right(b, c, shift);
result = (nmod_poly_equal(a, b));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("shift = %wd, c->length = %wd, n = %wu\n",
shift, c->length, a->mod.n);
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,119 @@
/*=============================================================================
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) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result = 1;
FLINT_TEST_INIT(state);
flint_printf("sin_series....");
fflush(stdout);
/* Check asin(sin(A)) = A */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t A, sinA, B;
slong n;
mp_limb_t mod;
do { mod = n_randtest_prime(state, 0); } while (mod == 2);
n = 1 + n_randtest(state) % 100;
n = FLINT_MIN(n, mod);
nmod_poly_init(A, mod);
nmod_poly_init(sinA, mod);
nmod_poly_init(B, mod);
nmod_poly_randtest(A, state, n_randint(state, 100));
nmod_poly_set_coeff_ui(A, 0, UWORD(0));
nmod_poly_sin_series(sinA, A, n);
nmod_poly_asin_series(B, sinA, n);
nmod_poly_truncate(A, n);
result = nmod_poly_equal(A, B);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("n = %wd, mod = %wu\n", n, mod);
flint_printf("A: "); nmod_poly_print(A), flint_printf("\n\n");
flint_printf("sin(A): "); nmod_poly_print(sinA), flint_printf("\n\n");
flint_printf("B: "); nmod_poly_print(B), flint_printf("\n\n");
abort();
}
nmod_poly_clear(A);
nmod_poly_clear(sinA);
nmod_poly_clear(B);
}
/* Check aliasing */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t A, B;
slong n;
mp_limb_t mod;
mod = n_randtest_prime(state, 0);
n = n_randtest(state) % 50;
n = FLINT_MIN(n, mod);
nmod_poly_init(A, mod);
nmod_poly_init(B, mod);
nmod_poly_randtest(A, state, n_randint(state, 50));
nmod_poly_set_coeff_ui(A, 0, UWORD(0));
nmod_poly_sin_series(B, A, n);
nmod_poly_sin_series(A, A, n);
result = nmod_poly_equal(A, B);
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(A), flint_printf("\n\n");
nmod_poly_print(B), flint_printf("\n\n");
abort();
}
nmod_poly_clear(A);
nmod_poly_clear(B);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,119 @@
/*=============================================================================
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) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result = 1;
FLINT_TEST_INIT(state);
flint_printf("sinh_series....");
fflush(stdout);
/* Check asinh(sinh(A)) = A */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t A, sinhA, B;
slong n;
mp_limb_t mod;
do { mod = n_randtest_prime(state, 0); } while (mod == 2);
n = 1 + n_randtest(state) % 100;
n = FLINT_MIN(n, mod);
nmod_poly_init(A, mod);
nmod_poly_init(sinhA, mod);
nmod_poly_init(B, mod);
nmod_poly_randtest(A, state, n_randint(state, 100));
nmod_poly_set_coeff_ui(A, 0, UWORD(0));
nmod_poly_sinh_series(sinhA, A, n);
nmod_poly_asinh_series(B, sinhA, n);
nmod_poly_truncate(A, n);
result = nmod_poly_equal(A, B);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("n = %wd, mod = %wu\n", n, mod);
flint_printf("A: "); nmod_poly_print(A), flint_printf("\n\n");
flint_printf("sinh(A): "); nmod_poly_print(sinhA), flint_printf("\n\n");
flint_printf("B: "); nmod_poly_print(B), flint_printf("\n\n");
abort();
}
nmod_poly_clear(A);
nmod_poly_clear(sinhA);
nmod_poly_clear(B);
}
/* Check aliasing */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t A, B;
slong n;
mp_limb_t mod;
mod = n_randtest_prime(state, 0);
n = n_randtest(state) % 50;
n = FLINT_MIN(n, mod);
nmod_poly_init(A, mod);
nmod_poly_init(B, mod);
nmod_poly_randtest(A, state, n_randint(state, 50));
nmod_poly_set_coeff_ui(A, 0, UWORD(0));
nmod_poly_sinh_series(B, A, n);
nmod_poly_sinh_series(A, A, n);
result = nmod_poly_equal(A, B);
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(A), flint_printf("\n\n");
nmod_poly_print(B), flint_printf("\n\n");
abort();
}
nmod_poly_clear(A);
nmod_poly_clear(B);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,160 @@
/*=============================================================================
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 <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i;
FLINT_TEST_INIT(state);
flint_printf("sqrt... ");
fflush(stdout);
/* Test aliasing */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b;
int square1, square2;
mp_limb_t mod;
mod = n_randtest_prime(state, 0);
nmod_poly_init(a, mod);
nmod_poly_init(b, mod);
nmod_poly_randtest(a, state, 1 + n_randint(state, 50));
if (n_randint(state, 2))
nmod_poly_mul(a, a, a);
square1 = nmod_poly_sqrt(b, a);
square2 = nmod_poly_sqrt(a, a);
if ((square1 != square2) || (square1 && !nmod_poly_equal(a, b)))
{
flint_printf("FAIL: aliasing:\n");
flint_printf("square1 = %d, square2 = %d\n\n", square1, square2);
flint_printf("a: "); nmod_poly_print(a); flint_printf("\n\n");
flint_printf("b: "); nmod_poly_print(b); flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
}
/* Test random squares */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
int square;
mp_limb_t mod;
mod = n_randtest_prime(state, 0);
nmod_poly_init(a, mod);
nmod_poly_init(b, mod);
nmod_poly_init(c, mod);
nmod_poly_randtest(a, state, 1 + n_randint(state, 50));
nmod_poly_mul(b, a, a);
square = nmod_poly_sqrt(c, b);
if (!square)
{
flint_printf("FAIL: square reported nonsquare:\n");
flint_printf("a: "); nmod_poly_print(a); flint_printf("\n\n");
flint_printf("b: "); nmod_poly_print(b); flint_printf("\n\n");
flint_printf("c: "); nmod_poly_print(c); flint_printf("\n\n");
abort();
}
nmod_poly_mul(c, c, c);
if (!nmod_poly_equal(c, b))
{
flint_printf("FAIL: sqrt(b)^2 != b:\n");
flint_printf("a: "); nmod_poly_print(a); flint_printf("\n\n");
flint_printf("b: "); nmod_poly_print(b); flint_printf("\n\n");
flint_printf("c: "); nmod_poly_print(c); flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Test "almost" squares */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
slong j;
int square;
mp_limb_t mod;
mod = n_randtest_prime(state, 0);
nmod_poly_init(a, mod);
nmod_poly_init(b, mod);
nmod_poly_init(c, mod);
nmod_poly_randtest_not_zero(a, state, 1 + n_randint(state, 50));
nmod_poly_mul(b, a, a);
j = n_randint(state, nmod_poly_length(b));
b->coeffs[j] = n_randint(state, mod);
_nmod_poly_normalise(b);
square = nmod_poly_sqrt(c, b);
if (square)
{
nmod_poly_mul(c, c, c);
if (!nmod_poly_equal(c, b))
{
flint_printf("FAIL: sqrt(b)^2 != b:\n");
flint_printf("a: "); nmod_poly_print(a); flint_printf("\n\n");
flint_printf("b: "); nmod_poly_print(b); flint_printf("\n\n");
flint_printf("c: "); nmod_poly_print(c); flint_printf("\n\n");
abort();
}
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,123 @@
/*=============================================================================
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 William Hart
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("sqrt_series....");
fflush(stdout);
/* Check g^2 = h mod x^m */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t h, g, r;
slong m;
mp_limb_t n;
do n = n_randtest_prime(state, 0);
while (n == UWORD(2));
nmod_poly_init(h, n);
nmod_poly_init(g, n);
nmod_poly_init(r, n);
do nmod_poly_randtest(h, state, n_randint(state, 1000));
while (h->length == 0);
nmod_poly_set_coeff_ui(h, 0, UWORD(1));
m = n_randint(state, h->length) + 1;
nmod_poly_sqrt_series(g, h, m);
nmod_poly_mullow(r, g, g, m);
nmod_poly_truncate(h, m);
result = (nmod_poly_equal(r, h));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(h), flint_printf("\n\n");
nmod_poly_print(g), flint_printf("\n\n");
nmod_poly_print(r), flint_printf("\n\n");
flint_printf("n = %wd\n", n);
abort();
}
nmod_poly_clear(h);
nmod_poly_clear(g);
nmod_poly_clear(r);
}
/* Check aliasing of h and g */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
nmod_poly_t g, h;
slong m;
mp_limb_t n;
do n = n_randtest_prime(state, 0);
while (n == UWORD(2));
nmod_poly_init(h, n);
nmod_poly_init(g, n);
do nmod_poly_randtest(h, state, n_randint(state, 500));
while (h->length == 0);
nmod_poly_set_coeff_ui(h, 0, UWORD(1));
m = n_randint(state, h->length) + 1;
nmod_poly_sqrt_series(g, h, m);
nmod_poly_sqrt_series(h, h, m);
result = (nmod_poly_equal(g, h));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(h), flint_printf("\n\n");
nmod_poly_print(g), flint_printf("\n\n");
flint_printf("n = %wd, m = %wd\n", n, m);
abort();
}
nmod_poly_clear(g);
nmod_poly_clear(h);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,142 @@
/*=============================================================================
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 <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "nmod_vec.h"
#include "nmod_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("sub....");
fflush(stdout);
/* Check a - b = a + neg(b) */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c, d;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_init(d, n);
nmod_poly_randtest(a, state, n_randint(state, 100));
nmod_poly_randtest(b, state, n_randint(state, 100));
nmod_poly_sub(c, a, b);
nmod_poly_neg(b, b);
nmod_poly_add(d, a, b);
result = (nmod_poly_equal(d, d));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(c), flint_printf("\n\n");
nmod_poly_print(d), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
nmod_poly_clear(d);
}
/* Check aliasing of a and c */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(a, state, n_randint(state, 100));
nmod_poly_randtest(b, state, n_randint(state, 100));
nmod_poly_sub(c, a, b);
nmod_poly_sub(a, a, b);
result = (nmod_poly_equal(a, c));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(c), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
/* Check aliasing of b and c */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
nmod_poly_t a, b, c;
mp_limb_t n = n_randtest_not_zero(state);
nmod_poly_init(a, n);
nmod_poly_init(b, n);
nmod_poly_init(c, n);
nmod_poly_randtest(a, state, n_randint(state, 100));
nmod_poly_randtest(b, state, n_randint(state, 100));
nmod_poly_sub(c, a, b);
nmod_poly_sub(b, a, b);
result = (nmod_poly_equal(b, c));
if (!result)
{
flint_printf("FAIL:\n");
nmod_poly_print(a), flint_printf("\n\n");
nmod_poly_print(b), flint_printf("\n\n");
nmod_poly_print(c), flint_printf("\n\n");
abort();
}
nmod_poly_clear(a);
nmod_poly_clear(b);
nmod_poly_clear(c);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

Some files were not shown because too many files have changed in this diff Show More