1 /*
2 Copyright (C) 2011 Fredrik Johansson
3
4 This file is part of FLINT.
5
6 FLINT is free software: you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License (LGPL) as published
8 by the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version. See <http://www.gnu.org/licenses/>.
10 */
11
12 #include "arith.h"
13
_arith_euler_number_zeta(fmpz_t res,ulong n)14 void _arith_euler_number_zeta(fmpz_t res, ulong n)
15 {
16 mpz_t r;
17 mpfr_t t, z, pi;
18 flint_bitcnt_t prec, pi_prec;
19
20 if (n % 2)
21 {
22 fmpz_zero(res);
23 return;
24 }
25
26 if (n < SMALL_EULER_LIMIT)
27 {
28 fmpz_set_ui(res, euler_number_small[n / 2]);
29 if (n % 4 == 2)
30 fmpz_neg(res, res);
31 return;
32 }
33
34 prec = arith_euler_number_size(n) + 10;
35 pi_prec = prec + FLINT_BIT_COUNT(n);
36
37 mpz_init(r);
38 mpfr_init2(t, prec);
39 mpfr_init2(z, prec);
40 mpfr_init2(pi, pi_prec);
41
42 flint_mpz_fac_ui(r, n);
43 mpfr_set_z(t, r, GMP_RNDN);
44 mpfr_mul_2exp(t, t, n + 2, GMP_RNDN);
45
46 /* pi^(n + 1) * L(n+1) */
47 mpfr_zeta_inv_euler_product(z, n + 1, 1);
48 mpfr_const_pi(pi, GMP_RNDN);
49 mpfr_pow_ui(pi, pi, n + 1, GMP_RNDN);
50 mpfr_mul(z, z, pi, GMP_RNDN);
51
52 mpfr_div(t, t, z, GMP_RNDN);
53
54 /* round */
55 mpfr_round(t, t);
56 mpfr_get_z(r, t, GMP_RNDN);
57 fmpz_set_mpz(res, r);
58
59 if (n % 4 == 2)
60 fmpz_neg(res, res);
61
62 mpz_clear(r);
63 mpfr_clear(t);
64 mpfr_clear(z);
65 mpfr_clear(pi);
66 }
67