ALL: Add flint

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

View File

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

View File

@@ -0,0 +1,128 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("asin_series....");
fflush(stdout);
/* Check aliasing of a and c */
for (i = 0; i < 20 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
slong n = n_randint(state, 50) + 1;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest_not_zero(a, state, n_randint(state, 50) + 1, 50);
fmpq_poly_set_coeff_ui(a, 0, UWORD(0));
fmpq_poly_canonicalise(a);
fmpq_poly_asin_series(b, a, n);
fmpq_poly_asin_series(a, a, n);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check asin(A) = atan(A/sqrt(1-A^2)) */
for (i = 0; i < 20 * flint_test_multiplier(); i++)
{
fmpq_poly_t A, B, asinA, atanB;
slong n = n_randint(state, 80) + 1;
fmpq_poly_init(A);
fmpq_poly_init(B);
fmpq_poly_init(asinA);
fmpq_poly_init(atanB);
fmpq_poly_randtest_not_zero(A, state, n_randint(state, 80) + 1, 80);
fmpq_poly_set_coeff_ui(A, 0, UWORD(0));
fmpq_poly_mullow(B, A, A, n);
fmpq_poly_neg(B, B);
fmpq_poly_set_coeff_ui(B, 0, UWORD(1));
fmpq_poly_invsqrt_series(B, B, n);
fmpq_poly_mullow(B, A, B, n);
fmpq_poly_asin_series(asinA, A, n);
fmpq_poly_atan_series(atanB, B, n);
cflags |= fmpq_poly_is_canonical(asinA) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(atanB) ? 0 : 2;
result = (fmpq_poly_equal(asinA, atanB) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("A = "), fmpq_poly_debug(A), flint_printf("\n\n");
flint_printf("B = "), fmpq_poly_debug(B), flint_printf("\n\n");
flint_printf("asin(A) = "), fmpq_poly_debug(asinA), flint_printf("\n\n");
flint_printf("atan(B) = "), fmpq_poly_debug(atanB), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(A);
fmpq_poly_clear(B);
fmpq_poly_clear(asinA);
fmpq_poly_clear(atanB);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,127 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("asinh_series....");
fflush(stdout);
/* Check aliasing of a and c */
for (i = 0; i < 20 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
slong n = n_randint(state, 50) + 1;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest_not_zero(a, state, n_randint(state, 50) + 1, 50);
fmpq_poly_set_coeff_ui(a, 0, UWORD(0));
fmpq_poly_canonicalise(a);
fmpq_poly_asinh_series(b, a, n);
fmpq_poly_asinh_series(a, a, n);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check asinh(A) = atanh(A/sqrt(1+A^2)) */
for (i = 0; i < 20 * flint_test_multiplier(); i++)
{
fmpq_poly_t A, B, asinhA, atanhB;
slong n = n_randint(state, 80) + 1;
fmpq_poly_init(A);
fmpq_poly_init(B);
fmpq_poly_init(asinhA);
fmpq_poly_init(atanhB);
fmpq_poly_randtest_not_zero(A, state, n_randint(state, 80) + 1, 80);
fmpq_poly_set_coeff_ui(A, 0, UWORD(0));
fmpq_poly_mullow(B, A, A, n);
fmpq_poly_set_coeff_ui(B, 0, UWORD(1));
fmpq_poly_invsqrt_series(B, B, n);
fmpq_poly_mullow(B, A, B, n);
fmpq_poly_asinh_series(asinhA, A, n);
fmpq_poly_atanh_series(atanhB, B, n);
cflags |= fmpq_poly_is_canonical(asinhA) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(atanhB) ? 0 : 2;
result = (fmpq_poly_equal(asinhA, atanhB) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("A = "), fmpq_poly_debug(A), flint_printf("\n\n");
flint_printf("B = "), fmpq_poly_debug(B), flint_printf("\n\n");
flint_printf("asinh(A) = "), fmpq_poly_debug(asinhA), flint_printf("\n\n");
flint_printf("atanh(B) = "), fmpq_poly_debug(atanhB), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(A);
fmpq_poly_clear(B);
fmpq_poly_clear(asinhA);
fmpq_poly_clear(atanhB);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,132 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("atan_series....");
fflush(stdout);
/* Check aliasing of a and c */
for (i = 0; i < 20 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
slong n = n_randint(state, 50) + 1;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest_not_zero(a, state, n_randint(state, 50) + 1, 50);
fmpq_poly_set_coeff_ui(a, 0, UWORD(0));
fmpq_poly_canonicalise(a);
fmpq_poly_atan_series(b, a, n);
fmpq_poly_atan_series(a, a, n);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check 2*atan(A) = atan(2*A/(1-A^2)) */
for (i = 0; i < 40 * flint_test_multiplier(); i++)
{
fmpq_poly_t A, B, atanA, atanB;
slong n = n_randint(state, 80) + 1;
fmpq_poly_init(A);
fmpq_poly_init(B);
fmpq_poly_init(atanA);
fmpq_poly_init(atanB);
fmpq_poly_randtest_not_zero(A, state, n_randint(state, 80) + 1, 80);
fmpq_poly_set_coeff_ui(A, 0, UWORD(0));
fmpq_poly_randtest_not_zero(B, state, n_randint(state, 80) + 1, 80);
fmpq_poly_set_coeff_ui(B, 0, UWORD(0));
fmpq_poly_mullow(B, A, A, n);
fmpq_poly_neg(B, B);
fmpq_poly_set_coeff_ui(B, 0, UWORD(1));
fmpq_poly_div_series(B, A, B, n);
fmpq_poly_add(B, B, B);
fmpq_poly_atan_series(atanA, A, n);
fmpq_poly_atan_series(atanB, B, n);
fmpq_poly_add(atanA, atanA, atanA);
cflags |= fmpq_poly_is_canonical(atanA) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(atanB) ? 0 : 2;
result = (fmpq_poly_equal(atanA, atanB) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("A = "), fmpq_poly_debug(A), flint_printf("\n\n");
flint_printf("B = "), fmpq_poly_debug(B), flint_printf("\n\n");
flint_printf("2*atan(A) = "), fmpq_poly_debug(atanA), flint_printf("\n\n");
flint_printf("atan(B) = "), fmpq_poly_debug(atanB), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(A);
fmpq_poly_clear(B);
fmpq_poly_clear(atanA);
fmpq_poly_clear(atanB);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,131 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("atanh_series....");
fflush(stdout);
/* Check aliasing of a and c */
for (i = 0; i < 20 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
slong n = n_randint(state, 50) + 1;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest_not_zero(a, state, n_randint(state, 50) + 1, 50);
fmpq_poly_set_coeff_ui(a, 0, UWORD(0));
fmpq_poly_canonicalise(a);
fmpq_poly_atanh_series(b, a, n);
fmpq_poly_atanh_series(a, a, n);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check 2*atanh(A) = atanh(2*A/(1+A^2)) */
for (i = 0; i < 20 * flint_test_multiplier(); i++)
{
fmpq_poly_t A, B, atanhA, atanhB;
slong n = n_randint(state, 80) + 1;
fmpq_poly_init(A);
fmpq_poly_init(B);
fmpq_poly_init(atanhA);
fmpq_poly_init(atanhB);
fmpq_poly_randtest_not_zero(A, state, n_randint(state, 80) + 1, 80);
fmpq_poly_set_coeff_ui(A, 0, UWORD(0));
fmpq_poly_randtest_not_zero(B, state, n_randint(state, 80) + 1, 80);
fmpq_poly_set_coeff_ui(B, 0, UWORD(0));
fmpq_poly_mullow(B, A, A, n);
fmpq_poly_set_coeff_ui(B, 0, UWORD(1));
fmpq_poly_div_series(B, A, B, n);
fmpq_poly_add(B, B, B);
fmpq_poly_atanh_series(atanhA, A, n);
fmpq_poly_atanh_series(atanhB, B, n);
fmpq_poly_add(atanhA, atanhA, atanhA);
cflags |= fmpq_poly_is_canonical(atanhA) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(atanhB) ? 0 : 2;
result = (fmpq_poly_equal(atanhA, atanhB) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("A = "), fmpq_poly_debug(A), flint_printf("\n\n");
flint_printf("B = "), fmpq_poly_debug(B), flint_printf("\n\n");
flint_printf("2*atanh(A) = "), fmpq_poly_debug(atanhA), flint_printf("\n\n");
flint_printf("atanh(B) = "), fmpq_poly_debug(atanhB), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(A);
fmpq_poly_clear(B);
fmpq_poly_clear(atanhA);
fmpq_poly_clear(atanhB);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

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

View 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) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("compose....");
fflush(stdout);
/* Check aliasing of the first argument */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
fmpq_poly_t f, g, h;
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_init(h);
fmpq_poly_randtest(g, state, n_randint(state, 50), 100);
fmpq_poly_randtest(h, state, n_randint(state, 20), 50);
fmpq_poly_compose(f, g, h);
fmpq_poly_compose(g, g, h);
cflags |= fmpq_poly_is_canonical(f) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(g) ? 0 : 2;
result = (fmpq_poly_equal(f, g) && !cflags);
if (!result)
{
flint_printf("FAIL (aliasing 1):\n");
fmpq_poly_debug(f), flint_printf("\n\n");
fmpq_poly_debug(g), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(f);
fmpq_poly_clear(g);
fmpq_poly_clear(h);
}
/* Check aliasing of the second argument */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
fmpq_poly_t f, g, h;
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_init(h);
fmpq_poly_randtest(g, state, n_randint(state, 50), 100);
fmpq_poly_randtest(h, state, n_randint(state, 20), 50);
fmpq_poly_compose(f, g, h);
fmpq_poly_compose(h, g, h);
cflags |= fmpq_poly_is_canonical(f) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(h) ? 0 : 2;
result = (fmpq_poly_equal(f, h) && !cflags);
if (!result)
{
flint_printf("FAIL (aliasing 2):\n");
fmpq_poly_debug(f), flint_printf("\n\n");
fmpq_poly_debug(h), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(f);
fmpq_poly_clear(g);
fmpq_poly_clear(h);
}
/* Compare with the naive method for g(h(t)) */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
fmpq_poly_t f, g, h, s, t, u;
mpq_t c;
slong k;
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_init(h);
fmpq_poly_init(s);
fmpq_poly_init(t);
fmpq_poly_init(u);
mpq_init(c);
fmpq_poly_randtest(g, state, n_randint(state, 20), 65);
fmpq_poly_randtest(h, state, n_randint(state, 20), 65);
fmpq_poly_zero(s);
fmpq_poly_set_ui(t, UWORD(1));
for (k = WORD(0); k < g->length; k++)
{
fmpq_poly_get_coeff_mpq(c, g, k);
fmpq_poly_scalar_mul_mpq(u, t, c);
fmpq_poly_add(s, s, u);
fmpq_poly_mul(t, t, h);
}
fmpq_poly_compose(f, g, h);
result = (fmpq_poly_equal(f, s));
if (!result)
{
flint_printf("FAIL (compare with naive):\n");
flint_printf("g = "), fmpq_poly_debug(g), flint_printf("\n\n");
flint_printf("h = "), fmpq_poly_debug(h), flint_printf("\n\n");
flint_printf("f = "), fmpq_poly_debug(f), flint_printf("\n\n");
flint_printf("s = "), fmpq_poly_debug(s), flint_printf("\n\n");
abort();
}
fmpq_poly_clear(f);
fmpq_poly_clear(g);
fmpq_poly_clear(h);
fmpq_poly_clear(s);
fmpq_poly_clear(t);
fmpq_poly_clear(u);
mpq_clear(c);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,152 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("compose_series....");
fflush(stdout);
/* Check aliasing of the first argument */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
fmpq_poly_t f, g, h;
slong n;
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_init(h);
fmpq_poly_randtest(g, state, n_randint(state, 40), 80);
fmpq_poly_randtest(h, state, n_randint(state, 20), 50);
fmpq_poly_set_coeff_ui(h, 0, 0);
n = n_randint(state, 20);
fmpq_poly_compose_series(f, g, h, n);
fmpq_poly_compose_series(g, g, h, n);
result = (fmpq_poly_equal(f, g));
if (!result)
{
flint_printf("FAIL (aliasing 1):\n");
fmpq_poly_print(f), flint_printf("\n\n");
fmpq_poly_print(g), flint_printf("\n\n");
abort();
}
fmpq_poly_clear(f);
fmpq_poly_clear(g);
fmpq_poly_clear(h);
}
/* Check aliasing of the second argument */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
fmpq_poly_t f, g, h;
slong n;
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_init(h);
fmpq_poly_randtest(g, state, n_randint(state, 40), 80);
fmpq_poly_randtest(h, state, n_randint(state, 20), 50);
fmpq_poly_set_coeff_ui(h, 0, 0);
n = n_randint(state, 20);
fmpq_poly_compose_series(f, g, h, n);
fmpq_poly_compose_series(h, g, h, n);
result = (fmpq_poly_equal(f, h));
if (!result)
{
flint_printf("FAIL (aliasing 2):\n");
fmpq_poly_print(f), flint_printf("\n\n");
fmpq_poly_print(h), flint_printf("\n\n");
abort();
}
fmpq_poly_clear(f);
fmpq_poly_clear(g);
fmpq_poly_clear(h);
}
/* Compare with compose */
for (i = 0; i < 20 * flint_test_multiplier(); i++)
{
fmpq_poly_t f, g, h, s, t;
slong n;
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_init(h);
fmpq_poly_init(s);
fmpq_poly_init(t);
fmpq_poly_randtest(g, state, n_randint(state, 40), 80);
fmpq_poly_randtest(h, state, n_randint(state, 20), 50);
fmpq_poly_set_coeff_ui(h, 0, 0);
n = n_randint(state, 20);
fmpq_poly_compose(s, g, h);
fmpq_poly_truncate(s, n);
fmpq_poly_compose_series(f, g, h, n);
result = (fmpq_poly_equal(f, s));
if (!result)
{
flint_printf("FAIL (comparison):\n");
flint_printf("n = %wd\n", n);
flint_printf("g = "), fmpq_poly_print(g), flint_printf("\n\n");
flint_printf("h = "), fmpq_poly_print(h), flint_printf("\n\n");
flint_printf("f = "), fmpq_poly_print(f), flint_printf("\n\n");
flint_printf("s = "), fmpq_poly_print(s), flint_printf("\n\n");
abort();
}
fmpq_poly_clear(f);
fmpq_poly_clear(g);
fmpq_poly_clear(h);
fmpq_poly_clear(s);
fmpq_poly_clear(t);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,152 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("compose_series_brent_kung....");
fflush(stdout);
/* Check aliasing of the first argument */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
fmpq_poly_t f, g, h;
slong n;
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_init(h);
fmpq_poly_randtest(g, state, n_randint(state, 40), 80);
fmpq_poly_randtest(h, state, n_randint(state, 20), 50);
fmpq_poly_set_coeff_ui(h, 0, 0);
n = n_randint(state, 20);
fmpq_poly_compose_series_brent_kung(f, g, h, n);
fmpq_poly_compose_series_brent_kung(g, g, h, n);
result = (fmpq_poly_equal(f, g));
if (!result)
{
flint_printf("FAIL (aliasing 1):\n");
fmpq_poly_print(f), flint_printf("\n\n");
fmpq_poly_print(g), flint_printf("\n\n");
abort();
}
fmpq_poly_clear(f);
fmpq_poly_clear(g);
fmpq_poly_clear(h);
}
/* Check aliasing of the second argument */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
fmpq_poly_t f, g, h;
slong n;
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_init(h);
fmpq_poly_randtest(g, state, n_randint(state, 40), 80);
fmpq_poly_randtest(h, state, n_randint(state, 20), 50);
fmpq_poly_set_coeff_ui(h, 0, 0);
n = n_randint(state, 20);
fmpq_poly_compose_series_brent_kung(f, g, h, n);
fmpq_poly_compose_series_brent_kung(h, g, h, n);
result = (fmpq_poly_equal(f, h));
if (!result)
{
flint_printf("FAIL (aliasing 2):\n");
fmpq_poly_print(f), flint_printf("\n\n");
fmpq_poly_print(h), flint_printf("\n\n");
abort();
}
fmpq_poly_clear(f);
fmpq_poly_clear(g);
fmpq_poly_clear(h);
}
/* Compare with compose */
for (i = 0; i < 20 * flint_test_multiplier(); i++)
{
fmpq_poly_t f, g, h, s, t;
slong n;
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_init(h);
fmpq_poly_init(s);
fmpq_poly_init(t);
fmpq_poly_randtest(g, state, n_randint(state, 40), 80);
fmpq_poly_randtest(h, state, n_randint(state, 20), 50);
fmpq_poly_set_coeff_ui(h, 0, 0);
n = n_randint(state, 20);
fmpq_poly_compose(s, g, h);
fmpq_poly_truncate(s, n);
fmpq_poly_compose_series_brent_kung(f, g, h, n);
result = (fmpq_poly_equal(f, s));
if (!result)
{
flint_printf("FAIL (comparison):\n");
flint_printf("n = %wd\n", n);
flint_printf("g = "), fmpq_poly_print(g), flint_printf("\n\n");
flint_printf("h = "), fmpq_poly_print(h), flint_printf("\n\n");
flint_printf("f = "), fmpq_poly_print(f), flint_printf("\n\n");
flint_printf("s = "), fmpq_poly_print(s), flint_printf("\n\n");
abort();
}
fmpq_poly_clear(f);
fmpq_poly_clear(g);
fmpq_poly_clear(h);
fmpq_poly_clear(s);
fmpq_poly_clear(t);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,152 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("compose_series_horner....");
fflush(stdout);
/* Check aliasing of the first argument */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
fmpq_poly_t f, g, h;
slong n;
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_init(h);
fmpq_poly_randtest(g, state, n_randint(state, 40), 80);
fmpq_poly_randtest(h, state, n_randint(state, 20), 50);
fmpq_poly_set_coeff_ui(h, 0, 0);
n = n_randint(state, 20);
fmpq_poly_compose_series_horner(f, g, h, n);
fmpq_poly_compose_series_horner(g, g, h, n);
result = (fmpq_poly_equal(f, g));
if (!result)
{
flint_printf("FAIL (aliasing 1):\n");
fmpq_poly_print(f), flint_printf("\n\n");
fmpq_poly_print(g), flint_printf("\n\n");
abort();
}
fmpq_poly_clear(f);
fmpq_poly_clear(g);
fmpq_poly_clear(h);
}
/* Check aliasing of the second argument */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
fmpq_poly_t f, g, h;
slong n;
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_init(h);
fmpq_poly_randtest(g, state, n_randint(state, 40), 80);
fmpq_poly_randtest(h, state, n_randint(state, 20), 50);
fmpq_poly_set_coeff_ui(h, 0, 0);
n = n_randint(state, 20);
fmpq_poly_compose_series_horner(f, g, h, n);
fmpq_poly_compose_series_horner(h, g, h, n);
result = (fmpq_poly_equal(f, h));
if (!result)
{
flint_printf("FAIL (aliasing 2):\n");
fmpq_poly_print(f), flint_printf("\n\n");
fmpq_poly_print(h), flint_printf("\n\n");
abort();
}
fmpq_poly_clear(f);
fmpq_poly_clear(g);
fmpq_poly_clear(h);
}
/* Compare with compose */
for (i = 0; i < 20 * flint_test_multiplier(); i++)
{
fmpq_poly_t f, g, h, s, t;
slong n;
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_init(h);
fmpq_poly_init(s);
fmpq_poly_init(t);
fmpq_poly_randtest(g, state, n_randint(state, 40), 80);
fmpq_poly_randtest(h, state, n_randint(state, 20), 50);
fmpq_poly_set_coeff_ui(h, 0, 0);
n = n_randint(state, 20);
fmpq_poly_compose(s, g, h);
fmpq_poly_truncate(s, n);
fmpq_poly_compose_series_horner(f, g, h, n);
result = (fmpq_poly_equal(f, s));
if (!result)
{
flint_printf("FAIL (comparison):\n");
flint_printf("n = %wd\n", n);
flint_printf("g = "), fmpq_poly_print(g), flint_printf("\n\n");
flint_printf("h = "), fmpq_poly_print(h), flint_printf("\n\n");
flint_printf("f = "), fmpq_poly_print(f), flint_printf("\n\n");
flint_printf("s = "), fmpq_poly_print(s), flint_printf("\n\n");
abort();
}
fmpq_poly_clear(f);
fmpq_poly_clear(g);
fmpq_poly_clear(h);
fmpq_poly_clear(s);
fmpq_poly_clear(t);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

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

View File

@@ -0,0 +1,129 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("cos_series....");
fflush(stdout);
/* Check aliasing of a and c */
for (i = 0; i < 20 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
slong n = n_randint(state, 50) + 1;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest_not_zero(a, state, n_randint(state, 50) + 1, 50);
fmpq_poly_set_coeff_ui(a, 0, UWORD(0));
fmpq_poly_canonicalise(a);
fmpq_poly_cos_series(b, a, n);
fmpq_poly_cos_series(a, a, n);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check 1-cos(A)^2 = sin(A)^2 */
for (i = 0; i < 20 * flint_test_multiplier(); i++)
{
fmpq_poly_t A, cosA, sinA, B, C, one;
slong n = n_randint(state, 80) + 1;
fmpq_poly_init(A);
fmpq_poly_init(cosA);
fmpq_poly_init(sinA);
fmpq_poly_init(B);
fmpq_poly_init(C);
fmpq_poly_init(one);
fmpq_poly_randtest_not_zero(A, state, n_randint(state, 60) + 1, 80);
fmpq_poly_set_coeff_ui(A, 0, UWORD(0));
fmpq_poly_cos_series(cosA, A, n);
fmpq_poly_sin_series(sinA, A, n);
fmpq_poly_mullow(B, cosA, cosA, n);
fmpq_poly_set_coeff_ui(one, 0, UWORD(1));
fmpq_poly_sub(B, one, B);
fmpq_poly_mullow(C, sinA, sinA, n);
cflags |= fmpq_poly_is_canonical(cosA) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(sinA) ? 0 : 2;
result = (fmpq_poly_equal(B, C) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("A = "), fmpq_poly_debug(A), flint_printf("\n\n");
flint_printf("cos(A) = "), fmpq_poly_debug(cosA), flint_printf("\n\n");
flint_printf("sin(A) = "), fmpq_poly_debug(sinA), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(A);
fmpq_poly_clear(cosA);
fmpq_poly_clear(sinA);
fmpq_poly_clear(B);
fmpq_poly_clear(C);
fmpq_poly_clear(one);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,129 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("cosh_series....");
fflush(stdout);
/* Check aliasing of a and c */
for (i = 0; i < 20 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
slong n = n_randint(state, 50) + 1;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest_not_zero(a, state, n_randint(state, 50) + 1, 50);
fmpq_poly_set_coeff_ui(a, 0, UWORD(0));
fmpq_poly_canonicalise(a);
fmpq_poly_cosh_series(b, a, n);
fmpq_poly_cosh_series(a, a, n);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check cosh(A)^2-1 = sinh(A)^2 */
for (i = 0; i < 20 * flint_test_multiplier(); i++)
{
fmpq_poly_t A, coshA, sinhA, B, C, one;
slong n = n_randint(state, 80) + 1;
fmpq_poly_init(A);
fmpq_poly_init(coshA);
fmpq_poly_init(sinhA);
fmpq_poly_init(B);
fmpq_poly_init(C);
fmpq_poly_init(one);
fmpq_poly_randtest_not_zero(A, state, n_randint(state, 60) + 1, 80);
fmpq_poly_set_coeff_ui(A, 0, UWORD(0));
fmpq_poly_cosh_series(coshA, A, n);
fmpq_poly_sinh_series(sinhA, A, n);
fmpq_poly_mullow(B, coshA, coshA, n);
fmpq_poly_set_coeff_ui(one, 0, UWORD(1));
fmpq_poly_sub(B, B, one);
fmpq_poly_mullow(C, sinhA, sinhA, n);
cflags |= fmpq_poly_is_canonical(coshA) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(sinhA) ? 0 : 2;
result = (fmpq_poly_equal(B, C) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("A = "), fmpq_poly_debug(A), flint_printf("\n\n");
flint_printf("cosh(A) = "), fmpq_poly_debug(coshA), flint_printf("\n\n");
flint_printf("sinh(A) = "), fmpq_poly_debug(sinhA), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(A);
fmpq_poly_clear(coshA);
fmpq_poly_clear(sinhA);
fmpq_poly_clear(B);
fmpq_poly_clear(C);
fmpq_poly_clear(one);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,146 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("derivative....");
fflush(stdout);
/* Check aliasing */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_derivative(b, a);
fmpq_poly_derivative(a, a);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check constants have derivative zero */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest(a, state, n_randint(state, 2), 200);
fmpq_poly_derivative(b, a);
cflags |= fmpq_poly_is_canonical(b) ? 0 : 1;
result = fmpq_poly_is_zero(b) && !cflags;
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check (f g)' = f' g + f g' */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c, d, lhs, rhs;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_init(d);
fmpq_poly_init(lhs);
fmpq_poly_init(rhs);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_randtest(b, state, n_randint(state, 100), 200);
fmpq_poly_mul(lhs, a, b);
fmpq_poly_derivative(lhs, lhs);
fmpq_poly_derivative(c, a);
fmpq_poly_derivative(d, b);
fmpq_poly_mul(c, c, b);
fmpq_poly_mul(d, a, d);
fmpq_poly_add(rhs, c, d);
cflags |= fmpq_poly_is_canonical(lhs) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(rhs) ? 0 : 2;
result = fmpq_poly_equal(lhs, rhs) && !cflags;
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
fmpq_poly_clear(d);
fmpq_poly_clear(lhs);
fmpq_poly_clear(rhs);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,152 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("div....");
fflush(stdout);
/* Check aliasing of q and a */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, q;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(q);
fmpq_poly_randtest(a, state, n_randint(state, 50), 200);
fmpq_poly_randtest_not_zero(b, state, n_randint(state, 50) + 1, 200);
fmpq_poly_div(q, a, b);
fmpq_poly_div(a, a, b);
cflags |= fmpq_poly_is_canonical(q) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(a) ? 0 : 2;
result = (fmpq_poly_equal(q, a) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("q = "), fmpq_poly_debug(q), flint_printf("\n\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("b = "), fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(q);
}
/* Check aliasing of q and b */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, q;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(q);
fmpq_poly_randtest(a, state, n_randint(state, 50), 200);
fmpq_poly_randtest_not_zero(b, state, n_randint(state, 50) + 1, 200);
fmpq_poly_div(q, a, b);
fmpq_poly_div(b, a, b);
cflags |= fmpq_poly_is_canonical(q) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(q, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("q = "), fmpq_poly_debug(q), flint_printf("\n\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("b = "), fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(q);
}
/* Compare with divrem */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, q, q2, r;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(q);
fmpq_poly_init(q2);
fmpq_poly_init(r);
fmpq_poly_randtest(a, state, n_randint(state, 50), 200);
fmpq_poly_randtest_not_zero(b, state, n_randint(state, 50) + 1, 200);
fmpq_poly_divrem(q, r, a, b);
fmpq_poly_div(q2, a, b);
cflags |= fmpq_poly_is_canonical(q) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(q2) ? 0 : 2;
result = (fmpq_poly_equal(q, q2) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("b = "), fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("q = "), fmpq_poly_debug(q), flint_printf("\n\n");
flint_printf("r = "), fmpq_poly_debug(r), flint_printf("\n\n");
flint_printf("q2 = "), fmpq_poly_debug(q2), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(q);
fmpq_poly_clear(q2);
fmpq_poly_clear(r);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View 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) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_poly.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("div_series....");
fflush(stdout);
/* Check aliasing q and a */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, q;
slong n = n_randint(state, 50) + 1;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(q);
fmpq_poly_randtest(a, state, n_randint(state, 50) + 1, 80);
fmpq_poly_randtest_not_zero(b, state, n_randint(state, 50) + 1, 80);
fmpq_poly_set_coeff_ui(b, 0, 1);
fmpq_poly_div_series(q, a, b, n);
fmpq_poly_div_series(a, a, b, n);
cflags |= fmpq_poly_is_canonical(q) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(a) ? 0 : 2;
result = (fmpq_poly_equal(q, a)) && !cflags;
if (!result)
{
flint_printf("FAIL (alias q and a):\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("b = "), fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("q = "), fmpq_poly_debug(q), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(q);
}
/* Check aliasing q and b */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, q;
slong n = n_randint(state, 50) + 1;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(q);
fmpq_poly_randtest(a, state, n_randint(state, 50) + 1, 80);
fmpq_poly_randtest_not_zero(b, state, n_randint(state, 50) + 1, 80);
fmpq_poly_set_coeff_ui(b, 0, 1);
fmpq_poly_div_series(q, a, b, n);
fmpq_poly_div_series(b, a, b, n);
cflags |= fmpq_poly_is_canonical(q) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(q, b)) && !cflags;
if (!result)
{
flint_printf("FAIL (alias q and b):\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("b = "), fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("q = "), fmpq_poly_debug(q), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(q);
}
/* Check that Q * B == A */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, p, q;
slong n = n_randint(state, 50) + 1;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(p);
fmpq_poly_init(q);
fmpq_poly_randtest(a, state, n_randint(state, 50) + 1, 80);
fmpq_poly_randtest_not_zero(b, state, n_randint(state, 50) + 1, 80);
fmpq_poly_set_coeff_ui(b, 0, 1);
fmpq_poly_div_series(q, a, b, n);
fmpq_poly_mullow(p, q, b, n);
fmpq_poly_truncate(a, n);
cflags |= fmpq_poly_is_canonical(q) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(p) ? 0 : 2;
cflags |= fmpq_poly_is_canonical(a) ? 0 : 4;
result = (fmpq_poly_equal(p, a)) && !cflags;
if (!result)
{
flint_printf("FAIL (check Q * B = A):\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("b = "), fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("p = "), fmpq_poly_debug(p), flint_printf("\n\n");
flint_printf("q = "), fmpq_poly_debug(q), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(p);
fmpq_poly_clear(q);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,169 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("divrem....");
fflush(stdout);
/* Check aliasing of {q,r} and {a,b} */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
fmpq_poly_t A, B;
fmpq_poly_t a, b, q, r;
fmpq_poly_init(A);
fmpq_poly_init(B);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(q);
fmpq_poly_init(r);
fmpq_poly_randtest(A, state, n_randint(state, 50), 200);
fmpq_poly_randtest_not_zero(B, state, n_randint(state, 50) + 1, 200);
fmpq_poly_set(a, A);
fmpq_poly_set(b, B);
fmpq_poly_divrem(q, r, a, b);
fmpq_poly_divrem(a, b, a, b);
cflags |= fmpq_poly_is_canonical(q) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(a) ? 0 : 2;
result = (fmpq_poly_equal(q, a)) && (fmpq_poly_equal(r, b)) && !cflags;
if (!result)
{
flint_printf("FAIL (aliasing {q,r} and {a,b}):\n\n");
flint_printf("A = "), fmpq_poly_debug(A), flint_printf("\n\n");
flint_printf("B = "), fmpq_poly_debug(B), flint_printf("\n\n");
flint_printf("q = "), fmpq_poly_debug(q), flint_printf("\n\n");
flint_printf("r = "), fmpq_poly_debug(r), flint_printf("\n\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("b = "), fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(A);
fmpq_poly_clear(B);
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(q);
fmpq_poly_clear(r);
}
/* Check aliasing of {q,r} and {b,a} */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, q, r;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(q);
fmpq_poly_init(r);
fmpq_poly_randtest(a, state, n_randint(state, 50), 200);
fmpq_poly_randtest_not_zero(b, state, n_randint(state, 50) + 1, 200);
fmpq_poly_divrem(q, r, a, b);
fmpq_poly_divrem(b, a, a, b);
cflags |= fmpq_poly_is_canonical(q) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(q, b)) && (fmpq_poly_equal(r, a)) && !cflags;
if (!result)
{
flint_printf("FAIL (aliasing of {q,r} and {b,a}):\n\n");
flint_printf("q = "), fmpq_poly_debug(q), flint_printf("\n\n");
flint_printf("r = "), fmpq_poly_debug(r), flint_printf("\n\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("b = "), fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(q);
fmpq_poly_clear(r);
}
/* check a = q b + r */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, q, r, rhs;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(q);
fmpq_poly_init(r);
fmpq_poly_init(rhs);
fmpq_poly_randtest(a, state, n_randint(state, 50), 200);
fmpq_poly_randtest_not_zero(b, state, n_randint(state, 50) + 1, 200);
fmpq_poly_divrem(q, r, a, b);
fmpq_poly_mul(rhs, q, b);
fmpq_poly_add(rhs, rhs, r);
cflags |= fmpq_poly_is_canonical(q) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(rhs) ? 0 : 2;
result = fmpq_poly_equal(a, rhs) && !cflags;
if (!result)
{
flint_printf("FAIL (a == q b + r):\n\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("b = "), fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("q = "), fmpq_poly_debug(q), flint_printf("\n\n");
flint_printf("r = "), fmpq_poly_debug(r), flint_printf("\n\n");
flint_printf("q b + r = "), fmpq_poly_debug(rhs), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(q);
fmpq_poly_clear(r);
fmpq_poly_clear(rhs);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,181 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("evaluate_fmpq....");
fflush(stdout);
/* Check aliasing */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpz_t a, b;
fmpq_t x, y;
fmpq_poly_t f;
fmpz_init(a);
fmpz_init(b);
fmpq_init(x);
fmpq_init(y);
fmpq_poly_init(f);
fmpq_poly_randtest(f, state, n_randint(state, 80), 100);
fmpz_randtest(a, state, 80);
fmpz_randtest_not_zero(b, state, 80);
fmpz_set(fmpq_numref(x), a);
fmpz_set(fmpq_denref(x), a);
fmpq_canonicalise(x);
fmpq_poly_evaluate_fmpq(y, f, x);
fmpq_poly_evaluate_fmpq(x, f, x);
result = (fmpq_equal(x, y));
if (!result)
{
flint_printf("FAIL:\n");
fmpz_print(a), flint_printf("\n\n");
fmpz_print(b), flint_printf("\n\n");
fmpq_poly_debug(f), flint_printf("\n\n");
abort();
}
fmpz_clear(a);
fmpz_clear(b);
fmpq_clear(x);
fmpq_clear(y);
fmpq_poly_clear(f);
}
/* Check that (f+g)(a) = f(a) + g(a) */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpz_t a, b;
fmpq_t x, y, z;
fmpq_poly_t f, g;
fmpz_init(a);
fmpz_init(b);
fmpq_init(x);
fmpq_init(y);
fmpq_init(z);
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_randtest(f, state, n_randint(state, 80), 100);
fmpq_poly_randtest(g, state, n_randint(state, 80), 100);
fmpz_randtest(a, state, 80);
fmpz_randtest_not_zero(b, state, 80);
fmpz_set(fmpq_numref(x), a);
fmpz_set(fmpq_denref(x), a);
fmpq_canonicalise(x);
fmpq_poly_evaluate_fmpq(y, f, x);
fmpq_poly_evaluate_fmpq(z, g, x);
fmpq_add(y, y, z);
fmpq_poly_add(f, f, g);
fmpq_poly_evaluate_fmpq(z, f, x);
result = (fmpq_equal(y, z));
if (!result)
{
flint_printf("FAIL:\n");
fmpz_print(a), flint_printf("\n\n");
fmpz_print(b), flint_printf("\n\n");
abort();
}
fmpz_clear(a);
fmpz_clear(b);
fmpq_clear(x);
fmpq_clear(y);
fmpq_clear(z);
fmpq_poly_clear(f);
fmpq_poly_clear(g);
}
/* Check that (f*g)(a) = f(a) * g(a) */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpz_t a, b;
fmpq_t x, y, z;
fmpq_poly_t f, g;
fmpz_init(a);
fmpz_init(b);
fmpq_init(x);
fmpq_init(y);
fmpq_init(z);
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_randtest(f, state, n_randint(state, 50), 80);
fmpq_poly_randtest(g, state, n_randint(state, 50), 80);
fmpz_randtest(a, state, 80);
fmpz_randtest_not_zero(b, state, 80);
fmpz_set(fmpq_numref(x), a);
fmpz_set(fmpq_denref(x), a);
fmpq_canonicalise(x);
fmpq_poly_evaluate_fmpq(y, f, x);
fmpq_poly_evaluate_fmpq(z, g, x);
fmpq_mul(y, y, z);
fmpq_poly_mul(f, f, g);
fmpq_poly_evaluate_fmpq(z, f, x);
result = (fmpq_equal(y, z));
if (!result)
{
flint_printf("FAIL:\n");
fmpz_print(a), flint_printf("\n\n");
fmpz_print(b), flint_printf("\n\n");
abort();
}
fmpz_clear(a);
fmpz_clear(b);
fmpq_clear(x);
fmpq_clear(y);
fmpq_clear(z);
fmpq_poly_clear(f);
fmpq_poly_clear(g);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View 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) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("evaluate_fmpz....");
fflush(stdout);
/* Check that (f+g)(a) = f(a) + g(a) */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz_t a;
fmpq_poly_t f, g, h;
fmpq_t x, y;
fmpq_init(x);
fmpq_init(y);
fmpz_init(a);
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_init(h);
fmpq_poly_randtest(f, state, n_randint(state, 100), 200);
fmpq_poly_randtest(g, state, n_randint(state, 100), 200);
fmpz_randtest(a, state, n_randint(state, 100));
fmpq_poly_evaluate_fmpz(x, f, a);
fmpq_poly_evaluate_fmpz(y, g, a);
fmpq_add(x, x, y);
fmpq_poly_add(h, f, g);
fmpq_poly_evaluate_fmpz(y, h, a);
result = (fmpq_equal(x, y));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("f = "), fmpq_poly_debug(f), flint_printf("\n");
flint_printf("g = "), fmpq_poly_debug(g), flint_printf("\n");
flint_printf("a = "), fmpz_print(a), flint_printf("\n");
flint_printf("f(a) + g(a) = "), fmpq_print(x), flint_printf("\n\n");
flint_printf("(f + g)(a) = "), fmpq_print(y), flint_printf("\n\n");
abort();
}
fmpq_clear(x);
fmpq_clear(y);
fmpz_clear(a);
fmpq_poly_clear(f);
fmpq_poly_clear(g);
fmpq_poly_clear(h);
}
/* Check that (f*g)(a) = f(a) * g(a) */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpz_t a;
fmpq_poly_t f, g;
fmpq_t x, y;
fmpq_init(x);
fmpq_init(y);
fmpz_init(a);
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_randtest(f, state, n_randint(state, 100), 200);
fmpq_poly_randtest(g, state, n_randint(state, 100), 200);
fmpz_randtest(a, state, n_randint(state, 100));
fmpq_poly_evaluate_fmpz(x, f, a);
fmpq_poly_evaluate_fmpz(y, g, a);
fmpq_mul(x, x, y);
fmpq_poly_mul(f, f, g);
fmpq_poly_evaluate_fmpz(y, f, a);
result = (fmpq_equal(x, y));
if (!result)
{
flint_printf("FAIL:\n");
fmpz_print(a), flint_printf("\n\n");
abort();
}
fmpq_clear(x);
fmpq_clear(y);
fmpz_clear(a);
fmpq_poly_clear(f);
fmpq_poly_clear(g);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,181 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("evaluate_mpq....");
fflush(stdout);
/* Check aliasing */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpz_t a, b;
mpq_t x, y;
fmpq_poly_t f;
fmpz_init(a);
fmpz_init(b);
mpq_init(x);
mpq_init(y);
fmpq_poly_init(f);
fmpq_poly_randtest(f, state, n_randint(state, 80), 100);
fmpz_randtest(a, state, 80);
fmpz_randtest_not_zero(b, state, 80);
fmpz_get_mpz(mpq_numref(x), a);
fmpz_get_mpz(mpq_denref(x), b);
mpq_canonicalize(x);
fmpq_poly_evaluate_mpq(y, f, x);
fmpq_poly_evaluate_mpq(x, f, x);
result = (mpq_equal(x, y));
if (!result)
{
flint_printf("FAIL:\n");
fmpz_print(a), flint_printf("\n\n");
fmpz_print(b), flint_printf("\n\n");
fmpq_poly_debug(f), flint_printf("\n\n");
abort();
}
fmpz_clear(a);
fmpz_clear(b);
mpq_clear(x);
mpq_clear(y);
fmpq_poly_clear(f);
}
/* Check that (f+g)(a) = f(a) + g(a) */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpz_t a, b;
mpq_t x, y, z;
fmpq_poly_t f, g;
fmpz_init(a);
fmpz_init(b);
mpq_init(x);
mpq_init(y);
mpq_init(z);
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_randtest(f, state, n_randint(state, 80), 100);
fmpq_poly_randtest(g, state, n_randint(state, 80), 100);
fmpz_randtest(a, state, 80);
fmpz_randtest_not_zero(b, state, 80);
fmpz_get_mpz(mpq_numref(x), a);
fmpz_get_mpz(mpq_denref(x), b);
mpq_canonicalize(x);
fmpq_poly_evaluate_mpq(y, f, x);
fmpq_poly_evaluate_mpq(z, g, x);
mpq_add(y, y, z);
fmpq_poly_add(f, f, g);
fmpq_poly_evaluate_mpq(z, f, x);
result = (mpq_equal(y, z));
if (!result)
{
flint_printf("FAIL:\n");
fmpz_print(a), flint_printf("\n\n");
fmpz_print(b), flint_printf("\n\n");
abort();
}
fmpz_clear(a);
fmpz_clear(b);
mpq_clear(x);
mpq_clear(y);
mpq_clear(z);
fmpq_poly_clear(f);
fmpq_poly_clear(g);
}
/* Check that (f*g)(a) = f(a) * g(a) */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpz_t a, b;
mpq_t x, y, z;
fmpq_poly_t f, g;
fmpz_init(a);
fmpz_init(b);
mpq_init(x);
mpq_init(y);
mpq_init(z);
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_randtest(f, state, n_randint(state, 50), 80);
fmpq_poly_randtest(g, state, n_randint(state, 50), 80);
fmpz_randtest(a, state, 80);
fmpz_randtest_not_zero(b, state, 80);
fmpz_get_mpz(mpq_numref(x), a);
fmpz_get_mpz(mpq_denref(x), b);
mpq_canonicalize(x);
fmpq_poly_evaluate_mpq(y, f, x);
fmpq_poly_evaluate_mpq(z, g, x);
mpq_mul(y, y, z);
fmpq_poly_mul(f, f, g);
fmpq_poly_evaluate_mpq(z, f, x);
result = (mpq_equal(y, z));
if (!result)
{
flint_printf("FAIL:\n");
fmpz_print(a), flint_printf("\n\n");
fmpz_print(b), flint_printf("\n\n");
abort();
}
fmpz_clear(a);
fmpz_clear(b);
mpq_clear(x);
mpq_clear(y);
mpq_clear(z);
fmpq_poly_clear(f);
fmpq_poly_clear(g);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,142 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("evaluate_mpz....");
fflush(stdout);
/* Check that (f+g)(a) = f(a) + g(a) */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpz_t a;
fmpq_t x;
mpz_t b;
mpq_t y, z;
fmpq_poly_t f, g;
fmpz_init(a);
fmpq_init(x);
mpz_init(b);
mpq_init(y);
mpq_init(z);
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_randtest(f, state, n_randint(state, 80), 100);
fmpq_poly_randtest(g, state, n_randint(state, 80), 100);
fmpz_randtest(a, state, 80);
fmpz_get_mpz(b, a);
fmpq_poly_evaluate_mpz(y, f, b);
fmpq_poly_evaluate_mpz(z, g, b);
mpq_add(y, y, z);
fmpq_poly_add(f, f, g);
fmpq_poly_evaluate_mpz(z, f, b);
result = (mpq_equal(y, z));
if (!result)
{
flint_printf("FAIL:\n");
fmpz_print(a), flint_printf("\n\n");
gmp_printf("y = %Qd\n\n", y);
gmp_printf("z = %Qd\n\n", z);
abort();
}
fmpz_clear(a);
fmpq_clear(x);
mpz_clear(b);
mpq_clear(y);
mpq_clear(z);
fmpq_poly_clear(f);
fmpq_poly_clear(g);
}
/* Check that (f*g)(a) = f(a) * g(a) */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpz_t a;
fmpq_t x;
mpz_t b;
mpq_t y, z;
fmpq_poly_t f, g;
fmpz_init(a);
fmpq_init(x);
mpz_init(b);
mpq_init(y);
mpq_init(z);
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_randtest(f, state, n_randint(state, 50), 80);
fmpq_poly_randtest(g, state, n_randint(state, 50), 80);
fmpz_randtest(a, state, 80);
fmpz_get_mpz(b, a);
fmpq_poly_evaluate_mpz(y, f, b);
fmpq_poly_evaluate_mpz(z, g, b);
mpq_mul(y, y, z);
fmpq_poly_mul(f, f, g);
fmpq_poly_evaluate_mpz(z, f, b);
result = (mpq_equal(y, z));
if (!result)
{
flint_printf("FAIL:\n");
fmpz_print(a), flint_printf("\n\n");
gmp_printf("y = %Qd\n\n", y);
gmp_printf("z = %Qd\n\n", z);
abort();
}
fmpz_clear(a);
fmpq_clear(x);
mpz_clear(b);
mpq_clear(y);
mpq_clear(z);
fmpq_poly_clear(f);
fmpq_poly_clear(g);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,137 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("exp_series....");
fflush(stdout);
/* Check aliasing of a and c */
for (i = 0; i < 20 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
slong n = n_randint(state, 50) + 1;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest_not_zero(a, state, n_randint(state, 50) + 1, 50);
fmpq_poly_set_coeff_ui(a, 0, UWORD(0));
fmpq_poly_canonicalise(a);
fmpq_poly_exp_series(b, a, n);
fmpq_poly_exp_series(a, a, n);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check exp(a+b) = exp(a) * exp(b) */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, ab, expa, expb, expab, expa_expb;
slong n = n_randint(state, 80) + 1;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(ab);
fmpq_poly_init(expa);
fmpq_poly_init(expb);
fmpq_poly_init(expab);
fmpq_poly_init(expa_expb);
fmpq_poly_randtest_not_zero(a, state, n_randint(state, 60) + 1, 80);
fmpq_poly_set_coeff_ui(a, 0, UWORD(0));
fmpq_poly_randtest_not_zero(b, state, n_randint(state, 60) + 1, 80);
fmpq_poly_set_coeff_ui(b, 0, UWORD(0));
fmpq_poly_add(ab, a, b);
fmpq_poly_exp_series(expab, ab, n);
fmpq_poly_exp_series(expa, a, n);
fmpq_poly_exp_series(expb, b, n);
fmpq_poly_mullow(expa_expb, expa, expb, n);
cflags |= fmpq_poly_is_canonical(expa) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(expb) ? 0 : 2;
cflags |= fmpq_poly_is_canonical(expab) ? 0 : 4;
result = (fmpq_poly_equal(expab, expa_expb) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("b = "), fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("exp(a) = "), fmpq_poly_debug(expa), flint_printf("\n\n");
flint_printf("exp(b) = "), fmpq_poly_debug(expb), flint_printf("\n\n");
flint_printf("exp(ab) = "), fmpq_poly_debug(expab), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(ab);
fmpq_poly_clear(expa);
fmpq_poly_clear(expb);
fmpq_poly_clear(expab);
fmpq_poly_clear(expa_expb);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,270 @@
/*=============================================================================
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 "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int cflags = 0, i, result;
FLINT_TEST_INIT(state);
flint_printf("gcd....");
fflush(stdout);
/* Check aliasing of a and c */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_randtest(a, state, n_randint(state, 100), 100);
fmpq_poly_randtest(b, state, n_randint(state, 100), 100);
fmpq_poly_gcd(c, a, b);
fmpq_poly_gcd(a, a, b);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(c) ? 0 : 2;
result = (fmpq_poly_equal(a, c) && !cflags);
if (!result)
{
flint_printf("FAIL (aliasing a, c):\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(c), flint_printf("\n\n");
flint_printf("cflags = %d\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
}
/* Check aliasing of b and c */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_randtest(a, state, n_randint(state, 100), 100);
fmpq_poly_randtest(b, state, n_randint(state, 100), 100);
fmpq_poly_gcd(c, a, b);
fmpq_poly_gcd(b, a, b);
cflags |= fmpq_poly_is_canonical(b) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(c) ? 0 : 2;
result = (fmpq_poly_equal(b, c) && !cflags);
if (!result)
{
flint_printf("FAIL (aliasing b, c):\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(c), flint_printf("\n\n");
flint_printf("cflags = %d\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
}
/* Generic case when a, b are most likely co-prime ***********************/
/* Verify commutativity and that c is monic */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_randtest(a, state, n_randint(state, 100), 100);
fmpq_poly_randtest(b, state, n_randint(state, 100), 100);
fmpq_poly_gcd(c, a, b);
fmpq_poly_gcd(a, b, a);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(c) ? 0 : 2;
result = (fmpq_poly_equal(a, c) && !cflags
&& (fmpq_poly_is_zero(c) || fmpq_poly_is_monic(c)));
if (!result)
{
flint_printf("FAIL (commutativity #1):\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(c), flint_printf("\n\n");
flint_printf("cflags = %d\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
}
/* Verify that GCD(a, b) divides a, b */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c, r1, r2;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_init(r1);
fmpq_poly_init(r2);
fmpq_poly_randtest(a, state, n_randint(state, 100), 100);
fmpq_poly_randtest(b, state, n_randint(state, 100), 100);
fmpq_poly_gcd(c, a, b);
if (!fmpq_poly_is_zero(c))
{
fmpq_poly_rem(r1, a, c);
fmpq_poly_rem(r2, b, c);
}
result = fmpq_poly_is_zero(r1) && fmpq_poly_is_zero(r2);
if (!result)
{
flint_printf("FAIL (division #1):\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(c), flint_printf("\n\n");
flint_printf("cflags = %d\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
fmpq_poly_clear(r1);
fmpq_poly_clear(r2);
}
/* Case when a, b are not co-prime ***************************************/
/* Verify commutativity and that c is monic */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c, t;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_init(t);
fmpq_poly_randtest(a, state, n_randint(state, 100), 100);
fmpq_poly_randtest(b, state, n_randint(state, 100), 100);
fmpq_poly_randtest(t, state, n_randint(state, 50), 20);
fmpq_poly_mul(a, a, t);
fmpq_poly_mul(b, b, t);
fmpq_poly_gcd(c, a, b);
fmpq_poly_gcd(a, b, a);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(c) ? 0 : 2;
result = (fmpq_poly_equal(a, c) && !cflags
&& (fmpq_poly_is_zero(c) || fmpq_poly_is_monic(c)));
if (!result)
{
flint_printf("FAIL (commutativity #2):\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(c), flint_printf("\n\n");
flint_printf("cflags = %d\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
fmpq_poly_clear(t);
}
/* Verify that GCD(a, b) divides a, b */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c, r1, r2, t;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_init(r1);
fmpq_poly_init(r2);
fmpq_poly_init(t);
fmpq_poly_randtest(a, state, n_randint(state, 100), 100);
fmpq_poly_randtest(b, state, n_randint(state, 100), 100);
fmpq_poly_randtest(t, state, n_randint(state, 50), 20);
fmpq_poly_mul(a, a, t);
fmpq_poly_mul(b, b, t);
fmpq_poly_gcd(c, a, b);
if (!fmpq_poly_is_zero(c))
{
fmpq_poly_rem(r1, a, c);
fmpq_poly_rem(r2, b, c);
}
result = fmpq_poly_is_zero(r1) && fmpq_poly_is_zero(r2);
if (!result)
{
flint_printf("FAIL (division #2):\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(c), flint_printf("\n\n");
flint_printf("cflags = %d\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
fmpq_poly_clear(r1);
fmpq_poly_clear(r2);
fmpq_poly_clear(t);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,90 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010, 2011 Sebastian Pancratz
Copyright (C) 2009 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, j, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("get/set_coeff_fmpq....");
fflush(stdout);
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
fmpq_poly_t a;
fmpq_t x, y;
slong coeff, len;
fmpq_poly_init(a);
fmpq_init(x);
fmpq_init(y);
len = (slong) (n_randint(state, 100) + 1);
for (j = 0; j < 50; j++)
{
fmpq_randtest(x, state, 200);
coeff = (slong) n_randint(state, len);
fmpq_poly_set_coeff_fmpq(a, coeff, x);
fmpq_poly_get_coeff_fmpq(y, a, coeff);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
result = (fmpq_equal(x, y) && !cflags);
if (!result)
{
flint_printf("FAIL:\n\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("coeff = %wd\n\n", coeff);
flint_printf("len = %wd\n\n", len);
flint_printf("cflags = %wu\n\n", cflags);
flint_printf("x = "), fmpq_print(x), flint_printf("\n");
flint_printf("y = "), fmpq_print(y), flint_printf("\n");
abort();
}
}
fmpq_clear(x);
fmpq_clear(y);
fmpq_poly_clear(a);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,98 @@
/*=============================================================================
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
Copyright (C) 2009 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, j, result;
ulong cflags = UWORD(0);
mpq_t n1, n2;
FLINT_TEST_INIT(state);
flint_printf("get/set_coeff_fmpz....");
fflush(stdout);
mpq_init(n1);
mpq_init(n2);
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a;
fmpz_t x1, x2;
slong coeff, len;
fmpq_poly_init(a);
fmpz_init(x1);
fmpz_init(x2);
len = (slong) (n_randint(state, 100) + 1);
for (j = 0; j < 100; j++)
{
fmpz_randtest(x1, state, 200);
fmpz_get_mpz(mpq_numref(n1), x1);
flint_mpz_set_si(mpq_denref(n1), 1);
coeff = (slong) n_randint(state, len);
fmpq_poly_set_coeff_fmpz(a, coeff, x1);
fmpq_poly_get_coeff_mpq(n2, a, coeff);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
result = (mpq_equal(n1, n2) && !cflags);
if (!result)
{
flint_printf("FAIL:\n\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("coeff = %wd\n\n", coeff);
flint_printf("len = %wd\n\n", len);
flint_printf("cflags = %wu\n\n", cflags);
gmp_printf("n1 = %Qd\n\n", n1);
gmp_printf("n2 = %Qd\n\n", n2);
abort();
}
}
fmpz_clear(x1);
fmpz_clear(x2);
fmpq_poly_clear(a);
}
mpq_clear(n1);
mpq_clear(n2);
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,102 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 Sebastian Pancratz
Copyright (C) 2009 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, j, result;
ulong cflags = UWORD(0);
mpq_t n1, n2;
FLINT_TEST_INIT(state);
flint_printf("get/set_coeff_mpq....");
fflush(stdout);
mpq_init(n1);
mpq_init(n2);
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
fmpq_poly_t a;
fmpz_t xnum, xden;
slong coeff, len;
fmpq_poly_init(a);
fmpz_init(xnum);
fmpz_init(xden);
len = (slong) (n_randint(state, 100) + 1);
for (j = 0; j < 50; j++)
{
fmpz_randtest(xnum, state, 200);
fmpz_randtest_not_zero(xden, state, 200);
fmpz_get_mpz(mpq_numref(n1), xnum);
fmpz_get_mpz(mpq_denref(n1), xden);
mpq_canonicalize(n1);
coeff = (slong) n_randint(state, len);
fmpq_poly_set_coeff_mpq(a, coeff, n1);
fmpq_poly_get_coeff_mpq(n2, a, coeff);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
result = (mpq_equal(n1, n2) && !cflags);
if (!result)
{
flint_printf("FAIL:\n\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("coeff = %wd\n\n", coeff);
flint_printf("len = %wd\n\n", len);
flint_printf("cflags = %wu\n\n", cflags);
gmp_printf("n1 = %Qd\n\n", n1);
gmp_printf("n2 = %Qd\n\n", n2);
abort();
}
}
fmpz_clear(xnum);
fmpz_clear(xden);
fmpq_poly_clear(a);
}
mpq_clear(n1);
mpq_clear(n2);
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,97 @@
/*=============================================================================
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
Copyright (C) 2009 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, j, result;
ulong cflags = UWORD(0);
mpq_t n1, n2;
FLINT_TEST_INIT(state);
flint_printf("get/set_coeff_mpz....");
fflush(stdout);
mpq_init(n1);
mpq_init(n2);
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a;
fmpz_t x1, x2;
slong coeff, len;
fmpq_poly_init(a);
fmpz_init(x1);
fmpz_init(x2);
len = (slong) (n_randint(state, 100) + 1);
for (j = 0; j < 100; j++)
{
fmpz_randtest(x1, state, 200);
fmpz_get_mpz(mpq_numref(n1), x1);
flint_mpz_set_si(mpq_denref(n1), 1);
coeff = (slong) n_randint(state, len);
fmpq_poly_set_coeff_mpz(a, coeff, mpq_numref(n1));
fmpq_poly_get_coeff_mpq(n2, a, coeff);
result = (mpq_equal(n1, n2));
if (!result)
{
flint_printf("FAIL:\n\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("coeff = %wd\n\n", coeff);
flint_printf("len = %wd\n\n", len);
flint_printf("cflags = %wu\n\n", cflags);
gmp_printf("n1 = %Qd\n\n", n1);
gmp_printf("n2 = %Qd\n\n", n2);
abort();
}
}
fmpz_clear(x1);
fmpz_clear(x2);
fmpq_poly_clear(a);
}
mpq_clear(n1);
mpq_clear(n2);
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,91 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpq_poly.h"
#include "long_extras.h"
#include "ulong_extras.h"
int
main(void)
{
int i, j, result;
ulong cflags = UWORD(0);
slong n;
mpq_t n_mpq;
FLINT_TEST_INIT(state);
flint_printf("get/set_coeff_si....");
fflush(stdout);
mpq_init(n_mpq);
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a;
slong coeff, len;
fmpq_poly_init(a);
len = (slong) n_randint(state, 100) + 1;
for (j = 0; j < 1000; j++)
{
n = z_randtest(state);
coeff = n_randint(state, len);
fmpq_poly_set_coeff_si(a, coeff, n);
fmpq_poly_get_coeff_mpq(n_mpq, a, coeff);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
result = (flint_mpz_cmp_ui(mpq_denref(n_mpq), 1) == 0
&& flint_mpz_cmp_si(mpq_numref(n_mpq), n) == 0
&& !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n");
flint_printf("len = %wd\n", len);
flint_printf("coeff = %wd\n", coeff);
flint_printf("cflags = %wu\n", cflags);
flint_printf("n = %wd\n", n);
gmp_printf("n_mpq = %Qd\n", n_mpq);
abort();
}
}
fmpq_poly_clear(a);
}
mpq_clear(n_mpq);
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,90 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 Sebastian Pancratz
Copyright (C) 2009 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, j, result;
ulong cflags = UWORD(0);
ulong n;
mpq_t n_mpq;
FLINT_TEST_INIT(state);
flint_printf("get/set_coeff_ui....");
fflush(stdout);
mpq_init(n_mpq);
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a;
slong coeff, len;
fmpq_poly_init(a);
len = (slong) (n_randint(state, 100) + 1);
fmpq_poly_randtest(a, state, len, 100);
for (j = 0; j < 1000; j++)
{
n = n_randtest(state);
coeff = n_randint(state, len);
fmpq_poly_set_coeff_ui(a, coeff, n);
fmpq_poly_get_coeff_mpq(n_mpq, a, coeff);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
result = (flint_mpz_cmp_ui(mpq_denref(n_mpq), 1) == 0
&& flint_mpz_cmp_ui(mpq_numref(n_mpq), n) == 0
&& !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n");
flint_printf("len = %wd\n", len);
flint_printf("coeff = %wd\n", coeff);
flint_printf("cflags = %wu\n", cflags);
flint_printf("n = %wu\n", n);
gmp_printf("n_mpq = %Qd\n", n_mpq);
abort();
}
}
fmpq_poly_clear(a);
}
mpq_clear(n_mpq);
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,80 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 Sebastian Pancratz
Copyright (C) 2009 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("get_set_str....");
fflush(stdout);
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
int ans;
char * str;
fmpq_poly_t f, g;
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_randtest(f, state, n_randint(state, 100), 200);
str = fmpq_poly_get_str(f);
ans = fmpq_poly_set_str(g, str);
cflags |= fmpq_poly_is_canonical(f) ? 0 : 1;
result = (ans == 0 && fmpq_poly_equal(f, g) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("f = "), fmpq_poly_debug(f), flint_printf("\n\n");
flint_printf("g = "), fmpq_poly_debug(g), flint_printf("\n\n");
flint_printf("ans = %d\n\n", ans);
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(f);
fmpq_poly_clear(g);
flint_free(str);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,157 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2011 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("get_slice....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c;
slong j1, j2;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_set(b, a);
j1 = n_randint(state, 100);
j2 = n_randint(state, 100);
fmpq_poly_get_slice(c, b, j1, j2);
fmpq_poly_get_slice(b, b, j1, j2);
cflags |= fmpq_poly_is_canonical(b) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(c) ? 0 : 2;
result = (fmpq_poly_equal(b, c) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(c), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
}
/* Check slice with i >= j is zero */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
slong j1, j2;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
j2 = n_randint(state, 60);
j1 = j2 + n_randint(state, 60);
fmpq_poly_get_slice(b, a, j1, j2);
cflags |= fmpq_poly_is_canonical(b) ? 0 : 1;
result = (fmpq_poly_is_zero(b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check transitivity when j1 <= k1 <= k2 <= j2 */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c, d;
slong j1, j2, k1, k2;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_init(d);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
j1 = n_randint(state, 20);
k1 = j1 + n_randint(state, 20);
k2 = k1 + n_randint(state, 20);
j2 = k2 + n_randint(state, 20);
fmpq_poly_get_slice(b, a, j1, j2);
fmpq_poly_get_slice(c, b, k1, k2);
fmpq_poly_get_slice(d, a, k1, k2);
cflags |= fmpq_poly_is_canonical(b) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(c) ? 0 : 2;
cflags |= fmpq_poly_is_canonical(d) ? 0 : 4;
result = (fmpq_poly_equal(c, d) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(c), flint_printf("\n\n");
fmpq_poly_debug(d), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
fmpq_poly_clear(d);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

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

View File

@@ -0,0 +1,109 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("integral....");
fflush(stdout);
/* Check aliasing */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_integral(b, a);
fmpq_poly_integral(a, a);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check inverse of fmpq_poly_derivative */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_integral(b, a);
fmpq_poly_derivative(c, b);
cflags |= fmpq_poly_is_canonical(b) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(c) ? 0 : 2;
result = fmpq_poly_equal(a, c) && !cflags;
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,97 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_vec.h"
#include "fmpz_poly.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i;
FLINT_TEST_INIT(state);
flint_printf("interpolate_fmpz_vec....");
fflush(stdout);
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t P;
fmpz *x, *y, *z;
fmpq_t q;
slong j, n, bits;
n = n_randint(state, 50);
bits = n_randint(state, 100);
x = _fmpz_vec_init(n);
y = _fmpz_vec_init(n);
z = _fmpz_vec_init(n);
fmpq_poly_init(P);
for (j = 0; j < n; j++)
fmpz_set_si(x + j, -n/2 + j);
_fmpz_vec_randtest(y, state, n, bits);
fmpq_poly_interpolate_fmpz_vec(P, x, y, n);
fmpq_init(q);
for (j = 0; j < n; j++)
{
fmpq_poly_evaluate_fmpz(q, P, x + j);
fmpz_set(z + j, fmpq_numref(q));
if (!fmpz_equal(z + j, y + j) || !fmpz_is_one(fmpq_denref(q)))
{
flint_printf("FAIL:\n");
flint_printf("x:\n"); _fmpz_vec_print(x, n); flint_printf("\n\n");
flint_printf("y:\n"); _fmpz_vec_print(y, n); flint_printf("\n\n");
flint_printf("P:\n"); fmpq_poly_print(P), flint_printf("\n\n");
abort();
}
}
fmpq_clear(q);
fmpq_poly_clear(P);
_fmpz_vec_clear(x, n);
_fmpz_vec_clear(y, n);
_fmpz_vec_clear(z, n);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

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

View File

@@ -0,0 +1,124 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("inv_series_newton....");
fflush(stdout);
/* Check aliasing of a and c */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
slong n = n_randint(state, 50) + 1;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest_not_zero(a, state, n_randint(state, 50) + 1, 50);
fmpz_randtest_not_zero(a->coeffs, state, 50);
fmpq_poly_canonicalise(a);
fmpq_poly_inv_series_newton(b, a, n);
fmpq_poly_inv_series_newton(a, a, n);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check Q^{-1} * Q is congruent 1 mod t^n */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c, one;
slong n = n_randint(state, 80) + 1;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_init(one);
fmpq_poly_randtest_not_zero(a, state, n_randint(state, 80) + 1, 80);
fmpz_randtest_not_zero(a->coeffs, state, 80);
fmpq_poly_canonicalise(a);
fmpq_poly_fit_length(one, 1);
fmpz_set_ui(one->coeffs, 1);
one->length = 1;
fmpq_poly_inv_series_newton(b, a, n);
fmpq_poly_mul(c, a, b);
fmpq_poly_truncate(c, n);
cflags |= fmpq_poly_is_canonical(b) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(c) ? 0 : 2;
result = (fmpq_poly_equal(c, one) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("b = "), fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("c = "), fmpq_poly_debug(c), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
fmpq_poly_clear(one);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,120 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("invsqrt_series....");
fflush(stdout);
/* Check aliasing of a and c */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
slong n = n_randint(state, 50) + 1;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest_not_zero(a, state, n_randint(state, 50) + 1, 50);
fmpq_poly_set_coeff_ui(a, 0, UWORD(1));
fmpq_poly_canonicalise(a);
fmpq_poly_invsqrt_series(b, a, n);
fmpq_poly_invsqrt_series(a, a, n);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check 1/((1/sqrt(a))^2) = a */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c;
slong n = n_randint(state, 80) + 1;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_randtest_not_zero(a, state, n_randint(state, 80) + 1, 80);
fmpq_poly_set_coeff_ui(a, 0, UWORD(1));
fmpq_poly_invsqrt_series(b, a, n);
fmpq_poly_mullow(c, b, b, n);
fmpq_poly_inv_series(c, c, n);
fmpq_poly_truncate(a, n);
cflags |= fmpq_poly_is_canonical(b) ? 0 : 1;
result = (fmpq_poly_equal(c, a) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("b = "), fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("c = "), fmpq_poly_debug(c), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,135 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("is_squarefree....");
fflush(stdout);
/* Check that polynomials of degree <= 1 are square-free */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
fmpq_poly_t f;
fmpq_poly_init(f);
fmpq_poly_randtest(f, state, n_randint(state, 2), 100);
result = (fmpq_poly_is_squarefree(f));
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(f), flint_printf("\n");
abort();
}
fmpq_poly_clear(f);
}
/* Check that a^2 f is not square-free */
for (i = 0; i < 20 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, f;
fmpq_poly_init(a);
fmpq_poly_randtest_not_zero(a, state, n_randint(state, 20) + 1, 40);
if (a->length < 2)
{
fmpq_poly_clear(a);
continue;
}
fmpq_poly_init(f);
fmpq_poly_randtest_not_zero(f, state, n_randint(state, 20) + 1, 40);
fmpq_poly_mul(a, a, a);
fmpq_poly_mul(f, a, f);
result = (!fmpq_poly_is_squarefree(f));
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(f), flint_printf("\n");
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(f);
}
/* Check that f + N*(x^M + 1) is square-free, for N >> f, M > deg(f) */
for (i = 0; i < 20 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, f;
fmpz_t N;
fmpq_poly_init(a);
fmpq_poly_set_coeff_si(a, 0, WORD(1));
fmpq_poly_set_coeff_si(a, n_randint(state, 20), WORD(1));
if (a->length < 2)
{
fmpq_poly_clear(a);
continue;
}
fmpq_poly_init(f);
fmpq_poly_randtest(f, state, a->length - 2, 40);
fmpz_init_set_ui(N, UWORD(1));
fmpz_mul_2exp(N, N, 45 + a->length);
fmpq_poly_scalar_mul_fmpz(a, a, N);
fmpq_poly_add(f, a, f);
result = fmpq_poly_is_squarefree(f);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(f), flint_printf("\n");
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(f);
fmpz_clear(N);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View 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) 2011 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int cflags = 0, i, result;
FLINT_TEST_INIT(state);
flint_printf("lcm....");
fflush(stdout);
/* Check aliasing of a and c */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_randtest(a, state, n_randint(state, 100), 100);
fmpq_poly_randtest(b, state, n_randint(state, 100), 100);
fmpq_poly_lcm(c, a, b);
fmpq_poly_lcm(a, a, b);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(c) ? 0 : 2;
result = (fmpq_poly_equal(a, c) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(c), flint_printf("\n\n");
flint_printf("cflags = %d\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
}
/* Check aliasing of b and c */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_randtest(a, state, n_randint(state, 100), 100);
fmpq_poly_randtest(b, state, n_randint(state, 100), 100);
fmpq_poly_lcm(c, a, b);
fmpq_poly_lcm(b, a, b);
cflags |= fmpq_poly_is_canonical(b) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(c) ? 0 : 2;
result = (fmpq_poly_equal(b, c) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(c), flint_printf("\n\n");
flint_printf("cflags = %d\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
}
/* Generic case when a, b are most likely co-prime ***********************/
/* Verify commutativity and that c is monic */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_randtest(a, state, n_randint(state, 100), 100);
fmpq_poly_randtest(b, state, n_randint(state, 100), 100);
fmpq_poly_lcm(c, a, b);
fmpq_poly_lcm(a, b, a);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(c) ? 0 : 2;
result = (fmpq_poly_equal(a, c) && !cflags
&& (fmpq_poly_is_zero(c) || fmpq_poly_is_monic(c)));
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(c), flint_printf("\n\n");
flint_printf("cflags = %d\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
}
/* Verify that LCM(a, b) GCD(a, b) == a b */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, lcm, gcd;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(lcm);
fmpq_poly_init(gcd);
fmpq_poly_randtest(a, state, n_randint(state, 100), 100);
fmpq_poly_randtest(b, state, n_randint(state, 100), 100);
fmpq_poly_lcm(lcm, a, b);
fmpq_poly_gcd(gcd, a, b);
fmpq_poly_mul(lcm, lcm, gcd);
fmpq_poly_mul(a, a, b);
fmpq_poly_make_monic(a, a);
result = fmpq_poly_equal(lcm, a);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(lcm), flint_printf("\n\n");
fmpq_poly_debug(gcd), flint_printf("\n\n");
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(lcm);
fmpq_poly_clear(gcd);
}
/* Case when a, b are not co-prime ***************************************/
/* Verify commutativity and that c is monic */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c, t;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_init(t);
fmpq_poly_randtest(a, state, n_randint(state, 100), 100);
fmpq_poly_randtest(b, state, n_randint(state, 100), 100);
fmpq_poly_randtest(t, state, n_randint(state, 50), 20);
fmpq_poly_mul(a, a, t);
fmpq_poly_mul(b, b, t);
fmpq_poly_lcm(c, a, b);
fmpq_poly_lcm(a, b, a);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(c) ? 0 : 2;
result = (fmpq_poly_equal(a, c) && !cflags
&& (fmpq_poly_is_zero(c) || fmpq_poly_is_monic(c)));
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(c), flint_printf("\n\n");
flint_printf("cflags = %d\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
fmpq_poly_clear(t);
}
/* Verify that LCM(a, b) GCD(a, b) == a b */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, lcm, gcd, t;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(lcm);
fmpq_poly_init(gcd);
fmpq_poly_init(t);
fmpq_poly_randtest(a, state, n_randint(state, 100), 100);
fmpq_poly_randtest(b, state, n_randint(state, 100), 100);
fmpq_poly_randtest(t, state, n_randint(state, 50), 20);
fmpq_poly_mul(a, a, t);
fmpq_poly_mul(b, b, t);
fmpq_poly_lcm(lcm, a, b);
fmpq_poly_gcd(gcd, a, b);
fmpq_poly_mul(lcm, lcm, gcd);
fmpq_poly_mul(a, a, b);
fmpq_poly_make_monic(a, a);
result = fmpq_poly_equal(lcm, a);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(lcm), flint_printf("\n\n");
fmpq_poly_debug(gcd), flint_printf("\n\n");
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(lcm);
fmpq_poly_clear(gcd);
fmpq_poly_clear(t);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,137 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("log_series....");
fflush(stdout);
/* Check aliasing of a and c */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
slong n = n_randint(state, 50) + 1;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest_not_zero(a, state, n_randint(state, 50) + 1, 50);
fmpq_poly_set_coeff_ui(a, 0, UWORD(1));
fmpq_poly_canonicalise(a);
fmpq_poly_log_series(b, a, n);
fmpq_poly_log_series(a, a, n);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check log(a*b) = log(a) + log(b) */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, ab, loga, logb, logab, loga_logb;
slong n = n_randint(state, 80) + 1;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(ab);
fmpq_poly_init(loga);
fmpq_poly_init(logb);
fmpq_poly_init(logab);
fmpq_poly_init(loga_logb);
fmpq_poly_randtest_not_zero(a, state, n_randint(state, 80) + 1, 80);
fmpq_poly_set_coeff_ui(a, 0, UWORD(1));
fmpq_poly_randtest_not_zero(b, state, n_randint(state, 80) + 1, 80);
fmpq_poly_set_coeff_ui(b, 0, UWORD(1));
fmpq_poly_mullow(ab, a, b, n);
fmpq_poly_log_series(logab, ab, n);
fmpq_poly_log_series(loga, a, n);
fmpq_poly_log_series(logb, b, n);
fmpq_poly_add(loga_logb, loga, logb);
cflags |= fmpq_poly_is_canonical(loga) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(logb) ? 0 : 2;
cflags |= fmpq_poly_is_canonical(logab) ? 0 : 4;
result = (fmpq_poly_equal(logab, loga_logb) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("b = "), fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("log(a) = "), fmpq_poly_debug(loga), flint_printf("\n\n");
flint_printf("log(b) = "), fmpq_poly_debug(logb), flint_printf("\n\n");
flint_printf("log(ab) = "), fmpq_poly_debug(logab), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(ab);
fmpq_poly_clear(loga);
fmpq_poly_clear(logb);
fmpq_poly_clear(logab);
fmpq_poly_clear(loga_logb);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,101 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("make_monic/is_monic....");
fflush(stdout);
/* Check aliasing */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t f, g;
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_randtest(f, state, n_randint(state, 100), 200);
fmpq_poly_make_monic(g, f);
fmpq_poly_make_monic(f, f);
cflags |= fmpq_poly_is_canonical(f) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(g) ? 0 : 2;
result = (fmpq_poly_equal(f, g) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(f), flint_printf("\n\n");
fmpq_poly_debug(g), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(f);
fmpq_poly_clear(g);
}
/* Check that the result of "monic" has "is_monic" return 1 */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t f;
fmpq_poly_init(f);
fmpq_poly_randtest_not_zero(f, state, n_randint(state, 100) + 1, 200);
fmpq_poly_make_monic(f, f);
cflags |= fmpq_poly_is_canonical(f) ? 0 : 1;
result = (fmpq_poly_is_monic(f) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(f), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(f);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,152 @@
/*=============================================================================
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
Copyright (C) 2009 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("mul....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_randtest(b, state, n_randint(state, 50), 500);
fmpq_poly_randtest(c, state, n_randint(state, 50), 500);
fmpq_poly_mul(a, b, c);
fmpq_poly_mul(b, b, c);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
}
/* Check aliasing of a and c */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_randtest(b, state, n_randint(state, 50), 500);
fmpq_poly_randtest(c, state, n_randint(state, 50), 500);
fmpq_poly_mul(a, b, c);
fmpq_poly_mul(c, b, c);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(c) ? 0 : 2;
result = (fmpq_poly_equal(a, c) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(c), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
}
/* Check (b*c)+(b*d) = b*(c+d) */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
fmpq_poly_t a1, a2, b, c, d;
fmpq_poly_init(a1);
fmpq_poly_init(a2);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_init(d);
fmpq_poly_randtest(b, state, n_randint(state, 100), 500);
fmpq_poly_randtest(c, state, n_randint(state, 100), 500);
fmpq_poly_randtest(d, state, n_randint(state, 100), 500);
fmpq_poly_mul(a1, b, c);
fmpq_poly_mul(a2, b, d);
fmpq_poly_add(a1, a1, a2);
fmpq_poly_add(c, c, d);
fmpq_poly_mul(a2, b, c);
cflags |= fmpq_poly_is_canonical(a1) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(a2) ? 0 : 2;
result = (fmpq_poly_equal(a1, a2) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a1), flint_printf("\n\n");
fmpq_poly_debug(a2), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a1);
fmpq_poly_clear(a2);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
fmpq_poly_clear(d);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,84 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpz_poly.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("mullow....");
fflush(stdout);
/* Compare with truncated product of a and b */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c;
slong trunc;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
trunc = n_randint(state, 50);
fmpq_poly_randtest(b, state, trunc, 200);
fmpq_poly_randtest(c, state, trunc, 200);
fmpq_poly_mullow(a, b, c, trunc);
fmpq_poly_mul(b, b, c);
fmpq_poly_truncate(b, trunc);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

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

View File

@@ -0,0 +1,127 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("pow....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
ulong exp;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest(b, state, n_randint(state, 10), 100);
exp = (ulong) n_randtest(state) % UWORD(20);
fmpq_poly_pow(a, b, exp);
fmpq_poly_pow(b, b, exp);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("exp = %wu\n", exp);
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("b = "), fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Compare with repeated multiplications by the base */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c;
ulong exp;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_randtest(b, state, n_randint(state, 10), 100);
exp = (ulong) n_randtest(state) % UWORD(20);
fmpq_poly_pow(a, b, exp);
if (exp == 0)
{
fmpq_poly_set_ui(c, 1);
}
else
{
ulong j;
fmpq_poly_set(c, b);
for (j = 1; j < exp; j++)
fmpq_poly_mul(c, c, b);
}
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
result = (fmpq_poly_equal(a, c) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("exp = %wu\n", exp);
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("c = "), fmpq_poly_debug(c), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,124 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("primitive_part....");
fflush(stdout);
/* Check aliasing */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t f, g;
fmpq_t x;
fmpq_init(x);
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_randtest(f, state, n_randint(state, 100), 200);
fmpq_randtest(x, state, 100);
fmpq_poly_scalar_mul_fmpq(f, f, x);
fmpq_poly_primitive_part(g, f);
fmpq_poly_primitive_part(f, f);
cflags |= fmpq_poly_is_canonical(f) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(g) ? 0 : 2;
result = (fmpq_poly_equal(f, g) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(f), flint_printf("\n\n");
fmpq_poly_debug(g), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_clear(x);
fmpq_poly_clear(f);
fmpq_poly_clear(g);
}
/* Check that content(f) primitive_part(f) = +- f */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t f, g;
fmpq_t x, y;
fmpq_init(x);
fmpq_init(y);
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_randtest(f, state, n_randint(state, 100), 200);
fmpq_randtest(x, state, 100);
fmpq_poly_scalar_mul_fmpq(f, f, x);
fmpq_poly_content(y, f);
fmpq_poly_primitive_part(g, f);
fmpq_poly_scalar_mul_fmpq(g, g, y);
if (!fmpq_poly_is_zero(f) && fmpz_sgn(f->coeffs + (f->length - 1)) < 0)
fmpq_poly_neg(g, g);
cflags |= fmpq_poly_is_canonical(f) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(g) ? 0 : 2;
result = (fmpq_poly_equal(f, g) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(f), flint_printf("\n\n");
fmpq_poly_debug(g), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_clear(x);
fmpq_clear(y);
fmpq_poly_clear(f);
fmpq_poly_clear(g);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,270 @@
/*=============================================================================
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_poly.h"
#include "fmpq_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;
FLINT_TEST_INIT(state);
flint_printf("print/ read....");
fflush(stdout);
/* Randomise n polynomials, write to and read from a pipe */
{
fmpq_poly_t *a;
a = flint_malloc(n * sizeof(fmpq_poly_t));
for (i = 0; i < n; i++)
{
fmpq_poly_init(a[i]);
fmpq_poly_randtest(a[i], state, 100, 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 = fmpq_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;
fmpq_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();
}
fmpq_poly_init(t);
i = 0;
while (!feof(in))
{
r = fmpq_poly_fread(in, t);
if (r <= 0)
{
flint_printf("FAIL:\n");
flint_printf("Read error.\n");
abort();
}
result = fmpq_poly_equal(t, a[i]);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a[i] = "), fmpq_poly_debug(a[i]), flint_printf("\n");
flint_printf("t = "), fmpq_poly_debug(t), flint_printf("\n");
abort();
}
++i;
}
fmpq_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++)
fmpq_poly_clear(a[i]);
flint_free(a);
}
/* Write bad data to a pipe and read it */
{
char str[5] = {'b', 'l', 'a', 'h', '\0'};
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;
fmpq_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();
}
fmpq_poly_init(t);
i = 0;
while (!feof(in))
{
r = fmpq_poly_fread(in, t);
if (r > 0)
{
flint_printf("FAIL:\n");
flint_printf("r = %d\n", r);
abort();
}
++i;
}
fmpq_poly_clear(t);
fclose(in);
}
/* For {'b','l','a','h','\0'} we expect 5 reads */
if (i != 5)
{
flint_printf("FAIL:\n");
flint_printf("Carried out %d reads, but \"%s\" has only 4 characters.\n", i, str);
abort();
}
}
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

View File

@@ -0,0 +1,152 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("rem....");
fflush(stdout);
/* Check aliasing of r and a */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, r;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(r);
fmpq_poly_randtest(a, state, n_randint(state, 50), 200);
fmpq_poly_randtest_not_zero(b, state, n_randint(state, 50) + 1, 200);
fmpq_poly_rem(r, a, b);
fmpq_poly_rem(a, a, b);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(r) ? 0 : 2;
result = (fmpq_poly_equal(r, a) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("r = "), fmpq_poly_debug(r), flint_printf("\n\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("b = "), fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(r);
}
/* Check aliasing of r and b */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, r;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(r);
fmpq_poly_randtest(a, state, n_randint(state, 50), 200);
fmpq_poly_randtest_not_zero(b, state, n_randint(state, 50) + 1, 200);
fmpq_poly_rem(r, a, b);
fmpq_poly_rem(b, a, b);
cflags |= fmpq_poly_is_canonical(b) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(r) ? 0 : 2;
result = (fmpq_poly_equal(r, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("r = "), fmpq_poly_debug(r), flint_printf("\n\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("b = "), fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(r);
}
/* Compare with divrem */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, q, r, r2;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(q);
fmpq_poly_init(r);
fmpq_poly_init(r2);
fmpq_poly_randtest(a, state, n_randint(state, 50), 200);
fmpq_poly_randtest_not_zero(b, state, n_randint(state, 50) + 1, 200);
fmpq_poly_divrem(q, r, a, b);
fmpq_poly_rem(r2, a, b);
cflags |= fmpq_poly_is_canonical(q) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(r2) ? 0 : 2;
result = (fmpq_poly_equal(r, r2) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("b = "), fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("q = "), fmpq_poly_debug(q), flint_printf("\n\n");
flint_printf("r = "), fmpq_poly_debug(r), flint_printf("\n\n");
flint_printf("r2 = "), fmpq_poly_debug(r2), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(q);
fmpq_poly_clear(r);
fmpq_poly_clear(r2);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,162 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("rem_powers_precomp....");
fflush(stdout);
/* Check aliasing of q and a */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, r;
fmpq_poly_powers_precomp_t binv;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(r);
fmpq_poly_randtest(a, state, n_randint(state, 50), 100);
fmpq_poly_randtest_not_zero(b, state, n_randint(state, 50) + 1, 100);
fmpq_poly_powers_precompute(binv, b);
fmpq_poly_rem_powers_precomp(r, a, b, binv);
fmpq_poly_rem_powers_precomp(a, a, b, binv);
result = (fmpq_poly_equal(r, a));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("r = "), fmpq_poly_debug(r), flint_printf("\n\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("b = "), fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_powers_clear(binv);
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(r);
}
/* Check aliasing of q and b */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, r;
fmpq_poly_powers_precomp_t binv;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(r);
fmpq_poly_randtest(a, state, n_randint(state, 50), 100);
fmpq_poly_randtest_not_zero(b, state, n_randint(state, 50) + 1, 100);
fmpq_poly_powers_precompute(binv, b);
fmpq_poly_rem_powers_precomp(r, a, b, binv);
fmpq_poly_rem_powers_precomp(b, a, b, binv);
result = (fmpq_poly_equal(r, b));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("r = "), fmpq_poly_debug(r), flint_printf("\n\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("b = "), fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_powers_clear(binv);
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(r);
}
/* Compare with divrem */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, q, r2, r;
fmpq_poly_powers_precomp_t binv;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(q);
fmpq_poly_init(r2);
fmpq_poly_init(r);
fmpq_poly_randtest(a, state, n_randint(state, 50), 100);
fmpq_poly_randtest_not_zero(b, state, n_randint(state, 50) + 1, 100);
fmpq_poly_powers_precompute(binv, b);
fmpq_poly_divrem(q, r, a, b);
fmpq_poly_rem_powers_precomp(r2, a, b, binv);
fmpq_poly_canonicalise(r2);
result = (fmpq_poly_equal(r, r2));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("b = "), fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("q = "), fmpq_poly_debug(q), flint_printf("\n\n");
flint_printf("r = "), fmpq_poly_debug(r), flint_printf("\n\n");
flint_printf("r2 = "), fmpq_poly_debug(r2), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_powers_clear(binv);
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(q);
fmpq_poly_clear(r2);
fmpq_poly_clear(r);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,117 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("rescale....");
fflush(stdout);
/* Check aliasing */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t f, g;
fmpq_t a;
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_randtest(f, state, n_randint(state, 100), 100);
fmpq_init(a);
fmpq_randtest(a, state, 100);
fmpq_poly_rescale(g, f, a);
fmpq_poly_rescale(f, f, a);
cflags |= fmpq_poly_is_canonical(f) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(g) ? 0 : 2;
result = (fmpq_poly_equal(f, g) && !cflags);
if (!result)
{
flint_printf("FAIL (aliasing):\n");
fmpq_poly_debug(f), flint_printf("\n\n");
fmpq_poly_debug(g), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(f);
fmpq_poly_clear(g);
fmpq_clear(a);
}
/* Check that rescaling by a and then by 1/a is the identity */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t f, g;
fmpq_t a;
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_randtest(f, state, n_randint(state, 100), 100);
fmpq_init(a);
fmpq_randtest_not_zero(a, state, 100);
fmpq_poly_rescale(g, f, a);
fmpq_inv(a, a);
fmpq_poly_rescale(g, g, a);
cflags |= fmpq_poly_is_canonical(f) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(g) ? 0 : 2;
result = (fmpq_poly_equal(f, g) && !cflags);
if (!result)
{
flint_printf("FAIL (composition of a and 1/a):\n");
fmpq_poly_debug(f), flint_printf("\n\n");
fmpq_poly_debug(g), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(f);
fmpq_poly_clear(g);
fmpq_clear(a);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,188 @@
/*=============================================================================
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 "fmpq_poly.h"
#include "ulong_extras.h"
#pragma GCC diagnostic ignored "-Woverlength-strings"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("resultant....");
fflush(stdout);
/* Check res(f, g) == (-1)^(deg f deg g) res(g, f) */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
fmpq_poly_t f, g;
fmpq_t x, y;
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_init(x);
fmpq_init(y);
fmpq_poly_randtest(f, state, n_randint(state, 60), 60);
fmpq_poly_randtest(g, state, n_randint(state, 60), 60);
fmpq_poly_resultant(x, f, g);
fmpq_poly_resultant(y, g, f);
if ((fmpq_poly_degree(f) * fmpq_poly_degree(g)) % 2)
fmpq_neg(y, y);
result = fmpq_equal(x, y);
if (!result)
{
flint_printf("FAIL (res(f,g) == (-1)^(m * n) res(g, f)):\n");
flint_printf("f = "), fmpq_poly_print(f), flint_printf("\n\n");
flint_printf("g = "), fmpq_poly_print(g), flint_printf("\n\n");
flint_printf("x = "), fmpq_print(x), flint_printf("\n\n");
flint_printf("y = "), fmpq_print(y), flint_printf("\n\n");
abort();
}
fmpq_poly_clear(f);
fmpq_poly_clear(g);
fmpq_clear(x);
fmpq_clear(y);
}
/* Check res(f h, g) == res(f, g) res(h, g) */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
fmpq_poly_t f, g, h;
fmpq_t x, y, z;
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_init(h);
fmpq_init(x);
fmpq_init(y);
fmpq_init(z);
fmpq_poly_randtest(f, state, n_randint(state, 60), 60);
fmpq_poly_randtest(g, state, n_randint(state, 60), 60);
fmpq_poly_randtest(h, state, n_randint(state, 60), 60);
fmpq_poly_resultant(y, f, g);
fmpq_poly_resultant(z, h, g);
fmpq_mul(y, y, z);
fmpq_poly_mul(f, f, h);
fmpq_poly_resultant(x, f, g);
result = fmpq_equal(x, y);
if (!result)
{
flint_printf("FAIL (res(f h, g) == res(f, g) res(h, g)):\n");
flint_printf("f = "), fmpq_poly_print(f), flint_printf("\n\n");
flint_printf("g = "), fmpq_poly_print(g), flint_printf("\n\n");
flint_printf("h = "), fmpq_poly_print(h), flint_printf("\n\n");
flint_printf("x = "), fmpq_print(x), flint_printf("\n\n");
flint_printf("y = "), fmpq_print(y), flint_printf("\n\n");
abort();
}
fmpq_poly_clear(f);
fmpq_poly_clear(g);
fmpq_poly_clear(h);
fmpq_clear(x);
fmpq_clear(y);
fmpq_clear(z);
}
/* fredrik's test case */
{
fmpq_poly_t f, g;
fmpq_t x, y;
int result;
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_init(x);
fmpq_init(y);
fmpq_poly_set_str(f, "49 16702090503 -23810415210 7561766512 801950253"
" 56796743 40735271 -15934 820601 -2712604160 -1577466 0 0 -7967 0"
" 0 0 -14491973 0 6566138489 -55769 0 130523361 4071137 15934"
" -501921 -59067338 63860755253 23924901 -15934 -262911 -7967"
" -4389817 0 185876611072 58470888545 130523361 -63736 -130618965"
" -39835 0 7967 0 55769 -7967 103571 111298990 47802 -3808226"
" -3800259");
fmpq_poly_set_str(g, "59 -458395/219902324736 151585/4581298432"
" 112595/219902324736 -2016245/54975581184 0 35/73300774912 0"
" -234880919/219902324736 7/219902324736 -7/1278501888"
" -6055/109951162368 7/27487790592 -504623/73300774912"
" 53673977/219902324736 0 611667/73300774912 -497/13743895296"
" 0 -6265/219902324736 2446675/73300774912 2345/219902324736"
" -371/73300774912 -427/6871947648 -3758096377/219902324736"
" 20595995/109951162368 -256459/73300774912 0 33690223/73300774912"
" -229369/219902324736 93205/219902324736 -7/107374182"
" -133/219902324736 -665/13743895296 -146503/219902324736 0"
" 7/219902324736 66633/73300774912 -855190385/219902324736"
" 229355/219902324736 0 161/219902324736 887299/219902324736"
" -427/7582838784 -611667/18325193728 -7/5114007552 833/54975581184"
" -7/109951162368 -5402264413/219902324736 7/5114007552 35/9162596864"
" 1133545/219902324736 -151319/73300774912 0 7/219902324736"
" 7/54975581184 0 -10367/109951162368 7/54975581184 -161/109951162368");
fmpq_poly_resultant(x, f, g);
fmpq_poly_resultant(y, g, f);
if ((fmpq_poly_degree(f) * fmpq_poly_degree(g)) % 2)
fmpq_neg(y, y);
result = fmpq_equal(x, y);
if (!result)
{
flint_printf("FAIL (res(f,g) == (-1)^(m * n) res(g, f)):\n");
flint_printf("x = "), fmpq_print(x), flint_printf("\n\n");
flint_printf("y = "), fmpq_print(y), flint_printf("\n\n");
abort();
}
fmpq_poly_clear(f);
fmpq_poly_clear(g);
fmpq_clear(x);
fmpq_clear(y);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,115 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("reverse....");
fflush(stdout);
/* Aliasing */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
slong n;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest(b, state, n_randint(state, 100), 200);
n = n_randint(state, 150);
fmpq_poly_reverse(a, b, n);
fmpq_poly_reverse(b, b, n);
result = (fmpq_poly_equal(a, b));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("n = %wd\n", n);
flint_printf("a = "), fmpq_poly_print(a), flint_printf("\n\n");
flint_printf("b = "), fmpq_poly_print(b), flint_printf("\n\n");
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Correctness (?) */
for (i = 0; i < 200 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
slong j, len, n;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest(b, state, n_randint(state, 100), 200);
n = n_randint(state, 150);
len = FLINT_MIN(n, b->length);
if (len)
{
fmpq_poly_fit_length(a, n);
for (j = 0; j < len; j++)
fmpz_set(a->coeffs + (n - len) + j, b->coeffs + (len - 1 - j));
fmpz_set(a->den, b->den);
_fmpq_poly_set_length(a, n);
fmpq_poly_canonicalise(a);
}
fmpq_poly_reverse(b, b, n);
result = (fmpq_poly_equal(a, b));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("n = %wd\n", n);
flint_printf("a = "), fmpq_poly_print(a), flint_printf("\n\n");
flint_printf("b = "), fmpq_poly_print(b), flint_printf("\n\n");
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,121 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("revert_series....");
fflush(stdout);
/* Check aliasing */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
fmpq_poly_t f, g;
slong n;
fmpq_poly_init(f);
fmpq_poly_init(g);
do {
fmpq_poly_randtest(g, state, n_randint(state, 50), 1+n_randint(state,100));
} while (fmpq_poly_length(g) < 2 || fmpz_is_zero(g->coeffs + 1));
fmpq_poly_set_coeff_ui(g, 0, 0);
n = n_randint(state, 50);
fmpq_poly_revert_series(f, g, n);
fmpq_poly_revert_series(g, g, n);
result = (fmpq_poly_equal(f, g));
if (!result)
{
flint_printf("FAIL (aliasing):\n");
fmpq_poly_print(f), flint_printf("\n\n");
fmpq_poly_print(g), flint_printf("\n\n");
abort();
}
fmpq_poly_clear(f);
fmpq_poly_clear(g);
}
/* Check f(f^(-1)) = id */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
fmpq_poly_t f, g, h;
slong n;
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_init(h);
do {
if (n_randint(state, 20) == 0)
fmpq_poly_randtest(g, state,
n_randint(state, 50), 1);
else
fmpq_poly_randtest(g, state,
n_randint(state, 50), 1+n_randint(state,100));
} while (fmpq_poly_length(g) < 2 || fmpz_is_zero(g->coeffs + 1));
fmpq_poly_set_coeff_ui(g, 0, 0);
n = n_randint(state, 50);
fmpq_poly_revert_series(f, g, n);
fmpq_poly_compose_series(h, g, f, n);
result = ((n <= 1 && fmpq_poly_is_zero(h)) ||
(h->length == 2 && fmpz_is_zero(h->coeffs + 0) &&
fmpz_is_one(h->coeffs + 1)));
if (!result)
{
flint_printf("FAIL (comparison):\n");
fmpq_poly_print(f), flint_printf("\n\n");
fmpq_poly_print(g), flint_printf("\n\n");
fmpq_poly_print(h), flint_printf("\n\n");
abort();
}
fmpq_poly_clear(f);
fmpq_poly_clear(g);
fmpq_poly_clear(h);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,121 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("revert_series_lagrange....");
fflush(stdout);
/* Check aliasing */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
fmpq_poly_t f, g;
slong n;
fmpq_poly_init(f);
fmpq_poly_init(g);
do {
fmpq_poly_randtest(g, state, n_randint(state, 50), 1+n_randint(state,100));
} while (fmpq_poly_length(g) < 2 || fmpz_is_zero(g->coeffs + 1));
fmpq_poly_set_coeff_ui(g, 0, 0);
n = n_randint(state, 50);
fmpq_poly_revert_series_lagrange(f, g, n);
fmpq_poly_revert_series_lagrange(g, g, n);
result = (fmpq_poly_equal(f, g));
if (!result)
{
flint_printf("FAIL (aliasing):\n");
fmpq_poly_print(f), flint_printf("\n\n");
fmpq_poly_print(g), flint_printf("\n\n");
abort();
}
fmpq_poly_clear(f);
fmpq_poly_clear(g);
}
/* Check f(f^(-1)) = id */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
fmpq_poly_t f, g, h;
slong n;
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_init(h);
do {
if (n_randint(state, 20) == 0)
fmpq_poly_randtest(g, state,
n_randint(state, 50), 1);
else
fmpq_poly_randtest(g, state,
n_randint(state, 50), 1+n_randint(state,100));
} while (fmpq_poly_length(g) < 2 || fmpz_is_zero(g->coeffs + 1));
fmpq_poly_set_coeff_ui(g, 0, 0);
n = n_randint(state, 50);
fmpq_poly_revert_series_lagrange(f, g, n);
fmpq_poly_compose_series(h, g, f, n);
result = ((n <= 1 && fmpq_poly_is_zero(h)) ||
(h->length == 2 && fmpz_is_zero(h->coeffs + 0) &&
fmpz_is_one(h->coeffs + 1)));
if (!result)
{
flint_printf("FAIL (comparison):\n");
fmpq_poly_print(f), flint_printf("\n\n");
fmpq_poly_print(g), flint_printf("\n\n");
fmpq_poly_print(h), flint_printf("\n\n");
abort();
}
fmpq_poly_clear(f);
fmpq_poly_clear(g);
fmpq_poly_clear(h);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,121 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("revert_series_lagrange_fast....");
fflush(stdout);
/* Check aliasing */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
fmpq_poly_t f, g;
slong n;
fmpq_poly_init(f);
fmpq_poly_init(g);
do {
fmpq_poly_randtest(g, state, n_randint(state, 50), 1+n_randint(state,100));
} while (fmpq_poly_length(g) < 2 || fmpz_is_zero(g->coeffs + 1));
fmpq_poly_set_coeff_ui(g, 0, 0);
n = n_randint(state, 50);
fmpq_poly_revert_series_lagrange_fast(f, g, n);
fmpq_poly_revert_series_lagrange_fast(g, g, n);
result = (fmpq_poly_equal(f, g));
if (!result)
{
flint_printf("FAIL (aliasing):\n");
fmpq_poly_print(f), flint_printf("\n\n");
fmpq_poly_print(g), flint_printf("\n\n");
abort();
}
fmpq_poly_clear(f);
fmpq_poly_clear(g);
}
/* Check f(f^(-1)) = id */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
fmpq_poly_t f, g, h;
slong n;
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_init(h);
do {
if (n_randint(state, 20) == 0)
fmpq_poly_randtest(g, state,
n_randint(state, 50), 1);
else
fmpq_poly_randtest(g, state,
n_randint(state, 50), 1+n_randint(state,100));
} while (fmpq_poly_length(g) < 2 || fmpz_is_zero(g->coeffs + 1));
fmpq_poly_set_coeff_ui(g, 0, 0);
n = n_randint(state, 50);
fmpq_poly_revert_series_lagrange_fast(f, g, n);
fmpq_poly_compose_series(h, g, f, n);
result = ((n <= 1 && fmpq_poly_is_zero(h)) ||
(h->length == 2 && fmpz_is_zero(h->coeffs + 0) &&
fmpz_is_one(h->coeffs + 1)));
if (!result)
{
flint_printf("FAIL (comparison):\n");
fmpq_poly_print(f), flint_printf("\n\n");
fmpq_poly_print(g), flint_printf("\n\n");
fmpq_poly_print(h), flint_printf("\n\n");
abort();
}
fmpq_poly_clear(f);
fmpq_poly_clear(g);
fmpq_poly_clear(h);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,121 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
FLINT_TEST_INIT(state);
flint_printf("revert_series_newton....");
fflush(stdout);
/* Check aliasing */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
fmpq_poly_t f, g;
slong n;
fmpq_poly_init(f);
fmpq_poly_init(g);
do {
fmpq_poly_randtest(g, state, n_randint(state, 50), 1+n_randint(state,100));
} while (fmpq_poly_length(g) < 2 || fmpz_is_zero(g->coeffs + 1));
fmpq_poly_set_coeff_ui(g, 0, 0);
n = n_randint(state, 50);
fmpq_poly_revert_series_newton(f, g, n);
fmpq_poly_revert_series_newton(g, g, n);
result = (fmpq_poly_equal(f, g));
if (!result)
{
flint_printf("FAIL (aliasing):\n");
fmpq_poly_print(f), flint_printf("\n\n");
fmpq_poly_print(g), flint_printf("\n\n");
abort();
}
fmpq_poly_clear(f);
fmpq_poly_clear(g);
}
/* Check f(f^(-1)) = id */
for (i = 0; i < 10 * flint_test_multiplier(); i++)
{
fmpq_poly_t f, g, h;
slong n;
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_init(h);
do {
if (n_randint(state, 20) == 0)
fmpq_poly_randtest(g, state,
n_randint(state, 50), 1);
else
fmpq_poly_randtest(g, state,
n_randint(state, 50), 1+n_randint(state,100));
} while (fmpq_poly_length(g) < 2 || fmpz_is_zero(g->coeffs + 1));
fmpq_poly_set_coeff_ui(g, 0, 0);
n = n_randint(state, 50);
fmpq_poly_revert_series_newton(f, g, n);
fmpq_poly_compose_series(h, g, f, n);
result = ((n <= 1 && fmpq_poly_is_zero(h)) ||
(h->length == 2 && fmpz_is_zero(h->coeffs + 0) &&
fmpz_is_one(h->coeffs + 1)));
if (!result)
{
flint_printf("FAIL (comparison):\n");
fmpq_poly_print(f), flint_printf("\n\n");
fmpq_poly_print(g), flint_printf("\n\n");
fmpq_poly_print(h), flint_printf("\n\n");
abort();
}
fmpq_poly_clear(f);
fmpq_poly_clear(g);
fmpq_poly_clear(h);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,176 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "long_extras.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("scalar_div_fmpq....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
fmpq_t z;
fmpq_init(z);
fmpq_randtest_not_zero(z, state, 100);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_scalar_div_fmpq(b, a, z);
fmpq_poly_scalar_div_fmpq(a, a, z);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL (aliasing):\n\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_print(z), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_clear(z);
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check that (a / n1) / n2 == a / (n1 * n2) */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, lhs, rhs;
fmpq_t z1, z2, z;
fmpq_init(z1);
fmpq_init(z2);
fmpq_init(z);
fmpq_randtest_not_zero(z1, state, 100);
fmpq_randtest_not_zero(z2, state, 100);
fmpq_mul(z, z1, z2);
fmpq_poly_init(a);
fmpq_poly_init(lhs);
fmpq_poly_init(rhs);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_scalar_div_fmpq(lhs, a, z1);
fmpq_poly_scalar_div_fmpq(lhs, lhs, z2);
fmpq_poly_scalar_div_fmpq(rhs, a, z);
cflags |= fmpq_poly_is_canonical(lhs) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(rhs) ? 0 : 2;
result = (fmpq_poly_equal(lhs, rhs) && !cflags);
if (!result)
{
flint_printf("FAIL (a / n1 / n2):\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_print(z1), flint_printf("\n\n");
fmpq_print(z2), flint_printf("\n\n");
fmpq_print(z), flint_printf("\n\n");
fmpq_poly_debug(lhs), flint_printf("\n\n");
fmpq_poly_debug(rhs), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_clear(z1);
fmpq_clear(z2);
fmpq_clear(z);
fmpq_poly_clear(a);
fmpq_poly_clear(lhs);
fmpq_poly_clear(rhs);
}
/* Check that (a + b) / n == a/n + b/n */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, lhs, rhs;
fmpq_t z;
fmpq_init(z);
fmpq_randtest_not_zero(z, state, 100);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(lhs);
fmpq_poly_init(rhs);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_randtest(b, state, n_randint(state, 100), 200);
fmpq_poly_scalar_div_fmpq(lhs, a, z);
fmpq_poly_scalar_div_fmpq(rhs, b, z);
fmpq_poly_add(rhs, lhs, rhs);
fmpq_poly_add(lhs, a, b);
fmpq_poly_scalar_div_fmpq(lhs, lhs, z);
cflags |= fmpq_poly_is_canonical(lhs) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(rhs) ? 0 : 2;
result = (fmpq_poly_equal(lhs, rhs) && !cflags);
if (!result)
{
flint_printf("FAIL ((a + b) / n):\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_print(z), flint_printf("\n\n");
fmpq_poly_debug(lhs), flint_printf("\n\n");
fmpq_poly_debug(rhs), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_clear(z);
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(lhs);
fmpq_poly_clear(rhs);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,216 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "long_extras.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("scalar_div_fmpz....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
fmpz_t n;
fmpz_init(n);
fmpz_randtest_not_zero(n, state, 200);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_scalar_div_fmpz(b, a, n);
fmpq_poly_scalar_div_fmpz(a, a, n);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL (aliasing):\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
fmpz_print(n);
abort();
}
fmpz_clear(n);
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Compare with fmpq_poly_scalar_mul_si */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c;
fmpz_t n1;
slong n;
n = z_randtest_not_zero(state);
fmpz_init(n1);
fmpz_set_si(n1, n);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_scalar_div_fmpz(b, a, n1);
fmpq_poly_scalar_div_si(c, a, n);
cflags |= fmpq_poly_is_canonical(b) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(c) ? 0 : 2;
result = (fmpq_poly_equal(b, c) && !cflags);
if (!result)
{
flint_printf("FAIL (comparison with _si):\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpz_print(n1), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(c), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpz_clear(n1);
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
}
/* Check that (a / n1) / n2 == a / (n1 * n2) */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, lhs, rhs;
fmpz_t n1, n2, n;
fmpz_init(n1);
fmpz_init(n2);
fmpz_init(n);
fmpz_randtest_not_zero(n1, state, 100);
fmpz_randtest_not_zero(n2, state, 100);
fmpz_mul(n, n1, n2);
fmpq_poly_init(a);
fmpq_poly_init(lhs);
fmpq_poly_init(rhs);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_scalar_div_fmpz(lhs, a, n1);
fmpq_poly_scalar_div_fmpz(lhs, lhs, n2);
fmpq_poly_scalar_div_fmpz(rhs, a, n);
cflags |= fmpq_poly_is_canonical(lhs) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(rhs) ? 0 : 2;
result = (fmpq_poly_equal(lhs, rhs) && !cflags);
if (!result)
{
flint_printf("FAIL (a / n1 / n2):\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpz_print(n1), flint_printf("\n\n");
fmpz_print(n2), flint_printf("\n\n");
fmpz_print(n), flint_printf("\n\n");
fmpq_poly_debug(lhs), flint_printf("\n\n");
fmpq_poly_debug(rhs), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpz_clear(n1);
fmpz_clear(n2);
fmpz_clear(n);
fmpq_poly_clear(a);
fmpq_poly_clear(lhs);
fmpq_poly_clear(rhs);
}
/* Check that (a + b) / n == a/n + b/n */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, lhs, rhs;
fmpz_t n;
fmpz_init(n);
fmpz_randtest_not_zero(n, state, 100);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(lhs);
fmpq_poly_init(rhs);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_randtest(b, state, n_randint(state, 100), 200);
fmpq_poly_scalar_div_fmpz(lhs, a, n);
fmpq_poly_scalar_div_fmpz(rhs, b, n);
fmpq_poly_add(rhs, lhs, rhs);
fmpq_poly_add(lhs, a, b);
fmpq_poly_scalar_div_fmpz(lhs, lhs, n);
cflags |= fmpq_poly_is_canonical(lhs) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(rhs) ? 0 : 2;
result = (fmpq_poly_equal(lhs, rhs) && !cflags);
if (!result)
{
flint_printf("FAIL ((a + b) / n):\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpz_print(n), flint_printf("\n\n");
fmpq_poly_debug(lhs), flint_printf("\n\n");
fmpq_poly_debug(rhs), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpz_clear(n);
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(lhs);
fmpq_poly_clear(rhs);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,208 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "long_extras.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("scalar_div_mpq....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
fmpz_t r, s;
mpq_t z;
mpq_init(z);
fmpz_init(r);
fmpz_init(s);
fmpz_randtest_not_zero(r, state, 100);
fmpz_randtest_not_zero(s, state, 100);
fmpz_get_mpz(mpq_numref(z), r);
fmpz_get_mpz(mpq_denref(z), s);
mpq_canonicalize(z);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_scalar_div_mpq(b, a, z);
fmpq_poly_scalar_div_mpq(a, a, z);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL (aliasing):\n\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
gmp_printf("z = %Qd\n\n", z);
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
mpq_clear(z);
fmpz_clear(r);
fmpz_clear(s);
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check that (a / n1) / n2 == a / (n1 * n2) */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, lhs, rhs;
fmpz_t r, s;
mpq_t z1, z2, z;
fmpz_init(r);
fmpz_init(s);
mpq_init(z1);
mpq_init(z2);
mpq_init(z);
fmpz_randtest_not_zero(r, state, 100);
fmpz_randtest_not_zero(s, state, 100);
fmpz_get_mpz(mpq_numref(z1), r);
fmpz_get_mpz(mpq_denref(z1), s);
mpq_canonicalize(z1);
fmpz_randtest_not_zero(r, state, 100);
fmpz_randtest_not_zero(s, state, 100);
fmpz_get_mpz(mpq_numref(z2), r);
fmpz_get_mpz(mpq_denref(z2), s);
mpq_canonicalize(z2);
mpq_mul(z, z1, z2);
fmpq_poly_init(a);
fmpq_poly_init(lhs);
fmpq_poly_init(rhs);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_scalar_div_mpq(lhs, a, z1);
fmpq_poly_scalar_div_mpq(lhs, lhs, z2);
fmpq_poly_scalar_div_mpq(rhs, a, z);
cflags |= fmpq_poly_is_canonical(lhs) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(rhs) ? 0 : 2;
result = (fmpq_poly_equal(lhs, rhs) && !cflags);
if (!result)
{
flint_printf("FAIL (a / n1 / n2):\n");
fmpq_poly_debug(a), flint_printf("\n\n");
gmp_printf("z1 = %Qd\n\n", z1);
gmp_printf("z2 = %Qd\n\n", z2);
gmp_printf("z = %Qd\n\n", z);
fmpq_poly_debug(lhs), flint_printf("\n\n");
fmpq_poly_debug(rhs), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
mpq_clear(z1);
mpq_clear(z2);
mpq_clear(z);
fmpz_clear(r);
fmpz_clear(s);
fmpq_poly_clear(a);
fmpq_poly_clear(lhs);
fmpq_poly_clear(rhs);
}
/* Check that (a + b) / n == a/n + b/n */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, lhs, rhs;
fmpz_t r, s;
mpq_t z;
fmpz_init(r);
fmpz_init(s);
mpq_init(z);
fmpz_randtest_not_zero(r, state, 100);
fmpz_randtest_not_zero(s, state, 100);
fmpz_get_mpz(mpq_numref(z), r);
fmpz_get_mpz(mpq_denref(z), s);
mpq_canonicalize(z);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(lhs);
fmpq_poly_init(rhs);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_randtest(b, state, n_randint(state, 100), 200);
fmpq_poly_scalar_div_mpq(lhs, a, z);
fmpq_poly_scalar_div_mpq(rhs, b, z);
fmpq_poly_add(rhs, lhs, rhs);
fmpq_poly_add(lhs, a, b);
fmpq_poly_scalar_div_mpq(lhs, lhs, z);
cflags |= fmpq_poly_is_canonical(lhs) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(rhs) ? 0 : 2;
result = (fmpq_poly_equal(lhs, rhs) && !cflags);
if (!result)
{
flint_printf("FAIL ((a + b) / n):\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
gmp_printf("z = %Qd\n\n", z);
fmpq_poly_debug(lhs), flint_printf("\n\n");
fmpq_poly_debug(rhs), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
mpq_clear(z);
fmpz_clear(r);
fmpz_clear(s);
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(lhs);
fmpq_poly_clear(rhs);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,230 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "long_extras.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("scalar_div_mpz....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
fmpz_t n;
mpz_t m;
fmpz_init(n);
mpz_init(m);
fmpz_randtest_not_zero(n, state, 200);
fmpz_get_mpz(m, n);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_scalar_div_mpz(b, a, m);
fmpq_poly_scalar_div_mpz(a, a, m);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL (aliasing):\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
fmpz_print(n);
abort();
}
fmpz_clear(n);
mpz_clear(m);
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Compare with fmpq_poly_scalar_mul_si */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c;
mpz_t n1;
slong n;
n = z_randtest_not_zero(state);
mpz_init(n1);
flint_mpz_set_si(n1, n);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_scalar_div_mpz(b, a, n1);
fmpq_poly_scalar_div_si(c, a, n);
cflags |= fmpq_poly_is_canonical(b) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(c) ? 0 : 2;
result = (fmpq_poly_equal(b, c) && !cflags);
if (!result)
{
flint_printf("FAIL (comparison with _si):\n");
fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("%wd", n), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(c), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
mpz_clear(n1);
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
}
/* Check that (a / n1) / n2 == a / (n1 * n2) */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, lhs, rhs;
fmpz_t n1, n2;
mpz_t m1, m2, m;
fmpz_init(n1);
fmpz_init(n2);
mpz_init(m1);
mpz_init(m2);
mpz_init(m);
fmpz_randtest_not_zero(n1, state, 100);
fmpz_randtest_not_zero(n2, state, 100);
fmpz_get_mpz(m1, n1);
fmpz_get_mpz(m2, n2);
mpz_mul(m, m1, m2);
fmpq_poly_init(a);
fmpq_poly_init(lhs);
fmpq_poly_init(rhs);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_scalar_div_mpz(lhs, a, m1);
fmpq_poly_scalar_div_mpz(lhs, lhs, m2);
fmpq_poly_scalar_div_mpz(rhs, a, m);
cflags |= fmpq_poly_is_canonical(lhs) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(rhs) ? 0 : 2;
result = (fmpq_poly_equal(lhs, rhs) && !cflags);
if (!result)
{
flint_printf("FAIL (a / n1 / n2):\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpz_print(n1), flint_printf("\n\n");
fmpz_print(n2), flint_printf("\n\n");
fmpq_poly_debug(lhs), flint_printf("\n\n");
fmpq_poly_debug(rhs), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpz_clear(n1);
fmpz_clear(n2);
mpz_clear(m1);
mpz_clear(m2);
mpz_clear(m);
fmpq_poly_clear(a);
fmpq_poly_clear(lhs);
fmpq_poly_clear(rhs);
}
/* Check that (a + b) / n == a/n + b/n */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, lhs, rhs;
fmpz_t n;
mpz_t m;
fmpz_init(n);
mpz_init(m);
fmpz_randtest_not_zero(n, state, 100);
fmpz_get_mpz(m, n);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(lhs);
fmpq_poly_init(rhs);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_randtest(b, state, n_randint(state, 100), 200);
fmpq_poly_scalar_div_mpz(lhs, a, m);
fmpq_poly_scalar_div_mpz(rhs, b, m);
fmpq_poly_add(rhs, lhs, rhs);
fmpq_poly_add(lhs, a, b);
fmpq_poly_scalar_div_mpz(lhs, lhs, m);
cflags |= fmpq_poly_is_canonical(lhs) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(rhs) ? 0 : 2;
result = (fmpq_poly_equal(lhs, rhs) && !cflags);
if (!result)
{
flint_printf("FAIL ((a + b) / n):\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpz_print(n), flint_printf("\n\n");
fmpq_poly_debug(lhs), flint_printf("\n\n");
fmpq_poly_debug(rhs), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpz_clear(n);
mpz_clear(m);
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(lhs);
fmpq_poly_clear(rhs);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,160 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "long_extras.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("scalar_div_si....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
slong n;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
n = z_randtest_not_zero(state);
fmpq_poly_scalar_div_si(b, a, n);
fmpq_poly_scalar_div_si(a, a, n);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Compare with fmpq_poly_scalar_div_ui */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
ulong n;
n = n_randtest_not_zero(state);
if (n > WORD_MAX)
n >>= 1;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_scalar_div_ui(b, a, n);
fmpq_poly_scalar_div_si(a, a, n);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check (a / n1) / n2 == a / (n1 * n2) */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c;
slong n1, n2;
ulong m;
while ((n1 = (slong) n_randbits(state, FLINT_BITS / 2)) == 0) ;
while ((n2 = (slong) n_randbits(state, FLINT_BITS / 2 - 1)) == 0) ;
m = n_randlimb(state);
if (m & UWORD(1))
n1 = -n1;
if (m & UWORD(2))
n2 = -n2;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_scalar_div_si(b, a, n1);
fmpq_poly_scalar_div_si(c, b, n2);
fmpq_poly_scalar_div_si(b, a, n1 * n2);
cflags |= fmpq_poly_is_canonical(b) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(c) ? 0 : 2;
result = (fmpq_poly_equal(b, c) && !cflags);
if (!result)
{
flint_printf("FAIL:\n\n");
flint_printf("n1 = %wu, n2 = %wu:\n\n", n1, n2);
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(c), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,118 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("scalar_div_ui....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
ulong n = n_randtest_not_zero(state);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_scalar_div_ui(b, a, n);
fmpq_poly_scalar_div_ui(a, a, n);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check (a / n1) / n2 = a / (n1 * n2) */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c;
ulong n1 = n_randbits(state, FLINT_BITS / 2);
ulong n2 = n_randbits(state, FLINT_BITS / 2);
if (n1 == UWORD(0))
n1 = UWORD(1);
if (n2 == UWORD(0))
n2 = UWORD(1);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_scalar_div_ui(b, a, n1);
fmpq_poly_scalar_div_ui(c, b, n2);
fmpq_poly_scalar_div_ui(b, a, n1 * n2);
cflags |= fmpq_poly_is_canonical(b) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(c) ? 0 : 2;
result = (fmpq_poly_equal(b, c) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf(" n1 = %wu, n2 = %wu:\n\n", n1, n2);
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(c), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,179 @@
/*=============================================================================
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
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "long_extras.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("scalar_mul_fmpq....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
fmpq_t z;
fmpq_init(z);
fmpq_randtest(z, state, 100);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_scalar_mul_fmpq(b, a, z);
fmpq_poly_scalar_mul_fmpq(a, a, z);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL (aliasing):\n\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("b = "), fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("z = "), fmpq_print(z), flint_printf("\n\n");
gmp_printf("z = %Qd\n\n", z);
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_clear(z);
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check that (a * n1) * n2 == a * (n1 * n2) */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, lhs, rhs;
fmpq_t z1, z2, z;
fmpq_init(z1);
fmpq_init(z2);
fmpq_init(z);
fmpq_randtest(z1, state, 100);
fmpq_randtest(z2, state, 100);
fmpq_mul(z, z1, z2);
fmpq_poly_init(a);
fmpq_poly_init(lhs);
fmpq_poly_init(rhs);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_scalar_mul_fmpq(lhs, a, z1);
fmpq_poly_scalar_mul_fmpq(lhs, lhs, z2);
fmpq_poly_scalar_mul_fmpq(rhs, a, z);
cflags |= fmpq_poly_is_canonical(lhs) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(rhs) ? 0 : 2;
result = (fmpq_poly_equal(lhs, rhs) && !cflags);
if (!result)
{
flint_printf("FAIL (a * n1 * n2):\n");
fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("z1 = "), fmpq_print(z1), flint_printf("\n\n");
flint_printf("z2 = "), fmpq_print(z2), flint_printf("\n\n");
flint_printf("z = "), fmpq_print(z), flint_printf("\n\n");
fmpq_poly_debug(lhs), flint_printf("\n\n");
fmpq_poly_debug(rhs), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_clear(z1);
fmpq_clear(z2);
fmpq_clear(z);
fmpq_poly_clear(a);
fmpq_poly_clear(lhs);
fmpq_poly_clear(rhs);
}
/* Check that (a + b) * n == a*n + b*n */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, lhs, rhs;
fmpq_t z;
fmpq_init(z);
fmpq_randtest(z, state, 100);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(lhs);
fmpq_poly_init(rhs);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_randtest(b, state, n_randint(state, 100), 200);
fmpq_poly_scalar_mul_fmpq(lhs, a, z);
fmpq_poly_scalar_mul_fmpq(rhs, b, z);
fmpq_poly_add(rhs, lhs, rhs);
fmpq_poly_add(lhs, a, b);
fmpq_poly_scalar_mul_fmpq(lhs, lhs, z);
cflags |= fmpq_poly_is_canonical(lhs) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(rhs) ? 0 : 2;
result = (fmpq_poly_equal(lhs, rhs) && !cflags);
if (!result)
{
flint_printf("FAIL ((a + b) / n):\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("z = "), fmpq_print(z), flint_printf("\n\n");
fmpq_poly_debug(lhs), flint_printf("\n\n");
fmpq_poly_debug(rhs), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_clear(z);
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(lhs);
fmpq_poly_clear(rhs);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

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

View File

@@ -0,0 +1,208 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "long_extras.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("scalar_mul_mpq....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
fmpz_t r, s;
mpq_t z;
mpq_init(z);
fmpz_init(r);
fmpz_init(s);
fmpz_randtest(r, state, 100);
fmpz_randtest_not_zero(s, state, 100);
fmpz_get_mpz(mpq_numref(z), r);
fmpz_get_mpz(mpq_denref(z), s);
mpq_canonicalize(z);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_scalar_mul_mpq(b, a, z);
fmpq_poly_scalar_mul_mpq(a, a, z);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL (aliasing):\n\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
gmp_printf("z = %Qd\n\n", z);
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
mpq_clear(z);
fmpz_clear(r);
fmpz_clear(s);
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check that (a * n1) * n2 == a * (n1 * n2) */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, lhs, rhs;
fmpz_t r, s;
mpq_t z1, z2, z;
fmpz_init(r);
fmpz_init(s);
mpq_init(z1);
mpq_init(z2);
mpq_init(z);
fmpz_randtest(r, state, 100);
fmpz_randtest_not_zero(s, state, 100);
fmpz_get_mpz(mpq_numref(z1), r);
fmpz_get_mpz(mpq_denref(z1), s);
mpq_canonicalize(z1);
fmpz_randtest(r, state, 100);
fmpz_randtest_not_zero(s, state, 100);
fmpz_get_mpz(mpq_numref(z2), r);
fmpz_get_mpz(mpq_denref(z2), s);
mpq_canonicalize(z2);
mpq_mul(z, z1, z2);
fmpq_poly_init(a);
fmpq_poly_init(lhs);
fmpq_poly_init(rhs);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_scalar_mul_mpq(lhs, a, z1);
fmpq_poly_scalar_mul_mpq(lhs, lhs, z2);
fmpq_poly_scalar_mul_mpq(rhs, a, z);
cflags |= fmpq_poly_is_canonical(lhs) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(rhs) ? 0 : 2;
result = (fmpq_poly_equal(lhs, rhs) && !cflags);
if (!result)
{
flint_printf("FAIL (a * n1 * n2):\n");
fmpq_poly_debug(a), flint_printf("\n\n");
gmp_printf("z1 = %Qd\n\n", z1);
gmp_printf("z2 = %Qd\n\n", z2);
gmp_printf("z = %Qd\n\n", z);
fmpq_poly_debug(lhs), flint_printf("\n\n");
fmpq_poly_debug(rhs), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
mpq_clear(z1);
mpq_clear(z2);
mpq_clear(z);
fmpz_clear(r);
fmpz_clear(s);
fmpq_poly_clear(a);
fmpq_poly_clear(lhs);
fmpq_poly_clear(rhs);
}
/* Check that (a + b) * n == a*n + b*n */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, lhs, rhs;
fmpz_t r, s;
mpq_t z;
fmpz_init(r);
fmpz_init(s);
mpq_init(z);
fmpz_randtest(r, state, 100);
fmpz_randtest_not_zero(s, state, 100);
fmpz_get_mpz(mpq_numref(z), r);
fmpz_get_mpz(mpq_denref(z), s);
mpq_canonicalize(z);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(lhs);
fmpq_poly_init(rhs);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_randtest(b, state, n_randint(state, 100), 200);
fmpq_poly_scalar_mul_mpq(lhs, a, z);
fmpq_poly_scalar_mul_mpq(rhs, b, z);
fmpq_poly_add(rhs, lhs, rhs);
fmpq_poly_add(lhs, a, b);
fmpq_poly_scalar_mul_mpq(lhs, lhs, z);
cflags |= fmpq_poly_is_canonical(lhs) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(rhs) ? 0 : 2;
result = (fmpq_poly_equal(lhs, rhs) && !cflags);
if (!result)
{
flint_printf("FAIL ((a + b) / n):\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
gmp_printf("z = %Qd\n\n", z);
fmpq_poly_debug(lhs), flint_printf("\n\n");
fmpq_poly_debug(rhs), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
mpq_clear(z);
fmpz_clear(r);
fmpz_clear(s);
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(lhs);
fmpq_poly_clear(rhs);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,168 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "long_extras.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("scalar_mul_mpz....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
fmpz_t n;
mpz_t m;
fmpz_init(n);
mpz_init(m);
fmpz_randtest(n, state, 200);
fmpz_get_mpz(m, n);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest(a, state, n_randint(state, 100), n_randint(state, 200));
fmpq_poly_scalar_mul_mpz(b, a, m);
fmpq_poly_scalar_mul_mpz(a, a, m);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpz_clear(n);
mpz_clear(m);
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check that n (a + b) == na + nb */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, lhs, rhs;
fmpz_t n;
mpz_t m;
fmpz_init(n);
mpz_init(m);
fmpz_randtest(n, state, 200);
fmpz_get_mpz(m, n);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(lhs);
fmpq_poly_init(rhs);
fmpq_poly_randtest(a, state, n_randint(state, 100), n_randint(state, 200));
fmpq_poly_randtest(b, state, n_randint(state, 100), n_randint(state, 200));
fmpq_poly_scalar_mul_mpz(lhs, a, m);
fmpq_poly_scalar_mul_mpz(rhs, b, m);
fmpq_poly_add(rhs, lhs, rhs);
fmpq_poly_add(lhs, a, b);
fmpq_poly_scalar_mul_mpz(lhs, lhs, m);
cflags |= fmpq_poly_is_canonical(lhs) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(rhs) ? 0 : 2;
result = (fmpq_poly_equal(lhs, rhs) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpz_clear(n);
mpz_clear(m);
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(lhs);
fmpq_poly_clear(rhs);
}
/* Compare with fmpq_poly_scalar_mul_si */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
mpz_t n1;
slong n;
n = z_randtest(state);
mpz_init(n1);
flint_mpz_set_si(n1, n);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest(a, state, n_randint(state, 100), n_randint(state, 200));
fmpq_poly_scalar_mul_mpz(b, a, n1);
fmpq_poly_scalar_mul_si(a, a, n);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
mpz_clear(n1);
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,152 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "long_extras.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("scalar_mul_si....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
slong n = z_randtest(state);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest(a, state, n_randint(state, 100), n_randint(state, 200));
fmpq_poly_scalar_mul_si(b, a, n);
fmpq_poly_scalar_mul_si(a, a, n);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Compare with fmpq_poly_scalar_mul_ui */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
ulong n = n_randbits(state, FLINT_BITS - 1);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest(a, state, n_randint(state, 100), n_randint(state, 200));
fmpq_poly_scalar_mul_ui(b, a, n);
fmpq_poly_scalar_mul_si(a, a, n);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check n2 * (n1 a) == (n1*n2) a */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c;
slong n1, n2;
ulong m;
n1 = (slong) n_randbits(state, FLINT_BITS / 2);
n2 = (slong) n_randbits(state, FLINT_BITS / 2 - 1);
m = n_randlimb(state);
if (m & UWORD(1))
n1 = -n1;
if (m & UWORD(2))
n2 = -n2;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_randtest(a, state, n_randint(state, 100), n_randint(state, 200));
fmpq_poly_scalar_mul_si(b, a, n1);
fmpq_poly_scalar_mul_si(c, b, n2);
fmpq_poly_scalar_mul_si(b, a, n1 * n2);
cflags |= fmpq_poly_is_canonical(b) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(c) ? 0 : 2;
result = (fmpq_poly_equal(b, c) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("n1 = %wu, n2 = %wu:\n\n", n1, n2);
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(c), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,154 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("scalar_mul_ui....");
fflush(stdout);
/* Check aliasing of a and b */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
ulong n = n_randtest(state);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest(a, state, n_randint(state, 100), n_randint(state, 200));
fmpq_poly_scalar_mul_ui(b, a, n);
fmpq_poly_scalar_mul_ui(a, a, n);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check that (a + b) * n == a * n + b * n */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, lhs, rhs;
ulong n = n_randtest(state);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(lhs);
fmpq_poly_init(rhs);
fmpq_poly_randtest(a, state, n_randint(state, 100), n_randint(state, 200));
fmpq_poly_randtest(b, state, n_randint(state, 100), n_randint(state, 200));
fmpq_poly_scalar_mul_ui(lhs, a, n);
fmpq_poly_scalar_mul_ui(rhs, b, n);
fmpq_poly_add(rhs, lhs, rhs);
fmpq_poly_add(lhs, a, b);
fmpq_poly_scalar_mul_ui(lhs, lhs, n);
cflags |= fmpq_poly_is_canonical(lhs) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(rhs) ? 0 : 2;
result = (fmpq_poly_equal(lhs, rhs) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("%li\n\n", n);
fmpq_poly_debug(lhs), flint_printf("\n\n");
fmpq_poly_debug(rhs), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(lhs);
fmpq_poly_clear(rhs);
}
/* Check (a * n1) * n2 = a * (n1 * n2) */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c;
ulong n1 = n_randbits(state, FLINT_BITS / 2);
ulong n2 = n_randbits(state, FLINT_BITS / 2);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_randtest(a, state, n_randint(state, 100), n_randint(state, 200));
fmpq_poly_scalar_mul_ui(b, a, n1);
fmpq_poly_scalar_mul_ui(c, b, n2);
fmpq_poly_scalar_mul_ui(b, a, n1 * n2);
cflags |= fmpq_poly_is_canonical(b) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(c) ? 0 : 2;
result = (fmpq_poly_equal(b, c) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("n1 = %wu, n2 = %wu:\n\n", n1, n2);
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(c), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,86 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("set_array_mpq....");
fflush(stdout);
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
slong j, n = 100;
fmpq_poly_t f, g;
mpq_t * a;
a = (mpq_t *) flint_malloc(n * sizeof(mpq_t));
for (j = 0; j < n; j++)
mpq_init(a[j]);
fmpq_poly_init(f);
fmpq_poly_init(g);
fmpq_poly_randtest(f, state, n_randint(state, n), 200);
for (j = 0; j < f->length; j++)
fmpq_poly_get_coeff_mpq(a[j], f, j);
fmpq_poly_set_array_mpq(g, (const mpq_t *) a, n);
cflags |= fmpq_poly_is_canonical(g) ? 0 : 1;
result = (fmpq_poly_equal(f, g) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("f = "), fmpq_poly_debug(f), flint_printf("\n\n");
flint_printf("g = "), fmpq_poly_debug(g), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(f);
fmpq_poly_clear(g);
for (j = 0; j < n; j++)
mpq_clear(a[j]);
flint_free(a);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,121 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2010 Sebastian Pancratz
Copyright (C) 2009 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_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 < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_set(b, a);
result = (fmpq_poly_equal(a, b));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n");
flint_printf("alloc = %wd\nlength = %wd\n\n", a->alloc, a->length);
flint_printf("b = "), fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("alloc = %wd\nlength = %wd\n\n", b->alloc, b->length);
flint_printf("equal(a, b) = %d\n", result);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
slong coeff = (slong) n_randint(state, 100);
mpq_t x1, x2;
fmpz_t x1fmpz;
mpq_init(x1);
mpq_init(x2);
fmpz_init(x1fmpz);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_set(b, a);
fmpq_poly_get_coeff_mpq(x2, b, coeff);
do
{
fmpz_randtest(x1fmpz, state, 200);
fmpz_get_mpz(mpq_numref(x1), x1fmpz);
flint_mpz_set_si(mpq_denref(x1), 1);
} while (mpq_equal(x1, x2));
fmpq_poly_set_coeff_mpq(b, coeff, x1);
result = (!fmpq_poly_equal(a, b));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n");
flint_printf("alloc = %wd\nlength = %wd\n\n", a->alloc, a->length);
flint_printf("b = "), fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("alloc = %wd\nlength = %wd\n\n", b->alloc, b->length);
flint_printf("!equal(a, b) = %d\n", result);
abort();
}
mpq_clear(x1);
mpq_clear(x2);
fmpz_clear(x1fmpz);
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,142 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("shift_left/right....");
fflush(stdout);
/* Check aliasing of a and b for left shift */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
slong shift = (slong) n_randint(state, 100);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_shift_left(b, a, shift);
fmpq_poly_shift_left(a, a, shift);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check aliasing of a and b for right shift */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
slong shift;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest_not_zero(a, state, n_randint(state, 100) + 1, 200);
shift = (slong) n_randint(state, a->length);
fmpq_poly_shift_right(b, a, shift);
fmpq_poly_shift_right(a, a, shift);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check shift left then right does nothing */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c;
slong shift = (slong) n_randint(state, 100);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_shift_left(b, a, shift);
fmpq_poly_shift_right(c, b, shift);
cflags |= fmpq_poly_is_canonical(b) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(c) ? 0 : 2;
result = (fmpq_poly_equal(c, a) && !cflags);
if (!result)
{
flint_printf("FAIL:\n\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(c), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,120 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("sin_series....");
fflush(stdout);
/* Check aliasing of a and c */
for (i = 0; i < 20 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
slong n = n_randint(state, 50) + 1;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest_not_zero(a, state, n_randint(state, 50) + 1, 50);
fmpq_poly_set_coeff_ui(a, 0, UWORD(0));
fmpq_poly_canonicalise(a);
fmpq_poly_sin_series(b, a, n);
fmpq_poly_sin_series(a, a, n);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check asin(sin(a)) = a */
for (i = 0; i < 20 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, sina, asinsina;
slong n = n_randint(state, 80) + 1;
fmpq_poly_init(a);
fmpq_poly_init(sina);
fmpq_poly_init(asinsina);
fmpq_poly_randtest_not_zero(a, state, n_randint(state, 60) + 1, 80);
fmpq_poly_set_coeff_ui(a, 0, UWORD(0));
fmpq_poly_sin_series(sina, a, n);
fmpq_poly_asin_series(asinsina, sina, n);
fmpq_poly_truncate(a, n);
cflags |= fmpq_poly_is_canonical(sina) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(asinsina) ? 0 : 2;
result = (fmpq_poly_equal(asinsina, a) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("sin(a) = "), fmpq_poly_debug(sina), flint_printf("\n\n");
flint_printf("asin(sin(a)) = "), fmpq_poly_debug(asinsina), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(sina);
fmpq_poly_clear(asinsina);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,120 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("sinh_series....");
fflush(stdout);
/* Check aliasing of a and c */
for (i = 0; i < 20 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
slong n = n_randint(state, 50) + 1;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest_not_zero(a, state, n_randint(state, 50) + 1, 50);
fmpq_poly_set_coeff_ui(a, 0, UWORD(0));
fmpq_poly_canonicalise(a);
fmpq_poly_sinh_series(b, a, n);
fmpq_poly_sinh_series(a, a, n);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check asinh(sinh(a)) = a */
for (i = 0; i < 20 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, sinha, asinhsinha;
slong n = n_randint(state, 80) + 1;
fmpq_poly_init(a);
fmpq_poly_init(sinha);
fmpq_poly_init(asinhsinha);
fmpq_poly_randtest_not_zero(a, state, n_randint(state, 60) + 1, 80);
fmpq_poly_set_coeff_ui(a, 0, UWORD(0));
fmpq_poly_sinh_series(sinha, a, n);
fmpq_poly_asinh_series(asinhsinha, sinha, n);
fmpq_poly_truncate(a, n);
cflags |= fmpq_poly_is_canonical(sinha) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(asinhsinha) ? 0 : 2;
result = (fmpq_poly_equal(asinhsinha, a) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("sinh(a) = "), fmpq_poly_debug(sinha), flint_printf("\n\n");
flint_printf("asinh(sinh(a)) = "), fmpq_poly_debug(asinhsinha), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(sinha);
fmpq_poly_clear(asinhsinha);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,119 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("sqrt_series....");
fflush(stdout);
/* Check aliasing of a and c */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
slong n = n_randint(state, 50) + 1;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest_not_zero(a, state, n_randint(state, 50) + 1, 50);
fmpq_poly_set_coeff_ui(a, 0, UWORD(1));
fmpq_poly_canonicalise(a);
fmpq_poly_sqrt_series(b, a, n);
fmpq_poly_sqrt_series(a, a, n);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check sqrt(a)^2 = a */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c;
slong n = n_randint(state, 80) + 1;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_randtest_not_zero(a, state, n_randint(state, 80) + 1, 80);
fmpq_poly_set_coeff_ui(a, 0, UWORD(1));
fmpq_poly_sqrt_series(b, a, n);
fmpq_poly_mullow(c, b, b, n);
fmpq_poly_truncate(a, n);
cflags |= fmpq_poly_is_canonical(b) ? 0 : 1;
result = (fmpq_poly_equal(c, a) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("b = "), fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("c = "), fmpq_poly_debug(c), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,150 @@
/*=============================================================================
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
Copyright (C) 2009 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("sub....");
fflush(stdout);
/* Check a - b = a + neg(b) */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c, d;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_init(d);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_randtest(b, state, n_randint(state, 100), 200);
fmpq_poly_sub(c, a, b);
fmpq_poly_neg(b, b);
fmpq_poly_add(d, a, b);
cflags |= fmpq_poly_is_canonical(c) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(d) ? 0 : 2;
result = (fmpq_poly_equal(c, d) && !cflags);
if (!result)
{
flint_printf("FAIL:\n\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(c), flint_printf("\n\n");
fmpq_poly_debug(d), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
fmpq_poly_clear(d);
}
/* Check aliasing of a and c */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_randtest(b, state, n_randint(state, 100), 200);
fmpq_poly_sub(c, a, b);
fmpq_poly_sub(a, a, b);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(c) ? 0 : 2;
result = (fmpq_poly_equal(a, c) && !cflags);
if (!result)
{
flint_printf("FAIL:\n\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(c), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
}
/* Check aliasing of b and c */
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_randtest(b, state, n_randint(state, 100), 200);
fmpq_poly_sub(c, a, b);
fmpq_poly_sub(b, a, b);
cflags |= fmpq_poly_is_canonical(b) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(c) ? 0 : 2;
result = (fmpq_poly_equal(b, c) && !cflags);
if (!result)
{
flint_printf("FAIL:\n\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(c), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,78 @@
/*=============================================================================
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
Copyright (C) 2009 William Hart
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_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 < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
fmpq_poly_randtest(b, state, n_randint(state, 100), 200);
fmpq_poly_set(c, b);
fmpq_poly_swap(a, b);
result = (fmpq_poly_equal(a, c));
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(c), flint_printf("\n\n");
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,120 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("tan_series....");
fflush(stdout);
/* Check aliasing of a and c */
for (i = 0; i < 20 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
slong n = n_randint(state, 50) + 1;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest_not_zero(a, state, n_randint(state, 50) + 1, 50);
fmpq_poly_set_coeff_ui(a, 0, UWORD(0));
fmpq_poly_canonicalise(a);
fmpq_poly_tan_series(b, a, n);
fmpq_poly_tan_series(a, a, n);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check atan(tan(a)) = a */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, tana, atantana; /* but what is an atantana? */
slong n = n_randint(state, 80) + 1;
fmpq_poly_init(a);
fmpq_poly_init(tana);
fmpq_poly_init(atantana);
fmpq_poly_randtest_not_zero(a, state, n_randint(state, 60) + 1, 80);
fmpq_poly_set_coeff_ui(a, 0, UWORD(0));
fmpq_poly_tan_series(tana, a, n);
fmpq_poly_atan_series(atantana, tana, n);
fmpq_poly_truncate(a, n);
cflags |= fmpq_poly_is_canonical(tana) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(atantana) ? 0 : 2;
result = (fmpq_poly_equal(atantana, a) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("tan(a) = "), fmpq_poly_debug(tana), flint_printf("\n\n");
flint_printf("atan(tan(a)) = "), fmpq_poly_debug(atantana), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(tana);
fmpq_poly_clear(atantana);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,120 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2009 William Hart
Copyright (C) 2010 Sebastian Pancratz
Copyright (C) 2011 Fredrik Johansson
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int i, result;
ulong cflags = UWORD(0);
FLINT_TEST_INIT(state);
flint_printf("tanh_series....");
fflush(stdout);
/* Check aliasing of a and c */
for (i = 0; i < 20 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
slong n = n_randint(state, 50) + 1;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest_not_zero(a, state, n_randint(state, 50) + 1, 50);
fmpq_poly_set_coeff_ui(a, 0, UWORD(0));
fmpq_poly_canonicalise(a);
fmpq_poly_tanh_series(b, a, n);
fmpq_poly_tanh_series(a, a, n);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
/* Check atanh(tanh(a)) = a */
for (i = 0; i < 50 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, tanha, atanhtanha;
slong n = n_randint(state, 80) + 1;
fmpq_poly_init(a);
fmpq_poly_init(tanha);
fmpq_poly_init(atanhtanha);
fmpq_poly_randtest_not_zero(a, state, n_randint(state, 60) + 1, 80);
fmpq_poly_set_coeff_ui(a, 0, UWORD(0));
fmpq_poly_tanh_series(tanha, a, n);
fmpq_poly_atanh_series(atanhtanha, tanha, n);
fmpq_poly_truncate(a, n);
cflags |= fmpq_poly_is_canonical(tanha) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(atanhtanha) ? 0 : 2;
result = (fmpq_poly_equal(atanhtanha, a) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n");
flint_printf("tanh(a) = "), fmpq_poly_debug(tanha), flint_printf("\n\n");
flint_printf("atanh(tanh(a)) = "), fmpq_poly_debug(atanhtanha), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(tanha);
fmpq_poly_clear(atanhtanha);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

@@ -0,0 +1,228 @@
/*=============================================================================
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 02160-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2011 Sebastian Pancratz
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz.h"
#include "fmpq_poly.h"
#include "ulong_extras.h"
int
main(void)
{
int cflags = 0, i, result;
FLINT_TEST_INIT(state);
flint_printf("xgcd....");
fflush(stdout);
/* Generic case, where a and b are coprime *******************************/
/* Verify d == s a + t b */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, d, e, f, s, t;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(d);
fmpq_poly_init(e);
fmpq_poly_init(f);
fmpq_poly_init(s);
fmpq_poly_init(t);
fmpq_poly_randtest(a, state, n_randint(state, 60), 80);
fmpq_poly_randtest(b, state, n_randint(state, 60), 80);
fmpq_poly_xgcd(d, s, t, a, b);
fmpq_poly_mul(e, s, a);
fmpq_poly_mul(f, t, b);
fmpq_poly_add(e, e, f);
cflags |= fmpq_poly_is_canonical(d) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(s) ? 0 : 2;
cflags |= fmpq_poly_is_canonical(t) ? 0 : 4;
result = (fmpq_poly_equal(d, e) && !cflags);
if (!result)
{
flint_printf("FAIL (correctness #1):\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(d), flint_printf("\n\n");
fmpq_poly_debug(s), flint_printf("\n\n");
fmpq_poly_debug(t), flint_printf("\n\n");
flint_printf("cflags = %d\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(d);
fmpq_poly_clear(e);
fmpq_poly_clear(f);
fmpq_poly_clear(s);
fmpq_poly_clear(t);
}
/* Verify consistency with GCD */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, d, s, t;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(d);
fmpq_poly_init(s);
fmpq_poly_init(t);
fmpq_poly_randtest(a, state, n_randint(state, 60), 80);
fmpq_poly_randtest(b, state, n_randint(state, 60), 80);
fmpq_poly_xgcd(d, s, t, a, b);
fmpq_poly_gcd(a, a, b);
cflags |= fmpq_poly_is_canonical(d) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(s) ? 0 : 2;
cflags |= fmpq_poly_is_canonical(t) ? 0 : 4;
result = (fmpq_poly_equal(d, a) && !cflags);
if (!result)
{
flint_printf("FAIL (GCD #1):\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(d), flint_printf("\n\n");
fmpq_poly_debug(s), flint_printf("\n\n");
fmpq_poly_debug(t), flint_printf("\n\n");
flint_printf("cflags = %d\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(d);
fmpq_poly_clear(s);
fmpq_poly_clear(t);
}
/* Generic case when a, b are most likely co-prime ***********************/
/* Verify d == s a + t b */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, d, s, t, z;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(d);
fmpq_poly_init(s);
fmpq_poly_init(t);
fmpq_poly_init(z);
fmpq_poly_randtest(a, state, n_randint(state, 60), 80);
fmpq_poly_randtest(b, state, n_randint(state, 60), 80);
fmpq_poly_randtest(z, state, n_randint(state, 20), 20);
fmpq_poly_mul(a, a, z);
fmpq_poly_mul(b, b, z);
fmpq_poly_xgcd(d, s, t, a, b);
fmpq_poly_mul(a, s, a);
fmpq_poly_mul(b, t, b);
fmpq_poly_add(a, a, b);
cflags |= fmpq_poly_is_canonical(d) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(s) ? 0 : 2;
cflags |= fmpq_poly_is_canonical(t) ? 0 : 4;
result = (fmpq_poly_equal(d, a) && !cflags);
if (!result)
{
flint_printf("FAIL (correctness #2):\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(d), flint_printf("\n\n");
fmpq_poly_debug(s), flint_printf("\n\n");
fmpq_poly_debug(t), flint_printf("\n\n");
flint_printf("cflags = %d\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(d);
fmpq_poly_clear(s);
fmpq_poly_clear(t);
fmpq_poly_clear(z);
}
/* Verify consistency with GCD */
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, d, s, t, z;
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(d);
fmpq_poly_init(s);
fmpq_poly_init(t);
fmpq_poly_init(z);
fmpq_poly_randtest(a, state, n_randint(state, 60), 80);
fmpq_poly_randtest(b, state, n_randint(state, 60), 80);
fmpq_poly_randtest(z, state, n_randint(state, 20), 20);
fmpq_poly_mul(a, a, z);
fmpq_poly_mul(b, b, z);
fmpq_poly_xgcd(d, s, t, a, b);
fmpq_poly_gcd(a, a, b);
cflags |= fmpq_poly_is_canonical(d) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(s) ? 0 : 2;
cflags |= fmpq_poly_is_canonical(t) ? 0 : 4;
result = (fmpq_poly_equal(d, a) && !cflags);
if (!result)
{
flint_printf("FAIL (GCD #2):\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(d), flint_printf("\n\n");
fmpq_poly_debug(s), flint_printf("\n\n");
fmpq_poly_debug(t), flint_printf("\n\n");
flint_printf("cflags = %d\n\n", cflags);
abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(d);
fmpq_poly_clear(s);
fmpq_poly_clear(t);
fmpq_poly_clear(z);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}

View File

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