File: bernoulli_div_fac_ui.c

package info (click to toggle)
flint-arb 1%3A2.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 14,672 kB
  • sloc: ansic: 204,753; sh: 570; makefile: 287; python: 268
file content (71 lines) | stat: -rw-r--r-- 1,655 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
    Copyright (C) 2014 Fredrik Johansson

    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/>.
*/

#include "mag.h"

const int mag_bernoulli_div_fac_ui_tab[32] =
{
    1, 536870912,
    -3, 715827883,
    -9, 763549742,
    -14, 581752185,
    -20, 930803495,
    -25, 752164440,
    -30, 609225645,
    -36, 987456906,
    -41, 800365631,
    -46, 648744507,
    -52, 1051701970,
    -57, 852476898,
    -62, 690991623,
    -67, 560096688,
    -73, 907994540,
    -78, 735992650,
};

/* computes upper bound for B_n / n! */
void
mag_bernoulli_div_fac_ui(mag_t z, ulong n)
{
    if (n % 2 == 1)
    {
        if (n == 1)
        {
            mag_one(z);
            mag_mul_2exp_si(z, z, -1);
        }
        else
        {
            mag_zero(z);
        }
    }
    else if (n < 32)
    {
        _fmpz_demote(MAG_EXPREF(z));
        MAG_EXP(z) = mag_bernoulli_div_fac_ui_tab[n];
        MAG_MAN(z) = mag_bernoulli_div_fac_ui_tab[n + 1];
    }
    else
    {
        /* upper bound for 1/(2pi) */
        mag_set_ui_2exp_si(z, 683565276, -32);

        /* 2 (1/(2pi))^n */
        mag_pow_ui(z, z, n);
        mag_mul_2exp_si(z, z, 1);

        /* we should multiply by an upper bound for zeta(n),
           but the error in the upper bound for 1/(2pi)
           used above is already larger than this factor
           when n >= 32, so there is no need */
    }
}