ALL: Add flint
This commit is contained in:
271
external/flint-2.4.3/nmod_poly_factor/test/t-factor.c
vendored
Normal file
271
external/flint-2.4.3/nmod_poly_factor/test/t-factor.c
vendored
Normal file
@@ -0,0 +1,271 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
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
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_vec.h"
|
||||
#include "nmod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int iter;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("factor....");
|
||||
fflush(stdout);
|
||||
|
||||
/* Default algorithm */
|
||||
for (iter = 0; iter < 10 * flint_test_multiplier(); iter++)
|
||||
{
|
||||
int result = 1;
|
||||
nmod_poly_t pol1, poly, quot, rem, product;
|
||||
nmod_poly_factor_t res;
|
||||
mp_limb_t modulus, lead = 1;
|
||||
slong length, num, i, j;
|
||||
ulong exp[5], prod1;
|
||||
|
||||
modulus = n_randtest_prime(state, 0);
|
||||
|
||||
nmod_poly_init(pol1, modulus);
|
||||
nmod_poly_init(poly, modulus);
|
||||
nmod_poly_init(quot, modulus);
|
||||
nmod_poly_init(rem, modulus);
|
||||
|
||||
nmod_poly_zero(pol1);
|
||||
nmod_poly_set_coeff_ui(pol1, 0, 1);
|
||||
|
||||
length = n_randint(state, 7) + 2;
|
||||
do
|
||||
{
|
||||
nmod_poly_randtest(poly, state, length);
|
||||
if (poly->length)
|
||||
nmod_poly_make_monic(poly, poly);
|
||||
}
|
||||
while ((!nmod_poly_is_irreducible(poly)) || (poly->length < 2));
|
||||
|
||||
exp[0] = n_randint(state, 30) + 1;
|
||||
prod1 = exp[0];
|
||||
for (i = 0; i < exp[0]; i++)
|
||||
nmod_poly_mul(pol1, pol1, poly);
|
||||
|
||||
num = n_randint(state, 5) + 1;
|
||||
for (i = 1; i < num; i++)
|
||||
{
|
||||
do
|
||||
{
|
||||
length = n_randint(state, 7) + 2;
|
||||
nmod_poly_randtest(poly, state, length);
|
||||
if (poly->length)
|
||||
{
|
||||
nmod_poly_make_monic(poly, poly);
|
||||
nmod_poly_divrem(quot, rem, pol1, poly);
|
||||
}
|
||||
}
|
||||
while ((!nmod_poly_is_irreducible(poly)) ||
|
||||
(poly->length < 2) || (rem->length == 0));
|
||||
exp[i] = n_randint(state, 30) + 1;
|
||||
prod1 *= exp[i];
|
||||
|
||||
for (j = 0; j < exp[i]; j++)
|
||||
nmod_poly_mul(pol1, pol1, poly);
|
||||
}
|
||||
|
||||
nmod_poly_factor_init(res);
|
||||
|
||||
switch (n_randint(state, 3))
|
||||
{
|
||||
case 0:
|
||||
lead = nmod_poly_factor(res, pol1);
|
||||
break;
|
||||
case 1:
|
||||
lead = nmod_poly_factor_with_berlekamp(res, pol1);
|
||||
break;
|
||||
case 2:
|
||||
if (modulus == 2)
|
||||
lead = nmod_poly_factor(res, pol1);
|
||||
else
|
||||
lead = nmod_poly_factor_with_cantor_zassenhaus(res, pol1);
|
||||
break;
|
||||
}
|
||||
|
||||
result &= (res->num == num);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("Error: number of factors incorrect, %wd, %wd\n",
|
||||
res->num, num);
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_init(product, pol1->mod.n);
|
||||
nmod_poly_set_coeff_ui(product, 0, 1);
|
||||
for (i = 0; i < res->num; i++)
|
||||
for (j = 0; j < res->exp[i]; j++)
|
||||
nmod_poly_mul(product, product, res->p + i);
|
||||
nmod_poly_scalar_mul_nmod(product, product, lead);
|
||||
result &= nmod_poly_equal(pol1, product);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("Error: product of factors does not equal original polynomial\n");
|
||||
nmod_poly_print(pol1); flint_printf("\n");
|
||||
nmod_poly_print(product); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
nmod_poly_clear(product);
|
||||
|
||||
nmod_poly_clear(quot);
|
||||
nmod_poly_clear(rem);
|
||||
nmod_poly_clear(pol1);
|
||||
nmod_poly_clear(poly);
|
||||
nmod_poly_factor_clear(res);
|
||||
}
|
||||
|
||||
/* Test deflation trick */
|
||||
for (iter = 0; iter < 10 * flint_test_multiplier(); iter++)
|
||||
{
|
||||
nmod_poly_t pol1, poly, quot, rem;
|
||||
nmod_poly_factor_t res, res2;
|
||||
mp_limb_t modulus;
|
||||
slong length, num, i, j;
|
||||
slong exp[5], prod1;
|
||||
ulong inflation;
|
||||
int found;
|
||||
|
||||
do {
|
||||
modulus = n_randtest_prime(state, 0);
|
||||
} while (modulus == 2); /* To compare with CZ */
|
||||
|
||||
nmod_poly_init(pol1, modulus);
|
||||
nmod_poly_init(poly, modulus);
|
||||
nmod_poly_init(quot, modulus);
|
||||
nmod_poly_init(rem, modulus);
|
||||
|
||||
nmod_poly_zero(pol1);
|
||||
nmod_poly_set_coeff_ui(pol1, 0, 1);
|
||||
|
||||
inflation = n_randint(state, 7) + 1;
|
||||
|
||||
length = n_randint(state, 7) + 2;
|
||||
do
|
||||
{
|
||||
nmod_poly_randtest(poly, state, length);
|
||||
if (poly->length)
|
||||
nmod_poly_make_monic(poly, poly);
|
||||
}
|
||||
while ((!nmod_poly_is_irreducible(poly)) || (poly->length < 2));
|
||||
nmod_poly_inflate(poly, poly, inflation);
|
||||
|
||||
exp[0] = n_randint(state, 6) + 1;
|
||||
prod1 = exp[0];
|
||||
for (i = 0; i < exp[0]; i++)
|
||||
nmod_poly_mul(pol1, pol1, poly);
|
||||
|
||||
num = n_randint(state, 5) + 1;
|
||||
for (i = 1; i < num; i++)
|
||||
{
|
||||
do
|
||||
{
|
||||
length = n_randint(state, 6) + 2;
|
||||
nmod_poly_randtest(poly, state, length);
|
||||
if (poly->length)
|
||||
{
|
||||
nmod_poly_make_monic(poly, poly);
|
||||
nmod_poly_divrem(quot, rem, pol1, poly);
|
||||
}
|
||||
}
|
||||
while ((!nmod_poly_is_irreducible(poly)) ||
|
||||
(poly->length < 2) || (rem->length == 0));
|
||||
exp[i] = n_randint(state, 6) + 1;
|
||||
prod1 *= exp[i];
|
||||
nmod_poly_inflate(poly, poly, inflation);
|
||||
|
||||
for (j = 0; j < exp[i]; j++)
|
||||
nmod_poly_mul(pol1, pol1, poly);
|
||||
}
|
||||
|
||||
nmod_poly_factor_init(res);
|
||||
nmod_poly_factor_init(res2);
|
||||
|
||||
switch (n_randint(state, 3))
|
||||
{
|
||||
case 0:
|
||||
nmod_poly_factor(res, pol1);
|
||||
break;
|
||||
case 1:
|
||||
nmod_poly_factor_with_berlekamp(res, pol1);
|
||||
break;
|
||||
case 2:
|
||||
nmod_poly_factor_with_cantor_zassenhaus(res, pol1);
|
||||
break;
|
||||
}
|
||||
|
||||
nmod_poly_factor_cantor_zassenhaus(res2, pol1);
|
||||
|
||||
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 (nmod_poly_equal(res->p + i, res2->p + j) &&
|
||||
res->exp[i] == res2->exp[j])
|
||||
{
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
flint_printf("FAIL: factor not found\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
nmod_poly_clear(quot);
|
||||
nmod_poly_clear(rem);
|
||||
nmod_poly_clear(pol1);
|
||||
nmod_poly_clear(poly);
|
||||
nmod_poly_factor_clear(res);
|
||||
nmod_poly_factor_clear(res2);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
110
external/flint-2.4.3/nmod_poly_factor/test/t-factor_berlekamp.c
vendored
Normal file
110
external/flint-2.4.3/nmod_poly_factor/test/t-factor_berlekamp.c
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2007 David Howden
|
||||
Copyright (C) 2007, 2008, 2009, 2010 William Hart
|
||||
Copyright (C) 2008 Richard Howell-Peak
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_vec.h"
|
||||
#include "nmod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int iter;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("factor_berlekamp....");
|
||||
fflush(stdout);
|
||||
|
||||
for (iter = 0; iter < 20 * flint_test_multiplier(); iter++)
|
||||
{
|
||||
int result = 1;
|
||||
nmod_poly_t pol1, poly, quot, rem;
|
||||
nmod_poly_factor_t res;
|
||||
mp_limb_t modulus;
|
||||
slong i, length, num;
|
||||
|
||||
modulus = n_randtest_prime(state, 0);
|
||||
|
||||
nmod_poly_init(pol1, modulus);
|
||||
nmod_poly_init(poly, modulus);
|
||||
nmod_poly_init(quot, modulus);
|
||||
nmod_poly_init(rem, modulus);
|
||||
|
||||
length = n_randint(state, 10) + 2;
|
||||
do
|
||||
{
|
||||
nmod_poly_randtest(pol1, state, length);
|
||||
if (pol1->length)
|
||||
nmod_poly_make_monic(pol1, pol1);
|
||||
}
|
||||
while ((!nmod_poly_is_irreducible(pol1)) || (pol1->length < 2));
|
||||
|
||||
num = n_randint(state, 5) + 1;
|
||||
for (i = 1; i < num; i++)
|
||||
{
|
||||
do
|
||||
{
|
||||
length = n_randint(state, 10) + 2;
|
||||
nmod_poly_randtest(poly, state, length);
|
||||
if (poly->length)
|
||||
{
|
||||
nmod_poly_make_monic(poly, poly);
|
||||
nmod_poly_divrem(quot, rem, pol1, poly);
|
||||
}
|
||||
}
|
||||
while ((!nmod_poly_is_irreducible(poly)) || (poly->length < 2)
|
||||
|| (rem->length == 0));
|
||||
nmod_poly_mul(pol1, pol1, poly);
|
||||
}
|
||||
|
||||
nmod_poly_factor_init(res);
|
||||
nmod_poly_factor_berlekamp(res, pol1);
|
||||
|
||||
result = (res->num == num);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL: %wu, %wd, %wd\n", modulus, num, res->num);
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_clear(quot);
|
||||
nmod_poly_clear(rem);
|
||||
nmod_poly_clear(pol1);
|
||||
nmod_poly_clear(poly);
|
||||
nmod_poly_factor_clear(res);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
144
external/flint-2.4.3/nmod_poly_factor/test/t-factor_cantor_zassenhaus.c
vendored
Normal file
144
external/flint-2.4.3/nmod_poly_factor/test/t-factor_cantor_zassenhaus.c
vendored
Normal file
@@ -0,0 +1,144 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
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
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "nmod_poly.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 < 20 * flint_test_multiplier(); iter++)
|
||||
{
|
||||
int result = 1;
|
||||
nmod_poly_t pol1, poly, quot, rem;
|
||||
nmod_poly_t product;
|
||||
nmod_poly_factor_t res;
|
||||
mp_limb_t modulus, lead;
|
||||
slong i, j, length, num;
|
||||
slong prod1, exp[5];
|
||||
|
||||
modulus = n_randtest_prime(state, 0);
|
||||
|
||||
nmod_poly_init(pol1, modulus);
|
||||
nmod_poly_init(poly, modulus);
|
||||
nmod_poly_init(quot, modulus);
|
||||
nmod_poly_init(rem, modulus);
|
||||
|
||||
nmod_poly_zero(pol1);
|
||||
nmod_poly_set_coeff_ui(pol1, 0, 1);
|
||||
|
||||
length = n_randint(state, 7) + 2;
|
||||
|
||||
do
|
||||
{
|
||||
nmod_poly_randtest(poly, state, length);
|
||||
if(!nmod_poly_is_zero(poly))
|
||||
nmod_poly_make_monic(poly, poly);
|
||||
}
|
||||
while ((poly->length < 2) || (!nmod_poly_is_irreducible(poly)));
|
||||
|
||||
exp[0] = n_randint(state, 30) + 1;
|
||||
prod1 = exp[0];
|
||||
for (i = 0; i < exp[0]; i++)
|
||||
nmod_poly_mul(pol1, pol1, poly);
|
||||
|
||||
num = n_randint(state, 5) + 1;
|
||||
|
||||
for (i = 1; i < num; i++)
|
||||
{
|
||||
do
|
||||
{
|
||||
length = n_randint(state, 7) + 2;
|
||||
nmod_poly_randtest(poly, state, length);
|
||||
if(!nmod_poly_is_zero(poly))
|
||||
{
|
||||
nmod_poly_make_monic(poly, poly);
|
||||
nmod_poly_divrem(quot, rem, pol1, poly);
|
||||
}
|
||||
}
|
||||
while ((!nmod_poly_is_irreducible(poly)) || (poly->length < 2) ||
|
||||
(rem->length == 0));
|
||||
|
||||
exp[i] = n_randint(state, 30) + 1;
|
||||
prod1 *= exp[i];
|
||||
for (j = 0; j < exp[i]; j++)
|
||||
nmod_poly_mul(pol1, pol1, poly);
|
||||
}
|
||||
|
||||
nmod_poly_factor_init(res);
|
||||
nmod_poly_factor_cantor_zassenhaus(res, pol1);
|
||||
result &= (res->num == num);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("Error: number of factors incorrect, %wd, %wd\n",
|
||||
res->num, num);
|
||||
}
|
||||
|
||||
nmod_poly_init(product, pol1->mod.n);
|
||||
nmod_poly_set_coeff_ui(product, 0, 1);
|
||||
for (i = 0; i < res->num; i++)
|
||||
for (j = 0; j < res->exp[i]; j++)
|
||||
nmod_poly_mul(product, product, res->p + i);
|
||||
|
||||
lead = pol1->coeffs[pol1->length - 1];
|
||||
nmod_poly_scalar_mul_nmod(product, product, lead);
|
||||
result &= nmod_poly_equal(pol1, product);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("Error: product of factors does not equal original polynomial\n");
|
||||
nmod_poly_print(pol1); flint_printf("\n");
|
||||
nmod_poly_print(product); flint_printf("\n");
|
||||
}
|
||||
|
||||
if (!result)
|
||||
abort();
|
||||
|
||||
|
||||
nmod_poly_clear(product);
|
||||
nmod_poly_clear(quot);
|
||||
nmod_poly_clear(rem);
|
||||
nmod_poly_clear(pol1);
|
||||
nmod_poly_clear(poly);
|
||||
nmod_poly_factor_clear(res);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
130
external/flint-2.4.3/nmod_poly_factor/test/t-factor_distinct_deg.c
vendored
Normal file
130
external/flint-2.4.3/nmod_poly_factor/test/t-factor_distinct_deg.c
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 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
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "nmod_poly.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++)
|
||||
{
|
||||
nmod_poly_t poly1, poly, q, r, product;
|
||||
nmod_poly_factor_t res;
|
||||
mp_limb_t modulus, lead;
|
||||
slong i, length, num;
|
||||
slong *degs;
|
||||
|
||||
modulus = n_randtest_prime(state, 0);
|
||||
|
||||
nmod_poly_init(poly1, modulus);
|
||||
nmod_poly_init(poly, modulus);
|
||||
nmod_poly_init(q, modulus);
|
||||
nmod_poly_init(r, modulus);
|
||||
|
||||
nmod_poly_zero(poly1);
|
||||
nmod_poly_set_coeff_ui(poly1, 0, 1);
|
||||
|
||||
length = n_randint(state, 7) + 2;
|
||||
do
|
||||
{
|
||||
nmod_poly_randtest(poly, state, length);
|
||||
if (poly->length)
|
||||
nmod_poly_make_monic(poly, poly);
|
||||
}
|
||||
while ((poly->length < 2) || (!nmod_poly_is_irreducible(poly)));
|
||||
|
||||
nmod_poly_mul(poly1, poly1, poly);
|
||||
|
||||
num = n_randint(state, 5) + 1;
|
||||
|
||||
for (i = 1; i < num; i++)
|
||||
{
|
||||
do
|
||||
{
|
||||
length = n_randint(state, 7) + 2;
|
||||
nmod_poly_randtest(poly, state, length);
|
||||
if (poly->length)
|
||||
{
|
||||
nmod_poly_make_monic(poly, poly);
|
||||
nmod_poly_divrem(q, r, poly1, poly);
|
||||
}
|
||||
}
|
||||
while ((poly->length < 2) || (!nmod_poly_is_irreducible(poly)) ||
|
||||
(r->length == 0));
|
||||
|
||||
nmod_poly_mul(poly1, poly1, poly);
|
||||
}
|
||||
|
||||
if (!(degs = flint_malloc((poly1->length - 1) * sizeof(slong))))
|
||||
{
|
||||
flint_printf("Fatal error: not enough memory.");
|
||||
abort();
|
||||
}
|
||||
nmod_poly_factor_init(res);
|
||||
nmod_poly_factor_distinct_deg(res, poly1, °s);
|
||||
|
||||
nmod_poly_init_preinv(product, poly1->mod.n, poly1->mod.ninv);
|
||||
nmod_poly_set_coeff_ui(product, 0, 1);
|
||||
for (i = 0; i < res->num; i++)
|
||||
nmod_poly_mul(product, product, res->p + i);
|
||||
|
||||
lead = poly1->coeffs[poly1->length - 1];
|
||||
nmod_poly_scalar_mul_nmod(product, product, lead);
|
||||
|
||||
if (!nmod_poly_equal(poly1, product))
|
||||
{
|
||||
flint_printf("Error: product of factors does not equal to the original polynomial\n");
|
||||
flint_printf("poly:\n"); nmod_poly_print(poly1); flint_printf("\n");
|
||||
flint_printf("product:\n"); nmod_poly_print(product); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
flint_free(degs);
|
||||
nmod_poly_clear(product);
|
||||
nmod_poly_clear(q);
|
||||
nmod_poly_clear(r);
|
||||
nmod_poly_clear(poly1);
|
||||
nmod_poly_clear(poly);
|
||||
nmod_poly_factor_clear(res);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
135
external/flint-2.4.3/nmod_poly_factor/test/t-factor_kaltofen_shoup.c
vendored
Normal file
135
external/flint-2.4.3/nmod_poly_factor/test/t-factor_kaltofen_shoup.c
vendored
Normal 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) 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
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "nmod_poly.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 < 200; iter++)
|
||||
{
|
||||
nmod_poly_t poly1, poly, q, r, product;
|
||||
nmod_poly_factor_t res;
|
||||
mp_limb_t modulus, lead;
|
||||
slong i, j, length, num;
|
||||
slong exp[5];
|
||||
|
||||
modulus = n_randtest_prime(state, 0);
|
||||
|
||||
nmod_poly_init(poly1, modulus);
|
||||
nmod_poly_init(poly, modulus);
|
||||
nmod_poly_init(q, modulus);
|
||||
nmod_poly_init(r, modulus);
|
||||
|
||||
nmod_poly_zero(poly1);
|
||||
nmod_poly_set_coeff_ui(poly1, 0, 1);
|
||||
|
||||
length = n_randint(state, 7) + 2;
|
||||
do
|
||||
{
|
||||
nmod_poly_randtest(poly, state, length);
|
||||
if (poly->length)
|
||||
nmod_poly_make_monic(poly, poly);
|
||||
}
|
||||
while ((poly->length < 2) || (!nmod_poly_is_irreducible(poly)));
|
||||
|
||||
exp[0] = n_randint(state, 30) + 1;
|
||||
for (i = 0; i < exp[0]; i++)
|
||||
nmod_poly_mul(poly1, poly1, poly);
|
||||
|
||||
num = n_randint(state, 5) + 1;
|
||||
|
||||
for (i = 1; i < num; i++)
|
||||
{
|
||||
do
|
||||
{
|
||||
length = n_randint(state, 7) + 2;
|
||||
nmod_poly_randtest(poly, state, length);
|
||||
if (poly->length)
|
||||
{
|
||||
nmod_poly_make_monic(poly, poly);
|
||||
nmod_poly_divrem(q, r, poly1, poly);
|
||||
}
|
||||
}
|
||||
while ((poly->length < 2) || (!nmod_poly_is_irreducible(poly)) ||
|
||||
(r->length == 0));
|
||||
|
||||
exp[i] = n_randint(state, 30) + 1;
|
||||
for (j = 0; j < exp[i]; j++)
|
||||
nmod_poly_mul(poly1, poly1, poly);
|
||||
}
|
||||
|
||||
nmod_poly_factor_init(res);
|
||||
nmod_poly_factor_kaltofen_shoup(res, poly1);
|
||||
|
||||
if (res->num != num)
|
||||
{
|
||||
flint_printf("Error: number of factors incorrect: %wd != %wd\n", res->num, num);
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_init_preinv(product, poly1->mod.n, poly1->mod.ninv);
|
||||
nmod_poly_set_coeff_ui(product, 0, 1);
|
||||
for (i = 0; i < res->num; i++)
|
||||
for (j = 0; j < res->exp[i]; j++)
|
||||
nmod_poly_mul(product, product, res->p + i);
|
||||
|
||||
lead = poly1->coeffs[poly1->length - 1];
|
||||
nmod_poly_scalar_mul_nmod(product, product, lead);
|
||||
|
||||
if (!nmod_poly_equal(poly1, product))
|
||||
{
|
||||
flint_printf("Error: product of factors does not equal to the original polynomial\n");
|
||||
flint_printf("poly:\n"); nmod_poly_print(poly1); flint_printf("\n");
|
||||
flint_printf("product:\n"); nmod_poly_print(product); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_clear(product);
|
||||
nmod_poly_clear(q);
|
||||
nmod_poly_clear(r);
|
||||
nmod_poly_clear(poly1);
|
||||
nmod_poly_clear(poly);
|
||||
nmod_poly_factor_clear(res);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
140
external/flint-2.4.3/nmod_poly_factor/test/t-factor_squarefree.c
vendored
Normal file
140
external/flint-2.4.3/nmod_poly_factor/test/t-factor_squarefree.c
vendored
Normal file
@@ -0,0 +1,140 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
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
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_vec.h"
|
||||
#include "nmod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int iter;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("factor_squarefree....");
|
||||
fflush(stdout);
|
||||
|
||||
for (iter = 0; iter < 30 * flint_test_multiplier(); iter++)
|
||||
{
|
||||
int result = 1;
|
||||
nmod_poly_t pol1, poly, quot, rem;
|
||||
nmod_poly_factor_t res;
|
||||
mp_limb_t modulus;
|
||||
slong exp[5], prod1;
|
||||
slong length, i, j, num;
|
||||
|
||||
modulus = n_randtest_prime(state, 0);
|
||||
|
||||
nmod_poly_init(pol1, modulus);
|
||||
nmod_poly_init(poly, modulus);
|
||||
nmod_poly_init(quot, modulus);
|
||||
nmod_poly_init(rem, modulus);
|
||||
|
||||
nmod_poly_zero(pol1);
|
||||
nmod_poly_set_coeff_ui(pol1, 0, 1);
|
||||
|
||||
length = n_randint(state, 7) + 2;
|
||||
|
||||
do
|
||||
{
|
||||
nmod_poly_randtest(poly, state, length);
|
||||
if(!nmod_poly_is_zero(poly))
|
||||
nmod_poly_make_monic(poly, poly);
|
||||
}
|
||||
while ((!nmod_poly_is_irreducible(poly)) || (poly->length < 2));
|
||||
exp[0] = n_randprime(state, 5, 0);
|
||||
|
||||
prod1 = exp[0];
|
||||
for (i = 0; i < exp[0]; i++)
|
||||
nmod_poly_mul(pol1, pol1, poly);
|
||||
|
||||
num = n_randint(state, 5) + 1;
|
||||
for (i = 1; i < num; i++)
|
||||
{
|
||||
do
|
||||
{
|
||||
length = n_randint(state, 7) + 2;
|
||||
nmod_poly_randtest(poly, state, length);
|
||||
if (poly->length)
|
||||
{
|
||||
nmod_poly_make_monic(poly, poly);
|
||||
nmod_poly_divrem(quot, rem, pol1, poly);
|
||||
}
|
||||
}
|
||||
while ((!nmod_poly_is_irreducible(poly)) ||
|
||||
(poly->length < 2) || (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++)
|
||||
nmod_poly_mul(pol1, pol1, poly);
|
||||
}
|
||||
|
||||
nmod_poly_factor_init(res);
|
||||
nmod_poly_factor_squarefree(res, pol1);
|
||||
|
||||
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. Modulus = %wu\n", modulus);
|
||||
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();
|
||||
}
|
||||
|
||||
nmod_poly_clear(quot);
|
||||
nmod_poly_clear(rem);
|
||||
nmod_poly_clear(pol1);
|
||||
nmod_poly_clear(poly);
|
||||
nmod_poly_factor_clear(res);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
109
external/flint-2.4.3/nmod_poly_factor/test/t-is_irreducible.c
vendored
Normal file
109
external/flint-2.4.3/nmod_poly_factor/test/t-is_irreducible.c
vendored
Normal 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) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_vec.h"
|
||||
#include "nmod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int iter;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("is_irreducible....");
|
||||
fflush(stdout);
|
||||
|
||||
for (iter = 0; iter < 200 * flint_test_multiplier(); iter++)
|
||||
{
|
||||
nmod_poly_t poly, poly2, poly3;
|
||||
nmod_poly_factor_t factors;
|
||||
mp_limb_t modulus;
|
||||
slong length, length2;
|
||||
int result = 1;
|
||||
|
||||
modulus = n_randtest_prime(state, 0);
|
||||
|
||||
nmod_poly_init(poly, modulus);
|
||||
nmod_poly_init(poly2, modulus);
|
||||
nmod_poly_init(poly3, modulus);
|
||||
|
||||
length = n_randint(state, 10) + 2;
|
||||
|
||||
do
|
||||
{
|
||||
nmod_poly_randtest(poly, state, length);
|
||||
if(!nmod_poly_is_zero(poly))
|
||||
nmod_poly_make_monic(poly, poly);
|
||||
}
|
||||
while ((!nmod_poly_is_irreducible(poly)) || (poly->length < 2));
|
||||
|
||||
nmod_poly_factor_init(factors);
|
||||
nmod_poly_factor_berlekamp(factors, poly);
|
||||
result &= (factors->num == 1);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("Irreducible polynomial should not have non-trivial factors!\n");
|
||||
flint_printf("poly = "), nmod_poly_print(poly), flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
nmod_poly_factor_clear(factors);
|
||||
|
||||
length2 = n_randint(state, 10) + 2;
|
||||
|
||||
do
|
||||
{
|
||||
nmod_poly_randtest(poly2, state, length2);
|
||||
if(!nmod_poly_is_zero(poly2))
|
||||
nmod_poly_make_monic(poly2, poly2);
|
||||
}
|
||||
while ((!nmod_poly_is_irreducible(poly2)) || (poly2->length < 2));
|
||||
|
||||
nmod_poly_mul(poly3, poly, poly2);
|
||||
|
||||
result &= !nmod_poly_is_irreducible(poly3);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("Error: reducible polynomial declared irreducible!\n");
|
||||
nmod_poly_print(poly3); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_clear(poly);
|
||||
nmod_poly_clear(poly2);
|
||||
nmod_poly_clear(poly3);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
115
external/flint-2.4.3/nmod_poly_factor/test/t-is_irreducible_ddf.c
vendored
Normal file
115
external/flint-2.4.3/nmod_poly_factor/test/t-is_irreducible_ddf.c
vendored
Normal 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) 2011 Fredrik Johansson
|
||||
Copyright (C) 2013 Martin Lee
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#undef ulong
|
||||
#define ulong ulongxx/* interferes with system includes */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#undef ulong
|
||||
|
||||
#include <gmp.h>
|
||||
|
||||
#define ulong mp_limb_t
|
||||
|
||||
#include "flint.h"
|
||||
#include "nmod_vec.h"
|
||||
#include "nmod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int iter;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("is_irreducible_ddf....");
|
||||
fflush(stdout);
|
||||
|
||||
for (iter = 0; iter < 200 * flint_test_multiplier(); iter++)
|
||||
{
|
||||
nmod_poly_t poly, poly2, poly3;
|
||||
mp_limb_t modulus;
|
||||
slong length, length2;
|
||||
int result = 1;
|
||||
|
||||
modulus = n_randtest_prime(state, 0);
|
||||
|
||||
nmod_poly_init(poly, modulus);
|
||||
nmod_poly_init(poly2, modulus);
|
||||
nmod_poly_init(poly3, modulus);
|
||||
|
||||
length = n_randint(state, 10) + 2;
|
||||
|
||||
do
|
||||
{
|
||||
nmod_poly_randtest(poly, state, length);
|
||||
if(!nmod_poly_is_zero(poly))
|
||||
nmod_poly_make_monic(poly, poly);
|
||||
}
|
||||
while ((poly->length < 2));
|
||||
|
||||
result &= (nmod_poly_is_irreducible_rabin (poly) == nmod_poly_is_irreducible_ddf (poly));
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("result of is_irreducible and is_irreducible_ddf does not coincide\n");
|
||||
flint_printf("poly = "), nmod_poly_print(poly), flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
length2 = n_randint(state, 10) + 2;
|
||||
|
||||
do
|
||||
{
|
||||
nmod_poly_randtest(poly2, state, length2);
|
||||
if(!nmod_poly_is_zero(poly2))
|
||||
nmod_poly_make_monic(poly2, poly2);
|
||||
}
|
||||
while ((!nmod_poly_is_irreducible_rabin(poly2)) || (poly2->length < 2));
|
||||
|
||||
nmod_poly_mul(poly3, poly, poly2);
|
||||
|
||||
result &= !nmod_poly_is_irreducible_ddf(poly3);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("Error: reducible polynomial declared irreducible!\n");
|
||||
nmod_poly_print(poly3); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_clear(poly);
|
||||
nmod_poly_clear(poly2);
|
||||
nmod_poly_clear(poly3);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
118
external/flint-2.4.3/nmod_poly_factor/test/t-is_irreducible_rabin.c
vendored
Normal file
118
external/flint-2.4.3/nmod_poly_factor/test/t-is_irreducible_rabin.c
vendored
Normal 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) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#undef ulong
|
||||
#define ulong ulongxx/* interferes with system includes */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#undef ulong
|
||||
|
||||
#include <gmp.h>
|
||||
|
||||
#define ulong mp_limb_t
|
||||
|
||||
#include "flint.h"
|
||||
#include "nmod_vec.h"
|
||||
#include "nmod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int iter;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("is_irreducible_rabin....");
|
||||
fflush(stdout);
|
||||
|
||||
for (iter = 0; iter < 200 * flint_test_multiplier(); iter++)
|
||||
{
|
||||
nmod_poly_t poly, poly2, poly3;
|
||||
nmod_poly_factor_t factors;
|
||||
mp_limb_t modulus;
|
||||
slong length, length2;
|
||||
int result = 1;
|
||||
|
||||
modulus = n_randtest_prime(state, 0);
|
||||
|
||||
nmod_poly_init(poly, modulus);
|
||||
nmod_poly_init(poly2, modulus);
|
||||
nmod_poly_init(poly3, modulus);
|
||||
|
||||
length = n_randint(state, 10) + 2;
|
||||
|
||||
do
|
||||
{
|
||||
nmod_poly_randtest(poly, state, length);
|
||||
if(!nmod_poly_is_zero(poly))
|
||||
nmod_poly_make_monic(poly, poly);
|
||||
}
|
||||
while ((!nmod_poly_is_irreducible_rabin(poly)) || (poly->length < 2));
|
||||
|
||||
nmod_poly_factor_init(factors);
|
||||
nmod_poly_factor_berlekamp(factors, poly);
|
||||
result &= (factors->num == 1);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("Irreducible polynomial should not have non-trivial factors!\n");
|
||||
flint_printf("poly = "), nmod_poly_print(poly), flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
nmod_poly_factor_clear(factors);
|
||||
|
||||
length2 = n_randint(state, 10) + 2;
|
||||
|
||||
do
|
||||
{
|
||||
nmod_poly_randtest(poly2, state, length2);
|
||||
if(!nmod_poly_is_zero(poly2))
|
||||
nmod_poly_make_monic(poly2, poly2);
|
||||
}
|
||||
while ((!nmod_poly_is_irreducible_rabin(poly2)) || (poly2->length < 2));
|
||||
|
||||
nmod_poly_mul(poly3, poly, poly2);
|
||||
|
||||
result &= !nmod_poly_is_irreducible_rabin(poly3);
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("Error: reducible polynomial declared irreducible!\n");
|
||||
nmod_poly_print(poly3); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_clear(poly);
|
||||
nmod_poly_clear(poly2);
|
||||
nmod_poly_clear(poly3);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
106
external/flint-2.4.3/nmod_poly_factor/test/t-is_squarefree.c
vendored
Normal file
106
external/flint-2.4.3/nmod_poly_factor/test/t-is_squarefree.c
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "nmod_vec.h"
|
||||
#include "nmod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int iter;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
|
||||
flint_printf("is_squarefree....");
|
||||
fflush(stdout);
|
||||
|
||||
for (iter = 0; iter < 200 * flint_test_multiplier(); iter++)
|
||||
{
|
||||
nmod_poly_t poly, Q, R, t;
|
||||
mp_limb_t modulus;
|
||||
slong i, num_factors, exp, max_exp;
|
||||
int v, result;
|
||||
|
||||
modulus = n_randtest_prime(state, 0);
|
||||
|
||||
nmod_poly_init(poly, modulus);
|
||||
nmod_poly_init(t, modulus);
|
||||
nmod_poly_init(Q, modulus);
|
||||
nmod_poly_init(R, modulus);
|
||||
|
||||
nmod_poly_set_coeff_ui(poly, 0, n_randint(state, modulus));
|
||||
num_factors = n_randint(state, 5);
|
||||
|
||||
max_exp = 0;
|
||||
for (i = 0; i < num_factors; i++)
|
||||
{
|
||||
do {
|
||||
nmod_poly_randtest(t, state, n_randint(state, 10));
|
||||
} while (!nmod_poly_is_irreducible(t) ||
|
||||
(nmod_poly_length(t) < 2));
|
||||
|
||||
exp = n_randint(state, 4) + 1;
|
||||
if (n_randint(state, 2) == 0)
|
||||
exp = 1;
|
||||
|
||||
nmod_poly_divrem(Q, R, poly, t);
|
||||
if (!nmod_poly_is_zero(R))
|
||||
{
|
||||
nmod_poly_pow(t, t, exp);
|
||||
nmod_poly_mul(poly, poly, t);
|
||||
max_exp = FLINT_MAX(exp, max_exp);
|
||||
}
|
||||
}
|
||||
|
||||
v = nmod_poly_is_squarefree(poly);
|
||||
|
||||
if (v == 1)
|
||||
result = (max_exp <= 1 && !nmod_poly_is_zero(poly));
|
||||
else
|
||||
result = (max_exp > 1 || nmod_poly_is_zero(poly));
|
||||
|
||||
if (!result)
|
||||
{
|
||||
flint_printf("FAIL: %wu, %wd, %d\n", modulus, max_exp, v);
|
||||
nmod_poly_print(poly); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
nmod_poly_clear(poly);
|
||||
nmod_poly_clear(t);
|
||||
nmod_poly_clear(Q);
|
||||
nmod_poly_clear(R);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user