ALL: Add flint
This commit is contained in:
121
external/flint-2.4.3/fmpz_mod_poly/test/t-add.c
vendored
Normal file
121
external/flint-2.4.3/fmpz_mod_poly/test/t-add.c
vendored
Normal 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, 2010 Sebastian Pancratz
|
||||
Copyright (C) 2009 William Hart
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_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 < 10000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, c;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 100));
|
||||
|
||||
fmpz_mod_poly_add(c, a, b);
|
||||
fmpz_mod_poly_add(a, a, b);
|
||||
|
||||
result = (fmpz_mod_poly_equal(a, c));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Check aliasing of b and c */
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, c;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 100));
|
||||
|
||||
fmpz_mod_poly_add(c, a, b);
|
||||
fmpz_mod_poly_add(b, a, b);
|
||||
|
||||
result = (fmpz_mod_poly_equal(b, c));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
170
external/flint-2.4.3/fmpz_mod_poly/test/t-compose_divconquer.c
vendored
Normal file
170
external/flint-2.4.3/fmpz_mod_poly/test/t-compose_divconquer.c
vendored
Normal 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) 2011, 2010 Sebastian Pancratz
|
||||
Copyright (C) 2009 William Hart
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("compose_divconquer....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
/* Check aliasing of a and c */
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, c;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 80));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 30));
|
||||
|
||||
fmpz_mod_poly_compose_divconquer(c, a, b);
|
||||
fmpz_mod_poly_compose_divconquer(a, a, b);
|
||||
|
||||
result = (fmpz_mod_poly_equal(a, c));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Check aliasing of b and c */
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, c;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 80));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 30));
|
||||
|
||||
fmpz_mod_poly_compose_divconquer(c, a, b);
|
||||
fmpz_mod_poly_compose_divconquer(b, a, b);
|
||||
|
||||
result = (fmpz_mod_poly_equal(b, c));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Compare with composition over Z[X] */
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, c, d;
|
||||
fmpz_poly_t A, B, C;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 80));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 30));
|
||||
|
||||
fmpz_poly_init(A);
|
||||
fmpz_poly_init(B);
|
||||
fmpz_poly_init(C);
|
||||
fmpz_mod_poly_get_fmpz_poly(A, a);
|
||||
fmpz_mod_poly_get_fmpz_poly(B, b);
|
||||
|
||||
fmpz_mod_poly_compose_divconquer(c, a, b);
|
||||
fmpz_poly_compose(C, A, B);
|
||||
fmpz_mod_poly_set_fmpz_poly(d, C);
|
||||
|
||||
result = (fmpz_mod_poly_equal(c, d));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(d), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(d);
|
||||
fmpz_poly_clear(A);
|
||||
fmpz_poly_clear(B);
|
||||
fmpz_poly_clear(C);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
170
external/flint-2.4.3/fmpz_mod_poly/test/t-compose_horner.c
vendored
Normal file
170
external/flint-2.4.3/fmpz_mod_poly/test/t-compose_horner.c
vendored
Normal 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) 2011, 2010 Sebastian Pancratz
|
||||
Copyright (C) 2009 William Hart
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("compose_horner....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
/* Check aliasing of a and c */
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, c;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 80));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 30));
|
||||
|
||||
fmpz_mod_poly_compose_horner(c, a, b);
|
||||
fmpz_mod_poly_compose_horner(a, a, b);
|
||||
|
||||
result = (fmpz_mod_poly_equal(a, c));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Check aliasing of b and c */
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, c;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 80));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 30));
|
||||
|
||||
fmpz_mod_poly_compose_horner(c, a, b);
|
||||
fmpz_mod_poly_compose_horner(b, a, b);
|
||||
|
||||
result = (fmpz_mod_poly_equal(b, c));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Compare with composition over Z[X] */
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, c, d;
|
||||
fmpz_poly_t A, B, C;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 80));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 30));
|
||||
|
||||
fmpz_poly_init(A);
|
||||
fmpz_poly_init(B);
|
||||
fmpz_poly_init(C);
|
||||
fmpz_mod_poly_get_fmpz_poly(A, a);
|
||||
fmpz_mod_poly_get_fmpz_poly(B, b);
|
||||
|
||||
fmpz_mod_poly_compose_horner(c, a, b);
|
||||
fmpz_poly_compose(C, A, B);
|
||||
fmpz_mod_poly_set_fmpz_poly(d, C);
|
||||
|
||||
result = (fmpz_mod_poly_equal(c, d));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(d), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(d);
|
||||
fmpz_poly_clear(A);
|
||||
fmpz_poly_clear(B);
|
||||
fmpz_poly_clear(C);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
202
external/flint-2.4.3/fmpz_mod_poly/test/t-compose_mod.c
vendored
Normal file
202
external/flint-2.4.3/fmpz_mod_poly/test/t-compose_mod.c
vendored
Normal file
@@ -0,0 +1,202 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2012 Lina Kulakova
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz_mod_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 < 1000; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, b, c, d, e;
|
||||
fmpz_t p;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
fmpz_mod_poly_init(e, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest_not_zero(c, state, n_randint(state, 20) + 1);
|
||||
|
||||
fmpz_mod_poly_compose_mod(d, a, b, c);
|
||||
fmpz_mod_poly_compose(e, a, b);
|
||||
fmpz_mod_poly_rem(e, e, c);
|
||||
|
||||
if (!fmpz_mod_poly_equal(d, e))
|
||||
{
|
||||
flint_printf("FAIL (composition):\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a); flint_printf("\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b); flint_printf("\n");
|
||||
flint_printf("c:\n"); fmpz_mod_poly_print(c); flint_printf("\n");
|
||||
flint_printf("d:\n"); fmpz_mod_poly_print(d); flint_printf("\n");
|
||||
flint_printf("e:\n"); fmpz_mod_poly_print(e); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(d);
|
||||
fmpz_mod_poly_clear(e);
|
||||
}
|
||||
|
||||
/* Test aliasing of res and a */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, b, c, d;
|
||||
fmpz_t p;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest_not_zero(c, state, n_randint(state, 20) + 1);
|
||||
|
||||
fmpz_mod_poly_compose_mod(d, a, b, c);
|
||||
fmpz_mod_poly_compose_mod(a, a, b, c);
|
||||
|
||||
if (!fmpz_mod_poly_equal(d, a))
|
||||
{
|
||||
flint_printf("FAIL (aliasing a):\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a); flint_printf("\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b); flint_printf("\n");
|
||||
flint_printf("c:\n"); fmpz_mod_poly_print(c); flint_printf("\n");
|
||||
flint_printf("d:\n"); fmpz_mod_poly_print(d); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(d);
|
||||
}
|
||||
|
||||
/* Test aliasing of res and b */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, b, c, d;
|
||||
fmpz_t p;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest_not_zero(c, state, n_randint(state, 20) + 1);
|
||||
|
||||
fmpz_mod_poly_compose_mod(d, a, b, c);
|
||||
fmpz_mod_poly_compose_mod(b, a, b, c);
|
||||
|
||||
if (!fmpz_mod_poly_equal(d, b))
|
||||
{
|
||||
flint_printf("FAIL (aliasing b)\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a); flint_printf("\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b); flint_printf("\n");
|
||||
flint_printf("c:\n"); fmpz_mod_poly_print(c); flint_printf("\n");
|
||||
flint_printf("d:\n"); fmpz_mod_poly_print(d); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(d);
|
||||
}
|
||||
|
||||
/* Test aliasing of res and c */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, b, c, d;
|
||||
fmpz_t p;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest_not_zero(c, state, n_randint(state, 20) + 1);
|
||||
|
||||
fmpz_mod_poly_compose_mod(d, a, b, c);
|
||||
fmpz_mod_poly_compose_mod(c, a, b, c);
|
||||
|
||||
if (!fmpz_mod_poly_equal(d, c))
|
||||
{
|
||||
flint_printf("FAIL (aliasing c)\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a); flint_printf("\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b); flint_printf("\n");
|
||||
flint_printf("c:\n"); fmpz_mod_poly_print(c); flint_printf("\n");
|
||||
flint_printf("d:\n"); fmpz_mod_poly_print(d); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(d);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
206
external/flint-2.4.3/fmpz_mod_poly/test/t-compose_mod_brent_kung.c
vendored
Normal file
206
external/flint-2.4.3/fmpz_mod_poly/test/t-compose_mod_brent_kung.c
vendored
Normal file
@@ -0,0 +1,206 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2012 Lina Kulakova
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz_mod_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 < 2000; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, b, c, d, e;
|
||||
fmpz_t p;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
fmpz_mod_poly_init(e, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest_not_zero(c, state, n_randint(state, 20) + 1);
|
||||
|
||||
fmpz_mod_poly_rem(a, a, c);
|
||||
fmpz_mod_poly_compose_mod_brent_kung(d, a, b, c);
|
||||
fmpz_mod_poly_compose(e, a, b);
|
||||
fmpz_mod_poly_rem(e, e, c);
|
||||
|
||||
if (!fmpz_mod_poly_equal(d, e))
|
||||
{
|
||||
flint_printf("FAIL (composition):\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a); flint_printf("\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b); flint_printf("\n");
|
||||
flint_printf("c:\n"); fmpz_mod_poly_print(c); flint_printf("\n");
|
||||
flint_printf("d:\n"); fmpz_mod_poly_print(d); flint_printf("\n");
|
||||
flint_printf("e:\n"); fmpz_mod_poly_print(e); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(d);
|
||||
fmpz_mod_poly_clear(e);
|
||||
}
|
||||
|
||||
/* Test aliasing of res and a */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, b, c, d;
|
||||
fmpz_t p;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest_not_zero(c, state, n_randint(state, 20) + 1);
|
||||
|
||||
fmpz_mod_poly_rem(a, a, c);
|
||||
fmpz_mod_poly_compose_mod_brent_kung(d, a, b, c);
|
||||
fmpz_mod_poly_compose_mod_brent_kung(a, a, b, c);
|
||||
|
||||
if (!fmpz_mod_poly_equal(d, a))
|
||||
{
|
||||
flint_printf("FAIL (aliasing a):\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a); flint_printf("\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b); flint_printf("\n");
|
||||
flint_printf("c:\n"); fmpz_mod_poly_print(c); flint_printf("\n");
|
||||
flint_printf("d:\n"); fmpz_mod_poly_print(d); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(d);
|
||||
}
|
||||
|
||||
/* Test aliasing of res and b */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, b, c, d;
|
||||
fmpz_t p;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest_not_zero(c, state, n_randint(state, 20) + 1);
|
||||
|
||||
fmpz_mod_poly_rem(a, a, c);
|
||||
fmpz_mod_poly_compose_mod_brent_kung(d, a, b, c);
|
||||
fmpz_mod_poly_compose_mod_brent_kung(b, a, b, c);
|
||||
|
||||
if (!fmpz_mod_poly_equal(d, b))
|
||||
{
|
||||
flint_printf("FAIL (aliasing b)\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a); flint_printf("\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b); flint_printf("\n");
|
||||
flint_printf("c:\n"); fmpz_mod_poly_print(c); flint_printf("\n");
|
||||
flint_printf("d:\n"); fmpz_mod_poly_print(d); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(d);
|
||||
}
|
||||
|
||||
/* Test aliasing of res and c */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, b, c, d;
|
||||
fmpz_t p;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest_not_zero(c, state, n_randint(state, 20) + 1);
|
||||
|
||||
fmpz_mod_poly_rem(a, a, c);
|
||||
fmpz_mod_poly_compose_mod_brent_kung(d, a, b, c);
|
||||
fmpz_mod_poly_compose_mod_brent_kung(c, a, b, c);
|
||||
|
||||
if (!fmpz_mod_poly_equal(d, c))
|
||||
{
|
||||
flint_printf("FAIL (aliasing c)\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a); flint_printf("\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b); flint_printf("\n");
|
||||
flint_printf("c:\n"); fmpz_mod_poly_print(c); flint_printf("\n");
|
||||
flint_printf("d:\n"); fmpz_mod_poly_print(d); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(d);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
253
external/flint-2.4.3/fmpz_mod_poly/test/t-compose_mod_brent_kung_precomp_preinv.c
vendored
Normal file
253
external/flint-2.4.3/fmpz_mod_poly/test/t-compose_mod_brent_kung_precomp_preinv.c
vendored
Normal file
@@ -0,0 +1,253 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2012 Lina Kulakova
|
||||
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 "fmpz_mod_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);
|
||||
|
||||
/* no aliasing */
|
||||
for (i = 0; i < 2000; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, b, c, cinv, d, e;
|
||||
fmpz_t p;
|
||||
fmpz_mat_t B;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(cinv, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
fmpz_mod_poly_init(e, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest_not_zero(c, state, n_randint(state, 20) + 1);
|
||||
|
||||
fmpz_mod_poly_reverse (cinv, c, c->length);
|
||||
fmpz_mod_poly_inv_series_newton (cinv, cinv, c->length);
|
||||
fmpz_mat_init (B, n_sqrt (c->length-1)+1, c->length-1);
|
||||
fmpz_mod_poly_precompute_matrix (B, b, c, cinv);
|
||||
|
||||
fmpz_mod_poly_rem(a, a, c);
|
||||
fmpz_mod_poly_compose_mod_brent_kung_precomp_preinv(d, a, B, c, cinv);
|
||||
fmpz_mod_poly_compose(e, a, b);
|
||||
fmpz_mod_poly_rem(e, e, c);
|
||||
|
||||
if (!fmpz_mod_poly_equal(d, e))
|
||||
{
|
||||
flint_printf("FAIL (composition):\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a); flint_printf("\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b); flint_printf("\n");
|
||||
flint_printf("c:\n"); fmpz_mod_poly_print(c); flint_printf("\n");
|
||||
flint_printf("d:\n"); fmpz_mod_poly_print(d); flint_printf("\n");
|
||||
flint_printf("e:\n"); fmpz_mod_poly_print(e); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mat_clear (B);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(cinv);
|
||||
fmpz_mod_poly_clear(d);
|
||||
fmpz_mod_poly_clear(e);
|
||||
}
|
||||
|
||||
/* Test aliasing of res and a */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, b, c, cinv, d;
|
||||
fmpz_t p;
|
||||
fmpz_mat_t B;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(cinv, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest_not_zero(c, state, n_randint(state, 20) + 1);
|
||||
|
||||
fmpz_mod_poly_reverse (cinv, c, c->length);
|
||||
fmpz_mod_poly_inv_series_newton (cinv, cinv, c->length);
|
||||
fmpz_mat_init (B, n_sqrt (c->length-1)+1, c->length-1);
|
||||
fmpz_mod_poly_precompute_matrix (B, b, c, cinv);
|
||||
|
||||
fmpz_mod_poly_rem(a, a, c);
|
||||
fmpz_mod_poly_compose_mod_brent_kung_precomp_preinv(d, a, B, c, cinv);
|
||||
fmpz_mod_poly_compose_mod_brent_kung_precomp_preinv(a, a, B, c, cinv);
|
||||
|
||||
if (!fmpz_mod_poly_equal(d, a))
|
||||
{
|
||||
flint_printf("FAIL (aliasing a):\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a); flint_printf("\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b); flint_printf("\n");
|
||||
flint_printf("c:\n"); fmpz_mod_poly_print(c); flint_printf("\n");
|
||||
flint_printf("d:\n"); fmpz_mod_poly_print(d); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mat_clear (B);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(cinv);
|
||||
fmpz_mod_poly_clear(d);
|
||||
}
|
||||
|
||||
/* Test aliasing of res and c */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, b, c, cinv, d;
|
||||
fmpz_t p;
|
||||
fmpz_mat_t B;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(cinv, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest_not_zero(c, state, n_randint(state, 20) + 1);
|
||||
|
||||
fmpz_mod_poly_reverse (cinv, c, c->length);
|
||||
fmpz_mod_poly_inv_series_newton (cinv, cinv, c->length);
|
||||
fmpz_mat_init (B, n_sqrt (c->length-1)+1, c->length-1);
|
||||
fmpz_mod_poly_precompute_matrix (B, b, c, cinv);
|
||||
|
||||
fmpz_mod_poly_rem(a, a, c);
|
||||
fmpz_mod_poly_compose_mod_brent_kung_precomp_preinv(d, a, B, c, cinv);
|
||||
fmpz_mod_poly_compose_mod_brent_kung_precomp_preinv(c, a, B, c, cinv);
|
||||
|
||||
if (!fmpz_mod_poly_equal(d, c))
|
||||
{
|
||||
flint_printf("FAIL (aliasing c)\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a); flint_printf("\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b); flint_printf("\n");
|
||||
flint_printf("c:\n"); fmpz_mod_poly_print(c); flint_printf("\n");
|
||||
flint_printf("d:\n"); fmpz_mod_poly_print(d); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mat_clear (B);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(cinv);
|
||||
fmpz_mod_poly_clear(d);
|
||||
}
|
||||
|
||||
/* Test aliasing of res and cinv */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, b, c, cinv, d;
|
||||
fmpz_t p;
|
||||
fmpz_mat_t B;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(cinv, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest_not_zero(c, state, n_randint(state, 20) + 1);
|
||||
|
||||
fmpz_mod_poly_reverse (cinv, c, c->length);
|
||||
fmpz_mod_poly_inv_series_newton (cinv, cinv, c->length);
|
||||
fmpz_mat_init (B, n_sqrt (c->length-1)+1, c->length-1);
|
||||
fmpz_mod_poly_precompute_matrix (B, b, c, cinv);
|
||||
|
||||
fmpz_mod_poly_rem(a, a, c);
|
||||
fmpz_mod_poly_compose_mod_brent_kung_precomp_preinv(d, a, B, c, cinv);
|
||||
fmpz_mod_poly_compose_mod_brent_kung_precomp_preinv(cinv, a, B, c, cinv);
|
||||
|
||||
if (!fmpz_mod_poly_equal(d, cinv))
|
||||
{
|
||||
flint_printf("FAIL (aliasing c)\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a); flint_printf("\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b); flint_printf("\n");
|
||||
flint_printf("c:\n"); fmpz_mod_poly_print(c); flint_printf("\n");
|
||||
flint_printf("d:\n"); fmpz_mod_poly_print(d); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mat_clear (B);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(cinv);
|
||||
fmpz_mod_poly_clear(d);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
281
external/flint-2.4.3/fmpz_mod_poly/test/t-compose_mod_brent_kung_preinv.c
vendored
Normal file
281
external/flint-2.4.3/fmpz_mod_poly/test/t-compose_mod_brent_kung_preinv.c
vendored
Normal file
@@ -0,0 +1,281 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2012 Lina Kulakova
|
||||
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 "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("compose_mod_brent_kung_preinv....");
|
||||
fflush(stdout);
|
||||
|
||||
/* no aliasing */
|
||||
for (i = 0; i < 2000; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, b, c, cinv, d, e;
|
||||
fmpz_t p;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(cinv, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
fmpz_mod_poly_init(e, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest_not_zero(c, state, n_randint(state, 20) + 1);
|
||||
|
||||
fmpz_mod_poly_reverse (cinv, c, c->length);
|
||||
fmpz_mod_poly_inv_series_newton (cinv, cinv, c->length);
|
||||
|
||||
fmpz_mod_poly_rem(a, a, c);
|
||||
fmpz_mod_poly_compose_mod_brent_kung_preinv(d, a, b, c, cinv);
|
||||
fmpz_mod_poly_compose(e, a, b);
|
||||
fmpz_mod_poly_rem(e, e, c);
|
||||
|
||||
if (!fmpz_mod_poly_equal(d, e))
|
||||
{
|
||||
flint_printf("FAIL (composition):\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a); flint_printf("\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b); flint_printf("\n");
|
||||
flint_printf("c:\n"); fmpz_mod_poly_print(c); flint_printf("\n");
|
||||
flint_printf("d:\n"); fmpz_mod_poly_print(d); flint_printf("\n");
|
||||
flint_printf("e:\n"); fmpz_mod_poly_print(e); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(cinv);
|
||||
fmpz_mod_poly_clear(d);
|
||||
fmpz_mod_poly_clear(e);
|
||||
}
|
||||
|
||||
/* Test aliasing of res and a */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, b, c, cinv, d;
|
||||
fmpz_t p;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(cinv, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest_not_zero(c, state, n_randint(state, 20) + 1);
|
||||
|
||||
fmpz_mod_poly_reverse (cinv, c, c->length);
|
||||
fmpz_mod_poly_inv_series_newton (cinv, cinv, c->length);
|
||||
|
||||
fmpz_mod_poly_rem(a, a, c);
|
||||
fmpz_mod_poly_compose_mod_brent_kung_preinv(d, a, b, c, cinv);
|
||||
fmpz_mod_poly_compose_mod_brent_kung_preinv(a, a, b, c, cinv);
|
||||
|
||||
if (!fmpz_mod_poly_equal(d, a))
|
||||
{
|
||||
flint_printf("FAIL (aliasing a):\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a); flint_printf("\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b); flint_printf("\n");
|
||||
flint_printf("c:\n"); fmpz_mod_poly_print(c); flint_printf("\n");
|
||||
flint_printf("d:\n"); fmpz_mod_poly_print(d); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(cinv);
|
||||
fmpz_mod_poly_clear(d);
|
||||
}
|
||||
|
||||
/* Test aliasing of res and b */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, b, c, cinv, d;
|
||||
fmpz_t p;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(cinv, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest_not_zero(c, state, n_randint(state, 20) + 1);
|
||||
|
||||
fmpz_mod_poly_reverse (cinv, c, c->length);
|
||||
fmpz_mod_poly_inv_series_newton (cinv, cinv, c->length);
|
||||
|
||||
fmpz_mod_poly_rem(a, a, c);
|
||||
fmpz_mod_poly_compose_mod_brent_kung_preinv(d, a, b, c, cinv);
|
||||
fmpz_mod_poly_compose_mod_brent_kung_preinv(b, a, b, c, cinv);
|
||||
|
||||
if (!fmpz_mod_poly_equal(d, b))
|
||||
{
|
||||
flint_printf("FAIL (aliasing b)\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a); flint_printf("\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b); flint_printf("\n");
|
||||
flint_printf("c:\n"); fmpz_mod_poly_print(c); flint_printf("\n");
|
||||
flint_printf("d:\n"); fmpz_mod_poly_print(d); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(cinv);
|
||||
fmpz_mod_poly_clear(d);
|
||||
}
|
||||
|
||||
/* Test aliasing of res and c */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, b, c, cinv, d;
|
||||
fmpz_t p;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(cinv, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest_not_zero(c, state, n_randint(state, 20) + 1);
|
||||
|
||||
fmpz_mod_poly_reverse (cinv, c, c->length);
|
||||
fmpz_mod_poly_inv_series_newton (cinv, cinv, c->length);
|
||||
|
||||
fmpz_mod_poly_rem(a, a, c);
|
||||
fmpz_mod_poly_compose_mod_brent_kung_preinv(d, a, b, c, cinv);
|
||||
fmpz_mod_poly_compose_mod_brent_kung_preinv(c, a, b, c, cinv);
|
||||
|
||||
if (!fmpz_mod_poly_equal(d, c))
|
||||
{
|
||||
flint_printf("FAIL (aliasing c)\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a); flint_printf("\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b); flint_printf("\n");
|
||||
flint_printf("c:\n"); fmpz_mod_poly_print(c); flint_printf("\n");
|
||||
flint_printf("d:\n"); fmpz_mod_poly_print(d); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(cinv);
|
||||
fmpz_mod_poly_clear(d);
|
||||
}
|
||||
|
||||
/* Test aliasing of res and cinv */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, b, c, cinv, d;
|
||||
fmpz_t p;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(cinv, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest_not_zero(c, state, n_randint(state, 20) + 1);
|
||||
|
||||
fmpz_mod_poly_reverse (cinv, c, c->length);
|
||||
fmpz_mod_poly_inv_series_newton (cinv, cinv, c->length);
|
||||
|
||||
fmpz_mod_poly_rem(a, a, c);
|
||||
fmpz_mod_poly_compose_mod_brent_kung_preinv(d, a, b, c, cinv);
|
||||
fmpz_mod_poly_compose_mod_brent_kung_preinv(cinv, a, b, c, cinv);
|
||||
|
||||
if (!fmpz_mod_poly_equal(d, cinv))
|
||||
{
|
||||
flint_printf("FAIL (aliasing c)\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a); flint_printf("\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b); flint_printf("\n");
|
||||
flint_printf("c:\n"); fmpz_mod_poly_print(c); flint_printf("\n");
|
||||
flint_printf("d:\n"); fmpz_mod_poly_print(d); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(cinv);
|
||||
fmpz_mod_poly_clear(d);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
202
external/flint-2.4.3/fmpz_mod_poly/test/t-compose_mod_horner.c
vendored
Normal file
202
external/flint-2.4.3/fmpz_mod_poly/test/t-compose_mod_horner.c
vendored
Normal file
@@ -0,0 +1,202 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2012 Lina Kulakova
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz_mod_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 < 1000; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, b, c, d, e;
|
||||
fmpz_t p;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
fmpz_mod_poly_init(e, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest_not_zero(c, state, n_randint(state, 20) + 1);
|
||||
|
||||
fmpz_mod_poly_compose_mod_horner(d, a, b, c);
|
||||
fmpz_mod_poly_compose(e, a, b);
|
||||
fmpz_mod_poly_rem(e, e, c);
|
||||
|
||||
if (!fmpz_mod_poly_equal(d, e))
|
||||
{
|
||||
flint_printf("FAIL (composition):\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a); flint_printf("\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b); flint_printf("\n");
|
||||
flint_printf("c:\n"); fmpz_mod_poly_print(c); flint_printf("\n");
|
||||
flint_printf("d:\n"); fmpz_mod_poly_print(d); flint_printf("\n");
|
||||
flint_printf("e:\n"); fmpz_mod_poly_print(e); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(d);
|
||||
fmpz_mod_poly_clear(e);
|
||||
}
|
||||
|
||||
/* Test aliasing of res and a */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, b, c, d;
|
||||
fmpz_t p;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest_not_zero(c, state, n_randint(state, 20) + 1);
|
||||
|
||||
fmpz_mod_poly_compose_mod_horner(d, a, b, c);
|
||||
fmpz_mod_poly_compose_mod_horner(a, a, b, c);
|
||||
|
||||
if (!fmpz_mod_poly_equal(d, a))
|
||||
{
|
||||
flint_printf("FAIL (aliasing a):\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a); flint_printf("\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b); flint_printf("\n");
|
||||
flint_printf("c:\n"); fmpz_mod_poly_print(c); flint_printf("\n");
|
||||
flint_printf("d:\n"); fmpz_mod_poly_print(d); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(d);
|
||||
}
|
||||
|
||||
/* Test aliasing of res and b */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, b, c, d;
|
||||
fmpz_t p;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest_not_zero(c, state, n_randint(state, 20) + 1);
|
||||
|
||||
fmpz_mod_poly_compose_mod_horner(d, a, b, c);
|
||||
fmpz_mod_poly_compose_mod_horner(b, a, b, c);
|
||||
|
||||
if (!fmpz_mod_poly_equal(d, b))
|
||||
{
|
||||
flint_printf("FAIL (aliasing b)\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a); flint_printf("\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b); flint_printf("\n");
|
||||
flint_printf("c:\n"); fmpz_mod_poly_print(c); flint_printf("\n");
|
||||
flint_printf("d:\n"); fmpz_mod_poly_print(d); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(d);
|
||||
}
|
||||
|
||||
/* Test aliasing of res and c */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, b, c, d;
|
||||
fmpz_t p;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_randtest_not_zero(c, state, n_randint(state, 20) + 1);
|
||||
|
||||
fmpz_mod_poly_compose_mod_horner(d, a, b, c);
|
||||
fmpz_mod_poly_compose_mod_horner(c, a, b, c);
|
||||
|
||||
if (!fmpz_mod_poly_equal(d, c))
|
||||
{
|
||||
flint_printf("FAIL (aliasing c)\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a); flint_printf("\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b); flint_printf("\n");
|
||||
flint_printf("c:\n"); fmpz_mod_poly_print(c); flint_printf("\n");
|
||||
flint_printf("d:\n"); fmpz_mod_poly_print(d); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(d);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
163
external/flint-2.4.3/fmpz_mod_poly/test/t-derivative.c
vendored
Normal file
163
external/flint-2.4.3/fmpz_mod_poly/test/t-derivative.c
vendored
Normal file
@@ -0,0 +1,163 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011, 2010 Sebastian Pancratz
|
||||
Copyright (C) 2009 William Hart
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("derivative....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
/* Check aliasing */
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, c;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_set(b, a);
|
||||
|
||||
fmpz_mod_poly_derivative(c, b);
|
||||
fmpz_mod_poly_derivative(b, b);
|
||||
|
||||
result = (fmpz_mod_poly_equal(b, c));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL (alias):\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Check constants have derivative zero */
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 2));
|
||||
|
||||
fmpz_mod_poly_derivative(b, a);
|
||||
|
||||
result = (b->length == 0);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL (da == 0):\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Check (f g)' = f' g + f g' */
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, c, d, lhs, rhs;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
fmpz_mod_poly_init(lhs, p);
|
||||
fmpz_mod_poly_init(rhs, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 100));
|
||||
|
||||
fmpz_mod_poly_mul(lhs, a, b);
|
||||
fmpz_mod_poly_derivative(lhs, lhs);
|
||||
fmpz_mod_poly_derivative(c, a);
|
||||
fmpz_mod_poly_derivative(d, b);
|
||||
fmpz_mod_poly_mul(c, c, b);
|
||||
fmpz_mod_poly_mul(d, a, d);
|
||||
fmpz_mod_poly_add(rhs, c, d);
|
||||
|
||||
result = fmpz_mod_poly_equal(lhs, rhs);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL (Leibniz):\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("(ab)' = "), fmpz_mod_poly_print(lhs), flint_printf("\n\n");
|
||||
flint_printf("a'b + ab' = "), fmpz_mod_poly_print(rhs), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(d);
|
||||
fmpz_mod_poly_clear(lhs);
|
||||
fmpz_mod_poly_clear(rhs);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
206
external/flint-2.4.3/fmpz_mod_poly/test/t-div_basecase.c
vendored
Normal file
206
external/flint-2.4.3/fmpz_mod_poly/test/t-div_basecase.c
vendored
Normal file
@@ -0,0 +1,206 @@
|
||||
/*=============================================================================
|
||||
|
||||
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
|
||||
Copyright (C) 2009 William Hart
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("div_basecase....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
/* Compare to divrem_basecase */
|
||||
for (i = 0; i < 5000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, q, q2, r2;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(q, p);
|
||||
fmpz_mod_poly_init(q2, p);
|
||||
fmpz_mod_poly_init(r2, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest_not_zero(b, state, n_randint(state, 100) + 1);
|
||||
|
||||
{
|
||||
fmpz_t d;
|
||||
fmpz *leadB = fmpz_mod_poly_lead(b);
|
||||
|
||||
fmpz_init(d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
while (!fmpz_is_one(d))
|
||||
{
|
||||
fmpz_divexact(leadB, leadB, d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
}
|
||||
fmpz_clear(d);
|
||||
}
|
||||
|
||||
fmpz_mod_poly_div_basecase(q, a, b);
|
||||
fmpz_mod_poly_divrem_basecase(q2, r2, a, b);
|
||||
|
||||
result = (fmpz_mod_poly_equal(q, q2));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("q = "), fmpz_mod_poly_print(q), flint_printf("\n\n");
|
||||
flint_printf("q2 = "), fmpz_mod_poly_print(q2), flint_printf("\n\n");
|
||||
flint_printf("r2 = "), fmpz_mod_poly_print(r2), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(q);
|
||||
fmpz_mod_poly_clear(q2);
|
||||
fmpz_mod_poly_clear(r2);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Alias a and q */
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, q;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(q, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest_not_zero(b, state, n_randint(state, 100) + 1);
|
||||
|
||||
{
|
||||
fmpz_t d;
|
||||
fmpz *leadB = fmpz_mod_poly_lead(b);
|
||||
|
||||
fmpz_init(d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
while (!fmpz_is_one(d))
|
||||
{
|
||||
fmpz_divexact(leadB, leadB, d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
}
|
||||
fmpz_clear(d);
|
||||
}
|
||||
|
||||
fmpz_mod_poly_div_basecase(q, a, b);
|
||||
fmpz_mod_poly_div_basecase(a, a, b);
|
||||
|
||||
result = (fmpz_mod_poly_equal(q, a));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("q = "), fmpz_mod_poly_print(q), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(q);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Alias b and q */
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, q;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(q, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest_not_zero(b, state, n_randint(state, 100) + 1);
|
||||
|
||||
{
|
||||
fmpz_t d;
|
||||
fmpz *leadB = fmpz_mod_poly_lead(b);
|
||||
|
||||
fmpz_init(d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
while (!fmpz_is_one(d))
|
||||
{
|
||||
fmpz_divexact(leadB, leadB, d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
}
|
||||
fmpz_clear(d);
|
||||
}
|
||||
|
||||
fmpz_mod_poly_div_basecase(q, a, b);
|
||||
fmpz_mod_poly_div_basecase(b, a, b);
|
||||
|
||||
result = (fmpz_mod_poly_equal(q, b));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("q = "), fmpz_mod_poly_print(q), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(q);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
297
external/flint-2.4.3/fmpz_mod_poly/test/t-div_newton_n_preinv.c
vendored
Normal file
297
external/flint-2.4.3/fmpz_mod_poly/test/t-div_newton_n_preinv.c
vendored
Normal file
@@ -0,0 +1,297 @@
|
||||
/*=============================================================================
|
||||
|
||||
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
|
||||
Copyright (C) 2009 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 "fmpz.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("div_newton_n_preinv....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
/* Compare to div_basecase */
|
||||
for (i = 0; i < 5000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, q, q2, binv;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(binv, p);
|
||||
fmpz_mod_poly_init(q, p);
|
||||
fmpz_mod_poly_init(q2, p);
|
||||
do
|
||||
fmpz_mod_poly_randtest_not_zero(b, state, n_randint(state, 100) + 1);
|
||||
while (b->length <= 2);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
if (a->length > 2*(b->length)-3)
|
||||
fmpz_mod_poly_truncate (a, 2*(b->length)-3);
|
||||
|
||||
{
|
||||
fmpz_t d;
|
||||
fmpz *leadB = fmpz_mod_poly_lead(b);
|
||||
|
||||
fmpz_init(d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
while (!fmpz_is_one(d))
|
||||
{
|
||||
fmpz_divexact(leadB, leadB, d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
}
|
||||
fmpz_clear(d);
|
||||
}
|
||||
|
||||
fmpz_mod_poly_reverse (binv, b, b->length);
|
||||
fmpz_mod_poly_inv_series_newton (binv, binv, b->length);
|
||||
fmpz_mod_poly_div_basecase(q, a, b);
|
||||
fmpz_mod_poly_div_newton_n_preinv(q2, a, b, binv);
|
||||
|
||||
result = (fmpz_mod_poly_equal(q, q2));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("q = "), fmpz_mod_poly_print(q), flint_printf("\n\n");
|
||||
flint_printf("q2 = "), fmpz_mod_poly_print(q2), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(binv);
|
||||
fmpz_mod_poly_clear(q);
|
||||
fmpz_mod_poly_clear(q2);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Alias a and q */
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, q, binv;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(binv, p);
|
||||
fmpz_mod_poly_init(q, p);
|
||||
do
|
||||
fmpz_mod_poly_randtest_not_zero(b, state, n_randint(state, 100) + 1);
|
||||
while (b->length <= 2);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
if (a->length > 2*(b->length)-3)
|
||||
fmpz_mod_poly_truncate (a, 2*(b->length)-3);
|
||||
|
||||
{
|
||||
fmpz_t d;
|
||||
fmpz *leadB = fmpz_mod_poly_lead(b);
|
||||
|
||||
fmpz_init(d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
while (!fmpz_is_one(d))
|
||||
{
|
||||
fmpz_divexact(leadB, leadB, d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
}
|
||||
fmpz_clear(d);
|
||||
}
|
||||
|
||||
fmpz_mod_poly_reverse (binv, b, b->length);
|
||||
fmpz_mod_poly_inv_series_newton (binv, binv, b->length);
|
||||
fmpz_mod_poly_div_newton_n_preinv(q, a, b, binv);
|
||||
fmpz_mod_poly_div_newton_n_preinv(a, a, b, binv);
|
||||
|
||||
result = (fmpz_mod_poly_equal(q, a));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("q = "), fmpz_mod_poly_print(q), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(binv);
|
||||
fmpz_mod_poly_clear(q);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Alias b and q */
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, q, binv;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(binv, p);
|
||||
fmpz_mod_poly_init(q, p);
|
||||
do
|
||||
fmpz_mod_poly_randtest_not_zero(b, state, n_randint(state, 100) + 1);
|
||||
while (b->length <= 2);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
if (a->length > 2*(b->length)-3)
|
||||
fmpz_mod_poly_truncate (a, 2*(b->length)-3);
|
||||
|
||||
{
|
||||
fmpz_t d;
|
||||
fmpz *leadB = fmpz_mod_poly_lead(b);
|
||||
|
||||
fmpz_init(d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
while (!fmpz_is_one(d))
|
||||
{
|
||||
fmpz_divexact(leadB, leadB, d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
}
|
||||
fmpz_clear(d);
|
||||
}
|
||||
|
||||
fmpz_mod_poly_reverse (binv, b, b->length);
|
||||
fmpz_mod_poly_inv_series_newton (binv, binv, b->length);
|
||||
fmpz_mod_poly_div_newton_n_preinv(q, a, b, binv);
|
||||
fmpz_mod_poly_div_newton_n_preinv(b, a, b, binv);
|
||||
|
||||
result = (fmpz_mod_poly_equal(q, b));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("q = "), fmpz_mod_poly_print(q), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(binv);
|
||||
fmpz_mod_poly_clear(q);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
|
||||
/* Alias binv and q */
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, q, binv;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(binv, p);
|
||||
fmpz_mod_poly_init(q, p);
|
||||
do
|
||||
fmpz_mod_poly_randtest_not_zero(b, state, n_randint(state, 100) + 1);
|
||||
while (b->length <= 2);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
if (a->length > 2*(b->length)-3)
|
||||
fmpz_mod_poly_truncate (a, 2*(b->length)-3);
|
||||
|
||||
{
|
||||
fmpz_t d;
|
||||
fmpz *leadB = fmpz_mod_poly_lead(b);
|
||||
|
||||
fmpz_init(d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
while (!fmpz_is_one(d))
|
||||
{
|
||||
fmpz_divexact(leadB, leadB, d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
}
|
||||
fmpz_clear(d);
|
||||
}
|
||||
|
||||
fmpz_mod_poly_reverse (binv, b, b->length);
|
||||
fmpz_mod_poly_inv_series_newton (binv, binv, b->length);
|
||||
fmpz_mod_poly_div_newton_n_preinv(q, a, b, binv);
|
||||
fmpz_mod_poly_div_newton_n_preinv(binv, a, b, binv);
|
||||
|
||||
result = (fmpz_mod_poly_equal(q, binv));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("binv = "), fmpz_mod_poly_print(binv), flint_printf("\n\n");
|
||||
flint_printf("q = "), fmpz_mod_poly_print(q), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(binv);
|
||||
fmpz_mod_poly_clear(q);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
213
external/flint-2.4.3/fmpz_mod_poly/test/t-divrem_basecase.c
vendored
Normal file
213
external/flint-2.4.3/fmpz_mod_poly/test/t-divrem_basecase.c
vendored
Normal 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) 2011 Sebastian Pancratz
|
||||
Copyright (C) 2009 William Hart
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("divrem_basecase....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
/* Check q*b + r = a, no aliasing */
|
||||
for (i = 0; i < 5000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, q, r, t;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(q, p);
|
||||
fmpz_mod_poly_init(r, p);
|
||||
fmpz_mod_poly_init(t, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest_not_zero(b, state, n_randint(state, 100) + 1);
|
||||
|
||||
{
|
||||
fmpz_t d;
|
||||
fmpz *leadB = fmpz_mod_poly_lead(b);
|
||||
|
||||
fmpz_init(d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
while (!fmpz_is_one(d))
|
||||
{
|
||||
fmpz_divexact(leadB, leadB, d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
}
|
||||
fmpz_clear(d);
|
||||
}
|
||||
|
||||
fmpz_mod_poly_divrem_basecase(q, r, a, b);
|
||||
fmpz_mod_poly_mul(t, q, b);
|
||||
fmpz_mod_poly_add(t, t, r);
|
||||
|
||||
result = (fmpz_mod_poly_equal(a, t));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("q = "), fmpz_mod_poly_print(q), flint_printf("\n\n");
|
||||
flint_printf("r = "), fmpz_mod_poly_print(r), flint_printf("\n\n");
|
||||
flint_printf("t = "), fmpz_mod_poly_print(t), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(q);
|
||||
fmpz_mod_poly_clear(r);
|
||||
fmpz_mod_poly_clear(t);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Alias a and q, b and r */
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, q, r;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(q, p);
|
||||
fmpz_mod_poly_init(r, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest_not_zero(b, state, n_randint(state, 100) + 1);
|
||||
|
||||
{
|
||||
fmpz_t d;
|
||||
fmpz *leadB = fmpz_mod_poly_lead(b);
|
||||
|
||||
fmpz_init(d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
while (!fmpz_is_one(d))
|
||||
{
|
||||
fmpz_divexact(leadB, leadB, d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
}
|
||||
fmpz_clear(d);
|
||||
}
|
||||
|
||||
fmpz_mod_poly_divrem_basecase(q, r, a, b);
|
||||
fmpz_mod_poly_divrem_basecase(a, b, a, b);
|
||||
|
||||
result = (fmpz_mod_poly_equal(q, a) && fmpz_mod_poly_equal(r, b));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("q = "), fmpz_mod_poly_print(q), flint_printf("\n\n");
|
||||
flint_printf("r = "), fmpz_mod_poly_print(r), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(q);
|
||||
fmpz_mod_poly_clear(r);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Alias b and q, a and r */
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, q, r;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(q, p);
|
||||
fmpz_mod_poly_init(r, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest_not_zero(b, state, n_randint(state, 100) + 1);
|
||||
|
||||
{
|
||||
fmpz_t d;
|
||||
fmpz *leadB = fmpz_mod_poly_lead(b);
|
||||
|
||||
fmpz_init(d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
while (!fmpz_is_one(d))
|
||||
{
|
||||
fmpz_divexact(leadB, leadB, d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
}
|
||||
fmpz_clear(d);
|
||||
}
|
||||
|
||||
fmpz_mod_poly_divrem_basecase(q, r, a, b);
|
||||
fmpz_mod_poly_divrem_basecase(b, a, a, b);
|
||||
|
||||
result = (fmpz_mod_poly_equal(q, b) && fmpz_mod_poly_equal(r, a));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("q = "), fmpz_mod_poly_print(q), flint_printf("\n\n");
|
||||
flint_printf("r = "), fmpz_mod_poly_print(r), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(q);
|
||||
fmpz_mod_poly_clear(r);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
213
external/flint-2.4.3/fmpz_mod_poly/test/t-divrem_divconquer.c
vendored
Normal file
213
external/flint-2.4.3/fmpz_mod_poly/test/t-divrem_divconquer.c
vendored
Normal 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) 2011 Sebastian Pancratz
|
||||
Copyright (C) 2009 William Hart
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("divrem_divconquer....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
/* Check q*b + r = a, no aliasing */
|
||||
for (i = 0; i < 5000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, q, r, t;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(q, p);
|
||||
fmpz_mod_poly_init(r, p);
|
||||
fmpz_mod_poly_init(t, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest_not_zero(b, state, n_randint(state, 100) + 1);
|
||||
|
||||
{
|
||||
fmpz_t d;
|
||||
fmpz *leadB = fmpz_mod_poly_lead(b);
|
||||
|
||||
fmpz_init(d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
while (!fmpz_is_one(d))
|
||||
{
|
||||
fmpz_divexact(leadB, leadB, d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
}
|
||||
fmpz_clear(d);
|
||||
}
|
||||
|
||||
fmpz_mod_poly_divrem_divconquer(q, r, a, b);
|
||||
fmpz_mod_poly_mul(t, q, b);
|
||||
fmpz_mod_poly_add(t, t, r);
|
||||
|
||||
result = (fmpz_mod_poly_equal(a, t));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL #1:\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("q = "), fmpz_mod_poly_print(q), flint_printf("\n\n");
|
||||
flint_printf("r = "), fmpz_mod_poly_print(r), flint_printf("\n\n");
|
||||
flint_printf("t = "), fmpz_mod_poly_print(t), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(q);
|
||||
fmpz_mod_poly_clear(r);
|
||||
fmpz_mod_poly_clear(t);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Alias a and q, b and r */
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, q, r;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(q, p);
|
||||
fmpz_mod_poly_init(r, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest_not_zero(b, state, n_randint(state, 100) + 1);
|
||||
|
||||
{
|
||||
fmpz_t d;
|
||||
fmpz *leadB = fmpz_mod_poly_lead(b);
|
||||
|
||||
fmpz_init(d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
while (!fmpz_is_one(d))
|
||||
{
|
||||
fmpz_divexact(leadB, leadB, d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
}
|
||||
fmpz_clear(d);
|
||||
}
|
||||
|
||||
fmpz_mod_poly_divrem_divconquer(q, r, a, b);
|
||||
fmpz_mod_poly_divrem_divconquer(a, b, a, b);
|
||||
|
||||
result = (fmpz_mod_poly_equal(q, a) && fmpz_mod_poly_equal(r, b));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL #2:\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("q = "), fmpz_mod_poly_print(q), flint_printf("\n\n");
|
||||
flint_printf("r = "), fmpz_mod_poly_print(r), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(q);
|
||||
fmpz_mod_poly_clear(r);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Alias b and q, a and r */
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, q, r;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(q, p);
|
||||
fmpz_mod_poly_init(r, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest_not_zero(b, state, n_randint(state, 100) + 1);
|
||||
|
||||
{
|
||||
fmpz_t d;
|
||||
fmpz *leadB = fmpz_mod_poly_lead(b);
|
||||
|
||||
fmpz_init(d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
while (!fmpz_is_one(d))
|
||||
{
|
||||
fmpz_divexact(leadB, leadB, d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
}
|
||||
fmpz_clear(d);
|
||||
}
|
||||
|
||||
fmpz_mod_poly_divrem_divconquer(q, r, a, b);
|
||||
fmpz_mod_poly_divrem_divconquer(b, a, a, b);
|
||||
|
||||
result = (fmpz_mod_poly_equal(q, b) && fmpz_mod_poly_equal(r, a));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL #3:\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("q = "), fmpz_mod_poly_print(q), flint_printf("\n\n");
|
||||
flint_printf("r = "), fmpz_mod_poly_print(r), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(q);
|
||||
fmpz_mod_poly_clear(r);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
176
external/flint-2.4.3/fmpz_mod_poly/test/t-divrem_f.c
vendored
Normal file
176
external/flint-2.4.3/fmpz_mod_poly/test/t-divrem_f.c
vendored
Normal 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) 2011 Sebastian Pancratz
|
||||
Copyright (C) 2009 William Hart
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("divrem_f....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
/* Check q*b + r = a when gcd(lead(B),p) = 1, no aliasing */
|
||||
for (i = 0; i < 5000; i++)
|
||||
{
|
||||
fmpz_t f, p;
|
||||
fmpz_mod_poly_t a, b, q, r, t;
|
||||
|
||||
fmpz_init(f);
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(q, p);
|
||||
fmpz_mod_poly_init(r, p);
|
||||
fmpz_mod_poly_init(t, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest_not_zero(b, state, n_randint(state, 100) + 1);
|
||||
|
||||
{
|
||||
fmpz_t d;
|
||||
fmpz *leadB = fmpz_mod_poly_lead(b);
|
||||
|
||||
fmpz_init(d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
while (!fmpz_is_one(d))
|
||||
{
|
||||
fmpz_divexact(leadB, leadB, d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
}
|
||||
fmpz_clear(d);
|
||||
}
|
||||
|
||||
fmpz_mod_poly_divrem_f(f, q, r, a, b);
|
||||
fmpz_mod_poly_mul(t, q, b);
|
||||
fmpz_mod_poly_add(t, t, r);
|
||||
|
||||
result = (fmpz_is_one(f) && fmpz_mod_poly_equal(a, t));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL (divrem):\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("f = "), fmpz_print(f), flint_printf("\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("q = "), fmpz_mod_poly_print(q), flint_printf("\n\n");
|
||||
flint_printf("r = "), fmpz_mod_poly_print(r), flint_printf("\n\n");
|
||||
flint_printf("t = "), fmpz_mod_poly_print(t), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(q);
|
||||
fmpz_mod_poly_clear(r);
|
||||
fmpz_mod_poly_clear(t);
|
||||
fmpz_clear(f);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Check f | p when gcd(lead(B),p) > 1 */
|
||||
for (i = 0; i < 5000; i++)
|
||||
{
|
||||
fmpz_t f, p, q1, q2;
|
||||
fmpz_mod_poly_t a, b, q, r, t;
|
||||
|
||||
fmpz_init(f);
|
||||
fmpz_init(p);
|
||||
fmpz_init(q1);
|
||||
fmpz_init(q2);
|
||||
fmpz_randtest_unsigned(q1, state, 2 * FLINT_BITS);
|
||||
fmpz_randtest_unsigned(q2, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(q1, q1, 2);
|
||||
fmpz_add_ui(q2, q2, 2);
|
||||
fmpz_mul(p, q1, q2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(q, p);
|
||||
fmpz_mod_poly_init(r, p);
|
||||
fmpz_mod_poly_init(t, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest_not_zero(b, state, n_randint(state, 100) + 1);
|
||||
|
||||
{
|
||||
fmpz_t d;
|
||||
fmpz *leadB = fmpz_mod_poly_lead(b);
|
||||
|
||||
fmpz_init(d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
if (fmpz_is_one(d))
|
||||
fmpz_set(leadB, q1);
|
||||
fmpz_clear(d);
|
||||
}
|
||||
|
||||
fmpz_mod_poly_divrem_f(f, q, r, a, b);
|
||||
fmpz_mod_poly_mul(t, q, b);
|
||||
fmpz_mod_poly_add(t, t, r);
|
||||
|
||||
result = (fmpz_cmp_ui(f, 1) > 0 && fmpz_cmp(f, p) < 0 && fmpz_divisible(p, f));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL (factor):\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("f = "), fmpz_print(f), flint_printf("\n\n");
|
||||
flint_printf("q1 = "), fmpz_print(q1), flint_printf("\n\n");
|
||||
flint_printf("q2 = "), fmpz_print(q2), flint_printf("\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("q = "), fmpz_mod_poly_print(q), flint_printf("\n\n");
|
||||
flint_printf("r = "), fmpz_mod_poly_print(r), flint_printf("\n\n");
|
||||
flint_printf("t = "), fmpz_mod_poly_print(t), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(q);
|
||||
fmpz_mod_poly_clear(r);
|
||||
fmpz_mod_poly_clear(t);
|
||||
fmpz_clear(f);
|
||||
fmpz_clear(p);
|
||||
fmpz_clear(q1);
|
||||
fmpz_clear(q2);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
521
external/flint-2.4.3/fmpz_mod_poly/test/t-divrem_newton_n_preinv.c
vendored
Normal file
521
external/flint-2.4.3/fmpz_mod_poly/test/t-divrem_newton_n_preinv.c
vendored
Normal file
@@ -0,0 +1,521 @@
|
||||
/*=============================================================================
|
||||
|
||||
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
|
||||
Copyright (C) 2009 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 "fmpz.h"
|
||||
#include "fmpz_mod_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 q*b + r = a, no aliasing */
|
||||
for (i = 0; i < 5000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, binv, q, r, t, q2, r2;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(binv, p);
|
||||
fmpz_mod_poly_init(q, p);
|
||||
fmpz_mod_poly_init(q2, p);
|
||||
fmpz_mod_poly_init(r, p);
|
||||
fmpz_mod_poly_init(r2, p);
|
||||
fmpz_mod_poly_init(t, p);
|
||||
do
|
||||
fmpz_mod_poly_randtest_not_zero(b, state, n_randint(state, 100) + 1);
|
||||
while (b->length <= 2);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
if (a->length > 2*(b->length)-3)
|
||||
fmpz_mod_poly_truncate (a, 2*(b->length)-3);
|
||||
|
||||
{
|
||||
fmpz_t d;
|
||||
fmpz *leadB = fmpz_mod_poly_lead(b);
|
||||
|
||||
fmpz_init(d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
while (!fmpz_is_one(d))
|
||||
{
|
||||
fmpz_divexact(leadB, leadB, d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
}
|
||||
fmpz_clear(d);
|
||||
}
|
||||
|
||||
fmpz_mod_poly_reverse (binv, b, b->length);
|
||||
fmpz_mod_poly_inv_series_newton (binv, binv, b->length);
|
||||
|
||||
fmpz_mod_poly_divrem_newton_n_preinv (q, r, a, b, binv);
|
||||
fmpz_mod_poly_mul(t, q, b);
|
||||
fmpz_mod_poly_add(t, t, r);
|
||||
|
||||
result = (fmpz_mod_poly_equal(a, t));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("q = "), fmpz_mod_poly_print(q), flint_printf("\n\n");
|
||||
flint_printf("r = "), fmpz_mod_poly_print(r), flint_printf("\n\n");
|
||||
flint_printf("t = "), fmpz_mod_poly_print(t), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_divrem_basecase(q2, r2, a, b);
|
||||
result = (fmpz_mod_poly_equal(q2, q));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("q = "), fmpz_mod_poly_print(q), flint_printf("\n\n");
|
||||
flint_printf("q2 = "), fmpz_mod_poly_print(q2), flint_printf("\n\n");
|
||||
flint_printf("r = "), fmpz_mod_poly_print(r), flint_printf("\n\n");
|
||||
flint_printf("t = "), fmpz_mod_poly_print(t), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(binv);
|
||||
fmpz_mod_poly_clear(q);
|
||||
fmpz_mod_poly_clear(q2);
|
||||
fmpz_mod_poly_clear(r);
|
||||
fmpz_mod_poly_clear(r2);
|
||||
fmpz_mod_poly_clear(t);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Alias a and q, b and r */
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, binv, q, r;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(binv, p);
|
||||
fmpz_mod_poly_init(q, p);
|
||||
fmpz_mod_poly_init(r, p);
|
||||
do
|
||||
fmpz_mod_poly_randtest_not_zero(b, state, n_randint(state, 100) + 1);
|
||||
while (b->length <= 2);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
if (a->length > 2*(b->length)-3)
|
||||
fmpz_mod_poly_truncate (a, 2*(b->length)-3);
|
||||
|
||||
{
|
||||
fmpz_t d;
|
||||
fmpz *leadB = fmpz_mod_poly_lead(b);
|
||||
|
||||
fmpz_init(d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
while (!fmpz_is_one(d))
|
||||
{
|
||||
fmpz_divexact(leadB, leadB, d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
}
|
||||
fmpz_clear(d);
|
||||
}
|
||||
|
||||
fmpz_mod_poly_reverse (binv, b, b->length);
|
||||
fmpz_mod_poly_inv_series_newton (binv, binv, b->length);
|
||||
|
||||
fmpz_mod_poly_divrem_newton_n_preinv(q, r, a, b, binv);
|
||||
fmpz_mod_poly_divrem_newton_n_preinv(a, b, a, b, binv);
|
||||
|
||||
result = (fmpz_mod_poly_equal(q, a) && fmpz_mod_poly_equal(r, b));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("q = "), fmpz_mod_poly_print(q), flint_printf("\n\n");
|
||||
flint_printf("r = "), fmpz_mod_poly_print(r), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(binv);
|
||||
fmpz_mod_poly_clear(q);
|
||||
fmpz_mod_poly_clear(r);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Alias b and q, a and r */
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, binv, q, r;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(binv, p);
|
||||
fmpz_mod_poly_init(q, p);
|
||||
fmpz_mod_poly_init(r, p);
|
||||
do
|
||||
fmpz_mod_poly_randtest_not_zero(b, state, n_randint(state, 100) + 1);
|
||||
while (b->length <= 2);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
if (a->length > 2*(b->length)-3)
|
||||
fmpz_mod_poly_truncate (a, 2*(b->length)-3);
|
||||
|
||||
{
|
||||
fmpz_t d;
|
||||
fmpz *leadB = fmpz_mod_poly_lead(b);
|
||||
|
||||
fmpz_init(d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
while (!fmpz_is_one(d))
|
||||
{
|
||||
fmpz_divexact(leadB, leadB, d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
}
|
||||
fmpz_clear(d);
|
||||
}
|
||||
|
||||
fmpz_mod_poly_reverse (binv, b, b->length);
|
||||
fmpz_mod_poly_inv_series_newton (binv, binv, b->length);
|
||||
|
||||
fmpz_mod_poly_divrem_newton_n_preinv(q, r, a, b, binv);
|
||||
fmpz_mod_poly_divrem_newton_n_preinv(b, a, a, b, binv);
|
||||
|
||||
result = (fmpz_mod_poly_equal(q, b) && fmpz_mod_poly_equal(r, a));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("q = "), fmpz_mod_poly_print(q), flint_printf("\n\n");
|
||||
flint_printf("r = "), fmpz_mod_poly_print(r), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(binv);
|
||||
fmpz_mod_poly_clear(q);
|
||||
fmpz_mod_poly_clear(r);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Alias binv and q, a and r*/
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, binv, q, r;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(binv, p);
|
||||
fmpz_mod_poly_init(q, p);
|
||||
fmpz_mod_poly_init(r, p);
|
||||
do
|
||||
fmpz_mod_poly_randtest_not_zero(b, state, n_randint(state, 100) + 1);
|
||||
while (b->length <= 2);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
if (a->length > 2*(b->length)-3)
|
||||
fmpz_mod_poly_truncate (a, 2*(b->length)-3);
|
||||
|
||||
{
|
||||
fmpz_t d;
|
||||
fmpz *leadB = fmpz_mod_poly_lead(b);
|
||||
|
||||
fmpz_init(d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
while (!fmpz_is_one(d))
|
||||
{
|
||||
fmpz_divexact(leadB, leadB, d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
}
|
||||
fmpz_clear(d);
|
||||
}
|
||||
|
||||
fmpz_mod_poly_reverse (binv, b, b->length);
|
||||
fmpz_mod_poly_inv_series_newton (binv, binv, b->length);
|
||||
|
||||
fmpz_mod_poly_divrem_newton_n_preinv(q, r, a, b, binv);
|
||||
fmpz_mod_poly_divrem_newton_n_preinv(binv, a, a, b, binv);
|
||||
|
||||
result = (fmpz_mod_poly_equal(q, binv) && fmpz_mod_poly_equal(r, a));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("binv = "), fmpz_mod_poly_print(binv), flint_printf("\n\n");
|
||||
flint_printf("q = "), fmpz_mod_poly_print(q), flint_printf("\n\n");
|
||||
flint_printf("r = "), fmpz_mod_poly_print(r), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(binv);
|
||||
fmpz_mod_poly_clear(q);
|
||||
fmpz_mod_poly_clear(r);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Alias binv and q, b and r*/
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, binv, q, r;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(binv, p);
|
||||
fmpz_mod_poly_init(q, p);
|
||||
fmpz_mod_poly_init(r, p);
|
||||
do
|
||||
fmpz_mod_poly_randtest_not_zero(b, state, n_randint(state, 100) + 1);
|
||||
while (b->length <= 2);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
if (a->length > 2*(b->length)-3)
|
||||
fmpz_mod_poly_truncate (a, 2*(b->length)-3);
|
||||
|
||||
{
|
||||
fmpz_t d;
|
||||
fmpz *leadB = fmpz_mod_poly_lead(b);
|
||||
|
||||
fmpz_init(d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
while (!fmpz_is_one(d))
|
||||
{
|
||||
fmpz_divexact(leadB, leadB, d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
}
|
||||
fmpz_clear(d);
|
||||
}
|
||||
|
||||
fmpz_mod_poly_reverse (binv, b, b->length);
|
||||
fmpz_mod_poly_inv_series_newton (binv, binv, b->length);
|
||||
|
||||
fmpz_mod_poly_divrem_newton_n_preinv(q, r, a, b, binv);
|
||||
fmpz_mod_poly_divrem_newton_n_preinv(binv, b, a, b, binv);
|
||||
|
||||
result = (fmpz_mod_poly_equal(q, binv) && fmpz_mod_poly_equal(r, b));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("binv = "), fmpz_mod_poly_print(binv), flint_printf("\n\n");
|
||||
flint_printf("q = "), fmpz_mod_poly_print(q), flint_printf("\n\n");
|
||||
flint_printf("r = "), fmpz_mod_poly_print(r), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(binv);
|
||||
fmpz_mod_poly_clear(q);
|
||||
fmpz_mod_poly_clear(r);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Alias a and q, binv and r*/
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, binv, q, r;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(binv, p);
|
||||
fmpz_mod_poly_init(q, p);
|
||||
fmpz_mod_poly_init(r, p);
|
||||
do
|
||||
fmpz_mod_poly_randtest_not_zero(b, state, n_randint(state, 100) + 1);
|
||||
while (b->length <= 2);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
if (a->length > 2*(b->length)-3)
|
||||
fmpz_mod_poly_truncate (a, 2*(b->length)-3);
|
||||
|
||||
{
|
||||
fmpz_t d;
|
||||
fmpz *leadB = fmpz_mod_poly_lead(b);
|
||||
|
||||
fmpz_init(d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
while (!fmpz_is_one(d))
|
||||
{
|
||||
fmpz_divexact(leadB, leadB, d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
}
|
||||
fmpz_clear(d);
|
||||
}
|
||||
|
||||
fmpz_mod_poly_reverse (binv, b, b->length);
|
||||
fmpz_mod_poly_inv_series_newton (binv, binv, b->length);
|
||||
|
||||
fmpz_mod_poly_divrem_newton_n_preinv(q, r, a, b, binv);
|
||||
fmpz_mod_poly_divrem_newton_n_preinv(a, binv, a, b, binv);
|
||||
|
||||
result = (fmpz_mod_poly_equal(q, a) && fmpz_mod_poly_equal(r, binv));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("binv = "), fmpz_mod_poly_print(binv), flint_printf("\n\n");
|
||||
flint_printf("q = "), fmpz_mod_poly_print(q), flint_printf("\n\n");
|
||||
flint_printf("r = "), fmpz_mod_poly_print(r), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(binv);
|
||||
fmpz_mod_poly_clear(q);
|
||||
fmpz_mod_poly_clear(r);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Alias b and q, binv and r*/
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, binv, q, r;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(binv, p);
|
||||
fmpz_mod_poly_init(q, p);
|
||||
fmpz_mod_poly_init(r, p);
|
||||
do
|
||||
fmpz_mod_poly_randtest_not_zero(b, state, n_randint(state, 100) + 1);
|
||||
while (b->length <= 2);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
if (a->length > 2*(b->length)-3)
|
||||
fmpz_mod_poly_truncate (a, 2*(b->length)-3);
|
||||
|
||||
{
|
||||
fmpz_t d;
|
||||
fmpz *leadB = fmpz_mod_poly_lead(b);
|
||||
|
||||
fmpz_init(d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
while (!fmpz_is_one(d))
|
||||
{
|
||||
fmpz_divexact(leadB, leadB, d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
}
|
||||
fmpz_clear(d);
|
||||
}
|
||||
|
||||
fmpz_mod_poly_reverse (binv, b, b->length);
|
||||
fmpz_mod_poly_inv_series_newton (binv, binv, b->length);
|
||||
|
||||
fmpz_mod_poly_divrem_newton_n_preinv(q, r, a, b, binv);
|
||||
fmpz_mod_poly_divrem_newton_n_preinv(b, binv, a, b, binv);
|
||||
|
||||
result = (fmpz_mod_poly_equal(q, b) && fmpz_mod_poly_equal(r, binv));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("binv = "), fmpz_mod_poly_print(binv), flint_printf("\n\n");
|
||||
flint_printf("q = "), fmpz_mod_poly_print(q), flint_printf("\n\n");
|
||||
flint_printf("r = "), fmpz_mod_poly_print(r), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(binv);
|
||||
fmpz_mod_poly_clear(q);
|
||||
fmpz_mod_poly_clear(r);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
130
external/flint-2.4.3/fmpz_mod_poly/test/t-evaluate_fmpz.c
vendored
Normal file
130
external/flint-2.4.3/fmpz_mod_poly/test/t-evaluate_fmpz.c
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
/*=============================================================================
|
||||
|
||||
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, 2010 Sebastian Pancratz
|
||||
Copyright (C) 2009 William Hart
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("evaluate_fmpz....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
/* Check aliasing */
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
fmpz_t a, b, p;
|
||||
fmpz_mod_poly_t f;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_init(a);
|
||||
fmpz_init(b);
|
||||
fmpz_randm(a, state, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_randtest(f, state, n_randint(state, 100));
|
||||
|
||||
fmpz_mod_poly_evaluate_fmpz(b, f, a);
|
||||
fmpz_mod_poly_evaluate_fmpz(a, f, a);
|
||||
|
||||
result = (fmpz_equal(a, b));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
fmpz_print(a), flint_printf("\n\n");
|
||||
fmpz_print(b), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_clear(a);
|
||||
fmpz_clear(b);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Check that the result agrees with Z[X] */
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
fmpz_t a, b, c, p;
|
||||
fmpz_mod_poly_t f;
|
||||
fmpz_poly_t g;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_init(a);
|
||||
fmpz_init(b);
|
||||
fmpz_init(c);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_poly_init(g);
|
||||
fmpz_randm(a, state, p);
|
||||
fmpz_mod_poly_randtest(f, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_get_fmpz_poly(g, f);
|
||||
|
||||
fmpz_mod_poly_evaluate_fmpz(b, f, a);
|
||||
fmpz_poly_evaluate_fmpz(c, g, a);
|
||||
fmpz_mod(c, c, p);
|
||||
|
||||
result = (fmpz_equal(b, c));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL (cmp with fmpz_poly):\n");
|
||||
fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
fmpz_poly_print(g), flint_printf("\n\n");
|
||||
fmpz_print(a), flint_printf("\n\n");
|
||||
fmpz_print(b), flint_printf("\n\n");
|
||||
fmpz_print(c), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(a);
|
||||
fmpz_clear(b);
|
||||
fmpz_clear(c);
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_poly_clear(g);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
106
external/flint-2.4.3/fmpz_mod_poly/test/t-evaluate_fmpz_vec_fast.c
vendored
Normal file
106
external/flint-2.4.3/fmpz_mod_poly/test/t-evaluate_fmpz_vec_fast.c
vendored
Normal 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, 2012 William Hart
|
||||
Copyright (C) 2011, 2012 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_poly.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result = 1;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("evaluate_fmpz_vec_fast....");
|
||||
fflush(stdout);
|
||||
|
||||
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
|
||||
{
|
||||
fmpz_mod_poly_t P;
|
||||
fmpz * x, * y, * z;
|
||||
fmpz_t mod;
|
||||
slong j, n, npoints;
|
||||
|
||||
fmpz_init(mod);
|
||||
|
||||
do
|
||||
{
|
||||
fmpz_randtest_unsigned(mod, state, 5);
|
||||
fmpz_add_ui(mod, mod, 2);
|
||||
} while (!fmpz_is_probabprime(mod));
|
||||
|
||||
npoints = n_randint(state, 10);
|
||||
n = n_randint(state, 10);
|
||||
|
||||
fmpz_mod_poly_init(P, mod);
|
||||
x = _fmpz_vec_init(npoints);
|
||||
y = _fmpz_vec_init(npoints);
|
||||
z = _fmpz_vec_init(npoints);
|
||||
|
||||
fmpz_mod_poly_randtest(P, state, n);
|
||||
|
||||
for (j = 0; j < npoints; j++)
|
||||
fmpz_randtest_mod(x + j, state, mod);
|
||||
|
||||
fmpz_mod_poly_evaluate_fmpz_vec_iter(y, P, x, npoints);
|
||||
fmpz_mod_poly_evaluate_fmpz_vec_fast(z, P, x, npoints);
|
||||
|
||||
result = _fmpz_vec_equal(y, z, npoints);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("mod=");
|
||||
fmpz_print(mod);
|
||||
flint_printf(", n=%wd, npoints=%wd\n\n", n, npoints);
|
||||
flint_printf("P: "); fmpz_mod_poly_print(P); flint_printf("\n\n");
|
||||
for (j = 0; j < npoints; j++)
|
||||
fmpz_print(y + j), flint_printf(" ");
|
||||
flint_printf("\n");
|
||||
for (j = 0; j < npoints; j++)
|
||||
fmpz_print(z + j), flint_printf(" ");
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(mod);
|
||||
fmpz_mod_poly_clear(P);
|
||||
_fmpz_vec_clear(x, npoints);
|
||||
_fmpz_vec_clear(y, npoints);
|
||||
_fmpz_vec_clear(z, npoints);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
335
external/flint-2.4.3/fmpz_mod_poly/test/t-gcd_euclidean.c
vendored
Normal file
335
external/flint-2.4.3/fmpz_mod_poly/test/t-gcd_euclidean.c
vendored
Normal file
@@ -0,0 +1,335 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("gcd_euclidean....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
/* Generic case, most likely co-prime arguments ******************************/
|
||||
|
||||
/* Check aliasing of a and c */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, c;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 100));
|
||||
|
||||
fmpz_mod_poly_gcd_euclidean(c, a, b);
|
||||
fmpz_mod_poly_gcd_euclidean(a, a, b);
|
||||
|
||||
result = (fmpz_mod_poly_equal(a, c));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Check aliasing of b and c */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, c;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 100));
|
||||
|
||||
fmpz_mod_poly_gcd_euclidean(c, a, b);
|
||||
fmpz_mod_poly_gcd_euclidean(b, a, b);
|
||||
|
||||
result = (fmpz_mod_poly_equal(b, c));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/*
|
||||
Check that g = GCD(a,b) divides a and b,
|
||||
and that 1 == GCD(a/g, b/g)
|
||||
*/
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, c, d, g, h, s, t;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
fmpz_mod_poly_init(g, p);
|
||||
fmpz_mod_poly_init(h, p);
|
||||
fmpz_mod_poly_init(s, p);
|
||||
fmpz_mod_poly_init(t, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 100));
|
||||
|
||||
fmpz_mod_poly_gcd_euclidean(g, a, b);
|
||||
|
||||
if (fmpz_mod_poly_is_zero(g))
|
||||
{
|
||||
result = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fmpz_mod_poly_divrem_basecase(c, s, a, g);
|
||||
fmpz_mod_poly_divrem_basecase(d, t, b, g);
|
||||
fmpz_mod_poly_gcd_euclidean(h, c, d);
|
||||
|
||||
result = (fmpz_mod_poly_is_zero(s) && fmpz_mod_poly_is_zero(t)
|
||||
&& (h->length == 1) && (fmpz_is_one(h->coeffs)));
|
||||
}
|
||||
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("c = "), fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
flint_printf("d = "), fmpz_mod_poly_print(d), flint_printf("\n\n");
|
||||
flint_printf("g = "), fmpz_mod_poly_print(g), flint_printf("\n\n");
|
||||
flint_printf("h = "), fmpz_mod_poly_print(h), flint_printf("\n\n");
|
||||
flint_printf("s = "), fmpz_mod_poly_print(s), flint_printf("\n\n");
|
||||
flint_printf("t = "), fmpz_mod_poly_print(t), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(d);
|
||||
fmpz_mod_poly_clear(g);
|
||||
fmpz_mod_poly_clear(h);
|
||||
fmpz_mod_poly_clear(s);
|
||||
fmpz_mod_poly_clear(t);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Special case, arguments share a factor ********************************/
|
||||
|
||||
/* Check aliasing of a and c */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, c, f;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest(f, state, n_randint(state, 20));
|
||||
fmpz_mod_poly_mul(a, a, f);
|
||||
fmpz_mod_poly_mul(b, b, f);
|
||||
|
||||
fmpz_mod_poly_gcd_euclidean(c, a, b);
|
||||
fmpz_mod_poly_gcd_euclidean(a, a, b);
|
||||
|
||||
result = (fmpz_mod_poly_equal(a, c));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Check aliasing of b and c */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, c, f;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest(f, state, n_randint(state, 20));
|
||||
fmpz_mod_poly_mul(a, a, f);
|
||||
fmpz_mod_poly_mul(b, b, f);
|
||||
|
||||
fmpz_mod_poly_gcd_euclidean(c, a, b);
|
||||
fmpz_mod_poly_gcd_euclidean(b, a, b);
|
||||
|
||||
result = (fmpz_mod_poly_equal(b, c));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/*
|
||||
Check that g = GCD(a,b) divides a and b,
|
||||
and that 1 == GCD(a/g, b/g)
|
||||
*/
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, c, d, f, g, h, s, t;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(g, p);
|
||||
fmpz_mod_poly_init(h, p);
|
||||
fmpz_mod_poly_init(s, p);
|
||||
fmpz_mod_poly_init(t, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest(f, state, n_randint(state, 20));
|
||||
fmpz_mod_poly_mul(a, a, f);
|
||||
fmpz_mod_poly_mul(b, b, f);
|
||||
|
||||
fmpz_mod_poly_gcd_euclidean(g, a, b);
|
||||
|
||||
if (fmpz_mod_poly_is_zero(g))
|
||||
{
|
||||
result = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fmpz_mod_poly_divrem_basecase(c, s, a, g);
|
||||
fmpz_mod_poly_divrem_basecase(d, t, b, g);
|
||||
fmpz_mod_poly_gcd_euclidean(h, c, d);
|
||||
|
||||
result = (fmpz_mod_poly_is_zero(s) && fmpz_mod_poly_is_zero(t)
|
||||
&& (h->length == 1) && (fmpz_is_one(h->coeffs)));
|
||||
}
|
||||
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("c = "), fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
flint_printf("d = "), fmpz_mod_poly_print(d), flint_printf("\n\n");
|
||||
flint_printf("g = "), fmpz_mod_poly_print(g), flint_printf("\n\n");
|
||||
flint_printf("h = "), fmpz_mod_poly_print(h), flint_printf("\n\n");
|
||||
flint_printf("s = "), fmpz_mod_poly_print(s), flint_printf("\n\n");
|
||||
flint_printf("t = "), fmpz_mod_poly_print(t), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(d);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(g);
|
||||
fmpz_mod_poly_clear(h);
|
||||
fmpz_mod_poly_clear(s);
|
||||
fmpz_mod_poly_clear(t);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
100
external/flint-2.4.3/fmpz_mod_poly/test/t-gcd_euclidean_f.c
vendored
Normal file
100
external/flint-2.4.3/fmpz_mod_poly/test/t-gcd_euclidean_f.c
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "fmpz.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("gcd_euclidean_f....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
Compare with the usual GCD function.
|
||||
|
||||
N.B. I checked by hand that this test shows both outcomes,
|
||||
i.e. trivial and non-trivial factors, sufficiently frequently.
|
||||
*/
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_t p, f;
|
||||
fmpz_mod_poly_t a, b, c, d;
|
||||
|
||||
fmpz_init(f);
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 100);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 60));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 60));
|
||||
|
||||
fmpz_mod_poly_gcd_euclidean_f(f, c, a, b);
|
||||
if (!fmpz_is_one(f))
|
||||
{
|
||||
result = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fmpz_mod_poly_gcd(d, a, b);
|
||||
result = fmpz_mod_poly_equal(c, d);
|
||||
}
|
||||
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("c = "), fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
flint_printf("d = "), fmpz_mod_poly_print(d), flint_printf("\n\n");
|
||||
flint_printf("f = "), fmpz_print(f), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(d);
|
||||
fmpz_clear(f);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
160
external/flint-2.4.3/fmpz_mod_poly/test/t-gcdinv.c
vendored
Normal file
160
external/flint-2.4.3/fmpz_mod_poly/test/t-gcdinv.c
vendored
Normal 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 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("gcdinv....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
/* Generic case, most likely co-prime arguments ******************************/
|
||||
|
||||
/* Compare with result from XGCD */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, d, g, s, t, u;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
fmpz_mod_poly_init(g, p);
|
||||
fmpz_mod_poly_init(s, p);
|
||||
fmpz_mod_poly_init(t, p);
|
||||
fmpz_mod_poly_init(u, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
do
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 100));
|
||||
while (b->length < 2);
|
||||
|
||||
fmpz_mod_poly_gcdinv(d, u, a, b);
|
||||
fmpz_mod_poly_xgcd(g, s, t, a, b);
|
||||
|
||||
result = ((fmpz_mod_poly_equal(d, g) && fmpz_mod_poly_equal(u, s))
|
||||
|| (fmpz_mod_poly_is_zero(d)));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("d = "), fmpz_mod_poly_print(d), flint_printf("\n\n");
|
||||
flint_printf("g = "), fmpz_mod_poly_print(g), flint_printf("\n\n");
|
||||
flint_printf("s = "), fmpz_mod_poly_print(s), flint_printf("\n\n");
|
||||
flint_printf("t = "), fmpz_mod_poly_print(t), flint_printf("\n\n");
|
||||
flint_printf("u = "), fmpz_mod_poly_print(u), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(d);
|
||||
fmpz_mod_poly_clear(g);
|
||||
fmpz_mod_poly_clear(s);
|
||||
fmpz_mod_poly_clear(t);
|
||||
fmpz_mod_poly_clear(u);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Special case, arguments share a factor ********************************/
|
||||
|
||||
/* Compare with result from XGCD */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, d, f, g, s, t, u;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(g, p);
|
||||
fmpz_mod_poly_init(s, p);
|
||||
fmpz_mod_poly_init(t, p);
|
||||
fmpz_mod_poly_init(u, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
do
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 100));
|
||||
while (b->length < 2);
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 20) + 1);
|
||||
fmpz_mod_poly_mul(a, f, a);
|
||||
fmpz_mod_poly_mul(b, f, b);
|
||||
|
||||
fmpz_mod_poly_gcdinv(d, u, a, b);
|
||||
fmpz_mod_poly_xgcd(g, s, t, a, b);
|
||||
|
||||
result = ((fmpz_mod_poly_equal(d, g) && fmpz_mod_poly_equal(u, s))
|
||||
|| (fmpz_mod_poly_is_zero(d)));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("d = "), fmpz_mod_poly_print(d), flint_printf("\n\n");
|
||||
flint_printf("f = "), fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("g = "), fmpz_mod_poly_print(g), flint_printf("\n\n");
|
||||
flint_printf("s = "), fmpz_mod_poly_print(s), flint_printf("\n\n");
|
||||
flint_printf("t = "), fmpz_mod_poly_print(t), flint_printf("\n\n");
|
||||
flint_printf("u = "), fmpz_mod_poly_print(u), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(d);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(g);
|
||||
fmpz_mod_poly_clear(s);
|
||||
fmpz_mod_poly_clear(t);
|
||||
fmpz_mod_poly_clear(u);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
84
external/flint-2.4.3/fmpz_mod_poly/test/t-get_set_fmpz_poly.c
vendored
Normal file
84
external/flint-2.4.3/fmpz_mod_poly/test/t-get_set_fmpz_poly.c
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("get/set_fmpz_poly....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b;
|
||||
fmpz_poly_t c;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_poly_init(c);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
|
||||
fmpz_mod_poly_get_fmpz_poly(c, a);
|
||||
fmpz_mod_poly_set_fmpz_poly(b, c);
|
||||
|
||||
result = fmpz_mod_poly_equal(a, b);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n");
|
||||
flint_printf("c = "), fmpz_poly_print(c), flint_printf("\n");
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_poly_clear(c);
|
||||
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
95
external/flint-2.4.3/fmpz_mod_poly/test/t-init_realloc_clear.c
vendored
Normal file
95
external/flint-2.4.3/fmpz_mod_poly/test/t-init_realloc_clear.c
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_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 < 10000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init2(a, p, n_randint(state, 100));
|
||||
fmpz_mod_poly_clear(a);
|
||||
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init2(a, p, n_randint(state, 100));
|
||||
fmpz_mod_poly_realloc(a, n_randint(state, 100));
|
||||
fmpz_mod_poly_clear(a);
|
||||
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_clear(a);
|
||||
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
104
external/flint-2.4.3/fmpz_mod_poly/test/t-inv_series_newton.c
vendored
Normal file
104
external/flint-2.4.3/fmpz_mod_poly/test/t-inv_series_newton.c
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_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^{-1} * Q is congruent 1 mod t^n */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, c, one;
|
||||
slong n = n_randint(state, 80) + 1;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(one, p);
|
||||
|
||||
fmpz_mod_poly_randtest_not_zero(a, state, n_randint(state, 80) + 1);
|
||||
{
|
||||
fmpz_t d;
|
||||
|
||||
fmpz_init(d);
|
||||
fmpz_gcd(d, a->coeffs, p);
|
||||
while (!fmpz_is_one(d))
|
||||
{
|
||||
fmpz_randm(a->coeffs, state, p);
|
||||
fmpz_gcd(d, a->coeffs, p);
|
||||
}
|
||||
fmpz_clear(d);
|
||||
}
|
||||
|
||||
fmpz_mod_poly_set_ui(one, 1);
|
||||
|
||||
fmpz_mod_poly_inv_series_newton(b, a, n);
|
||||
fmpz_mod_poly_mullow(c, a, b, n);
|
||||
|
||||
result = (fmpz_mod_poly_equal(c, one));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("c = "), fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(one);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
231
external/flint-2.4.3/fmpz_mod_poly/test/t-invmod.c
vendored
Normal file
231
external/flint-2.4.3/fmpz_mod_poly/test/t-invmod.c
vendored
Normal file
@@ -0,0 +1,231 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("invmod....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
/* Test aliasing *************************************************************/
|
||||
|
||||
/* Aliasing c and a */
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, c;
|
||||
int ans1, ans2;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
|
||||
do
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 100));
|
||||
while (b->length < 3);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
|
||||
ans1 = fmpz_mod_poly_invmod(c, a, b);
|
||||
ans2 = fmpz_mod_poly_invmod(a, a, b);
|
||||
|
||||
result = (ans1 == ans2 && fmpz_mod_poly_equal(a, c));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL (alias a and c):\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
flint_printf("ans1 = %d\n\n", ans1);
|
||||
flint_printf("ans2 = %d\n\n", ans2);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Aliasing c and b */
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, c;
|
||||
int ans1, ans2;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
|
||||
do
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 100));
|
||||
while (b->length < 3);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
|
||||
ans1 = fmpz_mod_poly_invmod(c, a, b);
|
||||
ans2 = fmpz_mod_poly_invmod(b, a, b);
|
||||
|
||||
result = ((ans1 == ans2) && fmpz_mod_poly_equal(b, c));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL (alias b and c):\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
flint_printf("ans1 = %d\n\n", ans1);
|
||||
flint_printf("ans2 = %d\n\n", ans2);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Compare with result from XGCD */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, g, s, t, u;
|
||||
int ans;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(g, p);
|
||||
fmpz_mod_poly_init(s, p);
|
||||
fmpz_mod_poly_init(t, p);
|
||||
fmpz_mod_poly_init(u, p);
|
||||
|
||||
do
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 100));
|
||||
while (b->length < 3);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
|
||||
ans = fmpz_mod_poly_invmod(u, a, b);
|
||||
fmpz_mod_poly_xgcd(g, s, t, a, b);
|
||||
|
||||
result = (((ans) && g->length == 1
|
||||
&& fmpz_is_one(g->coeffs) && fmpz_mod_poly_equal(s, u))
|
||||
|| (!(ans) && g->length > 1));
|
||||
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(g), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(s), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(t), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(u), flint_printf("\n\n");
|
||||
flint_printf("ans = %d\n\n", ans);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(g);
|
||||
fmpz_mod_poly_clear(s);
|
||||
fmpz_mod_poly_clear(t);
|
||||
fmpz_mod_poly_clear(u);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Special case, arguments share a factor ********************************/
|
||||
|
||||
/* Check correctness */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, f, u;
|
||||
int ans;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(u, p);
|
||||
|
||||
do
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 100));
|
||||
while (b->length < 2);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
do
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 20) + 1);
|
||||
while (f->length < 2);
|
||||
fmpz_mod_poly_mul(a, f, a);
|
||||
fmpz_mod_poly_mul(b, f, b);
|
||||
|
||||
ans = fmpz_mod_poly_invmod(u, a, b);
|
||||
|
||||
result = (!ans);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(u), flint_printf("\n\n");
|
||||
flint_printf("ans = %d\n\n", ans);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(u);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
161
external/flint-2.4.3/fmpz_mod_poly/test/t-mul.c
vendored
Normal file
161
external/flint-2.4.3/fmpz_mod_poly/test/t-mul.c
vendored
Normal file
@@ -0,0 +1,161 @@
|
||||
/*=============================================================================
|
||||
|
||||
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, 2010 Sebastian Pancratz
|
||||
Copyright (C) 2009 William Hart
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_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 < 2000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, c;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest(c, state, n_randint(state, 50));
|
||||
|
||||
fmpz_mod_poly_mul(a, b, c);
|
||||
fmpz_mod_poly_mul(b, b, c);
|
||||
|
||||
result = (fmpz_mod_poly_equal(a, b));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Check aliasing of a and c */
|
||||
for (i = 0; i < 2000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, c;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest(c, state, n_randint(state, 50));
|
||||
|
||||
fmpz_mod_poly_mul(a, b, c);
|
||||
fmpz_mod_poly_mul(c, b, c);
|
||||
|
||||
result = (fmpz_mod_poly_equal(a, c));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Check (b*c)+(b*d) = b*(c+d) */
|
||||
for (i = 0; i < 2000; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a1, a2, b, c, d;
|
||||
fmpz_t p;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a1, p);
|
||||
fmpz_mod_poly_init(a2, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest(c, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest(d, state, n_randint(state, 100));
|
||||
|
||||
fmpz_mod_poly_mul(a1, b, c);
|
||||
fmpz_mod_poly_mul(a2, b, d);
|
||||
fmpz_mod_poly_add(a1, a1, a2);
|
||||
|
||||
fmpz_mod_poly_add(c, c, d);
|
||||
fmpz_mod_poly_mul(a2, b, c);
|
||||
|
||||
result = (fmpz_mod_poly_equal(a1, a2));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a1), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(a2), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a1);
|
||||
fmpz_mod_poly_clear(a2);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(d);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
88
external/flint-2.4.3/fmpz_mod_poly/test/t-mullow.c
vendored
Normal file
88
external/flint-2.4.3/fmpz_mod_poly/test/t-mullow.c
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Sebastian Pancratz
|
||||
Copyright (C) 2009 William Hart
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_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 < 2000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, c;
|
||||
slong trunc;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
trunc = n_randint(state, 50);
|
||||
fmpz_mod_poly_randtest(b, state, trunc);
|
||||
fmpz_mod_poly_randtest(c, state, trunc);
|
||||
|
||||
fmpz_mod_poly_mullow(a, b, c, trunc);
|
||||
fmpz_mod_poly_mul(b, b, c);
|
||||
fmpz_mod_poly_truncate(b, trunc);
|
||||
|
||||
result = (fmpz_mod_poly_equal(a, b));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
213
external/flint-2.4.3/fmpz_mod_poly/test/t-mulmod.c
vendored
Normal file
213
external/flint-2.4.3/fmpz_mod_poly/test/t-mulmod.c
vendored
Normal 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) 2012 Lina Kulakova
|
||||
Copyright (C) 2011, 2010 Sebastian Pancratz
|
||||
Copyright (C) 2009 William Hart
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("mulmod....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
/* Check aliasing of res and a */
|
||||
for (i = 0; i < 2000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, res, f;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(res, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
|
||||
fmpz_mod_poly_mulmod(res, a, b, f);
|
||||
fmpz_mod_poly_mulmod(a, a, b, f);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res, a));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("res:\n"); fmpz_mod_poly_print(res), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(res);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Check aliasing of res and b */
|
||||
for (i = 0; i < 2000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, f, res;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(res, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
|
||||
fmpz_mod_poly_mulmod(res, a, b, f);
|
||||
fmpz_mod_poly_mulmod(b, a, b, f);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res, b));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("res:\n"); fmpz_mod_poly_print(res), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(res);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Check aliasing of res and f */
|
||||
for (i = 0; i < 2000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, f, res;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(res, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
|
||||
fmpz_mod_poly_mulmod(res, a, b, f);
|
||||
fmpz_mod_poly_mulmod(f, a, b, f);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res, f));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("res:\n"); fmpz_mod_poly_print(res), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(res);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* No aliasing */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, res1, res2, t, f;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
|
||||
fmpz_mod_poly_init(res1, p);
|
||||
fmpz_mod_poly_init(res2, p);
|
||||
fmpz_mod_poly_init(t, p);
|
||||
fmpz_mod_poly_mulmod(res1, a, b, f);
|
||||
fmpz_mod_poly_mul(res2, a, b);
|
||||
fmpz_mod_poly_divrem(t, res2, res2, f);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res1, res2));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("res1:\n"); fmpz_mod_poly_print(res1), flint_printf("\n\n");
|
||||
flint_printf("res2:\n"); fmpz_mod_poly_print(res2), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(res1);
|
||||
fmpz_mod_poly_clear(res2);
|
||||
fmpz_mod_poly_clear(t);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
305
external/flint-2.4.3/fmpz_mod_poly/test/t-mulmod_preinv.c
vendored
Normal file
305
external/flint-2.4.3/fmpz_mod_poly/test/t-mulmod_preinv.c
vendored
Normal file
@@ -0,0 +1,305 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 Lina Kulakova
|
||||
Copyright (C) 2011, 2010 Sebastian Pancratz
|
||||
Copyright (C) 2009 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 "fmpz.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("mulmod_preinv....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
/* Check aliasing of res and a */
|
||||
for (i = 0; i < 2000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, res, f, finv;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(finv, p);
|
||||
fmpz_mod_poly_init(res, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
if (a->length >= f->length)
|
||||
fmpz_mod_poly_rem (a, a, f);
|
||||
if (b->length >= f->length)
|
||||
fmpz_mod_poly_rem (b, b, f);
|
||||
|
||||
fmpz_mod_poly_reverse (finv, f, f->length);
|
||||
fmpz_mod_poly_inv_series_newton (finv, finv, f->length);
|
||||
|
||||
fmpz_mod_poly_mulmod_preinv(res, a, b, f, finv);
|
||||
fmpz_mod_poly_mulmod_preinv(a, a, b, f, finv);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res, a));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("res:\n"); fmpz_mod_poly_print(res), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(finv);
|
||||
fmpz_mod_poly_clear(res);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Check aliasing of res and b */
|
||||
for (i = 0; i < 2000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, f, finv, res;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(finv, p);
|
||||
fmpz_mod_poly_init(res, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
if (a->length >= f->length)
|
||||
fmpz_mod_poly_rem (a, a, f);
|
||||
if (b->length >= f->length)
|
||||
fmpz_mod_poly_rem (b, b, f);
|
||||
|
||||
fmpz_mod_poly_reverse (finv, f, f->length);
|
||||
fmpz_mod_poly_inv_series_newton (finv, finv, f->length);
|
||||
|
||||
fmpz_mod_poly_mulmod_preinv(res, a, b, f, finv);
|
||||
fmpz_mod_poly_mulmod_preinv(b, a, b, f, finv);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res, b));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("res:\n"); fmpz_mod_poly_print(res), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(finv);
|
||||
fmpz_mod_poly_clear(res);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Check aliasing of res and f */
|
||||
for (i = 0; i < 2000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, f, finv, res;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(finv, p);
|
||||
fmpz_mod_poly_init(res, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
if (a->length >= f->length)
|
||||
fmpz_mod_poly_rem (a, a, f);
|
||||
if (b->length >= f->length)
|
||||
fmpz_mod_poly_rem (b, b, f);
|
||||
|
||||
fmpz_mod_poly_reverse (finv, f, f->length);
|
||||
fmpz_mod_poly_inv_series_newton (finv, finv, f->length);
|
||||
|
||||
fmpz_mod_poly_mulmod_preinv(res, a, b, f, finv);
|
||||
fmpz_mod_poly_mulmod_preinv(f, a, b, f, finv);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res, f));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("res:\n"); fmpz_mod_poly_print(res), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(finv);
|
||||
fmpz_mod_poly_clear(res);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Check aliasing of res and finv */
|
||||
for (i = 0; i < 2000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, f, finv, res;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(finv, p);
|
||||
fmpz_mod_poly_init(res, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
if (a->length >= f->length)
|
||||
fmpz_mod_poly_rem (a, a, f);
|
||||
if (b->length >= f->length)
|
||||
fmpz_mod_poly_rem (b, b, f);
|
||||
|
||||
fmpz_mod_poly_reverse (finv, f, f->length);
|
||||
fmpz_mod_poly_inv_series_newton (finv, finv, f->length);
|
||||
|
||||
fmpz_mod_poly_mulmod_preinv(res, a, b, f, finv);
|
||||
fmpz_mod_poly_mulmod_preinv(finv, a, b, f, finv);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res, finv));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("finv:\n"); fmpz_mod_poly_print(finv), flint_printf("\n\n");
|
||||
flint_printf("res:\n"); fmpz_mod_poly_print(res), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(finv);
|
||||
fmpz_mod_poly_clear(res);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* No aliasing */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, res1, res2, f, finv;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(finv, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
if (a->length >= f->length)
|
||||
fmpz_mod_poly_rem (a, a, f);
|
||||
if (b->length >= f->length)
|
||||
fmpz_mod_poly_rem (b, b, f);
|
||||
|
||||
fmpz_mod_poly_reverse (finv, f, f->length);
|
||||
fmpz_mod_poly_inv_series_newton (finv, finv, f->length);
|
||||
|
||||
fmpz_mod_poly_init(res1, p);
|
||||
fmpz_mod_poly_init(res2, p);
|
||||
fmpz_mod_poly_mulmod(res1, a, b, f);
|
||||
fmpz_mod_poly_mulmod_preinv(res2, a, b, f, finv);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res1, res2));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("res1:\n"); fmpz_mod_poly_print(res1), flint_printf("\n\n");
|
||||
flint_printf("res2:\n"); fmpz_mod_poly_print(res2), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(finv);
|
||||
fmpz_mod_poly_clear(res1);
|
||||
fmpz_mod_poly_clear(res2);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
83
external/flint-2.4.3/fmpz_mod_poly/test/t-neg.c
vendored
Normal file
83
external/flint-2.4.3/fmpz_mod_poly/test/t-neg.c
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Sebastian Pancratz
|
||||
Copyright (C) 2009 William Hart
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("neg....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, c;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
|
||||
fmpz_mod_poly_neg(b, a);
|
||||
fmpz_mod_poly_neg(c, b);
|
||||
|
||||
result = (fmpz_mod_poly_equal(a, c));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
131
external/flint-2.4.3/fmpz_mod_poly/test/t-pow_trunc.c
vendored
Normal file
131
external/flint-2.4.3/fmpz_mod_poly/test/t-pow_trunc.c
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2010 William Hart
|
||||
Copyright (C) 2012 Lina Kulakova
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("pow_trunc....");
|
||||
fflush(stdout);
|
||||
|
||||
/* Check aliasing */
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, b, c;
|
||||
fmpz_t p;
|
||||
slong e, trunc;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 30));
|
||||
e = n_randint(state, 20);
|
||||
trunc = n_randint(state, 30);
|
||||
|
||||
fmpz_mod_poly_set(c, a);
|
||||
|
||||
fmpz_mod_poly_pow_trunc(b, a, e, trunc);
|
||||
fmpz_mod_poly_pow_trunc(c, c, e, trunc);
|
||||
|
||||
result = (fmpz_mod_poly_equal(b, c));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL aliasing:\n");
|
||||
flint_printf("a->length = %wd, p = %wu, exp = %wd, trunc = %wd\n",
|
||||
a->length, a->p, e, trunc);
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("c:\n"); fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
}
|
||||
|
||||
/* Check powering against naive method */
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, b, c;
|
||||
fmpz_t p;
|
||||
slong e, trunc;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 30));
|
||||
e = n_randint(state, 20);
|
||||
trunc = n_randint(state, 30);
|
||||
|
||||
fmpz_mod_poly_pow_trunc(b, a, e, trunc);
|
||||
fmpz_mod_poly_pow(c, a, e);
|
||||
fmpz_mod_poly_truncate(c, trunc);
|
||||
|
||||
result = (fmpz_mod_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, p = %wu, exp = %wd, trunc = %wd\n",
|
||||
a->length, a->p, e, trunc);
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("c:\n"); fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
131
external/flint-2.4.3/fmpz_mod_poly/test/t-pow_trunc_binexp.c
vendored
Normal file
131
external/flint-2.4.3/fmpz_mod_poly/test/t-pow_trunc_binexp.c
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2010 William Hart
|
||||
Copyright (C) 2012 Lina Kulakova
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("pow_trunc_binexp....");
|
||||
fflush(stdout);
|
||||
|
||||
/* Check aliasing */
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, b, c;
|
||||
fmpz_t p;
|
||||
slong e, trunc;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 30));
|
||||
e = n_randint(state, 20);
|
||||
trunc = n_randint(state, 30);
|
||||
|
||||
fmpz_mod_poly_set(c, a);
|
||||
|
||||
fmpz_mod_poly_pow_trunc_binexp(b, a, e, trunc);
|
||||
fmpz_mod_poly_pow_trunc_binexp(c, c, e, trunc);
|
||||
|
||||
result = (fmpz_mod_poly_equal(b, c));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a->length = %wd, p = %wu, exp = %wd, trunc = %wd\n",
|
||||
a->length, a->p, e, trunc);
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("c:\n"); fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
}
|
||||
|
||||
/* Check powering against naive method */
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, b, c;
|
||||
fmpz_t p;
|
||||
slong e, trunc;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 30));
|
||||
e = n_randint(state, 20);
|
||||
trunc = n_randint(state, 30);
|
||||
|
||||
fmpz_mod_poly_pow_trunc_binexp(b, a, e, trunc);
|
||||
fmpz_mod_poly_pow(c, a, e);
|
||||
fmpz_mod_poly_truncate(c, trunc);
|
||||
|
||||
result = (fmpz_mod_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, p = %wu, exp = %wd, trunc = %wd\n",
|
||||
a->length, a->p, e, trunc);
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b:\n"); fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("c:\n"); fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
238
external/flint-2.4.3/fmpz_mod_poly/test/t-powmod_fmpz_binexp.c
vendored
Normal file
238
external/flint-2.4.3/fmpz_mod_poly/test/t-powmod_fmpz_binexp.c
vendored
Normal file
@@ -0,0 +1,238 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2012 Lina Kulakova
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz_vec.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("powmod_fmpz_binexp....");
|
||||
fflush(stdout);
|
||||
|
||||
/* Aliasing of res and a */
|
||||
for (i = 0; i < 250; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, res, t, f;
|
||||
fmpz_t p;
|
||||
ulong exp;
|
||||
fmpz_t expz;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
exp = n_randint(state, 50);
|
||||
fmpz_init_set_ui(expz, exp);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(res, p);
|
||||
fmpz_mod_poly_init(t, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
|
||||
fmpz_mod_poly_powmod_fmpz_binexp(res, a, expz, f);
|
||||
fmpz_mod_poly_powmod_fmpz_binexp(a, a, expz, f);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res, a));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("res:\n"); fmpz_mod_poly_print(res), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(res);
|
||||
fmpz_mod_poly_clear(t);
|
||||
fmpz_clear(expz);
|
||||
}
|
||||
|
||||
/* Aliasing of res and f */
|
||||
for (i = 0; i < 250; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, res, t, f;
|
||||
fmpz_t p;
|
||||
ulong exp;
|
||||
fmpz_t expz;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
exp = n_randint(state, 50);
|
||||
fmpz_init_set_ui(expz, exp);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(res, p);
|
||||
fmpz_mod_poly_init(t, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
|
||||
fmpz_mod_poly_powmod_fmpz_binexp(res, a, expz, f);
|
||||
fmpz_mod_poly_powmod_fmpz_binexp(f, a, expz, f);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res, f));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("res:\n"); fmpz_mod_poly_print(res), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(res);
|
||||
fmpz_mod_poly_clear(t);
|
||||
fmpz_clear(expz);
|
||||
}
|
||||
|
||||
/* No aliasing */
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, res1, res2, t, f;
|
||||
fmpz_t p;
|
||||
ulong exp;
|
||||
fmpz_t expz;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
exp = n_randint(state, 50);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(res1, p);
|
||||
fmpz_mod_poly_init(res2, p);
|
||||
fmpz_mod_poly_init(t, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
fmpz_init_set_ui(expz, exp);
|
||||
|
||||
fmpz_mod_poly_powmod_fmpz_binexp(res1, a, expz, f);
|
||||
fmpz_mod_poly_powmod_ui_binexp(res2, a, exp, f);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res1, res2));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("res1:\n"); fmpz_mod_poly_print(res1), flint_printf("\n\n");
|
||||
flint_printf("res2:\n"); fmpz_mod_poly_print(res2), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(res1);
|
||||
fmpz_mod_poly_clear(res2);
|
||||
fmpz_mod_poly_clear(t);
|
||||
fmpz_clear(expz);
|
||||
}
|
||||
|
||||
/* Check that a^(b+c) = a^b * a^c */
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, res1, res2, res3, res4, t, f;
|
||||
fmpz_t p;
|
||||
fmpz_t exp1, exp2, exp3;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_init(exp1);
|
||||
fmpz_init(exp2);
|
||||
fmpz_randtest(exp1, state, 200);
|
||||
if (fmpz_sgn(exp1) == -1) fmpz_neg(exp1, exp1);
|
||||
fmpz_randtest(exp2, state, 200);
|
||||
if (fmpz_sgn(exp2) == -1) fmpz_neg(exp2, exp2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(res1, p);
|
||||
fmpz_mod_poly_init(res2, p);
|
||||
fmpz_mod_poly_init(res3, p);
|
||||
fmpz_mod_poly_init(res4, p);
|
||||
fmpz_mod_poly_init(t, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
|
||||
fmpz_mod_poly_powmod_fmpz_binexp(res1, a, exp1, f);
|
||||
fmpz_mod_poly_powmod_fmpz_binexp(res2, a, exp2, f);
|
||||
fmpz_mod_poly_mulmod(res4, res1, res2, f);
|
||||
fmpz_init(exp3);
|
||||
fmpz_add(exp3, exp1, exp2);
|
||||
fmpz_mod_poly_powmod_fmpz_binexp(res3, a, exp3, f);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res4, res3));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("res3:\n"); fmpz_mod_poly_print(res3), flint_printf("\n\n");
|
||||
flint_printf("res4:\n"); fmpz_mod_poly_print(res4), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(res1);
|
||||
fmpz_mod_poly_clear(res2);
|
||||
fmpz_mod_poly_clear(res3);
|
||||
fmpz_mod_poly_clear(res4);
|
||||
fmpz_mod_poly_clear(t);
|
||||
fmpz_clear(exp1);
|
||||
fmpz_clear(exp2);
|
||||
fmpz_clear(exp3);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
308
external/flint-2.4.3/fmpz_mod_poly/test/t-powmod_fmpz_binexp_preinv.c
vendored
Normal file
308
external/flint-2.4.3/fmpz_mod_poly/test/t-powmod_fmpz_binexp_preinv.c
vendored
Normal file
@@ -0,0 +1,308 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2012 Lina Kulakova
|
||||
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 "fmpz_vec.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("powmod_fmpz_binexp_preinv....");
|
||||
fflush(stdout);
|
||||
|
||||
/* Aliasing of res and a */
|
||||
for (i = 0; i < 250; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, res, f, finv;
|
||||
fmpz_t p;
|
||||
ulong exp;
|
||||
fmpz_t expz;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
exp = n_randint(state, 50);
|
||||
fmpz_init_set_ui(expz, exp);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(finv, p);
|
||||
fmpz_mod_poly_init(res, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
|
||||
fmpz_mod_poly_reverse (finv, f, f->length);
|
||||
fmpz_mod_poly_inv_series_newton (finv, finv, f->length);
|
||||
|
||||
fmpz_mod_poly_powmod_fmpz_binexp_preinv(res, a, expz, f, finv);
|
||||
fmpz_mod_poly_powmod_fmpz_binexp_preinv(a, a, expz, f, finv);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res, a));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("res:\n"); fmpz_mod_poly_print(res), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(finv);
|
||||
fmpz_mod_poly_clear(res);
|
||||
fmpz_clear(expz);
|
||||
}
|
||||
|
||||
/* Aliasing of res and f */
|
||||
for (i = 0; i < 250; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, res, f, finv;
|
||||
fmpz_t p;
|
||||
ulong exp;
|
||||
fmpz_t expz;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
exp = n_randint(state, 50);
|
||||
fmpz_init_set_ui(expz, exp);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(finv, p);
|
||||
fmpz_mod_poly_init(res, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
|
||||
fmpz_mod_poly_reverse (finv, f, f->length);
|
||||
fmpz_mod_poly_inv_series_newton (finv, finv, f->length);
|
||||
|
||||
fmpz_mod_poly_powmod_fmpz_binexp_preinv(res, a, expz, f, finv);
|
||||
fmpz_mod_poly_powmod_fmpz_binexp_preinv(f, a, expz, f, finv);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res, f));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("res:\n"); fmpz_mod_poly_print(res), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(finv);
|
||||
fmpz_mod_poly_clear(res);
|
||||
fmpz_clear(expz);
|
||||
}
|
||||
|
||||
/* Aliasing of res and finv */
|
||||
for (i = 0; i < 250; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, res, f, finv;
|
||||
fmpz_t p;
|
||||
ulong exp;
|
||||
fmpz_t expz;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
exp = n_randint(state, 50);
|
||||
fmpz_init_set_ui(expz, exp);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(finv, p);
|
||||
fmpz_mod_poly_init(res, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
|
||||
|
||||
fmpz_mod_poly_reverse (finv, f, f->length);
|
||||
fmpz_mod_poly_inv_series_newton (finv, finv, f->length);
|
||||
|
||||
fmpz_mod_poly_powmod_fmpz_binexp_preinv(res, a, expz, f, finv);
|
||||
fmpz_mod_poly_powmod_fmpz_binexp_preinv(finv, a, expz, f, finv);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res, finv));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("finv:\n"); fmpz_mod_poly_print(finv), flint_printf("\n\n");
|
||||
flint_printf("res:\n"); fmpz_mod_poly_print(res), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(finv);
|
||||
fmpz_mod_poly_clear(res);
|
||||
fmpz_clear(expz);
|
||||
}
|
||||
|
||||
/* No aliasing */
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, res1, res2, f, finv;
|
||||
fmpz_t p;
|
||||
ulong exp;
|
||||
fmpz_t expz;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
exp = n_randint(state, 50);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(finv, p);
|
||||
fmpz_mod_poly_init(res1, p);
|
||||
fmpz_mod_poly_init(res2, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
fmpz_init_set_ui(expz, exp);
|
||||
|
||||
fmpz_mod_poly_reverse (finv, f, f->length);
|
||||
fmpz_mod_poly_inv_series_newton (finv, finv, f->length);
|
||||
|
||||
fmpz_mod_poly_powmod_fmpz_binexp(res1, a, expz, f);
|
||||
fmpz_mod_poly_powmod_fmpz_binexp_preinv(res2, a, expz, f, finv);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res1, res2));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("finv:\n"); fmpz_mod_poly_print(finv), flint_printf("\n\n");
|
||||
flint_printf("res1:\n"); fmpz_mod_poly_print(res1), flint_printf("\n\n");
|
||||
flint_printf("res2:\n"); fmpz_mod_poly_print(res2), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(res1);
|
||||
fmpz_mod_poly_clear(res2);
|
||||
fmpz_mod_poly_clear(finv);
|
||||
fmpz_clear(expz);
|
||||
}
|
||||
|
||||
/* Check that a^(b+c) = a^b * a^c */
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, res1, res2, res3, res4, f, finv;
|
||||
fmpz_t p;
|
||||
fmpz_t exp1, exp2, exp3;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_init(exp1);
|
||||
fmpz_init(exp2);
|
||||
fmpz_randtest(exp1, state, 200);
|
||||
if (fmpz_sgn(exp1) == -1) fmpz_neg(exp1, exp1);
|
||||
fmpz_randtest(exp2, state, 200);
|
||||
if (fmpz_sgn(exp2) == -1) fmpz_neg(exp2, exp2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(finv, p);
|
||||
fmpz_mod_poly_init(res1, p);
|
||||
fmpz_mod_poly_init(res2, p);
|
||||
fmpz_mod_poly_init(res3, p);
|
||||
fmpz_mod_poly_init(res4, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
|
||||
fmpz_mod_poly_reverse (finv, f, f->length);
|
||||
fmpz_mod_poly_inv_series_newton (finv, finv, f->length);
|
||||
|
||||
fmpz_mod_poly_powmod_fmpz_binexp_preinv(res1, a, exp1, f, finv);
|
||||
fmpz_mod_poly_powmod_fmpz_binexp_preinv(res2, a, exp2, f, finv);
|
||||
fmpz_mod_poly_mulmod(res4, res1, res2, f);
|
||||
fmpz_init(exp3);
|
||||
fmpz_add(exp3, exp1, exp2);
|
||||
fmpz_mod_poly_powmod_fmpz_binexp_preinv(res3, a, exp3, f, finv);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res4, res3));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("res3:\n"); fmpz_mod_poly_print(res3), flint_printf("\n\n");
|
||||
flint_printf("res4:\n"); fmpz_mod_poly_print(res4), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(finv);
|
||||
fmpz_mod_poly_clear(res1);
|
||||
fmpz_mod_poly_clear(res2);
|
||||
fmpz_mod_poly_clear(res3);
|
||||
fmpz_mod_poly_clear(res4);
|
||||
fmpz_clear(exp1);
|
||||
fmpz_clear(exp2);
|
||||
fmpz_clear(exp3);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
232
external/flint-2.4.3/fmpz_mod_poly/test/t-powmod_ui_binexp.c
vendored
Normal file
232
external/flint-2.4.3/fmpz_mod_poly/test/t-powmod_ui_binexp.c
vendored
Normal file
@@ -0,0 +1,232 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2012 Lina Kulakova
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz_vec.h"
|
||||
#include "fmpz_mod_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 < 500; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, res1, t, f;
|
||||
fmpz_t p;
|
||||
ulong exp;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
exp = n_randint(state, 50);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(res1, p);
|
||||
fmpz_mod_poly_init(t, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
|
||||
fmpz_mod_poly_powmod_ui_binexp(res1, a, exp, f);
|
||||
fmpz_mod_poly_powmod_ui_binexp(a, a, exp, f);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res1, a));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("exp: %wu\n\n", exp);
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("res:\n"); fmpz_mod_poly_print(res1), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(res1);
|
||||
fmpz_mod_poly_clear(t);
|
||||
}
|
||||
|
||||
/* Aliasing of res and f */
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, res1, t, f;
|
||||
fmpz_t p;
|
||||
ulong exp;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
exp = n_randint(state, 50);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(res1, p);
|
||||
fmpz_mod_poly_init(t, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
|
||||
fmpz_mod_poly_powmod_ui_binexp(res1, a, exp, f);
|
||||
fmpz_mod_poly_powmod_ui_binexp(f, a, exp, f);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res1, f));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("exp: %wu\n\n", exp);
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("res1:\n"); fmpz_mod_poly_print(res1), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(res1);
|
||||
fmpz_mod_poly_clear(t);
|
||||
}
|
||||
|
||||
/* No aliasing */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, res1, res2, t, f;
|
||||
fmpz_t p;
|
||||
ulong exp;
|
||||
int j;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
exp = n_randint(state, 50);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(res1, p);
|
||||
fmpz_mod_poly_init(res2, p);
|
||||
fmpz_mod_poly_init(t, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
|
||||
fmpz_mod_poly_powmod_ui_binexp(res1, a, exp, f);
|
||||
|
||||
fmpz_mod_poly_zero(res2);
|
||||
fmpz_mod_poly_set_coeff_ui(res2, 0, 1);
|
||||
for (j = 1; j <= exp; j++)
|
||||
fmpz_mod_poly_mulmod(res2, res2, a, f);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res1, res2));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("exp: %wu\n\n", exp);
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("res1:\n"); fmpz_mod_poly_print(res1), flint_printf("\n\n");
|
||||
flint_printf("res2:\n"); fmpz_mod_poly_print(res2), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(res1);
|
||||
fmpz_mod_poly_clear(res2);
|
||||
fmpz_mod_poly_clear(t);
|
||||
}
|
||||
|
||||
/* Check that a^(b+c) = a^b * a^c */
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, res1, res2, res3, res4, t, f;
|
||||
fmpz_t p;
|
||||
ulong exp1, exp2, exp3;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
exp1 = n_randint(state, 50);
|
||||
exp2 = n_randint(state, 50);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(res1, p);
|
||||
fmpz_mod_poly_init(res2, p);
|
||||
fmpz_mod_poly_init(res3, p);
|
||||
fmpz_mod_poly_init(res4, p);
|
||||
fmpz_mod_poly_init(t, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
|
||||
fmpz_mod_poly_powmod_ui_binexp(res1, a, exp1, f);
|
||||
fmpz_mod_poly_powmod_ui_binexp(res2, a, exp2, f);
|
||||
fmpz_mod_poly_mulmod(res4, res1, res2, f);
|
||||
exp3 = exp1 + exp2;
|
||||
fmpz_mod_poly_powmod_ui_binexp(res3, a, exp3, f);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res4, res3));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("res3:\n"); fmpz_mod_poly_print(res3), flint_printf("\n\n");
|
||||
flint_printf("res4:\n"); fmpz_mod_poly_print(res4), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(res1);
|
||||
fmpz_mod_poly_clear(res2);
|
||||
fmpz_mod_poly_clear(res3);
|
||||
fmpz_mod_poly_clear(res4);
|
||||
fmpz_mod_poly_clear(t);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
294
external/flint-2.4.3/fmpz_mod_poly/test/t-powmod_ui_binexp_preinv.c
vendored
Normal file
294
external/flint-2.4.3/fmpz_mod_poly/test/t-powmod_ui_binexp_preinv.c
vendored
Normal file
@@ -0,0 +1,294 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2012 Lina Kulakova
|
||||
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 "fmpz_vec.h"
|
||||
#include "fmpz_mod_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 < 500; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, res, f, finv;
|
||||
fmpz_t p;
|
||||
ulong exp;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
exp = n_randint(state, 50);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(finv, p);
|
||||
fmpz_mod_poly_init(res, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
|
||||
fmpz_mod_poly_reverse (finv, f, f->length);
|
||||
fmpz_mod_poly_inv_series_newton (finv, finv, f->length);
|
||||
|
||||
fmpz_mod_poly_powmod_ui_binexp_preinv(res, a, exp, f, finv);
|
||||
fmpz_mod_poly_powmod_ui_binexp_preinv(a, a, exp, f, finv);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res, a));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("res:\n"); fmpz_mod_poly_print(res), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(finv);
|
||||
fmpz_mod_poly_clear(res);
|
||||
}
|
||||
|
||||
/* Aliasing of res and f */
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, res, f, finv;
|
||||
fmpz_t p;
|
||||
ulong exp;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
exp = n_randint(state, 50);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(finv, p);
|
||||
fmpz_mod_poly_init(res, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
|
||||
fmpz_mod_poly_reverse (finv, f, f->length);
|
||||
fmpz_mod_poly_inv_series_newton (finv, finv, f->length);
|
||||
|
||||
fmpz_mod_poly_powmod_ui_binexp_preinv(res, a, exp, f, finv);
|
||||
fmpz_mod_poly_powmod_ui_binexp_preinv(f, a, exp, f, finv);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res, f));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("res:\n"); fmpz_mod_poly_print(res), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(finv);
|
||||
fmpz_mod_poly_clear(res);
|
||||
}
|
||||
|
||||
/* Aliasing of res and finv */
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, res, f, finv;
|
||||
fmpz_t p;
|
||||
ulong exp;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
exp = n_randint(state, 50);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(finv, p);
|
||||
fmpz_mod_poly_init(res, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
|
||||
|
||||
fmpz_mod_poly_reverse (finv, f, f->length);
|
||||
fmpz_mod_poly_inv_series_newton (finv, finv, f->length);
|
||||
|
||||
fmpz_mod_poly_powmod_ui_binexp_preinv(res, a, exp, f, finv);
|
||||
fmpz_mod_poly_powmod_ui_binexp_preinv(finv, a, exp, f, finv);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res, finv));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("finv:\n"); fmpz_mod_poly_print(finv), flint_printf("\n\n");
|
||||
flint_printf("res:\n"); fmpz_mod_poly_print(res), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(finv);
|
||||
fmpz_mod_poly_clear(res);
|
||||
}
|
||||
|
||||
/* No aliasing */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, res1, res2, f, finv;
|
||||
fmpz_t p;
|
||||
ulong exp;
|
||||
int j;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
exp = n_randint(state, 50);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(finv, p);
|
||||
fmpz_mod_poly_init(res1, p);
|
||||
fmpz_mod_poly_init(res2, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
|
||||
fmpz_mod_poly_reverse (finv, f, f->length);
|
||||
fmpz_mod_poly_inv_series_newton (finv, finv, f->length);
|
||||
|
||||
fmpz_mod_poly_powmod_ui_binexp_preinv(res1, a, exp, f, finv);
|
||||
|
||||
fmpz_mod_poly_zero(res2);
|
||||
fmpz_mod_poly_set_coeff_ui(res2, 0, 1);
|
||||
for (j = 1; j <= exp; j++)
|
||||
fmpz_mod_poly_mulmod(res2, res2, a, f);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res1, res2));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("finv:\n"); fmpz_mod_poly_print(finv), flint_printf("\n\n");
|
||||
flint_printf("res1:\n"); fmpz_mod_poly_print(res1), flint_printf("\n\n");
|
||||
flint_printf("res2:\n"); fmpz_mod_poly_print(res2), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(res1);
|
||||
fmpz_mod_poly_clear(res2);
|
||||
fmpz_mod_poly_clear(finv);
|
||||
}
|
||||
|
||||
/* Check that a^(b+c) = a^b * a^c */
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, res1, res2, res3, res4, f, finv;
|
||||
fmpz_t p;
|
||||
ulong exp1, exp2, exp3;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
exp1 = n_randint(state, 50);
|
||||
exp2 = n_randint(state, 50);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(finv, p);
|
||||
fmpz_mod_poly_init(res1, p);
|
||||
fmpz_mod_poly_init(res2, p);
|
||||
fmpz_mod_poly_init(res3, p);
|
||||
fmpz_mod_poly_init(res4, p);
|
||||
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 50));
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
|
||||
fmpz_mod_poly_reverse (finv, f, f->length);
|
||||
fmpz_mod_poly_inv_series_newton (finv, finv, f->length);
|
||||
|
||||
fmpz_mod_poly_powmod_ui_binexp_preinv(res1, a, exp1, f, finv);
|
||||
fmpz_mod_poly_powmod_ui_binexp_preinv(res2, a, exp2, f, finv);
|
||||
fmpz_mod_poly_mulmod(res4, res1, res2, f);
|
||||
|
||||
exp3= exp1+exp2;
|
||||
fmpz_mod_poly_powmod_ui_binexp_preinv(res3, a, exp3, f, finv);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res4, res3));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("res3:\n"); fmpz_mod_poly_print(res3), flint_printf("\n\n");
|
||||
flint_printf("res4:\n"); fmpz_mod_poly_print(res4), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(finv);
|
||||
fmpz_mod_poly_clear(res1);
|
||||
fmpz_mod_poly_clear(res2);
|
||||
fmpz_mod_poly_clear(res3);
|
||||
fmpz_mod_poly_clear(res4);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
256
external/flint-2.4.3/fmpz_mod_poly/test/t-powmod_x_fmpz_preinv.c
vendored
Normal file
256
external/flint-2.4.3/fmpz_mod_poly/test/t-powmod_x_fmpz_preinv.c
vendored
Normal file
@@ -0,0 +1,256 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2012 Lina Kulakova
|
||||
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 "fmpz_vec.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("powmod_x_fmpz_preinv....");
|
||||
fflush(stdout);
|
||||
|
||||
/* No aliasing */
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_mod_poly_t a, res1, res2, f, finv;
|
||||
fmpz_t p;
|
||||
ulong exp;
|
||||
fmpz_t expz;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
exp = n_randint(state, 50);
|
||||
|
||||
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(finv, p);
|
||||
fmpz_mod_poly_init(res1, p);
|
||||
fmpz_mod_poly_init(res2, p);
|
||||
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
fmpz_init_set_ui(expz, exp);
|
||||
|
||||
fmpz_mod_poly_reverse (finv, f, f->length);
|
||||
fmpz_mod_poly_inv_series_newton (finv, finv, f->length);
|
||||
|
||||
fmpz_mod_poly_init2(a, p, f->length-1);
|
||||
fmpz_mod_poly_set_coeff_ui (a, 1, 1);
|
||||
fmpz_mod_poly_powmod_x_fmpz_preinv(res1, expz, f, finv);
|
||||
fmpz_mod_poly_powmod_fmpz_binexp_preinv(res2, a, expz, f, finv);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res1, res2));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("expz:\n"); fmpz_print(expz), flint_printf("\n\n");
|
||||
flint_printf("a:\n"); fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("finv:\n"); fmpz_mod_poly_print(finv), flint_printf("\n\n");
|
||||
flint_printf("res1:\n"); fmpz_mod_poly_print(res1), flint_printf("\n\n");
|
||||
flint_printf("res2:\n"); fmpz_mod_poly_print(res2), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(res1);
|
||||
fmpz_mod_poly_clear(res2);
|
||||
fmpz_mod_poly_clear(finv);
|
||||
fmpz_clear(expz);
|
||||
}
|
||||
|
||||
/* Aliasing of res and f */
|
||||
for (i = 0; i < 250; i++)
|
||||
{
|
||||
fmpz_mod_poly_t res, f, finv;
|
||||
fmpz_t p;
|
||||
ulong exp;
|
||||
fmpz_t expz;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
exp = n_randint(state, 50);
|
||||
fmpz_init_set_ui(expz, exp);
|
||||
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(finv, p);
|
||||
fmpz_mod_poly_init(res, p);
|
||||
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
|
||||
fmpz_mod_poly_reverse (finv, f, f->length);
|
||||
fmpz_mod_poly_inv_series_newton (finv, finv, f->length);
|
||||
|
||||
fmpz_mod_poly_powmod_x_fmpz_preinv(res, expz, f, finv);
|
||||
fmpz_mod_poly_powmod_x_fmpz_preinv(f, expz, f, finv);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res, f));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("finv:\n"); fmpz_mod_poly_print(finv), flint_printf("\n\n");
|
||||
flint_printf("expz:\n"); fmpz_print(expz), flint_printf("\n\n");
|
||||
flint_printf("res:\n"); fmpz_mod_poly_print(res), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(finv);
|
||||
fmpz_mod_poly_clear(res);
|
||||
fmpz_clear(expz);
|
||||
}
|
||||
|
||||
/* Aliasing of res and finv */
|
||||
for (i = 0; i < 250; i++)
|
||||
{
|
||||
fmpz_mod_poly_t res, f, finv;
|
||||
fmpz_t p;
|
||||
ulong exp;
|
||||
fmpz_t expz;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
exp = n_randint(state, 50);
|
||||
fmpz_init_set_ui(expz, exp);
|
||||
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(finv, p);
|
||||
fmpz_mod_poly_init(res, p);
|
||||
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
|
||||
|
||||
fmpz_mod_poly_reverse (finv, f, f->length);
|
||||
fmpz_mod_poly_inv_series_newton (finv, finv, f->length);
|
||||
|
||||
fmpz_mod_poly_powmod_x_fmpz_preinv(res, expz, f, finv);
|
||||
fmpz_mod_poly_powmod_x_fmpz_preinv(finv, expz, f, finv);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res, finv));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("expz:\n"); fmpz_print(expz), flint_printf("\n\n");
|
||||
flint_printf("finv:\n"); fmpz_mod_poly_print(finv), flint_printf("\n\n");
|
||||
flint_printf("res:\n"); fmpz_mod_poly_print(res), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(finv);
|
||||
fmpz_mod_poly_clear(res);
|
||||
fmpz_clear(expz);
|
||||
}
|
||||
|
||||
/* Check that x^(b+c) = x^b * x^c */
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_mod_poly_t res1, res2, res3, res4, f, finv;
|
||||
fmpz_t p;
|
||||
fmpz_t exp1, exp2, exp3;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_init(exp1);
|
||||
fmpz_init(exp2);
|
||||
fmpz_randtest(exp1, state, 200);
|
||||
if (fmpz_sgn(exp1) == -1) fmpz_neg(exp1, exp1);
|
||||
fmpz_randtest(exp2, state, 200);
|
||||
if (fmpz_sgn(exp2) == -1) fmpz_neg(exp2, exp2);
|
||||
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(finv, p);
|
||||
fmpz_mod_poly_init(res1, p);
|
||||
fmpz_mod_poly_init(res2, p);
|
||||
fmpz_mod_poly_init(res3, p);
|
||||
fmpz_mod_poly_init(res4, p);
|
||||
|
||||
fmpz_mod_poly_randtest_not_zero(f, state, n_randint(state, 50) + 1);
|
||||
|
||||
fmpz_mod_poly_reverse (finv, f, f->length);
|
||||
fmpz_mod_poly_inv_series_newton (finv, finv, f->length);
|
||||
|
||||
fmpz_mod_poly_powmod_x_fmpz_preinv(res1, exp1, f, finv);
|
||||
fmpz_mod_poly_powmod_x_fmpz_preinv(res2, exp2, f, finv);
|
||||
fmpz_mod_poly_mulmod(res4, res1, res2, f);
|
||||
fmpz_init(exp3);
|
||||
fmpz_add(exp3, exp1, exp2);
|
||||
fmpz_mod_poly_powmod_x_fmpz_preinv(res3, exp3, f, finv);
|
||||
|
||||
result = (fmpz_mod_poly_equal(res4, res3));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("f:\n"); fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("res3:\n"); fmpz_mod_poly_print(res3), flint_printf("\n\n");
|
||||
flint_printf("res4:\n"); fmpz_mod_poly_print(res4), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(finv);
|
||||
fmpz_mod_poly_clear(res1);
|
||||
fmpz_mod_poly_clear(res2);
|
||||
fmpz_mod_poly_clear(res3);
|
||||
fmpz_mod_poly_clear(res4);
|
||||
fmpz_clear(exp1);
|
||||
fmpz_clear(exp2);
|
||||
fmpz_clear(exp3);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
265
external/flint-2.4.3/fmpz_mod_poly/test/t-print_read.c
vendored
Normal file
265
external/flint-2.4.3/fmpz_mod_poly/test/t-print_read.c
vendored
Normal file
@@ -0,0 +1,265 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2010 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
|
||||
#if !defined (__WIN32) || defined(__CYGWIN__)
|
||||
|
||||
/*
|
||||
The function fdopen is declared in stdio.h. It is POSIX.1 compliant,
|
||||
but not ANSI compliant. The following line enables compilation with
|
||||
the "-ansi" flag.
|
||||
*/
|
||||
extern FILE * fdopen(int fildes, const char *mode);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i, j, n = 1000, result;
|
||||
|
||||
FILE *in, *out;
|
||||
int fd[2];
|
||||
pid_t childpid;
|
||||
fmpz_t two;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
fmpz_init(two);
|
||||
fmpz_set_ui(two,2);
|
||||
|
||||
flint_printf("print/ read....");
|
||||
fflush(stdout);
|
||||
|
||||
/* Randomise n polynomials, write to and read from a pipe */
|
||||
{
|
||||
fmpz_mod_poly_t *a;
|
||||
|
||||
a = flint_malloc(n * sizeof(fmpz_mod_poly_t));
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
fmpz_mod_poly_init(a[i],two);
|
||||
fmpz_mod_poly_randtest(a[i], state, n_randint(state, 100));
|
||||
}
|
||||
|
||||
if (pipe(fd))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("Failed to set-up the pipe.\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
if((childpid = fork()) == -1)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("Failed to fork the process.\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
if(childpid == 0) /* Child process */
|
||||
{
|
||||
int r;
|
||||
|
||||
close(fd[0]);
|
||||
out = fdopen(fd[1], "w");
|
||||
if (out == NULL)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("Could not open output file at the pipe.\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
for (j = 0; j < n; j++)
|
||||
{
|
||||
r = fmpz_mod_poly_fprint(out, a[j]);
|
||||
if ((j < n - 1) && (r > 0))
|
||||
r = flint_fprintf(out, "\n");
|
||||
|
||||
if (r <= 0)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("Write error.\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
fclose(out);
|
||||
exit(0);
|
||||
}
|
||||
else /* Parent process */
|
||||
{
|
||||
int r;
|
||||
fmpz_mod_poly_t t;
|
||||
|
||||
close(fd[1]);
|
||||
in = fdopen(fd[0], "r");
|
||||
if (in == NULL)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("Could not open input file at the pipe.\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_init(t,two);
|
||||
|
||||
i = 0;
|
||||
while (!feof(in))
|
||||
{
|
||||
r = fmpz_mod_poly_fread(in, t);
|
||||
if (r <= 0)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("Read error.\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
result = fmpz_mod_poly_equal(t, a[i]);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a[i] = "), fmpz_mod_poly_print(a[i]), flint_printf("\n");
|
||||
flint_printf("t = "), fmpz_mod_poly_print(t), flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(t);
|
||||
fclose(in);
|
||||
}
|
||||
|
||||
if (i != n)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("Only %d out of %d objects were processed.\n", i, n);
|
||||
abort();
|
||||
}
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
fmpz_mod_poly_clear(a[i]);
|
||||
flint_free(a);
|
||||
}
|
||||
|
||||
/* Write bad data to a pipe and read it */
|
||||
{
|
||||
if (pipe(fd))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("Failed to set-up the pipe.\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
if((childpid = fork()) == -1)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("Failed to fork the process.\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
if(childpid == 0) /* Child process */
|
||||
{
|
||||
int r;
|
||||
|
||||
close(fd[0]);
|
||||
out = fdopen(fd[1], "w");
|
||||
if (out == NULL)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("Could not open output file at the pipe.\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
r = flint_fprintf(out, "blah");
|
||||
if (r <= 0)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("Write error.\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fclose(out);
|
||||
exit(0);
|
||||
}
|
||||
else /* Parent process */
|
||||
{
|
||||
int r;
|
||||
fmpz_mod_poly_t t;
|
||||
|
||||
close(fd[1]);
|
||||
in = fdopen(fd[0], "r");
|
||||
if (in == NULL)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("Could not open input file at the pipe.\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_init(t,two);
|
||||
|
||||
i = 0;
|
||||
/* Only four junk bytes are sent and our read
|
||||
doesn't consume invalid bytes, so eof is never reached */
|
||||
for(i=0; i<500; i++)
|
||||
{
|
||||
r = fmpz_mod_poly_fread(in, t);
|
||||
if (r > 0)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("r = %d\n", r);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(t);
|
||||
fclose(in);
|
||||
}
|
||||
}
|
||||
|
||||
fmpz_clear(two);
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main(void)
|
||||
{
|
||||
flint_printf("print/ read....");
|
||||
fflush(stdout);
|
||||
flint_printf("SKIPPED\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
#endif
|
||||
148
external/flint-2.4.3/fmpz_mod_poly/test/t-radix.c
vendored
Normal file
148
external/flint-2.4.3/fmpz_mod_poly/test/t-radix.c
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
/*=============================================================================
|
||||
|
||||
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, 2010 Sebastian Pancratz
|
||||
Copyright (C) 2009 William Hart
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
static int _check(fmpz_mod_poly_struct **B,
|
||||
const fmpz_mod_poly_t F, const fmpz_mod_poly_t R)
|
||||
{
|
||||
const slong lenF = F->length;
|
||||
const slong lenR = R->length;
|
||||
const slong N = (lenF - 1) / (lenR - 1);
|
||||
|
||||
slong i;
|
||||
int result;
|
||||
|
||||
fmpz_mod_poly_t S;
|
||||
|
||||
fmpz_mod_poly_init(S, &(R->p));
|
||||
fmpz_mod_poly_set(S, B[N]);
|
||||
for (i = N; i > 0; i--)
|
||||
{
|
||||
fmpz_mod_poly_mul(S, S, R);
|
||||
fmpz_mod_poly_add(S, S, B[i - 1]);
|
||||
}
|
||||
result = fmpz_mod_poly_equal(F, S);
|
||||
fmpz_mod_poly_clear(S);
|
||||
return result;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("radix....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t f, r;
|
||||
fmpz_mod_poly_struct **b;
|
||||
fmpz_mod_poly_radix_t D;
|
||||
slong j, N;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(r, p);
|
||||
fmpz_mod_poly_randtest(f, state, n_randint(state, 500));
|
||||
do
|
||||
fmpz_mod_poly_randtest_not_zero(r, state, n_randint(state, 20) + 2);
|
||||
while (r->length < 2);
|
||||
|
||||
N = FLINT_MAX(0, fmpz_mod_poly_degree(f) / fmpz_mod_poly_degree(r));
|
||||
b = flint_malloc((N + 1) * sizeof(fmpz_mod_poly_struct *));
|
||||
for (j = 0; j <= N; j++)
|
||||
{
|
||||
b[j] = flint_malloc(sizeof(fmpz_mod_poly_struct));
|
||||
fmpz_mod_poly_init(b[j], p);
|
||||
}
|
||||
|
||||
/* Ensure that lead(r) is a unit mod p */
|
||||
{
|
||||
fmpz_t d;
|
||||
fmpz *leadR = fmpz_mod_poly_lead(r);
|
||||
|
||||
fmpz_init(d);
|
||||
fmpz_gcd(d, p, leadR);
|
||||
while (!fmpz_is_one(d))
|
||||
{
|
||||
fmpz_divexact(leadR, leadR, d);
|
||||
fmpz_gcd(d, p, leadR);
|
||||
}
|
||||
fmpz_clear(d);
|
||||
}
|
||||
|
||||
fmpz_mod_poly_radix_init(D, r, f->length - 1 + n_randint(state, 50));
|
||||
|
||||
fmpz_mod_poly_radix(b, f, D);
|
||||
|
||||
result = _check(b, f, r);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("result = %d\n", result);
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("f = "), fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
flint_printf("r = "), fmpz_mod_poly_print(r), flint_printf("\n\n");
|
||||
flint_printf("N = %wd\n\n", N);
|
||||
for (j = 0; j <= N; j++)
|
||||
{
|
||||
flint_printf("b[%wd] = ", j), fmpz_mod_poly_print(b[j]), flint_printf("\n\n");
|
||||
}
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(r);
|
||||
fmpz_mod_poly_radix_clear(D);
|
||||
for (j = 0; j <= N; j++)
|
||||
{
|
||||
fmpz_mod_poly_clear(b[j]);
|
||||
flint_free(b[j]);
|
||||
}
|
||||
flint_free(b);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
206
external/flint-2.4.3/fmpz_mod_poly/test/t-rem_basecase.c
vendored
Normal file
206
external/flint-2.4.3/fmpz_mod_poly/test/t-rem_basecase.c
vendored
Normal file
@@ -0,0 +1,206 @@
|
||||
/*=============================================================================
|
||||
|
||||
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
|
||||
Copyright (C) 2009 William Hart
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("rem_basecase....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
/* Check q*b + r = a, no aliasing */
|
||||
for (i = 0; i < 5000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, q, r, t;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(q, p);
|
||||
fmpz_mod_poly_init(r, p);
|
||||
fmpz_mod_poly_init(t, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest_not_zero(b, state, n_randint(state, 100) + 1);
|
||||
|
||||
{
|
||||
fmpz_t d;
|
||||
fmpz *leadB = fmpz_mod_poly_lead(b);
|
||||
|
||||
fmpz_init(d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
while (!fmpz_is_one(d))
|
||||
{
|
||||
fmpz_divexact(leadB, leadB, d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
}
|
||||
fmpz_clear(d);
|
||||
}
|
||||
|
||||
fmpz_mod_poly_divrem_basecase(q, r, a, b);
|
||||
fmpz_mod_poly_rem_basecase(t, a, b);
|
||||
|
||||
result = (fmpz_mod_poly_equal(r, t));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL (cmp with divrem):\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("q = "), fmpz_mod_poly_print(q), flint_printf("\n\n");
|
||||
flint_printf("r = "), fmpz_mod_poly_print(r), flint_printf("\n\n");
|
||||
flint_printf("t = "), fmpz_mod_poly_print(t), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(q);
|
||||
fmpz_mod_poly_clear(r);
|
||||
fmpz_mod_poly_clear(t);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Alias b and r */
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, r;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(r, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest_not_zero(b, state, n_randint(state, 100) + 1);
|
||||
|
||||
{
|
||||
fmpz_t d;
|
||||
fmpz *leadB = fmpz_mod_poly_lead(b);
|
||||
|
||||
fmpz_init(d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
while (!fmpz_is_one(d))
|
||||
{
|
||||
fmpz_divexact(leadB, leadB, d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
}
|
||||
fmpz_clear(d);
|
||||
}
|
||||
|
||||
fmpz_mod_poly_rem_basecase(r, a, b);
|
||||
fmpz_mod_poly_rem_basecase(b, a, b);
|
||||
|
||||
result = (fmpz_mod_poly_equal(r, b));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("r = "), fmpz_mod_poly_print(r), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(r);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* a and r */
|
||||
for (i = 0; i < 500; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, r;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(r, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest_not_zero(b, state, n_randint(state, 100) + 1);
|
||||
|
||||
{
|
||||
fmpz_t d;
|
||||
fmpz *leadB = fmpz_mod_poly_lead(b);
|
||||
|
||||
fmpz_init(d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
while (!fmpz_is_one(d))
|
||||
{
|
||||
fmpz_divexact(leadB, leadB, d);
|
||||
fmpz_gcd(d, p, leadB);
|
||||
}
|
||||
fmpz_clear(d);
|
||||
}
|
||||
|
||||
fmpz_mod_poly_rem_basecase(r, a, b);
|
||||
fmpz_mod_poly_rem_basecase(a, a, b);
|
||||
|
||||
result = (fmpz_mod_poly_equal(r, a));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
flint_printf("b = "), fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
flint_printf("r = "), fmpz_mod_poly_print(r), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(r);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
86
external/flint-2.4.3/fmpz_mod_poly/test/t-scalar_mul_fmpz.c
vendored
Normal file
86
external/flint-2.4.3/fmpz_mod_poly/test/t-scalar_mul_fmpz.c
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Sebastian Pancratz
|
||||
Copyright (C) 2009 William Hart
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("scalar_mul_fmpz....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
/* Check aliasing of a and b */
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
fmpz_t n, p;
|
||||
fmpz_mod_poly_t a, b;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_init(n);
|
||||
fmpz_randtest(n, state, 200);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
|
||||
fmpz_mod_poly_scalar_mul_fmpz(b, a, n);
|
||||
fmpz_mod_poly_scalar_mul_fmpz(a, a, n);
|
||||
|
||||
result = (fmpz_mod_poly_equal(a, b));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(n);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
120
external/flint-2.4.3/fmpz_mod_poly/test/t-set_equal.c
vendored
Normal file
120
external/flint-2.4.3/fmpz_mod_poly/test/t-set_equal.c
vendored
Normal 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) 2011 Sebastian Pancratz
|
||||
Copyright (C) 2009 William Hart
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("set/equal....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
/* Equal polynomials */
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
|
||||
fmpz_mod_poly_set(b, a);
|
||||
|
||||
result = (fmpz_mod_poly_equal(a, b));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b;
|
||||
slong coeff = n_randint(state, 100);
|
||||
fmpz_t x;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_init(x);
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
|
||||
fmpz_mod_poly_set(b, a);
|
||||
|
||||
fmpz_mod_poly_get_coeff_fmpz(x, b, coeff);
|
||||
fmpz_sub_ui(x, x, 1);
|
||||
fmpz_mod_poly_set_coeff_fmpz(b, coeff, x);
|
||||
|
||||
result = (!fmpz_mod_poly_equal(a, b));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("p = "), fmpz_print(p), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(x);
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
151
external/flint-2.4.3/fmpz_mod_poly/test/t-shift_left_right.c
vendored
Normal file
151
external/flint-2.4.3/fmpz_mod_poly/test/t-shift_left_right.c
vendored
Normal file
@@ -0,0 +1,151 @@
|
||||
/*=============================================================================
|
||||
|
||||
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
|
||||
Copyright (C) 2009 William Hart
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("shift_left/right....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
/* Check aliasing of a and b for left shift */
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b;
|
||||
slong shift = n_randint(state, 100);
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_randtest(a, state, 200);
|
||||
|
||||
fmpz_mod_poly_shift_left(b, a, shift);
|
||||
fmpz_mod_poly_shift_left(a, a, shift);
|
||||
|
||||
result = (fmpz_mod_poly_equal(a, b));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Check aliasing of a and b for right shift */
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b;
|
||||
slong shift;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_randtest_not_zero(a, state, 200);
|
||||
|
||||
shift = n_randint(state, a->length);
|
||||
|
||||
fmpz_mod_poly_shift_right(b, a, shift);
|
||||
fmpz_mod_poly_shift_right(a, a, shift);
|
||||
|
||||
result = (fmpz_mod_poly_equal(a, b));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Check shift left then right does nothing */
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, c;
|
||||
slong shift = n_randint(state, 100);
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_randtest(a, state, 200);
|
||||
|
||||
fmpz_mod_poly_shift_left(b, a, shift);
|
||||
fmpz_mod_poly_shift_right(c, b, shift);
|
||||
|
||||
result = (fmpz_mod_poly_equal(c, a));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
160
external/flint-2.4.3/fmpz_mod_poly/test/t-sub.c
vendored
Normal file
160
external/flint-2.4.3/fmpz_mod_poly/test/t-sub.c
vendored
Normal 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) 2011 Sebastian Pancratz
|
||||
Copyright (C) 2009 William Hart
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_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 < 10000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, c, d;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 100));
|
||||
|
||||
fmpz_mod_poly_sub(c, a, b);
|
||||
fmpz_mod_poly_neg(b, b);
|
||||
fmpz_mod_poly_add(d, a, b);
|
||||
|
||||
result = (fmpz_mod_poly_equal(d, d));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(d), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_mod_poly_clear(d);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Check aliasing of a and c */
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, c;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 100));
|
||||
|
||||
fmpz_mod_poly_sub(c, a, b);
|
||||
fmpz_mod_poly_sub(a, a, b);
|
||||
|
||||
result = (fmpz_mod_poly_equal(a, c));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Check aliasing of b and c */
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, c;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 100));
|
||||
|
||||
fmpz_mod_poly_sub(c, a, b);
|
||||
fmpz_mod_poly_sub(b, a, b);
|
||||
|
||||
result = (fmpz_mod_poly_equal(b, c));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
84
external/flint-2.4.3/fmpz_mod_poly/test/t-swap.c
vendored
Normal file
84
external/flint-2.4.3/fmpz_mod_poly/test/t-swap.c
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Sebastian Pancratz
|
||||
Copyright (C) 2009 William Hart
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("swap....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, c;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(c, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 100));
|
||||
|
||||
fmpz_mod_poly_set(c, b);
|
||||
fmpz_mod_poly_swap(a, b);
|
||||
|
||||
result = (fmpz_mod_poly_equal(a, c));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(c), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(c);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
166
external/flint-2.4.3/fmpz_mod_poly/test/t-xgcd.c
vendored
Normal file
166
external/flint-2.4.3/fmpz_mod_poly/test/t-xgcd.c
vendored
Normal 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) 2012 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("xgcd....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
/* Generic case, most likely co-prime arguments ******************************/
|
||||
|
||||
/* Compare with result from GCD and check correctness */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, d, g, s, t, v, w;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
fmpz_mod_poly_init(g, p);
|
||||
fmpz_mod_poly_init(s, p);
|
||||
fmpz_mod_poly_init(t, p);
|
||||
fmpz_mod_poly_init(v, p);
|
||||
fmpz_mod_poly_init(w, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 100));
|
||||
|
||||
fmpz_mod_poly_gcd(d, a, b);
|
||||
fmpz_mod_poly_xgcd(g, s, t, a, b);
|
||||
|
||||
fmpz_mod_poly_mul(v, s, a);
|
||||
fmpz_mod_poly_mul(w, t, b);
|
||||
fmpz_mod_poly_add(w, v, w);
|
||||
|
||||
result = (fmpz_mod_poly_equal(d, g) && fmpz_mod_poly_equal(g, w));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(d), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(g), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(s), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(t), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(v), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(w), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(d);
|
||||
fmpz_mod_poly_clear(g);
|
||||
fmpz_mod_poly_clear(s);
|
||||
fmpz_mod_poly_clear(t);
|
||||
fmpz_mod_poly_clear(v);
|
||||
fmpz_mod_poly_clear(w);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Special case, arguments share a factor ********************************/
|
||||
|
||||
/* Compare with result from GCD and check correctness */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, d, f, g, s, t, v, w;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(g, p);
|
||||
fmpz_mod_poly_init(s, p);
|
||||
fmpz_mod_poly_init(t, p);
|
||||
fmpz_mod_poly_init(v, p);
|
||||
fmpz_mod_poly_init(w, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest(f, state, n_randint(state, 20));
|
||||
fmpz_mod_poly_mul(a, a, f);
|
||||
fmpz_mod_poly_mul(b, b, f);
|
||||
|
||||
fmpz_mod_poly_gcd(d, a, b);
|
||||
fmpz_mod_poly_xgcd(g, s, t, a, b);
|
||||
|
||||
fmpz_mod_poly_mul(v, s, a);
|
||||
fmpz_mod_poly_mul(w, t, b);
|
||||
fmpz_mod_poly_add(w, v, w);
|
||||
|
||||
result = (fmpz_mod_poly_equal(d, g) && fmpz_mod_poly_equal(g, w));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(d), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(g), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(s), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(t), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(v), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(w), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(d);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(g);
|
||||
fmpz_mod_poly_clear(s);
|
||||
fmpz_mod_poly_clear(t);
|
||||
fmpz_mod_poly_clear(v);
|
||||
fmpz_mod_poly_clear(w);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
166
external/flint-2.4.3/fmpz_mod_poly/test/t-xgcd_euclidean.c
vendored
Normal file
166
external/flint-2.4.3/fmpz_mod_poly/test/t-xgcd_euclidean.c
vendored
Normal 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) 2012 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("xgcd_euclidean....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
/* Generic case, most likely co-prime arguments ******************************/
|
||||
|
||||
/* Compare with result from GCD and check correctness */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, d, g, s, t, v, w;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
fmpz_mod_poly_init(g, p);
|
||||
fmpz_mod_poly_init(s, p);
|
||||
fmpz_mod_poly_init(t, p);
|
||||
fmpz_mod_poly_init(v, p);
|
||||
fmpz_mod_poly_init(w, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 100));
|
||||
|
||||
fmpz_mod_poly_gcd_euclidean(d, a, b);
|
||||
fmpz_mod_poly_xgcd_euclidean(g, s, t, a, b);
|
||||
|
||||
fmpz_mod_poly_mul(v, s, a);
|
||||
fmpz_mod_poly_mul(w, t, b);
|
||||
fmpz_mod_poly_add(w, v, w);
|
||||
|
||||
result = (fmpz_mod_poly_equal(d, g) && fmpz_mod_poly_equal(g, w));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(d), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(g), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(s), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(t), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(v), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(w), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(d);
|
||||
fmpz_mod_poly_clear(g);
|
||||
fmpz_mod_poly_clear(s);
|
||||
fmpz_mod_poly_clear(t);
|
||||
fmpz_mod_poly_clear(v);
|
||||
fmpz_mod_poly_clear(w);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
/* Special case, arguments share a factor ********************************/
|
||||
|
||||
/* Compare with result from GCD and check correctness */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a, b, d, f, g, s, t, v, w;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, n_randtest_prime(state, 0));
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_init(b, p);
|
||||
fmpz_mod_poly_init(d, p);
|
||||
fmpz_mod_poly_init(f, p);
|
||||
fmpz_mod_poly_init(g, p);
|
||||
fmpz_mod_poly_init(s, p);
|
||||
fmpz_mod_poly_init(t, p);
|
||||
fmpz_mod_poly_init(v, p);
|
||||
fmpz_mod_poly_init(w, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest(b, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_randtest(f, state, n_randint(state, 20));
|
||||
fmpz_mod_poly_mul(a, a, f);
|
||||
fmpz_mod_poly_mul(b, b, f);
|
||||
|
||||
fmpz_mod_poly_gcd_euclidean(d, a, b);
|
||||
fmpz_mod_poly_xgcd_euclidean(g, s, t, a, b);
|
||||
|
||||
fmpz_mod_poly_mul(v, s, a);
|
||||
fmpz_mod_poly_mul(w, t, b);
|
||||
fmpz_mod_poly_add(w, v, w);
|
||||
|
||||
result = (fmpz_mod_poly_equal(d, g) && fmpz_mod_poly_equal(g, w));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(b), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(d), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(f), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(g), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(s), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(t), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(v), flint_printf("\n\n");
|
||||
fmpz_mod_poly_print(w), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_mod_poly_clear(b);
|
||||
fmpz_mod_poly_clear(d);
|
||||
fmpz_mod_poly_clear(f);
|
||||
fmpz_mod_poly_clear(g);
|
||||
fmpz_mod_poly_clear(s);
|
||||
fmpz_mod_poly_clear(t);
|
||||
fmpz_mod_poly_clear(v);
|
||||
fmpz_mod_poly_clear(w);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
75
external/flint-2.4.3/fmpz_mod_poly/test/t-zero.c
vendored
Normal file
75
external/flint-2.4.3/fmpz_mod_poly/test/t-zero.c
vendored
Normal 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, 2011 Sebastian Pancratz
|
||||
Copyright (C) 2009 William Hart
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int i, result;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("zero....");
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz_mod_poly_t a;
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_randtest_unsigned(p, state, 2 * FLINT_BITS);
|
||||
fmpz_add_ui(p, p, 2);
|
||||
|
||||
fmpz_mod_poly_init(a, p);
|
||||
fmpz_mod_poly_randtest(a, state, n_randint(state, 100));
|
||||
fmpz_mod_poly_zero(a);
|
||||
|
||||
result = (fmpz_mod_poly_is_zero(a));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("a = "), fmpz_mod_poly_print(a), flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_mod_poly_clear(a);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user