2016-04-26 17:20:05 +02:00
|
|
|
/*
|
2012-12-19 14:04:00 +01:00
|
|
|
Copyright (C) 2012 Fredrik Johansson
|
|
|
|
|
2016-04-26 17:20:05 +02:00
|
|
|
This file is part of Arb.
|
|
|
|
|
|
|
|
Arb is free software: you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Lesser General Public License (LGPL) as published
|
|
|
|
by the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version. See <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2012-12-19 14:04:00 +01:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "bernoulli.h"
|
2016-03-03 15:42:23 +01:00
|
|
|
#include "flint/ulong_extras.h"
|
|
|
|
#include "flint/nmod_poly.h"
|
|
|
|
#include "flint/nmod_vec.h"
|
2012-12-19 14:04:00 +01:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
flint_rand_t state;
|
2015-11-05 18:01:09 +00:00
|
|
|
slong nmax, n, bound, count;
|
2012-12-19 14:04:00 +01:00
|
|
|
mp_limb_t p, pinv, m1, m2;
|
|
|
|
nmod_poly_t A;
|
|
|
|
|
2015-11-06 16:17:27 +00:00
|
|
|
flint_printf("rev....");
|
2012-12-19 14:04:00 +01:00
|
|
|
fflush(stdout);
|
|
|
|
flint_randinit(state);
|
|
|
|
|
2016-04-10 17:24:58 +02:00
|
|
|
bound = 100000 * FLINT_MIN(1.0, arb_test_multiplier());
|
2012-12-19 14:04:00 +01:00
|
|
|
|
2015-11-06 15:34:19 +00:00
|
|
|
p = n_nextprime(UWORD(1) << (FLINT_BITS - 1), 0);
|
2012-12-19 14:04:00 +01:00
|
|
|
pinv = n_preinvert_limb(p);
|
|
|
|
|
|
|
|
nmod_poly_init(A, p);
|
|
|
|
nmod_poly_set_coeff_ui(A, 1, 1);
|
|
|
|
nmod_poly_exp_series(A, A, bound);
|
|
|
|
nmod_poly_shift_right(A, A, 1);
|
|
|
|
nmod_poly_inv_series(A, A, bound);
|
|
|
|
|
|
|
|
m1 = 1;
|
|
|
|
for (n = 0; n < A->length; n++)
|
|
|
|
{
|
|
|
|
A->coeffs[n] = n_mulmod2_preinv(A->coeffs[n], m1, p, pinv);
|
|
|
|
m1 = n_mulmod2_preinv(m1, n + 1, p, pinv);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (nmax = 0; nmax < bound; nmax = 1.5 * nmax + 2)
|
|
|
|
{
|
|
|
|
fmpz_t numer, denom;
|
|
|
|
bernoulli_rev_t iter;
|
|
|
|
|
|
|
|
fmpz_init(numer);
|
|
|
|
fmpz_init(denom);
|
|
|
|
|
|
|
|
nmax += (nmax % 2);
|
|
|
|
|
|
|
|
bernoulli_rev_init(iter, nmax);
|
|
|
|
|
|
|
|
if (nmax < 8000)
|
|
|
|
count = 4000;
|
|
|
|
else
|
|
|
|
count = 100;
|
|
|
|
|
2015-11-06 16:17:27 +00:00
|
|
|
/* flint_printf("nmax = %wd, count = %wd\n", nmax, count); */
|
2012-12-19 14:04:00 +01:00
|
|
|
|
|
|
|
for (n = nmax; n >= 0 && count > 0; n -= 2, count--)
|
|
|
|
{
|
|
|
|
bernoulli_rev_next(numer, denom, iter);
|
|
|
|
|
|
|
|
m1 = fmpz_fdiv_ui(numer, p);
|
|
|
|
m2 = fmpz_fdiv_ui(denom, p);
|
|
|
|
m2 = n_invmod(m2, p);
|
|
|
|
m1 = n_mulmod2_preinv(m1, m2, p, pinv);
|
|
|
|
m2 = nmod_poly_get_coeff_ui(A, n);
|
|
|
|
|
|
|
|
if (m1 != m2)
|
|
|
|
{
|
2015-11-06 16:17:27 +00:00
|
|
|
flint_printf("FAIL:\n");
|
|
|
|
flint_printf("nmax = %wd, n = %wd\n", nmax, n);
|
|
|
|
flint_printf("m1 = %wu mod %wu\n", m1, p);
|
|
|
|
flint_printf("m2 = %wu mod %wu\n", m2, p);
|
2017-02-28 16:50:03 +01:00
|
|
|
flint_abort();
|
2012-12-19 14:04:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bernoulli_rev_clear(iter);
|
|
|
|
|
|
|
|
fmpz_clear(numer);
|
|
|
|
fmpz_clear(denom);
|
|
|
|
}
|
|
|
|
|
|
|
|
flint_randclear(state);
|
2013-07-30 13:06:08 +02:00
|
|
|
flint_cleanup();
|
2015-11-06 16:17:27 +00:00
|
|
|
flint_printf("PASS\n");
|
2012-12-19 14:04:00 +01:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|