ALL: Add flint
This commit is contained in:
120
external/flint-2.4.3/arith/test/t-bell_number.c
vendored
Normal file
120
external/flint-2.4.3/arith/test/t-bell_number.c
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include <mpfr.h>
|
||||
#include "flint.h"
|
||||
#include "arith.h"
|
||||
#include "fmpz_vec.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
fmpz * b1;
|
||||
fmpz * b2;
|
||||
slong n, k;
|
||||
|
||||
const slong maxn = 400;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("bell_number....");
|
||||
fflush(stdout);
|
||||
|
||||
b1 = _fmpz_vec_init(maxn);
|
||||
|
||||
/* Consistency test */
|
||||
for (n = 0; n < maxn; n++)
|
||||
arith_bell_number(b1 + n, n);
|
||||
|
||||
for (n = 0; n < maxn; n++)
|
||||
{
|
||||
b2 = _fmpz_vec_init(n);
|
||||
arith_bell_number_vec(b2, n);
|
||||
|
||||
if (!_fmpz_vec_equal(b1, b2, n))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("n = %wd\n", n);
|
||||
abort();
|
||||
}
|
||||
|
||||
_fmpz_vec_clear(b2, n);
|
||||
}
|
||||
|
||||
/* Compare with B_n = sum of Stirling numbers of 2nd kind */
|
||||
for (n = 0; n < 1000; n += (n < 50) ? + 1 : n/4)
|
||||
{
|
||||
b2 = _fmpz_vec_init(n+1);
|
||||
|
||||
arith_stirling_number_2_vec(b2, n, n+1);
|
||||
|
||||
for (k = 1; k <= n; k++)
|
||||
fmpz_add(b2, b2, b2 + k);
|
||||
|
||||
arith_bell_number(b1, n);
|
||||
|
||||
if (!fmpz_equal(b1, b2))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("n = %wd\n", n);
|
||||
fmpz_print(b1);
|
||||
flint_printf("\n");
|
||||
fmpz_print(b2);
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
/* Also check nmod value */
|
||||
{
|
||||
nmod_t mod;
|
||||
mp_limb_t bb;
|
||||
|
||||
nmod_init(&mod, n_randtest_prime(state, 0));
|
||||
bb = arith_bell_number_nmod(n, mod);
|
||||
|
||||
if (fmpz_fdiv_ui(b1, mod.n) != bb)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("n = %wd\n", n);
|
||||
fmpz_print(b1);
|
||||
flint_printf("\n");
|
||||
flint_printf("should be %wu mod %wu\n", bb, mod.n);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
_fmpz_vec_clear(b2, n+1);
|
||||
}
|
||||
|
||||
_fmpz_vec_clear(b1, maxn);
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
72
external/flint-2.4.3/arith/test/t-bell_number_multi_mod.c
vendored
Normal file
72
external/flint-2.4.3/arith/test/t-bell_number_multi_mod.c
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 <mpfr.h>
|
||||
#include "flint.h"
|
||||
#include "arith.h"
|
||||
#include "fmpz_vec.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
slong i;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("bell_number_multi_mod....");
|
||||
fflush(stdout);
|
||||
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
slong n;
|
||||
fmpz_t b1, b2;
|
||||
|
||||
fmpz_init(b1);
|
||||
fmpz_init(b2);
|
||||
|
||||
n = n_randint(state, 500);
|
||||
|
||||
arith_bell_number_bsplit(b1, n);
|
||||
arith_bell_number_multi_mod(b2, n);
|
||||
|
||||
if (!fmpz_equal(b1, b2))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("n = %wd\n", n);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(b1);
|
||||
fmpz_clear(b2);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
77
external/flint-2.4.3/arith/test/t-bell_number_nmod.c
vendored
Normal file
77
external/flint-2.4.3/arith/test/t-bell_number_nmod.c
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 <mpfr.h>
|
||||
#include "flint.h"
|
||||
#include "arith.h"
|
||||
#include "fmpz_vec.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
slong i, j;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("bell_number_nmod....");
|
||||
fflush(stdout);
|
||||
|
||||
for (i = 0; i < 10; i++)
|
||||
{
|
||||
mp_ptr b;
|
||||
slong n;
|
||||
nmod_t mod;
|
||||
mp_limb_t p;
|
||||
|
||||
n = n_randint(state, 1000);
|
||||
p = n_randtest_prime(state, 0);
|
||||
|
||||
nmod_init(&mod, p);
|
||||
|
||||
b = _nmod_vec_init(n + 1);
|
||||
arith_bell_number_nmod_vec(b, n + 1, mod);
|
||||
|
||||
for (j = 0; j <= n; j++)
|
||||
{
|
||||
mp_limb_t u = arith_bell_number_nmod(j, mod);
|
||||
|
||||
if (u != b[j])
|
||||
{
|
||||
flint_printf("FAIL: p = %wu, i = %wd\n", p, j);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
_nmod_vec_clear(b);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
78
external/flint-2.4.3/arith/test/t-bell_number_nmod_vec.c
vendored
Normal file
78
external/flint-2.4.3/arith/test/t-bell_number_nmod_vec.c
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "arith.h"
|
||||
#include "nmod_vec.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
mp_ptr b1, b2;
|
||||
slong n;
|
||||
|
||||
const slong maxn = 3000;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("bell_number_nmod_vec....");
|
||||
fflush(stdout);
|
||||
|
||||
b1 = _nmod_vec_init(maxn);
|
||||
b2 = _nmod_vec_init(maxn);
|
||||
|
||||
for (n = 0; n < maxn; n += (n < 50) ? + 1 : n/4)
|
||||
{
|
||||
nmod_t mod;
|
||||
mp_limb_t p;
|
||||
|
||||
do {
|
||||
p = n_randtest_prime(state, 0);
|
||||
} while (p < n);
|
||||
|
||||
nmod_init(&mod, p);
|
||||
|
||||
arith_bell_number_nmod_vec_recursive(b1, n, mod);
|
||||
arith_bell_number_nmod_vec_series(b2, n, mod);
|
||||
|
||||
if (!_nmod_vec_equal(b1, b2, n))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("n = %wd\n", n);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
_nmod_vec_clear(b1);
|
||||
_nmod_vec_clear(b2);
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
69
external/flint-2.4.3/arith/test/t-bell_number_vec.c
vendored
Normal file
69
external/flint-2.4.3/arith/test/t-bell_number_vec.c
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "arith.h"
|
||||
#include "fmpz_vec.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
fmpz * b1;
|
||||
fmpz * b2;
|
||||
slong n;
|
||||
|
||||
const slong maxn = 1000;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("bell_number_vec....");
|
||||
fflush(stdout);
|
||||
|
||||
b1 = _fmpz_vec_init(maxn);
|
||||
b2 = _fmpz_vec_init(maxn);
|
||||
|
||||
for (n = 0; n < maxn; n += (n < 50) ? + 1 : n/4)
|
||||
{
|
||||
arith_bell_number_vec_recursive(b1, n);
|
||||
arith_bell_number_vec_multi_mod(b2, n);
|
||||
|
||||
if (!_fmpz_vec_equal(b1, b2, n))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("n = %wd\n", n);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
_fmpz_vec_clear(b1, maxn);
|
||||
_fmpz_vec_clear(b2, maxn);
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
120
external/flint-2.4.3/arith/test/t-bernoulli_number.c
vendored
Normal file
120
external/flint-2.4.3/arith/test/t-bernoulli_number.c
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include <mpfr.h>
|
||||
#include "flint.h"
|
||||
#include "arith.h"
|
||||
#include "profiler.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mat.h"
|
||||
#include "fmpq_poly.h"
|
||||
#include "fmpq.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
fmpz * num1;
|
||||
fmpz * den1;
|
||||
fmpz_t num2;
|
||||
fmpz_t den2;
|
||||
slong n, N;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("bernoulli_number....");
|
||||
fflush(stdout);
|
||||
|
||||
N = 4000;
|
||||
|
||||
num1 = _fmpz_vec_init(N);
|
||||
den1 = _fmpz_vec_init(N);
|
||||
fmpz_init(num2);
|
||||
fmpz_init(den2);
|
||||
|
||||
_arith_bernoulli_number_vec_multi_mod(num1, den1, N);
|
||||
|
||||
for (n = 0; n < N; n++)
|
||||
{
|
||||
_arith_bernoulli_number(num2, den2, n);
|
||||
|
||||
if (!fmpz_equal(num1 + n, num2))
|
||||
{
|
||||
flint_printf("FAIL: n = %wd, numerator\n", n);
|
||||
flint_printf("vec: "); fmpz_print(num1 + n); flint_printf("\n");
|
||||
flint_printf("single: "); fmpz_print(num2); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
if (!fmpz_equal(den1 + n, den2))
|
||||
{
|
||||
flint_printf("FAIL: n = %wd, denominator\n", n);
|
||||
flint_printf("vec: "); fmpz_print(den1 + n); flint_printf("\n");
|
||||
flint_printf("single: "); fmpz_print(den2); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
/* Check non underscore versions */
|
||||
do
|
||||
{
|
||||
slong N = 100;
|
||||
fmpq * x;
|
||||
fmpq_t t;
|
||||
|
||||
fmpq_init(t);
|
||||
x = flint_malloc(sizeof(fmpq) * N);
|
||||
|
||||
for (n = 0; n < N; n++)
|
||||
fmpq_init(x + n);
|
||||
|
||||
arith_bernoulli_number_vec(x, N);
|
||||
for (n = 0; n < N; n++)
|
||||
{
|
||||
arith_bernoulli_number(t, n);
|
||||
if (!fmpq_equal(x + n, t))
|
||||
{
|
||||
flint_printf("FAIL!: n = %wd\n", n);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
for (n = 0; n < N; n++)
|
||||
fmpq_clear(x + n);
|
||||
flint_free(x);
|
||||
fmpq_clear(t);
|
||||
|
||||
} while (0);
|
||||
|
||||
_fmpz_vec_clear(num1, N);
|
||||
_fmpz_vec_clear(den1, N);
|
||||
fmpz_clear(num2);
|
||||
fmpz_clear(den2);
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
67
external/flint-2.4.3/arith/test/t-bernoulli_number_denom.c
vendored
Normal file
67
external/flint-2.4.3/arith/test/t-bernoulli_number_denom.c
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "arith.h"
|
||||
#include "fmpz.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
fmpz_t s, t;
|
||||
slong n;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("bernoulli_number_denom....");
|
||||
fflush(stdout);
|
||||
|
||||
fmpz_init(s);
|
||||
fmpz_init(t);
|
||||
|
||||
for (n = 0; n < 1000; n++)
|
||||
{
|
||||
arith_bernoulli_number_denom(t, n);
|
||||
fmpz_addmul_ui(s, t, n_nth_prime(n+1));
|
||||
}
|
||||
|
||||
fmpz_set_str(t, "34549631155954474103407159", 10);
|
||||
|
||||
if (!fmpz_equal(s, t))
|
||||
{
|
||||
flint_printf("FAIL: Hash disagrees with known value\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(s);
|
||||
fmpz_clear(t);
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
102
external/flint-2.4.3/arith/test/t-bernoulli_number_vec.c
vendored
Normal file
102
external/flint-2.4.3/arith/test/t-bernoulli_number_vec.c
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include <mpfr.h>
|
||||
#include "flint.h"
|
||||
#include "arith.h"
|
||||
#include "profiler.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mat.h"
|
||||
#include "fmpq_poly.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
fmpz * num1;
|
||||
fmpz * num2;
|
||||
fmpz * num3;
|
||||
fmpz * den1;
|
||||
fmpz * den2;
|
||||
fmpz * den3;
|
||||
slong i, n, N;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("bernoulli_number_vec....");
|
||||
fflush(stdout);
|
||||
|
||||
N = 2000;
|
||||
|
||||
num1 = _fmpz_vec_init(N);
|
||||
num2 = _fmpz_vec_init(N);
|
||||
num3 = _fmpz_vec_init(N);
|
||||
den1 = _fmpz_vec_init(N);
|
||||
den2 = _fmpz_vec_init(N);
|
||||
den3 = _fmpz_vec_init(N);
|
||||
|
||||
for (n = 0; n < N; n += (n<100) ? 1 : n/3)
|
||||
{
|
||||
_arith_bernoulli_number_vec_recursive(num1, den1, n);
|
||||
_arith_bernoulli_number_vec_multi_mod(num2, den2, n);
|
||||
_arith_bernoulli_number_vec_zeta(num3, den3, n);
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
if (!fmpz_equal(num1 + i, num2 + i) ||
|
||||
!fmpz_equal(num1 + i, num3 + i))
|
||||
{
|
||||
flint_printf("FAIL: n = %wd, numerator of B_%wd\n", n, i);
|
||||
flint_printf("recursive: "); fmpz_print(num1 + i); flint_printf("\n");
|
||||
flint_printf("multi_mod: "); fmpz_print(num2 + i); flint_printf("\n");
|
||||
flint_printf("zeta: "); fmpz_print(num3 + i); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
if (!fmpz_equal(den1 + i, den2 + i) ||
|
||||
!fmpz_equal(den1 + i, den3 + i))
|
||||
{
|
||||
flint_printf("FAIL: n = %wd, denominator of B_%wd\n", n, i);
|
||||
flint_printf("recursive: "); fmpz_print(den1 + i); flint_printf("\n");
|
||||
flint_printf("multi_mod: "); fmpz_print(den2 + i); flint_printf("\n");
|
||||
flint_printf("zeta: "); fmpz_print(den3 + i); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_fmpz_vec_clear(num1, N);
|
||||
_fmpz_vec_clear(num2, N);
|
||||
_fmpz_vec_clear(num3, N);
|
||||
_fmpz_vec_clear(den1, N);
|
||||
_fmpz_vec_clear(den2, N);
|
||||
_fmpz_vec_clear(den3, N);
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
89
external/flint-2.4.3/arith/test/t-bernoulli_polynomial.c
vendored
Normal file
89
external/flint-2.4.3/arith/test/t-bernoulli_polynomial.c
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 <mpfr.h>
|
||||
#include "flint.h"
|
||||
#include "arith.h"
|
||||
#include "profiler.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mat.h"
|
||||
#include "fmpq_poly.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
fmpq_poly_t P, Q;
|
||||
mpz_t t;
|
||||
|
||||
slong k, n;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("bernoulli_polynomial....");
|
||||
fflush(stdout);
|
||||
|
||||
for (n = 0; n <= 100; n++)
|
||||
{
|
||||
fmpq_poly_init(P);
|
||||
fmpq_poly_init(Q);
|
||||
|
||||
mpz_init(t);
|
||||
|
||||
for (k = 0; k <= n; k++)
|
||||
{
|
||||
arith_bernoulli_polynomial(P, k);
|
||||
flint_mpz_bin_uiui(t, n+1, k);
|
||||
fmpq_poly_scalar_mul_mpz(P, P, t);
|
||||
fmpq_poly_add(Q, Q, P);
|
||||
}
|
||||
|
||||
fmpq_poly_scalar_div_ui(Q, Q, n+1);
|
||||
mpz_clear(t);
|
||||
|
||||
fmpq_poly_zero(P);
|
||||
fmpq_poly_set_coeff_ui(P, n, UWORD(1));
|
||||
|
||||
if (!fmpq_poly_equal(P, Q))
|
||||
{
|
||||
flint_printf("ERROR: sum up to n = %wd did not add to x^n\n", n);
|
||||
flint_printf("Sum: ");
|
||||
fmpq_poly_print_pretty(Q, "x");
|
||||
flint_printf("\nExpected: ");
|
||||
fmpq_poly_print_pretty(P, "x");
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpq_poly_clear(P);
|
||||
fmpq_poly_clear(Q);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
82
external/flint-2.4.3/arith/test/t-chebyshev_t_polynomial.c
vendored
Normal file
82
external/flint-2.4.3/arith/test/t-chebyshev_t_polynomial.c
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "arith.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_poly.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
fmpz_poly_t T0, T1, T2, t;
|
||||
slong n;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("chebyshev_t_polynomial....");
|
||||
fflush(stdout);
|
||||
|
||||
fmpz_poly_init(T0);
|
||||
fmpz_poly_init(T1);
|
||||
fmpz_poly_init(T2);
|
||||
fmpz_poly_init(t);
|
||||
|
||||
arith_chebyshev_t_polynomial(T0, 0);
|
||||
arith_chebyshev_t_polynomial(T1, 1);
|
||||
|
||||
for (n = 2; n <= 500; n++)
|
||||
{
|
||||
arith_chebyshev_t_polynomial(T2, n);
|
||||
|
||||
/* Verify T_{n+1} = 2 x T_n - T_{n-1} */
|
||||
fmpz_poly_scalar_mul_ui(t, T1, UWORD(2));
|
||||
fmpz_poly_shift_left(t, t, 1);
|
||||
fmpz_poly_sub(t, t, T0);
|
||||
|
||||
if (!fmpz_poly_equal(t, T2))
|
||||
{
|
||||
flint_printf("FAIL: n = %wd\n", n);
|
||||
flint_printf("t: "); fmpz_poly_print_pretty(t, "x"); flint_printf("\n");
|
||||
flint_printf("T2: "); fmpz_poly_print_pretty(T2, "x"); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_poly_swap(T0, T1);
|
||||
fmpz_poly_swap(T1, T2);
|
||||
}
|
||||
|
||||
fmpz_poly_clear(T0);
|
||||
fmpz_poly_clear(T1);
|
||||
fmpz_poly_clear(T2);
|
||||
fmpz_poly_clear(t);
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
72
external/flint-2.4.3/arith/test/t-chebyshev_u_polynomial.c
vendored
Normal file
72
external/flint-2.4.3/arith/test/t-chebyshev_u_polynomial.c
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "arith.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_poly.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
fmpz_poly_t T, U;
|
||||
|
||||
slong n;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("chebyshev_u_polynomial....");
|
||||
fflush(stdout);
|
||||
|
||||
fmpz_poly_init(T);
|
||||
fmpz_poly_init(U);
|
||||
|
||||
for (n = 0; n <= 500; n++)
|
||||
{
|
||||
arith_chebyshev_u_polynomial(U, n);
|
||||
arith_chebyshev_t_polynomial(T, n + 1);
|
||||
fmpz_poly_derivative(T, T);
|
||||
fmpz_poly_scalar_divexact_ui(T, T, n + 1);
|
||||
|
||||
if (!fmpz_poly_equal(T, U))
|
||||
{
|
||||
flint_printf("FAIL: n = %wd\n", n);
|
||||
flint_printf("T: "); fmpz_poly_print_pretty(T, "x"); flint_printf("\n");
|
||||
flint_printf("U: "); fmpz_poly_print_pretty(U, "x"); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fmpz_poly_clear(T);
|
||||
fmpz_poly_clear(U);
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
129
external/flint-2.4.3/arith/test/t-cyclotomic_cos_polynomial.c
vendored
Normal file
129
external/flint-2.4.3/arith/test/t-cyclotomic_cos_polynomial.c
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include <mpfr.h>
|
||||
#include "flint.h"
|
||||
#include "arith.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_poly.h"
|
||||
|
||||
|
||||
/*
|
||||
Generated with Mathematica:
|
||||
Table[Mod[MinimalPolynomial[Cos[2 Pi/n]][1337], 31337], {n,1,500}]
|
||||
*/
|
||||
|
||||
static const short testdata[] = {
|
||||
1,
|
||||
1336, 1338, 2675, 1337, 8113, 2673, 6283, 2719, 29508, 2765, 6949,
|
||||
5437, 2788, 26742, 25554, 26194, 29376, 29506, 30945, 15614, 8957,
|
||||
16643, 9263, 21050, 30556, 10533, 1570, 11562, 3988, 16546, 26642, 4041,
|
||||
3581, 109, 9839, 27175, 11691, 1460, 28287, 18369, 16503, 3184, 13336,
|
||||
23083, 12495, 3246, 14160, 8081, 5301, 8652, 28989, 24149, 17733, 1568,
|
||||
4800, 28863, 29280, 13741, 30919, 29819, 28584, 8913, 550, 6207, 13930,
|
||||
23373, 12644, 15265, 27975, 30386, 1603, 15894, 22276, 3138, 11610,
|
||||
2208, 515, 30817, 23050, 4333, 25031, 13615, 5116, 18609, 25490, 14555,
|
||||
22663, 8425, 21751, 19293, 3, 10688, 26829, 14467, 1426, 12413, 5305,
|
||||
25377, 27164, 3711,
|
||||
9613, 22340, 7457, 3704, 1795, 22877, 31060, 17472, 11317, 22274,
|
||||
11036, 7796, 27242, 22174, 3663, 10507, 16599, 18192, 15208, 7257, 7022,
|
||||
10810, 27891, 18495, 7032, 11383, 20768, 27351, 31089, 27723, 10486,
|
||||
2075, 25298, 20531, 28548, 25342, 6510, 20657, 15608, 5534, 22145,
|
||||
30150, 25222, 12128, 389, 21860, 9631, 4536, 4704, 3677, 27282, 26668,
|
||||
20784, 15684, 12847, 1307, 10586, 24355, 27553, 10952, 8886, 25029,
|
||||
29278, 29964, 17943, 1006, 5895, 11466, 16679, 17500, 5414, 3420, 17644,
|
||||
5165, 6255, 2807, 30577, 26277, 14032, 2425, 13945, 27988, 17437, 28204,
|
||||
11853, 12265, 8097, 24919, 10703, 18081, 19121, 23364, 14035, 2382,
|
||||
1722, 21617, 11863, 27682, 8538, 26401,
|
||||
1487, 14570, 14213, 18315, 30244, 14611, 25421, 13954, 29802,
|
||||
29118, 5788, 7547, 9710, 21645, 17858, 20672, 2295, 21286, 7217, 30405,
|
||||
5090, 22674, 5747, 5809, 13789, 16385, 23732, 12258, 10944, 14669, 2043,
|
||||
1453, 13510, 12422, 24073, 3025, 28094, 2770, 9198, 27411, 24736, 28958,
|
||||
23508, 27897, 17838, 10690, 5375, 29469, 22458, 9466, 28541, 16308,
|
||||
20491, 10320, 9836, 673, 26630, 20819, 25687, 19263, 16620, 28683,
|
||||
30268, 1113, 26632, 18450, 17555, 20121, 18083, 12796, 26659, 9788,
|
||||
10448, 2828, 29753, 26653, 13636, 6270, 10398, 16224, 1481, 1153, 26387,
|
||||
17835, 19289, 2683, 1937, 16760, 14372, 12632, 15716, 12423, 24202,
|
||||
14543, 10763, 27059, 437, 18647, 17133, 27774,
|
||||
2039, 3931, 7737, 20470, 11068, 26238, 28463, 22610, 28349, 23819,
|
||||
22780, 4101, 13218, 12878, 25048, 25163, 11032, 10129, 2571, 9319,
|
||||
11708, 6704, 19105, 11593, 24863, 26090, 15235, 18038, 22056, 19624,
|
||||
12066, 9798, 16508, 22376, 15776, 10595, 28391, 18898, 11645, 16655,
|
||||
19391, 11364, 28198, 4348, 6653, 11962, 22652, 18750, 22125, 21504,
|
||||
23718, 25662, 6768, 24234, 29605, 8280, 5246, 23064, 1360, 21538, 4374,
|
||||
8186, 7540, 24091, 3017, 23007, 12000, 11289, 8698, 22118, 5505, 18535,
|
||||
29647, 15878, 4416, 8598, 13062, 8878, 9674, 5066, 17770, 24888, 20643,
|
||||
1345, 22570, 1363, 3710, 18429, 11731, 14885, 12983, 18600, 26334,
|
||||
27101, 17858, 22221, 2471, 911, 12033, 2824,
|
||||
6354, 984, 28507, 3521, 17963, 6558, 11166, 24004, 24367, 8572,
|
||||
19198, 6937, 15220, 13122, 3540, 589, 17503, 14073, 14954, 26020, 12974,
|
||||
20684, 19844, 17852, 1097, 10831, 23848, 7013, 15683, 15954, 22290,
|
||||
30257, 15807, 22775, 13607, 9428, 30055, 11607, 30426, 2579, 340, 29747,
|
||||
25213, 28551, 5705, 15704, 10625, 16932, 3215, 16716, 6698, 21470,
|
||||
29839, 511, 23506, 4338, 30506, 18038, 20430, 20586, 18225, 7721, 15812,
|
||||
3140, 22149, 4949, 8125, 9897, 6323, 20612, 2012, 23744, 9414, 16497,
|
||||
5557, 5225, 8518, 30549, 21805, 5692, 25222, 16326, 22995, 27432, 16385,
|
||||
23506, 9911, 23131, 3880, 30647, 13222, 10416, 5619, 2078, 9411, 12398,
|
||||
22772, 7328, 17932, 19965,
|
||||
-1
|
||||
};
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
fmpz_poly_t p;
|
||||
slong n;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("cyclotomic_cos_polynomial....");
|
||||
fflush(stdout);
|
||||
|
||||
fmpz_poly_init(p);
|
||||
|
||||
for (n = 0; testdata[n] != -1; n++)
|
||||
{
|
||||
mp_limb_t y;
|
||||
arith_cos_minpoly(p, n);
|
||||
y = fmpz_poly_evaluate_mod(p, 1337, 31337);
|
||||
|
||||
if (y != testdata[n])
|
||||
{
|
||||
flint_printf("FAIL: n = %wd\n", n);
|
||||
flint_printf("y = %wu\n", y);
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
fmpz_poly_clear(p);
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
145
external/flint-2.4.3/arith/test/t-cyclotomic_polynomial.c
vendored
Normal file
145
external/flint-2.4.3/arith/test/t-cyclotomic_polynomial.c
vendored
Normal 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) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "arith.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
void cyclotomic_naive(fmpz_poly_t poly, ulong n)
|
||||
{
|
||||
fmpz_poly_t t;
|
||||
slong d;
|
||||
|
||||
fmpz_poly_init(t);
|
||||
|
||||
fmpz_poly_set_ui(poly, UWORD(1));
|
||||
for (d = 1; d <= n; d++)
|
||||
{
|
||||
if (n % d == 0)
|
||||
{
|
||||
if (n_moebius_mu(n / d) == 1)
|
||||
{
|
||||
fmpz_poly_zero(t);
|
||||
fmpz_poly_set_coeff_si(t, d, 1);
|
||||
fmpz_poly_set_coeff_si(t, 0, -1);
|
||||
fmpz_poly_mul(poly, poly, t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (d = 1; d <= n; d++)
|
||||
{
|
||||
if (n % d == 0)
|
||||
{
|
||||
if (n_moebius_mu(n / d) == -1)
|
||||
{
|
||||
fmpz_poly_zero(t);
|
||||
fmpz_poly_set_coeff_si(t, d, 1);
|
||||
fmpz_poly_set_coeff_si(t, 0, -1);
|
||||
fmpz_poly_div(poly, poly, t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmpz_poly_clear(t);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
fmpz_poly_t A, B;
|
||||
slong n;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("cyclotomic_polynomial....");
|
||||
fflush(stdout);
|
||||
|
||||
for (n = 0; n <= 1000; n++)
|
||||
{
|
||||
fmpz_poly_init(A);
|
||||
fmpz_poly_init(B);
|
||||
|
||||
arith_cyclotomic_polynomial(A, n);
|
||||
cyclotomic_naive(B, n);
|
||||
|
||||
if (!fmpz_poly_equal(A, B))
|
||||
{
|
||||
flint_printf("FAIL: wrong value of Phi_%wd(x)\n", n);
|
||||
flint_printf("Computed:\n");
|
||||
fmpz_poly_print_pretty(A, "x");
|
||||
flint_printf("\n\nExpected:\n");
|
||||
fmpz_poly_print_pretty(B, "x");
|
||||
flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_poly_clear(A);
|
||||
fmpz_poly_clear(B);
|
||||
}
|
||||
|
||||
/* We verify the first value that does not fit on 32 bits.
|
||||
This exercises the slow path at least on a 32 bit system.
|
||||
Testing the 64 bit value is a bit too much to do by default
|
||||
as it requires ~2 GB of memory and takes a few minutes. */
|
||||
{
|
||||
fmpz_t h, ref;
|
||||
|
||||
const ulong nn = UWORD(10163195);
|
||||
/* const ulong nn = UWORD(169828113); 64-bit case */
|
||||
|
||||
fmpz_init(h);
|
||||
fmpz_init(ref);
|
||||
fmpz_set_str(ref, "1376877780831", 10);
|
||||
/* fmpz_set_str(ref, "31484567640915734941", 10); 64-bit case */
|
||||
|
||||
fmpz_poly_init(A);
|
||||
arith_cyclotomic_polynomial(A, UWORD(10163195));
|
||||
fmpz_poly_height(h, A);
|
||||
|
||||
if (!fmpz_equal(h, ref))
|
||||
{
|
||||
flint_printf("Bad computation of Phi_%wd(x)\n", nn);
|
||||
flint_printf("Computed height:\n");
|
||||
fmpz_print(h);
|
||||
flint_printf("\nExpected height:\n");
|
||||
fmpz_print(ref);
|
||||
flint_printf("\n\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_poly_clear(A);
|
||||
fmpz_clear(h);
|
||||
fmpz_clear(ref);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
192
external/flint-2.4.3/arith/test/t-dedekind_sum.c
vendored
Normal file
192
external/flint-2.4.3/arith/test/t-dedekind_sum.c
vendored
Normal file
@@ -0,0 +1,192 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpq.h"
|
||||
#include "arith.h"
|
||||
#include "ulong_extras.h"
|
||||
#include "math.h"
|
||||
|
||||
/*
|
||||
The results in the following random test cases were computed with the
|
||||
naive implementation. Doing a live comparison with large values against
|
||||
the naive implementation would take too much time.
|
||||
*/
|
||||
static const slong testdata[][4] =
|
||||
{
|
||||
/* h, k, p/q */
|
||||
{WORD(20816815), WORD(29229), WORD(-10669), WORD(87687)},
|
||||
{WORD(-481962612), WORD(709105), WORD(-910639), WORD(141821)},
|
||||
{WORD(-70965), WORD(3384), WORD(1785), WORD(752)},
|
||||
{WORD(1899905), WORD(6657), WORD(-43795), WORD(5706)},
|
||||
{WORD(-1893), WORD(511167), WORD(-3411568), WORD(170389)},
|
||||
{WORD(1417295), WORD(10180), WORD(3543), WORD(4072)},
|
||||
{WORD(-1149), WORD(9350), WORD(6971), WORD(9350)},
|
||||
{WORD(-15520), WORD(22977640), WORD(-70331425), WORD(574441)},
|
||||
{WORD(3339), WORD(9873153), WORD(270746882), WORD(1097017)},
|
||||
{WORD(470645896), WORD(71754), WORD(-21713), WORD(107631)},
|
||||
{WORD(1153), WORD(1332403), WORD(258755243), WORD(2664806)},
|
||||
{WORD(-501576), WORD(292801), WORD(269095), WORD(292801)},
|
||||
{WORD(1861), WORD(34440), WORD(-723059), WORD(206640)},
|
||||
{WORD(-4278761), WORD(239321), WORD(791947), WORD(239321)},
|
||||
{WORD(9414763), WORD(30776409), WORD(-93285463), WORD(92329227)},
|
||||
{WORD(4872687), WORD(2199), WORD(146), WORD(733)},
|
||||
{WORD(-22349505), WORD(60581653), WORD(27694241), WORD(60581653)},
|
||||
{WORD(85739724), WORD(9289), WORD(961), WORD(2654)},
|
||||
{WORD(-5616), WORD(124023), WORD(-31447), WORD(41341)},
|
||||
{WORD(99382204), WORD(1378843), WORD(-2537405), WORD(2757686)},
|
||||
{WORD(1903), WORD(15842), WORD(102), WORD(89)},
|
||||
{WORD(-907226), WORD(5818), WORD(5608), WORD(2909)},
|
||||
{WORD(-948920), WORD(4768), WORD(-4815), WORD(1192)},
|
||||
{WORD(-352220914), WORD(15390287), WORD(-171358081), WORD(30780574)},
|
||||
{WORD(-159206), WORD(3028284), WORD(12921745), WORD(4542426)},
|
||||
{WORD(61951448), WORD(1624), WORD(-341), WORD(406)},
|
||||
{WORD(-49167), WORD(2092), WORD(-32915), WORD(4184)},
|
||||
{WORD(-20878222), WORD(586303210), WORD(-530581301), WORD(293151605)},
|
||||
{WORD(-1435637), WORD(3483), WORD(-4787), WORD(20898)},
|
||||
{WORD(-1129797), WORD(171620), WORD(238211), WORD(68648)},
|
||||
{WORD(-177095), WORD(2914), WORD(1132), WORD(1457)},
|
||||
{WORD(-343227551), WORD(1509), WORD(-3289), WORD(4527)},
|
||||
{WORD(57497376), WORD(1351), WORD(373), WORD(2702)},
|
||||
{WORD(3350543), WORD(5771893), WORD(-51196457), WORD(5771893)},
|
||||
{WORD(-44408), WORD(1670), WORD(367), WORD(1670)},
|
||||
{WORD(-4139), WORD(59959), WORD(-286689), WORD(119918)},
|
||||
{WORD(7397588), WORD(16695), WORD(-41627), WORD(20034)},
|
||||
{WORD(-78900791), WORD(10792), WORD(-30905), WORD(21584)},
|
||||
{WORD(-1204294), WORD(10134), WORD(-8945), WORD(30402)},
|
||||
{WORD(27649424), WORD(57014291), WORD(731583513), WORD(114028582)},
|
||||
{WORD(3275043), WORD(436410815), WORD(2018428417), WORD(174564326)},
|
||||
#if FLINT64 /* skip on 32 bit only because of the literals */
|
||||
{WORD(61247), WORD(81381215), WORD(3622491319), WORD(32552486)},
|
||||
{WORD(-52118), WORD(125095621), WORD(-24931204413), WORD(125095621)},
|
||||
{WORD(201446493), WORD(951783261), WORD(2467429915), WORD(634522174)},
|
||||
{WORD(176112), WORD(72187934), WORD(2692844825), WORD(72187934)},
|
||||
{WORD(1272), WORD(8722219), WORD(9972821075), WORD(17444438)},
|
||||
#endif
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
fmpz_t hh, kk;
|
||||
fmpq_t s1, s2;
|
||||
slong i, h, k;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("dedekind_sum....");
|
||||
fflush(stdout);
|
||||
|
||||
fmpz_init(hh);
|
||||
fmpz_init(kk);
|
||||
fmpq_init(s1);
|
||||
fmpq_init(s2);
|
||||
|
||||
for (k = -200; k < 200; k++)
|
||||
{
|
||||
for (h = -200; h < 200; h++)
|
||||
{
|
||||
fmpz_set_si(hh, h);
|
||||
fmpz_set_si(kk, k);
|
||||
|
||||
arith_dedekind_sum(s1, hh, kk);
|
||||
arith_dedekind_sum_naive(s2, hh, kk);
|
||||
|
||||
if (!fmpq_equal(s1, s2))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("s(%wd,%wd)\n", h, k);
|
||||
flint_printf("s1: "); fmpq_print(s1); flint_printf("\n");
|
||||
flint_printf("s2: "); fmpq_print(s2); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Test large values, 10-30 bits */
|
||||
for (i = 0; testdata[i][0] != 0; i++)
|
||||
{
|
||||
h = testdata[i][0];
|
||||
k = testdata[i][1];
|
||||
|
||||
fmpz_set_si(hh, h);
|
||||
fmpz_set_si(kk, k);
|
||||
|
||||
arith_dedekind_sum(s1, hh, kk);
|
||||
|
||||
fmpz_set_si(fmpq_numref(s2), testdata[i][2]);
|
||||
fmpz_set_si(fmpq_denref(s2), testdata[i][3]);
|
||||
|
||||
if (!fmpq_equal(s1, s2))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("s(%wd,%wd)\n", h, k);
|
||||
flint_printf("s1: "); fmpq_print(s1); flint_printf("\n");
|
||||
flint_printf("s2: "); fmpq_print(s2); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
/* Check a large value computed with Pari */
|
||||
fmpz_set_ui(hh, 1);
|
||||
fmpz_mul_2exp(hh, hh, 1000);
|
||||
fmpz_add_ui(hh, hh, 1);
|
||||
fmpz_set_ui(kk, 1);
|
||||
fmpz_mul_2exp(kk, kk, 1001);
|
||||
fmpz_add_ui(kk, kk, 1);
|
||||
|
||||
arith_dedekind_sum(s1, hh, kk);
|
||||
if ((fmpz_fdiv_ui(fmpq_numref(s1), 1000000000) != 906445312) ||
|
||||
(fmpz_fdiv_ui(fmpq_denref(s1), 1000000000) != 8416259))
|
||||
{
|
||||
flint_printf("Wrong large value:\n");
|
||||
fmpq_print(s1);
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
|
||||
/* Just check that nothing crashes with bignums */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_randtest(hh, state, 300);
|
||||
fmpz_randtest(kk, state, 300);
|
||||
|
||||
arith_dedekind_sum(s1, hh, kk);
|
||||
}
|
||||
|
||||
fmpz_clear(hh);
|
||||
fmpz_clear(kk);
|
||||
fmpq_clear(s1);
|
||||
fmpq_clear(s2);
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
86
external/flint-2.4.3/arith/test/t-dedekind_sum_coprime_d.c
vendored
Normal file
86
external/flint-2.4.3/arith/test/t-dedekind_sum_coprime_d.c
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpq.h"
|
||||
#include "arith.h"
|
||||
#include "ulong_extras.h"
|
||||
#include "math.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
double s1, s2f;
|
||||
fmpz_t hh, kk;
|
||||
fmpq_t s2;
|
||||
slong h, k;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("dedekind_sum_coprime_d....");
|
||||
fflush(stdout);
|
||||
|
||||
fmpz_init(hh);
|
||||
fmpz_init(kk);
|
||||
fmpq_init(s2);
|
||||
|
||||
for (k = 0; k < 300; k++)
|
||||
{
|
||||
for (h = 0; h <= k; h++)
|
||||
{
|
||||
if (n_gcd(k, h) == 1)
|
||||
{
|
||||
fmpz_set_si(hh, h);
|
||||
fmpz_set_si(kk, k);
|
||||
|
||||
s1 = arith_dedekind_sum_coprime_d(h, k);
|
||||
arith_dedekind_sum_naive(s2, hh, kk);
|
||||
|
||||
s2f = ((double)fmpz_get_si(fmpq_numref(s2))) /
|
||||
fmpz_get_si(fmpq_denref(s2));
|
||||
|
||||
if (fabs(s1 - s2f) > 1e-10)
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("s(%wd,%wd)\n", h, k);
|
||||
flint_printf("s1: %.20f\n", s1);
|
||||
flint_printf("s2: %.20f\n", s2f);
|
||||
flint_printf("Exact: "); fmpq_print(s2); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmpz_clear(hh);
|
||||
fmpz_clear(kk);
|
||||
fmpq_clear(s2);
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
83
external/flint-2.4.3/arith/test/t-dedekind_sum_coprime_large.c
vendored
Normal file
83
external/flint-2.4.3/arith/test/t-dedekind_sum_coprime_large.c
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpq.h"
|
||||
#include "arith.h"
|
||||
#include "ulong_extras.h"
|
||||
#include "math.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
fmpz_t hh, kk;
|
||||
fmpq_t s1, s2;
|
||||
slong h, k;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("dedekind_sum_coprime_large....");
|
||||
fflush(stdout);
|
||||
|
||||
fmpz_init(hh);
|
||||
fmpz_init(kk);
|
||||
fmpq_init(s1);
|
||||
fmpq_init(s2);
|
||||
|
||||
for (k = 0; k < 300; k++)
|
||||
{
|
||||
for (h = 0; h <= k; h++)
|
||||
{
|
||||
if (n_gcd(k, h) == 1)
|
||||
{
|
||||
fmpz_set_si(hh, h);
|
||||
fmpz_set_si(kk, k);
|
||||
|
||||
arith_dedekind_sum_coprime_large(s1, hh, kk);
|
||||
arith_dedekind_sum_naive(s2, hh, kk);
|
||||
|
||||
if (!fmpq_equal(s1, s2))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("s(%wd,%wd)\n", h, k);
|
||||
flint_printf("s1: "); fmpq_print(s1); flint_printf("\n");
|
||||
flint_printf("s2: "); fmpq_print(s2); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmpz_clear(hh);
|
||||
fmpz_clear(kk);
|
||||
fmpq_clear(s1);
|
||||
fmpq_clear(s2);
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
94
external/flint-2.4.3/arith/test/t-divisor_sigma.c
vendored
Normal file
94
external/flint-2.4.3/arith/test/t-divisor_sigma.c
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2010 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz_poly.h"
|
||||
#include "fmpz.h"
|
||||
#include "arith.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
void fmpz_sigma_naive(fmpz_t x, ulong n, ulong k)
|
||||
{
|
||||
slong i = 0;
|
||||
|
||||
fmpz_t t;
|
||||
fmpz_poly_t p;
|
||||
fmpz_init(t);
|
||||
fmpz_poly_init(p);
|
||||
fmpz_set_ui(t, n);
|
||||
arith_divisors(p, t);
|
||||
|
||||
fmpz_zero(x);
|
||||
for (i = 0; i < p->length; i++)
|
||||
{
|
||||
fmpz_poly_get_coeff_fmpz(t, p, i);
|
||||
fmpz_pow_ui(t, t, k);
|
||||
fmpz_add(x, x, t);
|
||||
}
|
||||
|
||||
fmpz_clear(t);
|
||||
fmpz_poly_clear(p);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
fmpz_t m, a, b;
|
||||
slong n, k;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("divisor_sigma....");
|
||||
fflush(stdout);
|
||||
|
||||
fmpz_init(a);
|
||||
fmpz_init(b);
|
||||
fmpz_init(m);
|
||||
|
||||
for (n = 0; n < 5000; n++)
|
||||
{
|
||||
for (k = 0; k < 10; k++)
|
||||
{
|
||||
fmpz_set_ui(m, n);
|
||||
arith_divisor_sigma(a, m, k);
|
||||
fmpz_sigma_naive(b, n, k);
|
||||
if (!fmpz_equal(a, b))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("wrong value for n=%wd, k=%wd\n", n, k);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmpz_clear(a);
|
||||
fmpz_clear(b);
|
||||
fmpz_clear(m);
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
86
external/flint-2.4.3/arith/test/t-divisors.c
vendored
Normal file
86
external/flint-2.4.3/arith/test/t-divisors.c
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2010 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz_poly.h"
|
||||
#include "arith.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
void arith_divisors_naive(fmpz_poly_t p, slong n)
|
||||
{
|
||||
slong k;
|
||||
slong i = 0;
|
||||
|
||||
n = FLINT_ABS(n);
|
||||
|
||||
fmpz_poly_zero(p);
|
||||
for (k = 1; k <= n; k++)
|
||||
{
|
||||
if (n % k == 0)
|
||||
{
|
||||
fmpz_poly_set_coeff_si(p, i, k);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
fmpz_t t;
|
||||
fmpz_poly_t a, b;
|
||||
slong n;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("divisors....");
|
||||
fflush(stdout);
|
||||
|
||||
fmpz_init(t);
|
||||
fmpz_poly_init(a);
|
||||
fmpz_poly_init(b);
|
||||
|
||||
for (n = -1000; n < 1000; n++)
|
||||
{
|
||||
fmpz_set_si(t, n);
|
||||
arith_divisors(a, t);
|
||||
arith_divisors_naive(b, n);
|
||||
if (!fmpz_poly_equal(a, b))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("wrong value for n=%wd\n", n);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
fmpz_clear(t);
|
||||
fmpz_poly_clear(a);
|
||||
fmpz_poly_clear(b);
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
81
external/flint-2.4.3/arith/test/t-euler_number_vec.c
vendored
Normal file
81
external/flint-2.4.3/arith/test/t-euler_number_vec.c
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 <mpfr.h>
|
||||
#include "flint.h"
|
||||
#include "arith.h"
|
||||
#include "profiler.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_vec.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
fmpz * r;
|
||||
fmpz_t s, t;
|
||||
slong k, n;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("euler_number_vec....");
|
||||
fflush(stdout);
|
||||
|
||||
for (n = 2; n <= 3000; n += (n<100) ? 2 : n/3)
|
||||
{
|
||||
n += n % 2;
|
||||
r = _fmpz_vec_init(n + 1);
|
||||
fmpz_init(s);
|
||||
fmpz_init(t);
|
||||
|
||||
arith_euler_number_vec(r, n + 1);
|
||||
|
||||
/* sum binomial(n,k) E_k = 0 */
|
||||
fmpz_set_ui(t, UWORD(1));
|
||||
for (k = 0; k <= n; k++)
|
||||
{
|
||||
fmpz_addmul(s, r + k, t);
|
||||
fmpz_mul_ui(t, t, n - k);
|
||||
fmpz_divexact_ui(t, t, k + 1);
|
||||
}
|
||||
|
||||
if (!fmpz_is_zero(s))
|
||||
{
|
||||
flint_printf("ERROR: sum over 0,...,n = %wd\n", n);
|
||||
_fmpz_vec_print(r, n + 1);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(s);
|
||||
fmpz_clear(t);
|
||||
_fmpz_vec_clear(r, n + 1);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
74
external/flint-2.4.3/arith/test/t-euler_number_zeta.c
vendored
Normal file
74
external/flint-2.4.3/arith/test/t-euler_number_zeta.c
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 <mpfr.h>
|
||||
#include "flint.h"
|
||||
#include "arith.h"
|
||||
#include "profiler.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mat.h"
|
||||
#include "fmpq_poly.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
fmpz * ress;
|
||||
fmpz_t res;
|
||||
slong n, N;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("euler_number_zeta....");
|
||||
fflush(stdout);
|
||||
|
||||
N = 3000;
|
||||
|
||||
ress = _fmpz_vec_init(N);
|
||||
arith_euler_number_vec(ress, N);
|
||||
|
||||
for (n = 0; n < N; n++)
|
||||
{
|
||||
fmpz_init(res);
|
||||
|
||||
arith_euler_number(res, n);
|
||||
if (!fmpz_equal(res, ress + n))
|
||||
{
|
||||
flint_printf("FAIL: n = %wd\n", n);
|
||||
flint_printf("Value: "); fmpz_print(res); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(res);
|
||||
}
|
||||
|
||||
_fmpz_vec_clear(ress, N);
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
118
external/flint-2.4.3/arith/test/t-euler_phi.c
vendored
Normal file
118
external/flint-2.4.3/arith/test/t-euler_phi.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) 2010 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "arith.h"
|
||||
#include "ulong_extras.h"
|
||||
#include "profiler.h"
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
slong i;
|
||||
ulong n;
|
||||
fmpz_t x, y, z;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("euler_phi....");
|
||||
fflush(stdout);
|
||||
|
||||
fmpz_init(x);
|
||||
fmpz_init(y);
|
||||
fmpz_init(z);
|
||||
|
||||
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
fmpz_set_ui(x, i);
|
||||
arith_euler_phi(y, x);
|
||||
arith_euler_phi(x, x);
|
||||
fmpz_set_ui(z, n_euler_phi(i));
|
||||
if (!fmpz_equal(x, y) || !fmpz_equal(x, z))
|
||||
{
|
||||
flint_printf("FAIL: %wd\n", i);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
/* Aliasing test */
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_randtest(x, state, FLINT_BITS);
|
||||
fmpz_randtest(y, state, 5);
|
||||
fmpz_pow_ui(y, y, n_randtest(state) % 100);
|
||||
fmpz_mul(x, x, y);
|
||||
fmpz_set(z, x);
|
||||
arith_euler_phi(y, x);
|
||||
arith_euler_phi(x, x);
|
||||
if (!fmpz_equal(x, y))
|
||||
{
|
||||
flint_printf("FAIL: ");
|
||||
fmpz_print(z);
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
/* Power of a single prime, phi(p^n) = (p-1) * p^(n-1) */
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
n = (n_randtest(state) % 100) + 1;
|
||||
fmpz_set_ui(x, n_nth_prime(i+1));
|
||||
fmpz_pow_ui(x, x, n);
|
||||
arith_euler_phi(x, x);
|
||||
fmpz_set_ui(y, n_nth_prime(i+1));
|
||||
fmpz_pow_ui(y, y, n-1);
|
||||
fmpz_mul_ui(y, y, n_nth_prime(i+1)-1);
|
||||
if (!fmpz_equal(x, y))
|
||||
{
|
||||
flint_printf("FAIL: %wu ^ %wu\n", n_nth_prime(i+1), n);
|
||||
}
|
||||
}
|
||||
|
||||
/* Something nontrivial */
|
||||
fmpz_set_str(x, "10426024348053113487152988625265848110501553295256578345594388516660144", 10);
|
||||
fmpz_set_str(y, "2265085829098571747262267425315881590169106756213617459200000000000000", 10);
|
||||
arith_euler_phi(x, x);
|
||||
if (!fmpz_equal(x, y))
|
||||
{
|
||||
flint_printf("FAIL: special test value\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
|
||||
|
||||
fmpz_clear(x);
|
||||
fmpz_clear(y);
|
||||
fmpz_clear(z);
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
93
external/flint-2.4.3/arith/test/t-euler_polynomial.c
vendored
Normal file
93
external/flint-2.4.3/arith/test/t-euler_polynomial.c
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 <mpfr.h>
|
||||
#include "flint.h"
|
||||
#include "arith.h"
|
||||
#include "profiler.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mat.h"
|
||||
#include "fmpq_poly.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
fmpq_poly_t P, Q;
|
||||
mpz_t t;
|
||||
|
||||
slong k, n;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("euler_polynomial....");
|
||||
fflush(stdout);
|
||||
|
||||
for (n = 0; n <= 100; n++)
|
||||
{
|
||||
fmpq_poly_init(P);
|
||||
fmpq_poly_init(Q);
|
||||
|
||||
mpz_init(t);
|
||||
|
||||
for (k = 0; k < n; k++)
|
||||
{
|
||||
arith_euler_polynomial(P, k);
|
||||
flint_mpz_bin_uiui(t, n, k);
|
||||
fmpq_poly_scalar_mul_mpz(P, P, t);
|
||||
fmpq_poly_add(Q, Q, P);
|
||||
}
|
||||
|
||||
fmpq_poly_scalar_div_ui(Q, Q, 2);
|
||||
|
||||
arith_euler_polynomial(P, n);
|
||||
fmpq_poly_add(Q, Q, P);
|
||||
|
||||
mpz_clear(t);
|
||||
|
||||
fmpq_poly_zero(P);
|
||||
fmpq_poly_set_coeff_ui(P, n, UWORD(1));
|
||||
|
||||
if (!fmpq_poly_equal(P, Q))
|
||||
{
|
||||
flint_printf("ERROR: sum up to n = %wd did not add to x^n\n", n);
|
||||
flint_printf("Sum: ");
|
||||
fmpq_poly_print_pretty(Q, "x");
|
||||
flint_printf("\nExpected: ");
|
||||
fmpq_poly_print_pretty(P, "x");
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpq_poly_clear(P);
|
||||
fmpq_poly_clear(Q);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
154
external/flint-2.4.3/arith/test/t-harmonic.c
vendored
Normal file
154
external/flint-2.4.3/arith/test/t-harmonic.c
vendored
Normal file
@@ -0,0 +1,154 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2010,2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "arith.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpq.h"
|
||||
#include "ulong_extras.h"
|
||||
#include "profiler.h"
|
||||
|
||||
|
||||
void numerical_test(fmpq_t res, slong n, double ans)
|
||||
{
|
||||
const double tol = 1e-13;
|
||||
double err;
|
||||
|
||||
mpq_t tmp;
|
||||
mpq_init(tmp);
|
||||
|
||||
arith_harmonic_number(res, n);
|
||||
fmpq_get_mpq(tmp, res);
|
||||
err = mpq_get_d(tmp) - ans;
|
||||
err = FLINT_ABS(err);
|
||||
|
||||
if (err > tol)
|
||||
{
|
||||
flint_printf("FAIL: %wd %.16f %.16f\n", n, mpq_get_d(tmp), ans);
|
||||
abort();
|
||||
}
|
||||
|
||||
mpq_clear(tmp);
|
||||
}
|
||||
|
||||
void
|
||||
mpq_harmonic_balanced(mpq_t res, slong a, slong b)
|
||||
{
|
||||
slong k;
|
||||
mpq_t t;
|
||||
|
||||
mpq_init(t);
|
||||
|
||||
if (b - a < 50)
|
||||
{
|
||||
flint_mpq_set_ui(res, 0, UWORD(1));
|
||||
for (k = a; k <= b; k++)
|
||||
{
|
||||
flint_mpq_set_ui(t, UWORD(1), k);
|
||||
mpq_add(res, res, t);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mpq_harmonic_balanced(res, a, (a+b)/2);
|
||||
mpq_harmonic_balanced(t, (a+b)/2+1, b);
|
||||
mpq_add(res, res, t);
|
||||
}
|
||||
|
||||
mpq_clear(t);
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
slong i;
|
||||
mpq_t x, y;
|
||||
fmpq_t t;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("harmonic_number....");
|
||||
fflush(stdout);
|
||||
|
||||
fmpq_init(t);
|
||||
mpq_init(x);
|
||||
mpq_init(y);
|
||||
|
||||
for (i = -2; i < 1000; i++)
|
||||
{
|
||||
mpq_harmonic_balanced(x, 1, i);
|
||||
arith_harmonic_number(t, i);
|
||||
fmpq_get_mpq(y, t);
|
||||
|
||||
if (!mpq_equal(x, y))
|
||||
{
|
||||
flint_printf("FAIL: %wd\n", i);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
numerical_test(t, 1000, 7.4854708605503449127);
|
||||
numerical_test(t, 1001, 7.4864698615493459117);
|
||||
numerical_test(t, 1002, 7.4874678655413618797);
|
||||
numerical_test(t, 1003, 7.4884648745144426375);
|
||||
|
||||
numerical_test(t, 10000, 9.7876060360443822642);
|
||||
numerical_test(t, 10001, 9.7877060260453821642);
|
||||
numerical_test(t, 10002, 9.7878060060493813643);
|
||||
numerical_test(t, 10003, 9.7879059760583786652);
|
||||
numerical_test(t, 10004, 9.7880059360743722677);
|
||||
|
||||
numerical_test(t, 20000, 10.480728217229327573);
|
||||
numerical_test(t, 30000, 10.886184992119899362);
|
||||
numerical_test(t, 40000, 11.173862897945522882);
|
||||
numerical_test(t, 50000, 11.397003949278482638);
|
||||
numerical_test(t, 60000, 11.579323839415955783);
|
||||
numerical_test(t, 70000, 11.733473328773164956);
|
||||
numerical_test(t, 80000, 11.867003828544530692);
|
||||
numerical_test(t, 90000, 11.984786169759202469);
|
||||
|
||||
numerical_test(t, 100000, 12.090146129863427947);
|
||||
numerical_test(t, 100001, 12.090156129763428947);
|
||||
numerical_test(t, 100002, 12.090166129563432947);
|
||||
numerical_test(t, 100003, 12.090176129263441947);
|
||||
numerical_test(t, 100004, 12.090186128863457946);
|
||||
|
||||
numerical_test(t, 300000, 13.188755085205611713);
|
||||
numerical_test(t, 500000, 13.699580042305528322);
|
||||
numerical_test(t, 700000, 14.036051993212618803);
|
||||
numerical_test(t, 900000, 14.287366262763433338);
|
||||
|
||||
mpq_clear(x);
|
||||
mpq_clear(y);
|
||||
fmpq_clear(t);
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
70
external/flint-2.4.3/arith/test/t-landau_function_vec.c
vendored
Normal file
70
external/flint-2.4.3/arith/test/t-landau_function_vec.c
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 "arith.h"
|
||||
#include "fmpz_vec.h"
|
||||
|
||||
static const mp_limb_t known[] = {
|
||||
1, 1, 2, 3, 4, 6, 6, 12, 15, 20, 30, 30, 60, 60, 84, 105, 140, 210,
|
||||
210, 420, 420, 420, 420, 840, 840, 1260, 1260, 1540, 2310, 2520,
|
||||
4620, 4620, 5460, 5460, 9240, 9240, 13860, 13860, 16380, 16380,
|
||||
27720, 30030, 32760, 60060, 60060, 60060, 60060, 120120
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
fmpz * res;
|
||||
slong k, n;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("landau_function_vec....");
|
||||
fflush(stdout);
|
||||
|
||||
n = 45;
|
||||
res = _fmpz_vec_init(n);
|
||||
arith_landau_function_vec(res, n);
|
||||
|
||||
for (k = 0; k < n; k++)
|
||||
{
|
||||
if (fmpz_cmp_ui(res + k, known[k]))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("k = %wd, res[k] = %wd, expected: %wd\n",
|
||||
k, fmpz_get_si(res + k), known[k]);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
_fmpz_vec_clear(res, n);
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
86
external/flint-2.4.3/arith/test/t-legendre_polynomial.c
vendored
Normal file
86
external/flint-2.4.3/arith/test/t-legendre_polynomial.c
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "arith.h"
|
||||
#include "profiler.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mat.h"
|
||||
#include "fmpq_poly.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
fmpq_poly_t Pn, Pn1, Pn2, R;
|
||||
|
||||
slong n;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("legendre_polynomial....");
|
||||
fflush(stdout);
|
||||
|
||||
fmpq_poly_init(Pn);
|
||||
fmpq_poly_init(Pn1);
|
||||
fmpq_poly_init(Pn2);
|
||||
fmpq_poly_init(R);
|
||||
|
||||
fmpq_poly_set_ui(Pn, UWORD(1));
|
||||
fmpq_poly_set_coeff_ui(Pn1, 1, UWORD(1));
|
||||
|
||||
for (n = 0; n <= 500; n++)
|
||||
{
|
||||
arith_legendre_polynomial(R, n);
|
||||
|
||||
if (!fmpq_poly_equal(Pn, R))
|
||||
{
|
||||
flint_printf("FAIL: n = %wd\n", n);
|
||||
flint_printf("Direct: "); fmpq_poly_print_pretty(R, "x"); flint_printf("\n");
|
||||
flint_printf("Recur.: "); fmpq_poly_print_pretty(Pn, "x"); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpq_poly_shift_left(Pn2, Pn1, 1);
|
||||
fmpq_poly_scalar_mul_ui(Pn2, Pn2, 2*n + 3);
|
||||
fmpq_poly_scalar_mul_si(Pn, Pn, -(n+1));
|
||||
fmpq_poly_add(Pn2, Pn2, Pn);
|
||||
fmpq_poly_scalar_div_ui(Pn2, Pn2, n+2);
|
||||
|
||||
fmpq_poly_swap(Pn, Pn1);
|
||||
fmpq_poly_swap(Pn1, Pn2);
|
||||
}
|
||||
|
||||
fmpq_poly_clear(Pn);
|
||||
fmpq_poly_clear(Pn1);
|
||||
fmpq_poly_clear(Pn2);
|
||||
fmpq_poly_clear(R);
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
98
external/flint-2.4.3/arith/test/t-moebius_mu.c
vendored
Normal file
98
external/flint-2.4.3/arith/test/t-moebius_mu.c
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2010 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "arith.h"
|
||||
#include "ulong_extras.h"
|
||||
#include "profiler.h"
|
||||
|
||||
|
||||
void check(fmpz_t n, int expected)
|
||||
{
|
||||
int mu;
|
||||
|
||||
mu = arith_moebius_mu(n);
|
||||
if (mu != expected)
|
||||
{
|
||||
flint_printf("FAIL:");
|
||||
fmpz_print(n);
|
||||
flint_printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
fmpz_t x;
|
||||
ulong p;
|
||||
slong i, j, k, l;
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("moebius_mu....");
|
||||
fflush(stdout);
|
||||
|
||||
fmpz_init(x);
|
||||
|
||||
for (i = -1000; i < 1000; i++)
|
||||
{
|
||||
fmpz_set_si(x, i);
|
||||
check(x, n_moebius_mu(FLINT_ABS(i)));
|
||||
}
|
||||
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
fmpz_set_ui(x, 1);
|
||||
/* Product of some primes */
|
||||
k = n_randtest(state) % 10;
|
||||
l = n_randtest(state) % 10;
|
||||
for (j = 0; j < k; j++)
|
||||
{
|
||||
l += (n_randtest(state) % 10) + 1;
|
||||
fmpz_mul_ui(x, x, n_nth_prime(l+1));
|
||||
}
|
||||
|
||||
check(x, (k % 2 ? -1 : 1));
|
||||
fmpz_neg(x, x);
|
||||
|
||||
check(x, (k % 2 ? -1 : 1));
|
||||
fmpz_abs(x, x);
|
||||
|
||||
/* No longer square-free */
|
||||
p = n_nth_prime(n_randtest(state) % 100 + 1);
|
||||
fmpz_mul_ui(x, x, p*p);
|
||||
check(x, 0);
|
||||
}
|
||||
|
||||
fmpz_clear(x);
|
||||
|
||||
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
160
external/flint-2.4.3/arith/test/t-number_of_partitions.c
vendored
Normal file
160
external/flint-2.4.3/arith/test/t-number_of_partitions.c
vendored
Normal file
@@ -0,0 +1,160 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include <mpfr.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_vec.h"
|
||||
#include "arith.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
/* Values mod 10^9 generated with Sage */
|
||||
static const ulong testdata[][2] =
|
||||
{
|
||||
{100000, 421098519},
|
||||
{100001, 33940350},
|
||||
{100002, 579731933},
|
||||
{100003, 625213730},
|
||||
{100004, 539454200},
|
||||
{100005, 69672418},
|
||||
{100006, 865684292},
|
||||
{100007, 641916724},
|
||||
{100008, 36737908},
|
||||
{100009, 293498270},
|
||||
{100010, 177812057},
|
||||
{100011, 756857293},
|
||||
{100012, 950821113},
|
||||
{100013, 824882014},
|
||||
{100014, 533894560},
|
||||
{100015, 660734788},
|
||||
{100016, 835912257},
|
||||
{100017, 302982816},
|
||||
{100018, 468609888},
|
||||
{100019, 221646940},
|
||||
{1000000, 104673818},
|
||||
{1000001, 980212296},
|
||||
{1000002, 709795681},
|
||||
{1000003, 530913758},
|
||||
{1000004, 955452980},
|
||||
{1000005, 384388683},
|
||||
{1000006, 138665072},
|
||||
{1000007, 144832602},
|
||||
{1000008, 182646067},
|
||||
{1000009, 659145045},
|
||||
{1000010, 17911162},
|
||||
{1000011, 606326324},
|
||||
{1000012, 99495156},
|
||||
{1000013, 314860251},
|
||||
{1000014, 497563335},
|
||||
{1000015, 726842109},
|
||||
{1000016, 301469541},
|
||||
{1000017, 227491620},
|
||||
{1000018, 704160927},
|
||||
{1000019, 995311980},
|
||||
{10000000, 677288980},
|
||||
{10000001, 433805210},
|
||||
{10000002, 365406948},
|
||||
{10000003, 120899894},
|
||||
{10000004, 272822040},
|
||||
{10000005, 71938624},
|
||||
{10000006, 637670808},
|
||||
{10000007, 766947591},
|
||||
{10000008, 980210244},
|
||||
{10000009, 965734705},
|
||||
{10000010, 187411691},
|
||||
{10000011, 485652153},
|
||||
{10000012, 825498761},
|
||||
{10000013, 895802660},
|
||||
{10000014, 152775845},
|
||||
{10000015, 791493402},
|
||||
{10000016, 299640598},
|
||||
{10000017, 383615481},
|
||||
{10000018, 378922331},
|
||||
{10000019, 37059200},
|
||||
{100000000, 836637702},
|
||||
{100000001, 66421565},
|
||||
{100000002, 747849093},
|
||||
{100000003, 465329748},
|
||||
{100000004, 166747980},
|
||||
{0, 0},
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
fmpz_t p;
|
||||
fmpz * v;
|
||||
|
||||
slong i;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("number_of_partitions....");
|
||||
fflush(stdout);
|
||||
|
||||
fmpz_init(p);
|
||||
v = _fmpz_vec_init(3000);
|
||||
|
||||
arith_number_of_partitions_vec(v, 3000);
|
||||
|
||||
for (i = 0; i < 3000; i++)
|
||||
{
|
||||
arith_number_of_partitions(p, i);
|
||||
if (!fmpz_equal(p, v + i))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("p(%wd) does not agree with power series\n", i);
|
||||
flint_printf("Computed p(%wd): ", i); fmpz_print(p); flint_printf("\n");
|
||||
flint_printf("Expected: "); fmpz_print(v + i); flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
_fmpz_vec_clear(v, 3000);
|
||||
|
||||
for (i = 0; testdata[i][0] != 0; i++)
|
||||
{
|
||||
arith_number_of_partitions(p, testdata[i][0]);
|
||||
|
||||
if (fmpz_fdiv_ui(p, 1000000000) != testdata[i][1])
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("p(%wd) does not agree with known value mod 10^9\n",
|
||||
testdata[i][0]);
|
||||
flint_printf("Computed: %wu\n", fmpz_fdiv_ui(p, 1000000000));
|
||||
flint_printf("Expected: %wu\n", testdata[i][1]);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
fmpz_clear(p);
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
120
external/flint-2.4.3/arith/test/t-number_of_partitions_vec.c
vendored
Normal file
120
external/flint-2.4.3/arith/test/t-number_of_partitions_vec.c
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "arith.h"
|
||||
#include "fmpz_vec.h"
|
||||
#include "ulong_extras.h"
|
||||
#include "profiler.h"
|
||||
#include "nmod_vec.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
fmpz * p;
|
||||
mp_ptr pmod;
|
||||
slong k, n;
|
||||
|
||||
const slong maxn = 1000;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("number_of_partitions_vec....");
|
||||
fflush(stdout);
|
||||
|
||||
p = _fmpz_vec_init(maxn);
|
||||
pmod = _nmod_vec_init(maxn);
|
||||
|
||||
for (n = 0; n < maxn; n += (n < 50) ? + 1 : n/4)
|
||||
{
|
||||
fmpz_t s, t;
|
||||
nmod_t mod;
|
||||
nmod_init(&mod, n_randtest_prime(state, 0));
|
||||
|
||||
arith_number_of_partitions_vec(p, n);
|
||||
arith_number_of_partitions_nmod_vec(pmod, n, mod);
|
||||
|
||||
for (k = 0; k < n; k++)
|
||||
{
|
||||
if (fmpz_fdiv_ui(p + k, mod.n) != pmod[k])
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("n = %wd, k = %wd\n", n, k);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
if (n > 1)
|
||||
{
|
||||
fmpz_init(s);
|
||||
fmpz_init(t);
|
||||
|
||||
for (k = 1; k < n; k++)
|
||||
{
|
||||
slong j;
|
||||
|
||||
j = n - 1 - k*(3*k - 1)/2;
|
||||
if (j >= 0)
|
||||
fmpz_set(t, p + j);
|
||||
else
|
||||
fmpz_zero(t);
|
||||
|
||||
j = n - 1 - k*(3*k + 1)/2;
|
||||
if (j >= 0)
|
||||
fmpz_add(t, t, p + j);
|
||||
|
||||
if (k % 2)
|
||||
fmpz_add(s, s, t);
|
||||
else
|
||||
fmpz_sub(s, s, t);
|
||||
}
|
||||
|
||||
if (!fmpz_equal(s, p + n - 1))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("n = %wd\n", n);
|
||||
fmpz_print(s);
|
||||
flint_printf("\n");
|
||||
fmpz_print(p + n - 1);
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_clear(s);
|
||||
fmpz_clear(t);
|
||||
}
|
||||
}
|
||||
|
||||
_fmpz_vec_clear(p, maxn);
|
||||
_nmod_vec_clear(pmod);
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
66
external/flint-2.4.3/arith/test/t-pi_chudnovsky.c
vendored
Normal file
66
external/flint-2.4.3/arith/test/t-pi_chudnovsky.c
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2010 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "flint.h"
|
||||
#include "arith.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
slong k;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("pi_chudnovsky....");
|
||||
fflush(stdout);
|
||||
|
||||
for (k = 2; k < 20; k++)
|
||||
{
|
||||
mpfr_t x, y;
|
||||
|
||||
mpfr_init2(x, WORD(1) << k);
|
||||
mpfr_init2(y, WORD(1) << k);
|
||||
|
||||
mpfr_const_pi(x, MPFR_RNDN);
|
||||
mpfr_pi_chudnovsky(y, MPFR_RNDN);
|
||||
|
||||
if (!mpfr_equal_p(x, y))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("Wrong value at prec = %wd\n", WORD(1) << k);
|
||||
abort();
|
||||
}
|
||||
|
||||
mpfr_clear(x);
|
||||
mpfr_clear(y);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
69
external/flint-2.4.3/arith/test/t-primorial.c
vendored
Normal file
69
external/flint-2.4.3/arith/test/t-primorial.c
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2010 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "flint.h"
|
||||
#include "arith.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ulong k;
|
||||
fmpz_t x;
|
||||
fmpz_t y;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("primorial....");
|
||||
fflush(stdout);
|
||||
|
||||
fmpz_init(x);
|
||||
fmpz_init(y);
|
||||
fmpz_set_ui(y, 1);
|
||||
|
||||
for (k = 0; k < 10000; k++)
|
||||
{
|
||||
arith_primorial(x, k);
|
||||
if (n_is_prime(k))
|
||||
fmpz_mul_ui(y, y, k);
|
||||
if (!fmpz_equal(x, y))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("primorial of %wu disagrees with direct product\n", k);
|
||||
fmpz_print(x);
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
fmpz_clear(x);
|
||||
fmpz_clear(y);
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
172
external/flint-2.4.3/arith/test/t-ramanujan_tau.c
vendored
Normal file
172
external/flint-2.4.3/arith/test/t-ramanujan_tau.c
vendored
Normal file
@@ -0,0 +1,172 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2010 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "flint.h"
|
||||
#include "arith.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
void check_value(slong n, char *ans)
|
||||
{
|
||||
fmpz_t x, y;
|
||||
fmpz_init(x);
|
||||
fmpz_init(y);
|
||||
fmpz_set_si(y, n);
|
||||
arith_ramanujan_tau(x, y);
|
||||
fmpz_set_str(y, ans, 10);
|
||||
if (!fmpz_equal(x,y))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("tau(%wd) gave ", n);
|
||||
fmpz_print(x);
|
||||
flint_printf(", expected %s\n", ans);
|
||||
abort();
|
||||
}
|
||||
fmpz_clear(x);
|
||||
fmpz_clear(y);
|
||||
}
|
||||
|
||||
void consistency_check(slong n)
|
||||
{
|
||||
fmpz_poly_t p;
|
||||
fmpz_t x, y;
|
||||
slong k;
|
||||
|
||||
fmpz_poly_init(p);
|
||||
fmpz_init(x);
|
||||
fmpz_init(y);
|
||||
|
||||
arith_ramanujan_tau_series(p, n);
|
||||
if (p->length != n && !(n == 1 && p->length == 0))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("wrong length of polynomial %wd\n", n);
|
||||
abort();
|
||||
}
|
||||
|
||||
for (k=0; k<n; k++)
|
||||
{
|
||||
fmpz_set_si(y, k);
|
||||
arith_ramanujan_tau(x, y);
|
||||
fmpz_poly_get_coeff_fmpz(y, p, k);
|
||||
if (!fmpz_equal(x,y))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("different tau n=%wd, k=%wd\n", n, k);
|
||||
fmpz_print(x);
|
||||
flint_printf("\n");
|
||||
fmpz_print(y);
|
||||
flint_printf("\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
fmpz_clear(x);
|
||||
fmpz_clear(y);
|
||||
fmpz_poly_clear(p);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("ramanujan_tau....");
|
||||
fflush(stdout);
|
||||
|
||||
check_value(0, "0");
|
||||
check_value(1, "1");
|
||||
check_value(2, "-24");
|
||||
check_value(3, "252");
|
||||
check_value(4, "-1472");
|
||||
check_value(5, "4830");
|
||||
check_value(6, "-6048");
|
||||
check_value(7, "-16744");
|
||||
check_value(8, "84480");
|
||||
check_value(9, "-113643");
|
||||
check_value(10, "-115920");
|
||||
check_value(11, "534612");
|
||||
check_value(12, "-370944");
|
||||
check_value(13, "-577738");
|
||||
check_value(14, "401856");
|
||||
check_value(15, "1217160");
|
||||
check_value(16, "987136");
|
||||
check_value(17, "-6905934");
|
||||
check_value(18, "2727432");
|
||||
check_value(19, "10661420");
|
||||
check_value(20, "-7109760");
|
||||
check_value(21, "-4219488");
|
||||
check_value(22, "-12830688");
|
||||
check_value(23, "18643272");
|
||||
check_value(24, "21288960");
|
||||
check_value(25, "-25499225");
|
||||
check_value(26, "13865712");
|
||||
check_value(27, "-73279080");
|
||||
check_value(28, "24647168");
|
||||
check_value(29, "128406630");
|
||||
check_value(30, "-29211840");
|
||||
check_value(31, "-52843168");
|
||||
check_value(32, "-196706304");
|
||||
check_value(33, "134722224");
|
||||
check_value(34, "165742416");
|
||||
check_value(35, "-80873520");
|
||||
check_value(36, "167282496");
|
||||
check_value(37, "-182213314");
|
||||
check_value(38, "-255874080");
|
||||
check_value(39, "-145589976");
|
||||
check_value(40, "408038400");
|
||||
check_value(41, "308120442");
|
||||
check_value(42, "101267712");
|
||||
check_value(43, "-17125708");
|
||||
check_value(44, "-786948864");
|
||||
check_value(45, "-548895690");
|
||||
check_value(46, "-447438528");
|
||||
check_value(47, "2687348496");
|
||||
check_value(48, "248758272");
|
||||
check_value(49, "-1696965207");
|
||||
|
||||
check_value(1000, "-30328412970240000");
|
||||
check_value(10000, "-482606811957501440000");
|
||||
check_value(100000, "-2983637890141033828147200000");
|
||||
check_value(5040, "9072480147209256960");
|
||||
check_value(25401600, "-982963272212951631424865761586105548800");
|
||||
check_value(100003, "1194906306375914517502892252");
|
||||
check_value(15251, "-67392761749743476612496");
|
||||
check_value(16777216, "5141538908507386166920374725609506471936");
|
||||
check_value(43046721, "447670851294004737003138291024309833342241");
|
||||
check_value(462594208,
|
||||
"-313042078739616847874899392539635327193629261824");
|
||||
|
||||
consistency_check(0);
|
||||
consistency_check(1);
|
||||
consistency_check(2);
|
||||
consistency_check(3);
|
||||
consistency_check(10);
|
||||
consistency_check(11);
|
||||
consistency_check(100);
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
215
external/flint-2.4.3/arith/test/t-stirling.c
vendored
Normal file
215
external/flint-2.4.3/arith/test/t-stirling.c
vendored
Normal file
@@ -0,0 +1,215 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2010 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "arith.h"
|
||||
#include "fmpz_vec.h"
|
||||
#include "fmpz_mat.h"
|
||||
#include "ulong_extras.h"
|
||||
#include "profiler.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
fmpz_mat_t mat, mat2, mat3;
|
||||
|
||||
fmpz * row;
|
||||
fmpz_t s;
|
||||
|
||||
slong n, k, mm, nn;
|
||||
|
||||
const slong maxn = 40;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("stirling....");
|
||||
fflush(stdout);
|
||||
|
||||
fmpz_init(s);
|
||||
|
||||
for (mm = 0; mm < maxn / 2; mm++)
|
||||
{
|
||||
/* Consistency test for stirling1u */
|
||||
|
||||
for (nn = 0; nn < maxn; nn++)
|
||||
{
|
||||
fmpz_mat_init(mat, mm, nn);
|
||||
arith_stirling_matrix_1u(mat);
|
||||
|
||||
for (n = 0; n < mm; n++)
|
||||
{
|
||||
for (k = 0; k < nn; k++)
|
||||
{
|
||||
row = _fmpz_vec_init(k);
|
||||
arith_stirling_number_1u_vec(row, n, k);
|
||||
if (!_fmpz_vec_equal(row, mat->rows[n], k))
|
||||
{
|
||||
flint_printf("stirling1u mat != vec ");
|
||||
flint_printf("nn,n,k=%wd,%wd,%wd\n", nn, n, k);
|
||||
flint_printf("mat: ");
|
||||
_fmpz_vec_print(mat->rows[n], k);
|
||||
flint_printf("\nvec: ");
|
||||
_fmpz_vec_print(row, k);
|
||||
abort();
|
||||
}
|
||||
_fmpz_vec_clear(row, k);
|
||||
|
||||
arith_stirling_number_1u(s, n, k);
|
||||
if (!fmpz_equal(mat->rows[n]+k, s))
|
||||
{
|
||||
flint_printf("stirling1u mat != single ");
|
||||
flint_printf("nn,n,k=%wd,%wd,%wd\n", nn, n, k);
|
||||
flint_printf("mat: ");
|
||||
fmpz_print(mat->rows[n]+k);
|
||||
flint_printf("\nsingle: ");
|
||||
fmpz_print(s);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmpz_mat_clear(mat);
|
||||
}
|
||||
|
||||
/* Consistency test for stirling1 */
|
||||
for (nn = 0; nn < maxn; nn++)
|
||||
{
|
||||
fmpz_mat_init(mat, mm, nn);
|
||||
arith_stirling_matrix_1(mat);
|
||||
|
||||
for (n = 0; n < mm; n++)
|
||||
{
|
||||
for (k = 0; k < nn; k++)
|
||||
{
|
||||
row = _fmpz_vec_init(k);
|
||||
arith_stirling_number_1_vec(row, n, k);
|
||||
if (!_fmpz_vec_equal(row, mat->rows[n], k))
|
||||
{
|
||||
flint_printf("stirling1 mat != vec ");
|
||||
flint_printf("nn,n,k=%wd,%wd,%wd\n", nn, n, k);
|
||||
flint_printf("mat: ");
|
||||
_fmpz_vec_print(mat->rows[n], k);
|
||||
flint_printf("\nvec: ");
|
||||
_fmpz_vec_print(row, k);
|
||||
abort();
|
||||
}
|
||||
_fmpz_vec_clear(row, k);
|
||||
|
||||
arith_stirling_number_1(s, n, k);
|
||||
if (!fmpz_equal(mat->rows[n]+k, s))
|
||||
{
|
||||
flint_printf("stirling1 mat != single ");
|
||||
flint_printf("nn,n,k=%wd,%wd,%wd\n", nn, n, k);
|
||||
flint_printf("mat: ");
|
||||
fmpz_print(mat->rows[n]+k);
|
||||
flint_printf("\nsingle: ");
|
||||
fmpz_print(s);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmpz_mat_clear(mat);
|
||||
}
|
||||
|
||||
/* Consistency test for stirling2 */
|
||||
for (nn = 0; nn < maxn; nn++)
|
||||
{
|
||||
fmpz_mat_init(mat, mm, nn);
|
||||
arith_stirling_matrix_2(mat);
|
||||
|
||||
for (n = 0; n < mm; n++)
|
||||
{
|
||||
for (k = 0; k < nn; k++)
|
||||
{
|
||||
row = _fmpz_vec_init(k);
|
||||
arith_stirling_number_2_vec(row, n, k);
|
||||
if (!_fmpz_vec_equal(row, mat->rows[n], k))
|
||||
{
|
||||
flint_printf("stirling2 mat != vec ");
|
||||
flint_printf("nn,n,k=%wd,%wd,%wd\n", nn, n, k);
|
||||
flint_printf("mat: ");
|
||||
_fmpz_vec_print(mat->rows[n], k);
|
||||
flint_printf("\nvec: ");
|
||||
_fmpz_vec_print(row, k);
|
||||
abort();
|
||||
}
|
||||
_fmpz_vec_clear(row, k);
|
||||
|
||||
arith_stirling_number_2(s, n, k);
|
||||
if (!fmpz_equal(mat->rows[n]+k, s))
|
||||
{
|
||||
flint_printf("stirling2 mat != single ");
|
||||
flint_printf("nn,n,k=%wd,%wd,%wd\n", nn, n, k);
|
||||
flint_printf("mat: ");
|
||||
fmpz_print(mat->rows[n]+k);
|
||||
flint_printf("\nsingle: ");
|
||||
fmpz_print(s);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmpz_mat_clear(mat);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Matrix inverse test */
|
||||
for (nn = 1; nn < 50; nn++)
|
||||
{
|
||||
fmpz_mat_init(mat, nn, nn);
|
||||
fmpz_mat_init(mat2, nn, nn);
|
||||
fmpz_mat_init(mat3, nn, nn);
|
||||
|
||||
arith_stirling_matrix_1(mat);
|
||||
arith_stirling_matrix_2(mat2);
|
||||
fmpz_mat_mul(mat3, mat, mat2);
|
||||
|
||||
for (n = 0; n < nn; n++)
|
||||
{
|
||||
for (k = 0; k < nn; k++)
|
||||
{
|
||||
if (fmpz_get_ui(mat3->rows[n]+k) != (n == k))
|
||||
{
|
||||
flint_printf("not identity matrix: %wd, %wd, %wd\n", nn, n, k);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
fmpz_mat_clear(mat);
|
||||
fmpz_mat_clear(mat2);
|
||||
fmpz_mat_clear(mat3);
|
||||
}
|
||||
|
||||
fmpz_clear(s);
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
88
external/flint-2.4.3/arith/test/t-sum_of_squares.c
vendored
Normal file
88
external/flint-2.4.3/arith/test/t-sum_of_squares.c
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "arith.h"
|
||||
#include "fmpz_vec.h"
|
||||
|
||||
#define N 10
|
||||
|
||||
static const fmpz known[N][N] = {
|
||||
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||
{1, 2, 0, 0, 2, 0, 0, 0, 0, 2},
|
||||
{1, 4, 4, 0, 4, 8, 0, 0, 4, 4},
|
||||
{1, 6, 12, 8, 6, 24, 24, 0, 12, 30},
|
||||
{1, 8, 24, 32, 24, 48, 96, 64, 24, 104},
|
||||
{1, 10, 40, 80, 90, 112, 240, 320, 200, 250},
|
||||
{1, 12, 60, 160, 252, 312, 544, 960, 1020, 876},
|
||||
{1, 14, 84, 280, 574, 840, 1288, 2368, 3444, 3542},
|
||||
{1, 16, 112, 448, 1136, 2016, 3136, 5504, 9328, 12112},
|
||||
{1, 18, 144, 672, 2034, 4320, 7392, 12672, 22608, 34802}
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
fmpz * r;
|
||||
fmpz_t t;
|
||||
slong i, j;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("sum_of_squares....");
|
||||
fflush(stdout);
|
||||
|
||||
r = _fmpz_vec_init(N);
|
||||
fmpz_init(t);
|
||||
|
||||
for (i = 0; i < N; i++)
|
||||
{
|
||||
arith_sum_of_squares_vec(r, i, N);
|
||||
|
||||
for (j = 0; j < N; j++)
|
||||
{
|
||||
fmpz_set_ui(t, j);
|
||||
arith_sum_of_squares(t, i, t);
|
||||
|
||||
if (!fmpz_equal(t, r + j) || !fmpz_equal(t, known[i] + j))
|
||||
{
|
||||
flint_printf("FAIL:\n");
|
||||
flint_printf("i, j = %wd, %wd, r[j] = %wd, r(j) = %wd, "
|
||||
"expected: %wd\n",
|
||||
i, j, fmpz_get_si(r + j), fmpz_get_si(t), known[i][j]);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_fmpz_vec_clear(r, N);
|
||||
fmpz_clear(t);
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
80
external/flint-2.4.3/arith/test/t-swinnerton_dyer_polynomial.c
vendored
Normal file
80
external/flint-2.4.3/arith/test/t-swinnerton_dyer_polynomial.c
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
/*=============================================================================
|
||||
|
||||
This file is part of FLINT.
|
||||
|
||||
FLINT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FLINT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FLINT; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
=============================================================================*/
|
||||
/******************************************************************************
|
||||
|
||||
Copyright (C) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "arith.h"
|
||||
#include "profiler.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mat.h"
|
||||
#include "fmpq_poly.h"
|
||||
|
||||
static const mp_limb_t known_values[] =
|
||||
{
|
||||
UWORD(2147483629),
|
||||
UWORD(1073742093),
|
||||
UWORD(1342248677),
|
||||
UWORD(3319936736),
|
||||
UWORD(2947821228),
|
||||
UWORD(1019513834),
|
||||
UWORD(3324951530),
|
||||
UWORD(1995039408),
|
||||
UWORD(3505683295),
|
||||
UWORD(3567639420),
|
||||
UWORD(394942914)
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
fmpz_poly_t S;
|
||||
mp_limb_t r;
|
||||
slong n;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
flint_printf("swinnerton_dyer_polynomial....");
|
||||
fflush(stdout);
|
||||
|
||||
for (n = 0; n <= 10; n++)
|
||||
{
|
||||
fmpz_poly_init(S);
|
||||
arith_swinnerton_dyer_polynomial(S, n);
|
||||
r = fmpz_poly_evaluate_mod(S, UWORD(2147483629), UWORD(4294967291));
|
||||
|
||||
if (r != known_values[n])
|
||||
{
|
||||
flint_printf("ERROR: wrong evaluation of S_%wd\n", n);
|
||||
abort();
|
||||
}
|
||||
|
||||
fmpz_poly_clear(S);
|
||||
}
|
||||
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
flint_printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user