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,278 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2007 David Howden
Copyright (C) 2007, 2008, 2009, 2010 William Hart
Copyright (C) 2008 Richard Howell-Peak
Copyright (C) 2011 Fredrik Johansson
Copyright (C) 2013 Mike Hansen
******************************************************************************/
#ifdef T
#include "templates.h"
int
main(void)
{
int iter;
FLINT_TEST_INIT(state);
flint_printf("factor....");
fflush(stdout);
/* Default algorithm */
for (iter = 0; iter < flint_test_multiplier(); iter++)
{
int result = 1;
TEMPLATE(T, poly_t) pol1, poly, quot, rem, product;
TEMPLATE(T, poly_factor_t) res;
TEMPLATE(T, ctx_t) ctx;
TEMPLATE(T, t) lead;
slong length, num, i, j;
ulong exp[5], prod1;
TEMPLATE(T, ctx_randtest) (ctx, state);
TEMPLATE(T, poly_init) (pol1, ctx);
TEMPLATE(T, poly_init) (poly, ctx);
TEMPLATE(T, poly_init) (quot, ctx);
TEMPLATE(T, poly_init) (rem, ctx);
TEMPLATE(T, poly_zero) (pol1, ctx);
TEMPLATE(T, poly_one) (pol1, ctx);
length = n_randint(state, 4) + 2;
TEMPLATE(T, poly_randtest_irreducible) (poly, state, length, ctx);
exp[0] = n_randint(state, 3) + 1;
prod1 = exp[0];
for (i = 0; i < exp[0]; i++)
TEMPLATE(T, poly_mul) (pol1, pol1, poly, ctx);
num = n_randint(state, 3) + 1;
for (i = 1; i < num; i++)
{
do
{
length = n_randint(state, 3) + 2;
TEMPLATE(T, poly_randtest_irreducible) (poly, state, length,
ctx);
TEMPLATE(T, poly_divrem) (quot, rem, pol1, poly, ctx);
}
while ((poly->length < 2) || (rem->length == 0));
exp[i] = n_randint(state, 3) + 1;
prod1 *= exp[i];
for (j = 0; j < exp[i]; j++)
TEMPLATE(T, poly_mul) (pol1, pol1, poly, ctx);
}
TEMPLATE(T, poly_factor_init) (res, ctx);
TEMPLATE(T, init) (lead, ctx);
switch (n_randint(state, 4))
{
case 0:
TEMPLATE(T, poly_factor) (res, lead, pol1, ctx);
break;
case 1:
TEMPLATE(T, poly_factor_with_berlekamp) (res, lead, pol1, ctx);
break;
case 2:
if (fmpz_is_even(TEMPLATE(T, ctx_prime) (ctx)))
TEMPLATE(T, poly_factor) (res, lead, pol1, ctx);
else
TEMPLATE(T, poly_factor_with_cantor_zassenhaus) (res, lead,
pol1,
ctx);
break;
case 3:
TEMPLATE(T, poly_factor_with_kaltofen_shoup) (res, lead, pol1,
ctx);
break;
}
fflush(stdout);
result &= (res->num == num);
if (!result)
{
flint_printf("Error: number of factors incorrect, %wd, %wd\n",
res->num, num);
abort();
}
TEMPLATE(T, poly_init) (product, ctx);
TEMPLATE(T, poly_one) (product, ctx);
for (i = 0; i < res->num; i++)
for (j = 0; j < res->exp[i]; j++)
TEMPLATE(T, poly_mul) (product, product, res->poly + i, ctx);
TEMPLATE(T, TEMPLATE(poly_scalar_mul, T)) (product, product, lead,
ctx);
result &= TEMPLATE(T, poly_equal) (pol1, product, ctx);
if (!result)
{
flint_printf
("Error: product of factors does not equal original polynomial\n");
TEMPLATE(T, poly_print_pretty) (pol1, "x", ctx);
flint_printf("\n");
TEMPLATE(T, poly_print_pretty) (product, "x", ctx);
flint_printf("\n");
abort();
}
TEMPLATE(T, poly_clear) (product, ctx);
TEMPLATE(T, poly_clear) (quot, ctx);
TEMPLATE(T, poly_clear) (rem, ctx);
TEMPLATE(T, poly_clear) (pol1, ctx);
TEMPLATE(T, poly_clear) (poly, ctx);
TEMPLATE(T, poly_factor_clear) (res, ctx);
TEMPLATE(T, clear) (lead, ctx);
TEMPLATE(T, ctx_clear) (ctx);
}
/* Test deflation trick */
for (iter = 0; iter < flint_test_multiplier(); iter++)
{
TEMPLATE(T, poly_t) pol1, poly, quot, rem;
TEMPLATE(T, poly_factor_t) res, res2;
TEMPLATE(T, ctx_t) ctx;
TEMPLATE(T, t) lead;
slong length, num, i, j;
slong exp[5], prod1;
ulong inflation;
int found;
TEMPLATE(T, ctx_randtest) (ctx, state);
TEMPLATE(T, poly_init) (pol1, ctx);
TEMPLATE(T, poly_init) (poly, ctx);
TEMPLATE(T, poly_init) (quot, ctx);
TEMPLATE(T, poly_init) (rem, ctx);
TEMPLATE(T, poly_zero) (pol1, ctx);
TEMPLATE(T, poly_one) (pol1, ctx);
inflation = n_randint(state, 7) + 1;
length = n_randint(state, 4) + 2;
TEMPLATE(T, poly_randtest_irreducible) (poly, state, length, ctx);
TEMPLATE(T, poly_inflate) (poly, poly, inflation, ctx);
exp[0] = n_randint(state, 6) + 1;
prod1 = exp[0];
for (i = 0; i < exp[0]; i++)
TEMPLATE(T, poly_mul) (pol1, pol1, poly, ctx);
num = n_randint(state, 5) + 1;
for (i = 1; i < num; i++)
{
do
{
length = n_randint(state, 6) + 2;
TEMPLATE(T, poly_randtest_irreducible) (poly, state, length,
ctx);
TEMPLATE(T, poly_divrem) (quot, rem, pol1, poly, ctx);
}
while ((poly->length < 2) || (rem->length == 0));
exp[i] = n_randint(state, 6) + 1;
prod1 *= exp[i];
TEMPLATE(T, poly_inflate) (poly, poly, inflation, ctx);
for (j = 0; j < exp[i]; j++)
TEMPLATE(T, poly_mul) (pol1, pol1, poly, ctx);
}
TEMPLATE(T, poly_factor_init) (res, ctx);
TEMPLATE(T, poly_factor_init) (res2, ctx);
TEMPLATE(T, init) (lead, ctx);
switch (n_randint(state, 4))
{
case 0:
TEMPLATE(T, poly_factor) (res, lead, pol1, ctx);
break;
case 1:
TEMPLATE(T, poly_factor_with_berlekamp) (res, lead, pol1, ctx);
break;
case 2:
TEMPLATE(T, poly_factor_with_cantor_zassenhaus) (res, lead,
pol1, ctx);
break;
case 3:
TEMPLATE(T, poly_factor_with_kaltofen_shoup) (res, lead, pol1,
ctx);
break;
}
TEMPLATE(T, poly_factor_cantor_zassenhaus) (res2, pol1, ctx);
if (res->num != res2->num)
{
flint_printf("FAIL: different number of factors found\n");
abort();
}
for (i = 0; i < res->num; i++)
{
found = 0;
for (j = 0; j < res2->num; j++)
{
if (TEMPLATE(T, poly_equal)
(res->poly + i, res2->poly + j, ctx)
&& res->exp[i] == res2->exp[j])
{
found = 1;
break;
}
}
if (!found)
{
flint_printf("FAIL: factor not found\n");
abort();
}
}
TEMPLATE(T, poly_clear) (quot, ctx);
TEMPLATE(T, poly_clear) (rem, ctx);
TEMPLATE(T, poly_clear) (pol1, ctx);
TEMPLATE(T, poly_clear) (poly, ctx);
TEMPLATE(T, poly_factor_clear) (res, ctx);
TEMPLATE(T, poly_factor_clear) (res2, ctx);
TEMPLATE(T, clear) (lead, ctx);
TEMPLATE(T, ctx_clear) (ctx);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}
#endif

View File

@@ -0,0 +1,153 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2007 David Howden
Copyright (C) 2007, 2008, 2009, 2010 William Hart
Copyright (C) 2008 Richard Howell-Peak
Copyright (C) 2011 Fredrik Johansson
Copyright (C) 2012 Lina Kulakova
Copyright (C) 2013 Mike Hansen
******************************************************************************/
#ifdef T
#include "templates.h"
int
main(void)
{
int iter;
FLINT_TEST_INIT(state);
flint_printf("factor_berlekamp....");
fflush(stdout);
for (iter = 0; iter < 10 * flint_test_multiplier(); iter++)
{
TEMPLATE(T, ctx_t) ctx;
TEMPLATE(T, poly_t) poly1, poly, q, r, product;
TEMPLATE(T, poly_factor_t) res;
slong i, j, length, num;
slong exp[5];
TEMPLATE(T, ctx_randtest) (ctx, state);
TEMPLATE(T, poly_init) (poly1, ctx);
TEMPLATE(T, poly_init) (poly, ctx);
TEMPLATE(T, poly_init) (q, ctx);
TEMPLATE(T, poly_init) (r, ctx);
TEMPLATE(T, poly_zero) (poly1, ctx);
TEMPLATE(T, poly_one) (poly1, ctx);
length = n_randint(state, 4) + 2;
do
{
TEMPLATE(T, poly_randtest) (poly, state, length, ctx);
if (poly->length)
TEMPLATE(T, poly_make_monic) (poly, poly, ctx);
}
while ((poly->length < 2)
|| (!TEMPLATE(T, poly_is_irreducible) (poly, ctx)));
exp[0] = n_randint(state, 5) + 1;
for (i = 0; i < exp[0]; i++)
TEMPLATE(T, poly_mul) (poly1, poly1, poly, ctx);
num = n_randint(state, 5) + 1;
for (i = 1; i < num; i++)
{
do
{
length = n_randint(state, 5) + 2;
TEMPLATE(T, poly_randtest) (poly, state, length, ctx);
if (poly->length)
{
TEMPLATE(T, poly_make_monic) (poly, poly, ctx);
TEMPLATE(T, poly_divrem) (q, r, poly1, poly, ctx);
}
}
while ((poly->length < 2)
|| (!TEMPLATE(T, poly_is_irreducible) (poly, ctx))
|| (r->length == 0));
exp[i] = n_randint(state, 5) + 1;
for (j = 0; j < exp[i]; j++)
TEMPLATE(T, poly_mul) (poly1, poly1, poly, ctx);
}
TEMPLATE(T, poly_factor_init) (res, ctx);
TEMPLATE(T, poly_factor_berlekamp) (res, poly1, ctx);
if (res->num != num)
{
flint_printf("Error: number of factors incorrect: %wd != %wd\n",
res->num, num);
TEMPLATE(T, ctx_print) (ctx);
flint_printf("\n");
TEMPLATE(T, poly_print_pretty) (poly1, "x", ctx);
flint_printf("\n");
abort();
}
TEMPLATE(T, poly_init) (product, ctx);
TEMPLATE(T, poly_one) (product, ctx);
for (i = 0; i < res->num; i++)
for (j = 0; j < res->exp[i]; j++)
TEMPLATE(T, poly_mul) (product, product, res->poly + i, ctx);
TEMPLATE3(T, poly_scalar_mul, T) (product, product,
poly1->coeffs + poly1->length - 1,
ctx);
if (!TEMPLATE(T, poly_equal) (poly1, product, ctx))
{
flint_printf
("Error: product of factors does not equal to the original polynomial\n");
flint_printf("poly:\n");
TEMPLATE(T, poly_print) (poly1, ctx);
flint_printf("\n");
flint_printf("product:\n");
TEMPLATE(T, poly_print) (product, ctx);
flint_printf("\n");
abort();
}
TEMPLATE(T, poly_clear) (product, ctx);
TEMPLATE(T, poly_clear) (q, ctx);
TEMPLATE(T, poly_clear) (r, ctx);
TEMPLATE(T, poly_clear) (poly1, ctx);
TEMPLATE(T, poly_clear) (poly, ctx);
TEMPLATE(T, poly_factor_clear) (res, ctx);
TEMPLATE(T, ctx_clear) (ctx);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}
#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) 2007 David Howden
Copyright (C) 2007, 2008, 2009, 2010 William Hart
Copyright (C) 2008 Richard Howell-Peak
Copyright (C) 2011 Fredrik Johansson
Copyright (C) 2012 Lina Kulakova
Copyright (C) 2013 Mike Hansen
******************************************************************************/
#ifdef T
#include "templates.h"
#include <stdlib.h>
#include "ulong_extras.h"
int
main(void)
{
int iter;
FLINT_TEST_INIT(state);
flint_printf("factor_cantor_zassenhaus....");
fflush(stdout);
for (iter = 0; iter < 2 * flint_test_multiplier(); iter++)
{
TEMPLATE(T, poly_t) poly1, poly, q, r, product;
TEMPLATE(T, poly_factor_t) res;
TEMPLATE(T, ctx_t) ctx;
slong i, j, length, num;
slong exp[5];
TEMPLATE(T, ctx_randtest) (ctx, state);
TEMPLATE(T, poly_init) (poly1, ctx);
TEMPLATE(T, poly_init) (poly, ctx);
TEMPLATE(T, poly_init) (q, ctx);
TEMPLATE(T, poly_init) (r, ctx);
TEMPLATE(T, poly_zero) (poly1, ctx);
TEMPLATE(T, poly_one) (poly1, ctx);
length = n_randint(state, 4) + 2;
do
{
TEMPLATE(T, poly_randtest) (poly, state, length, ctx);
if (poly->length)
TEMPLATE(T, poly_make_monic) (poly, poly, ctx);
}
while ((poly->length != length)
|| (!TEMPLATE(T, poly_is_irreducible) (poly, ctx)));
exp[0] = n_randint(state, 5) + 1;
for (i = 0; i < exp[0]; i++)
TEMPLATE(T, poly_mul) (poly1, poly1, poly, ctx);
num = n_randint(state, 5) + 1;
for (i = 1; i < num; i++)
{
do
{
length = n_randint(state, 4) + 2;
TEMPLATE(T, poly_randtest) (poly, state, length, ctx);
if (poly->length)
{
TEMPLATE(T, poly_make_monic) (poly, poly, ctx);
TEMPLATE(T, poly_divrem) (q, r, poly1, poly, ctx);
}
}
while ((poly->length != length)
|| (!TEMPLATE(T, poly_is_irreducible) (poly, ctx))
|| (r->length == 0));
exp[i] = n_randint(state, 5) + 1;
for (j = 0; j < exp[i]; j++)
TEMPLATE(T, poly_mul) (poly1, poly1, poly, ctx);
}
TEMPLATE(T, poly_factor_init) (res, ctx);
TEMPLATE(T, poly_factor_cantor_zassenhaus) (res, poly1, ctx);
if (res->num != num)
{
flint_printf("Error: number of factors incorrect: %wd != %wd\n",
res->num, num);
abort();
}
TEMPLATE(T, poly_init) (product, ctx);
TEMPLATE(T, poly_one) (product, ctx);
for (i = 0; i < res->num; i++)
for (j = 0; j < res->exp[i]; j++)
TEMPLATE(T, poly_mul) (product, product, res->poly + i, ctx);
TEMPLATE(T, TEMPLATE(poly_scalar_mul, T)) (product, product,
poly1->coeffs +
(poly1->length - 1), ctx);
if (!TEMPLATE(T, poly_equal) (poly1, product, ctx))
{
flint_printf
("Error: product of factors does not equal to the original polynomial\n");
flint_printf("poly:\n");
TEMPLATE(T, poly_print) (poly1, ctx);
flint_printf("\n");
flint_printf("product:\n");
TEMPLATE(T, poly_print) (product, ctx);
flint_printf("\n");
abort();
}
TEMPLATE(T, poly_clear) (product, ctx);
TEMPLATE(T, poly_clear) (q, ctx);
TEMPLATE(T, poly_clear) (r, ctx);
TEMPLATE(T, poly_clear) (poly1, ctx);
TEMPLATE(T, poly_clear) (poly, ctx);
TEMPLATE(T, poly_factor_clear) (res, ctx);
TEMPLATE(T, ctx_clear) (ctx);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}
#endif

View File

@@ -0,0 +1,145 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2007 David Howden
Copyright (C) 2007, 2008, 2009, 2010 William Hart
Copyright (C) 2008 Richard Howell-Peak
Copyright (C) 2011 Fredrik Johansson
Copyright (C) 2012 Lina Kulakova
Copyright (C) 2013 Mike Hansen
******************************************************************************/
#ifdef T
#include "templates.h"
#include <stdlib.h>
#include "ulong_extras.h"
int
main(void)
{
int iter;
FLINT_TEST_INIT(state);
flint_printf("factor_distinct_deg....");
fflush(stdout);
for (iter = 0; iter < 200; iter++)
{
TEMPLATE(T, ctx_t) ctx;
TEMPLATE(T, poly_t) poly1, poly, q, r, product;
TEMPLATE(T, poly_factor_t) res;
slong i, length, num;
slong *degs;
TEMPLATE(T, ctx_randtest) (ctx, state);
TEMPLATE(T, poly_init) (poly1, ctx);
TEMPLATE(T, poly_init) (poly, ctx);
TEMPLATE(T, poly_init) (q, ctx);
TEMPLATE(T, poly_init) (r, ctx);
TEMPLATE(T, poly_zero) (poly1, ctx);
TEMPLATE(T, poly_one) (poly1, ctx);
length = n_randint(state, 7) + 2;
do
{
TEMPLATE(T, poly_randtest) (poly, state, length, ctx);
if (poly->length)
TEMPLATE(T, poly_make_monic) (poly, poly, ctx);
}
while ((poly->length < 2)
|| (!TEMPLATE(T, poly_is_irreducible) (poly, ctx)));
TEMPLATE(T, poly_mul) (poly1, poly1, poly, ctx);
num = n_randint(state, 5) + 1;
for (i = 1; i < num; i++)
{
do
{
length = n_randint(state, 7) + 2;
TEMPLATE(T, poly_randtest) (poly, state, length, ctx);
if (poly->length)
{
TEMPLATE(T, poly_make_monic) (poly, poly, ctx);
TEMPLATE(T, poly_divrem) (q, r, poly1, poly, ctx);
}
}
while ((poly->length < 2)
|| (!TEMPLATE(T, poly_is_irreducible) (poly, ctx))
|| (r->length == 0));
TEMPLATE(T, poly_mul) (poly1, poly1, poly, ctx);
}
if (!(degs = flint_malloc((poly1->length - 1) * sizeof(slong))))
{
flint_printf("Fatal error: not enough memory.");
abort();
}
TEMPLATE(T, poly_factor_init) (res, ctx);
TEMPLATE(T, poly_factor_distinct_deg) (res, poly1, &degs, ctx);
TEMPLATE(T, poly_init) (product, ctx);
TEMPLATE(T, poly_one) (product, ctx);
for (i = 0; i < res->num; i++)
TEMPLATE(T, poly_mul) (product, product, res->poly + i, ctx);
TEMPLATE(T, TEMPLATE(poly_scalar_mul, T)) (product, product,
poly1->coeffs +
(poly1->length - 1), ctx);
if (!TEMPLATE(T, poly_equal) (poly1, product, ctx))
{
flint_printf
("Error: product of factors does not equal to the original polynomial\n");
flint_printf("poly:\n");
TEMPLATE(T, poly_print) (poly1, ctx);
flint_printf("\n");
flint_printf("product:\n");
TEMPLATE(T, poly_print) (product, ctx);
flint_printf("\n");
abort();
}
flint_free(degs);
TEMPLATE(T, poly_clear) (product, ctx);
TEMPLATE(T, poly_clear) (q, ctx);
TEMPLATE(T, poly_clear) (r, ctx);
TEMPLATE(T, poly_clear) (poly1, ctx);
TEMPLATE(T, poly_clear) (poly, ctx);
TEMPLATE(T, poly_factor_clear) (res, ctx);
TEMPLATE(T, ctx_clear) (ctx);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}
#endif

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) 2012 Lina Kulakova
Copyright (C) 2013 Mike Hansen
******************************************************************************/
#ifdef T
#include "templates.h"
#include <stdlib.h>
#include "ulong_extras.h"
int
main(void)
{
int iter;
FLINT_TEST_INIT(state);
flint_printf("factor_equal_deg_prob....");
fflush(stdout);
for (iter = 0; iter < 5 * flint_test_multiplier(); iter++)
{
TEMPLATE(T, ctx_t) ctx;
TEMPLATE(T, poly_t) poly1, poly2, q, r;
slong length;
int i, num;
TEMPLATE(T, ctx_randtest) (ctx, state);
TEMPLATE(T, poly_init) (q, ctx);
TEMPLATE(T, poly_init) (r, ctx);
TEMPLATE(T, poly_init) (poly1, ctx);
TEMPLATE(T, poly_init) (poly2, ctx);
length = n_randint(state, 10) + 2;
do
{
TEMPLATE(T, poly_randtest) (poly1, state, length, ctx);
if (poly1->length)
TEMPLATE(T, poly_make_monic) (poly1, poly1, ctx);
}
while ((poly1->length != length)
|| (!TEMPLATE(T, poly_is_irreducible) (poly1, ctx)));
num = n_randint(state, 5) + 1;
for (i = 0; i < num; i++)
{
do
{
TEMPLATE(T, poly_randtest) (poly2, state, length, ctx);
if (poly2->length)
TEMPLATE(T, poly_make_monic) (poly2, poly2, ctx);
}
while ((poly2->length != length)
|| (!TEMPLATE(T, poly_is_irreducible) (poly2, ctx)));
TEMPLATE(T, poly_mul) (poly1, poly1, poly2, ctx);
}
while (!TEMPLATE(T, poly_factor_equal_deg_prob)
(poly2, state, poly1, length - 1, ctx))
{
};
TEMPLATE(T, poly_divrem) (q, r, poly1, poly2, ctx);
if (!TEMPLATE(T, poly_is_zero) (r, ctx))
{
flint_printf("FAIL:\n");
flint_printf
("Error: factor does not divide original polynomial\n");
flint_printf("factor:\n");
TEMPLATE(T, poly_print) (poly2, ctx);
flint_printf("\n\n");
flint_printf("polynomial:\n");
TEMPLATE(T, poly_print) (poly1, ctx);
flint_printf("\n\n");
abort();
}
TEMPLATE(T, poly_clear) (q, ctx);
TEMPLATE(T, poly_clear) (r, ctx);
TEMPLATE(T, poly_clear) (poly1, ctx);
TEMPLATE(T, poly_clear) (poly2, ctx);
TEMPLATE(T, ctx_clear) (ctx);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}
#endif

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) 2007 David Howden
Copyright (C) 2007, 2008, 2009, 2010 William Hart
Copyright (C) 2008 Richard Howell-Peak
Copyright (C) 2011 Fredrik Johansson
Copyright (C) 2012 Lina Kulakova
Copyright (C) 2013 Mike Hansen
******************************************************************************/
#ifdef T
#include "templates.h"
#include <stdlib.h>
#include "ulong_extras.h"
int
main(void)
{
int iter;
FLINT_TEST_INIT(state);
flint_printf("factor_kaltofen_shoup....");
fflush(stdout);
for (iter = 0; iter < 10 * flint_test_multiplier(); iter++)
{
TEMPLATE(T, ctx_t) ctx;
TEMPLATE(T, poly_t) poly1, poly, q, r, product;
TEMPLATE(T, poly_factor_t) res;
slong i, j, length, num;
slong exp[5];
TEMPLATE(T, ctx_randtest) (ctx, state);
TEMPLATE(T, poly_init) (poly1, ctx);
TEMPLATE(T, poly_init) (poly, ctx);
TEMPLATE(T, poly_init) (q, ctx);
TEMPLATE(T, poly_init) (r, ctx);
TEMPLATE(T, poly_one) (poly1, ctx);
length = n_randint(state, 7) + 2;
do
{
TEMPLATE(T, poly_randtest) (poly, state, length, ctx);
if (poly->length)
TEMPLATE(T, poly_make_monic) (poly, poly, ctx);
}
while ((poly->length != length)
|| (!TEMPLATE(T, poly_is_irreducible) (poly, ctx)));
exp[0] = n_randint(state, 5) + 1;
for (i = 0; i < exp[0]; i++)
{
TEMPLATE(T, poly_mul) (poly1, poly1, poly, ctx);
}
num = n_randint(state, 5) + 1;
for (i = 1; i < num; i++)
{
do
{
length = n_randint(state, 5) + 2;
TEMPLATE(T, poly_randtest) (poly, state, length, ctx);
if (poly->length)
{
TEMPLATE(T, poly_make_monic) (poly, poly, ctx);
TEMPLATE(T, poly_divrem) (q, r, poly1, poly, ctx);
}
}
while ((poly->length != length)
|| (!TEMPLATE(T, poly_is_irreducible) (poly, ctx))
|| (r->length == 0));
exp[i] = n_randint(state, 5) + 1;
for (j = 0; j < exp[i]; j++)
{
TEMPLATE(T, poly_mul) (poly1, poly1, poly, ctx);
}
}
TEMPLATE(T, poly_factor_init) (res, ctx);
TEMPLATE(T, poly_factor_kaltofen_shoup) (res, poly1, ctx);
if (res->num != num)
{
flint_printf("Error: number of factors incorrect: %wd != %wd\n",
res->num, num);
abort();
}
TEMPLATE(T, poly_init) (product, ctx);
TEMPLATE(T, poly_one) (product, ctx);
for (i = 0; i < res->num; i++)
{
for (j = 0; j < res->exp[i]; j++)
{
TEMPLATE(T, poly_mul) (product, product, res->poly + i, ctx);
}
}
TEMPLATE(T, TEMPLATE(poly_scalar_mul, T)) (product, product,
poly1->coeffs +
(poly1->length - 1), ctx);
if (!TEMPLATE(T, poly_equal) (poly1, product, ctx))
{
flint_printf
("Error: product of factors does not equal to the original polynomial\n");
TEMPLATE(T, ctx_print) (ctx);
flint_printf("\n");
flint_printf("poly:\n");
TEMPLATE(T, poly_print_pretty) (poly1, "x", ctx);
flint_printf("\n");
flint_printf("product:\n");
TEMPLATE(T, poly_print_pretty) (product, "x", ctx);
flint_printf("\n");
abort();
}
TEMPLATE(T, ctx_clear) (ctx);
TEMPLATE(T, poly_clear) (product, ctx);
TEMPLATE(T, poly_clear) (q, ctx);
TEMPLATE(T, poly_clear) (r, ctx);
TEMPLATE(T, poly_clear) (poly1, ctx);
TEMPLATE(T, poly_clear) (poly, ctx);
TEMPLATE(T, poly_factor_clear) (res, ctx);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}
#endif

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) 2007 David Howden
Copyright (C) 2007, 2008, 2009, 2010 William Hart
Copyright (C) 2008 Richard Howell-Peak
Copyright (C) 2011 Fredrik Johansson
Copyright (C) 2012 Lina Kulakova
Copyright (C) 2013 Mike Hansen
******************************************************************************/
#ifdef T
#include "templates.h"
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int iter;
FLINT_TEST_INIT(state);
flint_printf("factor_squarefree....");
fflush(stdout);
for (iter = 0; iter < 5 * flint_test_multiplier(); iter++)
{
int result = 1;
TEMPLATE(T, ctx_t) ctx;
TEMPLATE(T, poly_t) pol1, poly, quot, rem;
TEMPLATE(T, poly_factor_t) res;
slong exp[5], prod1;
slong length, i, j, num;
TEMPLATE(T, ctx_randtest) (ctx, state);
TEMPLATE(T, poly_init) (pol1, ctx);
TEMPLATE(T, poly_init) (poly, ctx);
TEMPLATE(T, poly_init) (quot, ctx);
TEMPLATE(T, poly_init) (rem, ctx);
TEMPLATE(T, poly_one) (pol1, ctx);
length = n_randint(state, 5) + 2;
do
{
TEMPLATE(T, poly_randtest) (poly, state, length, ctx);
TEMPLATE(T, poly_make_monic) (poly, poly, ctx);
}
while ((poly->length != length)
|| (!TEMPLATE(T, poly_is_irreducible) (poly, ctx)));
exp[0] = n_randprime(state, 5, 0);
prod1 = exp[0];
for (i = 0; i < exp[0]; i++)
TEMPLATE(T, poly_mul) (pol1, pol1, poly, ctx);
num = n_randint(state, 5) + 1;
for (i = 1; i < num; i++)
{
do
{
length = n_randint(state, 7) + 2;
TEMPLATE(T, poly_randtest) (poly, state, length, ctx);
if (poly->length)
{
TEMPLATE(T, poly_make_monic) (poly, poly, ctx);
TEMPLATE(T, poly_divrem) (quot, rem, pol1, poly, ctx);
}
}
while ((!TEMPLATE(T, poly_is_irreducible) (poly, ctx)) ||
(poly->length != length) || (rem->length == 0));
do
exp[i] = n_randprime(state, 5, 0);
while (prod1 % exp[i] == 0);
prod1 *= exp[i];
for (j = 0; j < exp[i]; j++)
TEMPLATE(T, poly_mul) (pol1, pol1, poly, ctx);
}
TEMPLATE(T, poly_factor_init) (res, ctx);
TEMPLATE(T, poly_factor_squarefree) (res, pol1, ctx);
result &= (res->num == num);
if (result)
{
ulong prod2 = 1;
for (i = 0; i < num; i++)
prod2 *= res->exp[i];
result &= (prod1 == prod2);
}
if (!result)
{
flint_printf("Error: exp don't match. Ctx = ");
TEMPLATE(T, ctx_print) (ctx);
flint_printf("\n");
for (i = 0; i < res->num; i++)
flint_printf("%wd ", res->exp[i]);
flint_printf("\n");
for (i = 0; i < num; i++)
flint_printf("%wd ", exp[i]);
flint_printf("\n");
abort();
}
TEMPLATE(T, poly_clear) (quot, ctx);
TEMPLATE(T, poly_clear) (rem, ctx);
TEMPLATE(T, poly_clear) (pol1, ctx);
TEMPLATE(T, poly_clear) (poly, ctx);
TEMPLATE(T, poly_factor_clear) (res, ctx);
TEMPLATE(T, ctx_clear) (ctx);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}
#endif

View File

@@ -0,0 +1,108 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2011 Fredrik Johansson
Copyright (C) 2012 Lina Kulakova
Copyright (C) 2013 Mike Hansen
******************************************************************************/
#ifdef T
#include "templates.h"
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int iter;
FLINT_TEST_INIT(state);
flint_printf("is_irreducible....");
fflush(stdout);
for (iter = 0; iter < 5 * flint_test_multiplier(); iter++)
{
TEMPLATE(T, ctx_t) ctx;
TEMPLATE(T, poly_t) poly1, poly2;
slong length;
int i, num;
TEMPLATE(T, ctx_randtest) (ctx, state);
TEMPLATE(T, poly_init) (poly1, ctx);
TEMPLATE(T, poly_init) (poly2, ctx);
length = n_randint(state, 5) + 2;
do
{
TEMPLATE(T, poly_randtest) (poly1, state, length, ctx);
if (!TEMPLATE(T, poly_is_zero) (poly1, ctx))
TEMPLATE(T, poly_make_monic) (poly1, poly1, ctx);
}
while ((!TEMPLATE(T, poly_is_irreducible) (poly1, ctx))
|| (poly1->length < 2));
num = n_randint(state, 5) + 1;
for (i = 0; i < num; i++)
{
do
{
TEMPLATE(T, poly_randtest) (poly2, state, length, ctx);
if (!TEMPLATE(T, poly_is_zero) (poly2, ctx))
TEMPLATE(T, poly_make_monic) (poly2, poly2, ctx);
}
while ((!TEMPLATE(T, poly_is_irreducible) (poly2, ctx))
|| (poly2->length < 2));
TEMPLATE(T, poly_mul) (poly1, poly1, poly2, ctx);
}
if (TEMPLATE(T, poly_is_irreducible) (poly1, ctx))
{
flint_printf
("Error: reducible polynomial declared irreducible!\n");
flint_printf("poly:\n");
TEMPLATE(T, poly_print) (poly1, ctx);
flint_printf("\n");
abort();
}
TEMPLATE(T, poly_clear) (poly1, ctx);
TEMPLATE(T, poly_clear) (poly2, ctx);
TEMPLATE(T, ctx_clear) (ctx);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}
#endif

View File

@@ -0,0 +1,108 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2011 Fredrik Johansson
Copyright (C) 2012 Lina Kulakova
Copyright (C) 2013 Mike Hansen
******************************************************************************/
#ifdef T
#include "templates.h"
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int iter;
FLINT_TEST_INIT(state);
flint_printf("is_irreducible_ben_or....");
fflush(stdout);
for (iter = 0; iter < 50; iter++)
{
TEMPLATE(T, ctx_t) ctx;
TEMPLATE(T, poly_t) poly1, poly2;
slong length;
int i, num;
TEMPLATE(T, ctx_randtest) (ctx, state);
TEMPLATE(T, poly_init) (poly1, ctx);
TEMPLATE(T, poly_init) (poly2, ctx);
length = n_randint(state, 7) + 2;
do
{
TEMPLATE(T, poly_randtest) (poly1, state, length, ctx);
if (!TEMPLATE(T, poly_is_zero) (poly1, ctx))
TEMPLATE(T, poly_make_monic) (poly1, poly1, ctx);
}
while ((!TEMPLATE(T, poly_is_irreducible_ben_or) (poly1, ctx))
|| (poly1->length < 2));
num = n_randint(state, 5) + 1;
for (i = 0; i < num; i++)
{
do
{
TEMPLATE(T, poly_randtest) (poly2, state, length, ctx);
if (!TEMPLATE(T, poly_is_zero) (poly2, ctx))
TEMPLATE(T, poly_make_monic) (poly2, poly2, ctx);
}
while ((!TEMPLATE(T, poly_is_irreducible_ben_or) (poly2, ctx))
|| (poly2->length < 2));
TEMPLATE(T, poly_mul) (poly1, poly1, poly2, ctx);
}
if (TEMPLATE(T, poly_is_irreducible_ben_or) (poly1, ctx))
{
flint_printf
("Error: reducible polynomial declared irreducible!\n");
flint_printf("poly:\n");
TEMPLATE(T, poly_print) (poly1, ctx);
flint_printf("\n");
abort();
}
TEMPLATE(T, poly_clear) (poly1, ctx);
TEMPLATE(T, poly_clear) (poly2, ctx);
TEMPLATE(T, ctx_clear) (ctx);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}
#endif

View File

@@ -0,0 +1,108 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2011 Fredrik Johansson
Copyright (C) 2012 Lina Kulakova
Copyright (C) 2013 Mike Hansen
******************************************************************************/
#ifdef T
#include "templates.h"
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int iter;
FLINT_TEST_INIT(state);
flint_printf("is_irreducible_ddf....");
fflush(stdout);
for (iter = 0; iter < 50; iter++)
{
TEMPLATE(T, ctx_t) ctx;
TEMPLATE(T, poly_t) poly1, poly2;
slong length;
int i, num;
TEMPLATE(T, ctx_randtest) (ctx, state);
TEMPLATE(T, poly_init) (poly1, ctx);
TEMPLATE(T, poly_init) (poly2, ctx);
length = n_randint(state, 7) + 2;
do
{
TEMPLATE(T, poly_randtest) (poly1, state, length, ctx);
if (!TEMPLATE(T, poly_is_zero) (poly1, ctx))
TEMPLATE(T, poly_make_monic) (poly1, poly1, ctx);
}
while ((!TEMPLATE(T, poly_is_irreducible_ddf) (poly1, ctx))
|| (poly1->length < 2));
num = n_randint(state, 5) + 1;
for (i = 0; i < num; i++)
{
do
{
TEMPLATE(T, poly_randtest) (poly2, state, length, ctx);
if (!TEMPLATE(T, poly_is_zero) (poly2, ctx))
TEMPLATE(T, poly_make_monic) (poly2, poly2, ctx);
}
while ((!TEMPLATE(T, poly_is_irreducible_ddf) (poly2, ctx))
|| (poly2->length < 2));
TEMPLATE(T, poly_mul) (poly1, poly1, poly2, ctx);
}
if (TEMPLATE(T, poly_is_irreducible_ddf) (poly1, ctx))
{
flint_printf
("Error: reducible polynomial declared irreducible!\n");
flint_printf("poly:\n");
TEMPLATE(T, poly_print) (poly1, ctx);
flint_printf("\n");
abort();
}
TEMPLATE(T, poly_clear) (poly1, ctx);
TEMPLATE(T, poly_clear) (poly2, ctx);
TEMPLATE(T, ctx_clear) (ctx);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}
#endif

View File

@@ -0,0 +1,123 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2011 Fredrik Johansson
Copyright (C) 2012 Lina Kulakova
Copyright (C) 2013 Mike Hansen
******************************************************************************/
#ifdef T
#include "templates.h"
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include "flint.h"
#include "fmpz_vec.h"
#include "ulong_extras.h"
int
main(void)
{
int iter;
FLINT_TEST_INIT(state);
flint_printf("is_squarefree....");
fflush(stdout);
for (iter = 0; iter < 200 * flint_test_multiplier(); iter++)
{
TEMPLATE(T, ctx_t) ctx;
TEMPLATE(T, poly_t) poly, Q, R, t;
fmpz_t x;
slong i, num_factors, exp, max_exp;
int v, result;
TEMPLATE(T, ctx_randtest) (ctx, state);
TEMPLATE(T, poly_init) (poly, ctx);
TEMPLATE(T, poly_init) (t, ctx);
TEMPLATE(T, poly_init) (Q, ctx);
TEMPLATE(T, poly_init) (R, ctx);
fmpz_init(x);
fmpz_randtest_mod(x, state, TEMPLATE(T, ctx_prime) (ctx));
TEMPLATE(T, poly_set_coeff_fmpz) (poly, 0, x, ctx);
num_factors = n_randint(state, 5);
max_exp = 0;
for (i = 0; i < num_factors; i++)
{
do
{
TEMPLATE(T, poly_randtest) (t, state, n_randint(state, 10),
ctx);
} while (!TEMPLATE(T, poly_is_irreducible) (t, ctx)
|| (TEMPLATE(T, poly_length) (t, ctx) < 2));
exp = n_randint(state, 4) + 1;
if (n_randint(state, 2) == 0)
exp = 1;
TEMPLATE(T, poly_divrem) (Q, R, poly, t, ctx);
if (!TEMPLATE(T, poly_is_zero) (R, ctx))
{
TEMPLATE(T, poly_pow) (t, t, exp, ctx);
TEMPLATE(T, poly_mul) (poly, poly, t, ctx);
max_exp = FLINT_MAX(exp, max_exp);
}
}
v = TEMPLATE(T, poly_is_squarefree) (poly, ctx);
if (v == 1)
result = (max_exp <= 1 && !TEMPLATE(T, poly_is_zero) (poly, ctx));
else
result = (max_exp > 1 || TEMPLATE(T, poly_is_zero) (poly, ctx));
if (!result)
{
flint_printf("FAIL: ");
TEMPLATE(T, ctx_print) (ctx);
flint_printf(" %wd, %d\n", max_exp, v);
TEMPLATE(T, poly_print) (poly, ctx);
flint_printf("\n");
abort();
}
TEMPLATE(T, poly_clear) (poly, ctx);
TEMPLATE(T, poly_clear) (t, ctx);
TEMPLATE(T, poly_clear) (Q, ctx);
TEMPLATE(T, poly_clear) (R, ctx);
TEMPLATE(T, ctx_clear) (ctx);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}
#endif

View File

@@ -0,0 +1,114 @@
/*=============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2013 Mike Hansen
******************************************************************************/
#ifdef T
#include "templates.h"
int
main(void)
{
int i, j;
FLINT_TEST_INIT(state);
flint_printf("iterated_frobenius_preinv....");
fflush(stdout);
for (j = 0; j < 20 * flint_test_multiplier(); j++)
{
int result;
fmpz_t q;
slong n;
TEMPLATE(T, ctx_t) ctx;
TEMPLATE(T, poly_t) v, vinv, *h1, *h2;
TEMPLATE(T, ctx_randtest) (ctx, state);
fmpz_init(q);
TEMPLATE(T, ctx_order) (q, ctx);
TEMPLATE(T, poly_init) (v, ctx);
TEMPLATE(T, poly_init) (vinv, ctx);
TEMPLATE(T, poly_randtest_monic) (v, state, n_randint(state, 20) + 1,
ctx);
TEMPLATE(T, poly_reverse) (vinv, v, v->length, ctx);
TEMPLATE(T, poly_inv_series_newton) (vinv, vinv, v->length, ctx);
n = n_randint(state, 5) + 2;
if (!(h1 = flint_malloc((2 * n) * sizeof(TEMPLATE(T, poly_struct)))))
{
flint_printf("Exception (t-fq_poly_iterated_frobenius_preinv):\n");
flint_printf("Not enough memory.\n");
abort();
}
h2 = h1 + n;
for (i = 0; i < 2 * n; i++)
TEMPLATE(T, poly_init) (h1[i], ctx);
TEMPLATE(T, poly_iterated_frobenius_preinv) (h1, n, v, vinv, ctx);
TEMPLATE(T, poly_gen) (h2[0], ctx);
for (i = 1; i < n; i++)
TEMPLATE(T, poly_powmod_fmpz_sliding_preinv) (h2[i], h2[i - 1], q,
0, v, vinv, ctx);
result = 1;
for (i = 0; i < n; i++)
result = result && TEMPLATE(T, poly_equal) (h1[i], h2[i], ctx);
if (!result)
{
flint_printf("FAIL (composition):\n");
flint_printf("v:\n");
TEMPLATE(T, poly_print) (v, ctx);
flint_printf("\n");
abort();
}
TEMPLATE(T, poly_clear) (v, ctx);
TEMPLATE(T, poly_clear) (vinv, ctx);
for (i = 0; i < 2 * n; i++)
TEMPLATE(T, poly_clear) (h1[i], ctx);
flint_free(h1);
TEMPLATE(T, ctx_clear) (ctx);
fmpz_clear(q);
}
FLINT_TEST_CLEANUP(state);
flint_printf("PASS\n");
return 0;
}
#endif