ALL: Add flint
This commit is contained in:
353
external/flint-2.4.3/nmod_poly_factor/profile/p-factor.c
vendored
Normal file
353
external/flint-2.4.3/nmod_poly_factor/profile/p-factor.c
vendored
Normal file
@@ -0,0 +1,353 @@
|
||||
/*=============================================================================
|
||||
|
||||
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
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <gmp.h>
|
||||
|
||||
#include "flint.h"
|
||||
#include "nmod_poly.h"
|
||||
|
||||
#define NP 100 /* number of moduli */
|
||||
#define ND 8 /* number of degrees */
|
||||
|
||||
/*
|
||||
Benchmarking code for factorisation in nmod_poly.
|
||||
|
||||
Test how the relation between n (degree of polynomial) and p
|
||||
affects working time for Cantor-Zassenhaus, Berlekamp and
|
||||
Kaltofen-Shoup algorithms. p and n are chosen independently.
|
||||
*/
|
||||
|
||||
int main(void)
|
||||
{
|
||||
FLINT_TEST_INIT(state);
|
||||
nmod_poly_t f, g;
|
||||
nmod_poly_factor_t res;
|
||||
mp_limb_t modulus;
|
||||
int i, j, k, n, num;
|
||||
double t, T1, T2, T3, T4;
|
||||
|
||||
const slong degs[] = {8, 16, 32, 64, 128, 256, 512, 1024};
|
||||
const int iter_count[] = {10000, 5000, 1000, 500, 300, 100, 50, 20};
|
||||
|
||||
|
||||
|
||||
flint_printf("Random polynomials\n");
|
||||
for (i = 0; i < NP; i++)
|
||||
{
|
||||
modulus = n_randtest_prime(state, 0);
|
||||
flint_printf("========== p: %wu\n", modulus);
|
||||
fflush(stdout);
|
||||
|
||||
for (j = 0; j < ND; j++)
|
||||
{
|
||||
n = degs[j];
|
||||
flint_printf(">>>>>n: %d\n", n);
|
||||
fflush(stdout);
|
||||
|
||||
T1 = 0;
|
||||
T2 = 0;
|
||||
T3 = 0;
|
||||
for (k = 0; k < iter_count[j]; k++)
|
||||
{
|
||||
nmod_poly_init(f, modulus);
|
||||
nmod_poly_randtest_not_zero(f, state, n);
|
||||
|
||||
t = clock();
|
||||
nmod_poly_factor_init(res);
|
||||
nmod_poly_factor_with_cantor_zassenhaus(res, f);
|
||||
nmod_poly_factor_clear(res);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
T1 += t;
|
||||
|
||||
t = clock();
|
||||
nmod_poly_factor_init(res);
|
||||
nmod_poly_factor_with_berlekamp(res, f);
|
||||
nmod_poly_factor_clear(res);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
T2 += t;
|
||||
|
||||
t = clock();
|
||||
nmod_poly_factor_init(res);
|
||||
nmod_poly_factor_kaltofen_shoup(res, f);
|
||||
nmod_poly_factor_clear(res);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
T3 += t;
|
||||
|
||||
nmod_poly_clear(f);
|
||||
}
|
||||
|
||||
flint_printf("CZ: %.2lf B: %.2lf KS: %.2lf\n", T1, T2, T3);
|
||||
fflush(stdout);
|
||||
|
||||
if (T1 > T3 + 1)
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* This code checks whether nmod_poly_factor
|
||||
made a correct choice between CZ, B and KS */
|
||||
|
||||
flint_printf("Check choice correctness\n");
|
||||
for (i = 0; i < NP; i++)
|
||||
{
|
||||
modulus = n_randtest_prime(state, 0);
|
||||
flint_printf("========== p: %wu\n", modulus);
|
||||
fflush(stdout);
|
||||
|
||||
for (j = 0; j < ND; j++)
|
||||
{
|
||||
n = degs[j];
|
||||
flint_printf(">>>>>n: %d\n", n);
|
||||
fflush(stdout);
|
||||
|
||||
T1 = 0;
|
||||
T2 = 0;
|
||||
T3 = 0;
|
||||
T4 = 0;
|
||||
for (k = 0; k < iter_count[j]; k++)
|
||||
{
|
||||
nmod_poly_init(f, modulus);
|
||||
nmod_poly_randtest_not_zero(f, state, n);
|
||||
|
||||
t = clock();
|
||||
nmod_poly_factor_init(res);
|
||||
nmod_poly_factor_with_cantor_zassenhaus(res, f);
|
||||
nmod_poly_factor_clear(res);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
T1 += t;
|
||||
|
||||
t = clock();
|
||||
nmod_poly_factor_init(res);
|
||||
nmod_poly_factor_berlekamp(res, f);
|
||||
nmod_poly_factor_clear(res);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
T2 += t;
|
||||
|
||||
t = clock();
|
||||
nmod_poly_factor_init(res);
|
||||
nmod_poly_factor_kaltofen_shoup(res, f);
|
||||
nmod_poly_factor_clear(res);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
T3 += t;
|
||||
|
||||
t = clock();
|
||||
nmod_poly_factor_init(res);
|
||||
nmod_poly_factor(res, f);
|
||||
nmod_poly_factor_clear(res);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
T4 += t;
|
||||
|
||||
nmod_poly_clear(f);
|
||||
}
|
||||
|
||||
flint_printf("CZ: %.2lf B: %.2lf KS: %.2lf F: %.2lf\n", T1, T2, T3, T4);
|
||||
fflush(stdout);
|
||||
|
||||
if (T1 > T3 + 1)
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
flint_printf("Irreducible polynomials\n");
|
||||
for (i = 0; i < NP; i++)
|
||||
{
|
||||
modulus = n_randtest_prime(state, 0);
|
||||
flint_printf("========== p: %wu\n", modulus);
|
||||
fflush(stdout);
|
||||
|
||||
for (j = 0; j < ND; j++)
|
||||
{
|
||||
n = degs[j];
|
||||
flint_printf(">>>>>n: %d\n", n);
|
||||
fflush(stdout);
|
||||
|
||||
T1 = 0;
|
||||
T2 = 0;
|
||||
T3 = 0;
|
||||
for (k = 0; k < iter_count[j]; k++)
|
||||
{
|
||||
nmod_poly_init(f, modulus);
|
||||
nmod_poly_randtest_irreducible(f, state, n);
|
||||
|
||||
t = clock();
|
||||
nmod_poly_factor_init(res);
|
||||
nmod_poly_factor_with_cantor_zassenhaus(res, f);
|
||||
nmod_poly_factor_clear(res);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
T1 += t;
|
||||
|
||||
t = clock();
|
||||
nmod_poly_factor_init(res);
|
||||
nmod_poly_factor_with_berlekamp(res, f);
|
||||
nmod_poly_factor_clear(res);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
T2 += t;
|
||||
|
||||
t = clock();
|
||||
nmod_poly_factor_init(res);
|
||||
nmod_poly_factor_kaltofen_shoup(res, f);
|
||||
nmod_poly_factor_clear(res);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
T3 += t;
|
||||
|
||||
nmod_poly_clear(f);
|
||||
}
|
||||
|
||||
flint_printf("CZ: %.2lf B: %.2lf KS: %.2lf\n", T1, T2, T3);
|
||||
fflush(stdout);
|
||||
|
||||
if (T1 > T3 + 1)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
flint_printf("Product of two irreducible polynomials\n");
|
||||
for (i = 0; i < NP; i++)
|
||||
{
|
||||
modulus = n_randtest_prime(state, 0);
|
||||
flint_printf("========== p: %wu\n", modulus);
|
||||
fflush(stdout);
|
||||
|
||||
for (j = 0; j < ND; j++)
|
||||
{
|
||||
n = (degs[j] >> 1);
|
||||
flint_printf(">>>>>n: %d\n", n);
|
||||
fflush(stdout);
|
||||
|
||||
T1 = 0;
|
||||
T2 = 0;
|
||||
T3 = 0;
|
||||
for (k = 0; k < iter_count[j]; k++)
|
||||
{
|
||||
nmod_poly_init(f, modulus);
|
||||
nmod_poly_init(g, modulus);
|
||||
nmod_poly_randtest_irreducible(f, state, n);
|
||||
nmod_poly_randtest_irreducible(g, state, n);
|
||||
nmod_poly_mul(f, f, g);
|
||||
|
||||
t = clock();
|
||||
nmod_poly_factor_init(res);
|
||||
nmod_poly_factor_with_cantor_zassenhaus(res, f);
|
||||
nmod_poly_factor_clear(res);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
T1 += t;
|
||||
|
||||
t = clock();
|
||||
nmod_poly_factor_init(res);
|
||||
nmod_poly_factor_with_berlekamp(res, f);
|
||||
nmod_poly_factor_clear(res);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
T2 += t;
|
||||
|
||||
t = clock();
|
||||
nmod_poly_factor_init(res);
|
||||
nmod_poly_factor_kaltofen_shoup(res, f);
|
||||
nmod_poly_factor_clear(res);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
T3 += t;
|
||||
|
||||
nmod_poly_clear(f);
|
||||
nmod_poly_clear(g);
|
||||
}
|
||||
|
||||
flint_printf("CZ: %.2lf B: %.2lf KS: %.2lf\n", T1, T2, T3);
|
||||
fflush(stdout);
|
||||
|
||||
if (T1 > T3 + 1)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
flint_printf("Product of 8 small irreducible polynomials\n");
|
||||
for (i = 0; i < NP; i++)
|
||||
{
|
||||
modulus = n_randtest_prime(state, 0);
|
||||
flint_printf("========== p: %wu\n", modulus);
|
||||
fflush(stdout);
|
||||
|
||||
for (j = 1; j < ND; j++)
|
||||
{
|
||||
n = (degs[j] >> 3);
|
||||
flint_printf(">>>>>n: %d\n", n);
|
||||
fflush(stdout);
|
||||
|
||||
T1 = 0;
|
||||
T2 = 0;
|
||||
T3 = 0;
|
||||
for (k = 0; k < iter_count[j]; k++)
|
||||
{
|
||||
nmod_poly_init(f, modulus);
|
||||
nmod_poly_init(g, modulus);
|
||||
nmod_poly_randtest_irreducible(f, state, n);
|
||||
for (num = 1; num < 8; num++)
|
||||
{
|
||||
nmod_poly_randtest_irreducible(g, state, n);
|
||||
nmod_poly_mul(f, f, g);
|
||||
}
|
||||
|
||||
t = clock();
|
||||
nmod_poly_factor_init(res);
|
||||
nmod_poly_factor_with_cantor_zassenhaus(res, f);
|
||||
nmod_poly_factor_clear(res);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
T1 += t;
|
||||
|
||||
t = clock();
|
||||
nmod_poly_factor_init(res);
|
||||
nmod_poly_factor_with_berlekamp(res, f);
|
||||
nmod_poly_factor_clear(res);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
T2 += t;
|
||||
|
||||
t = clock();
|
||||
nmod_poly_factor_init(res);
|
||||
nmod_poly_factor_kaltofen_shoup(res, f);
|
||||
nmod_poly_factor_clear(res);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
T3 += t;
|
||||
|
||||
nmod_poly_clear(f);
|
||||
nmod_poly_clear(g);
|
||||
}
|
||||
|
||||
flint_printf("CZ: %.2lf B: %.2lf KS: %.2lf\n", T1, T2, T3);
|
||||
fflush(stdout);
|
||||
|
||||
if (T1 > T3 + 1)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
flint_randclear(state);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
75
external/flint-2.4.3/nmod_poly_factor/profile/p-factorbench.c
vendored
Normal file
75
external/flint-2.4.3/nmod_poly_factor/profile/p-factorbench.c
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2013 Martin Lee
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <gmp.h>
|
||||
|
||||
#include "flint.h"
|
||||
#include "nmod_poly.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
|
||||
double t;
|
||||
nmod_poly_t f, g, h;
|
||||
for (int i= 15001;i < 16000; i++)
|
||||
{
|
||||
nmod_poly_init2 (f, 17, i/2+1);
|
||||
nmod_poly_init2 (g, 17, i+1);
|
||||
|
||||
nmod_poly_set_coeff_ui (f, i/2, 1);
|
||||
nmod_poly_set_coeff_ui (f, 1, 1);
|
||||
nmod_poly_set_coeff_ui (f, 0, ((i%17)*(i%17)+3) % 17);
|
||||
|
||||
nmod_poly_set_coeff_ui (g, i, 1);
|
||||
nmod_poly_set_coeff_ui (g, i/2+1, 1);
|
||||
nmod_poly_set_coeff_ui (g, 1, ((i % 17)+1)%17);
|
||||
nmod_poly_set_coeff_ui (g, 0, 15);
|
||||
|
||||
nmod_poly_init (h, 17);
|
||||
nmod_poly_gcd (h, f, g);
|
||||
|
||||
if (!nmod_poly_is_one (h))
|
||||
{
|
||||
flint_printf ("i= %d\n", i);
|
||||
nmod_poly_factor_t factors;
|
||||
nmod_poly_factor_init (factors);
|
||||
t= clock();
|
||||
nmod_poly_factor (factors, h);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
flint_printf("factorization %.2lf\n", t);
|
||||
nmod_poly_factor_clear (factors);
|
||||
}
|
||||
|
||||
nmod_poly_clear (f);
|
||||
nmod_poly_clear (g);
|
||||
nmod_poly_clear (h);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user