Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

Bernoulli

Compute Bernoulli Numbers


Description

Compute the nth Bernoulli number, or generate all Bernoulli numbers up to the nth, using diverse methods, that is, algorithms.

NOTE the current default methods will be changed – to get better accuracy!

Usage

Bernoulli    (n, method = c("sumBin", "sumRamanujan", "asymptotic"),
              verbose = FALSE)
Bernoulli.all(n, method = c("A-T", "sumBin", "sumRamanujan", "asymptotic"),
              precBits = NULL, verbose = getOption("verbose"))

Arguments

n

positive integer, indicating the index of the largest (and last) of the Bernoulli numbers needed.

method

character string, specifying which method should be applied. The default for Bernoulli.all(), "A-T" stands for the Akiyama-Tanigawa algorithm which is nice and simple but has bad numerical properties. It can however work with high precision "mpfr"-numbers, see precBits. "sumRamanujan" is somewhat more efficient but not yet implemented.

precBits

currently only for method = "A-T"NULL or a positive integer indicating the precision of the initial numbrs in bits, using "Rmpfr"'s package multiprecision arithmetic.

verbose

(for "A-T":) logical indicating if the intermediate results of the algorithm should be printed.

Value

Bernoulli():

a number

Bernoulli.all():

a numeric vector of length n, containing B(n)

References

Kaneko, Masanobu (2000) The Akiyama-Tanigawa algorithm for Bernoulli numbers; Journal of Integer Sequences 3, article 00.2.9

See Also

Examples

## The example for the paper
MASS::fractions(Bernoulli.all(8, verbose=TRUE))

B10 <- Bernoulli.all(10)
MASS::fractions(B10)

system.time(B50  <- Bernoulli.all(50))#  {does not cache} -- still "no time"
system.time(B100 <- Bernoulli.all(100))# still less than a milli second

## Using Bernoulli() is not much slower, but hopefully *more* accurate!
## Check first - TODO
system.time(B.1c <- Bernoulli(100))# caches ..
system.time(B1c. <- Bernoulli(100))# ==> now much faster
stopifnot(identical(B.1c, B1c.))

if(FALSE)## reset the cache:
assign("Bern.tab", list(), envir = copula:::.nacopEnv)

## More experiments in the source of the copula package ../tests/Stirling-etc.R

copula

Multivariate Dependence with Copulas

v1.0-1
GPL (>= 3) | file LICENCE
Authors
Marius Hofert [aut] (<https://orcid.org/0000-0001-8009-4665>), Ivan Kojadinovic [aut] (<https://orcid.org/0000-0002-2903-1543>), Martin Maechler [aut, cre] (<https://orcid.org/0000-0002-8685-9910>), Jun Yan [aut] (<https://orcid.org/0000-0003-4401-7296>), Johanna G. Nešlehová [ctb] (evTestK(), <https://orcid.org/0000-0001-9634-4796>), Rebecca Morger [ctb] (fitCopula.ml(): code for free mixCopula weight parameters)
Initial release
2020-12-07

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.