Learn R Programming

DPQ (version 0.4-3)

Bern: Bernoulli Numbers

Description

Return the \(n\)-th Bernoulli number \(B_n\), (or \(B_n^+\), see the reference), where \(B_1 = + \frac 1 2\).

Usage

Bern(n, verbose = getOption("verbose", FALSE))

Arguments

n

integer, \(n \ge 0\).

verbose

logical indicating if computation should be traced.

Value

The number \(B_n\) of type numeric.

A side effect is the caching of computed Bernoulli numbers in the hidden environment .bernoulliEnv.

References

https://en.wikipedia.org/wiki/Bernoulli_number

See Also

Bernoulli in Rmpfr in arbitrary precision via Riemann's \(\zeta\) function.

The next version of package gmp is to contain BernoulliQ(), providing exact Bernoulli numbers as big rationals (class "bigq").

Examples

Run this code
# NOT RUN {
(B.0.10 <- vapply(0:10, Bern, 1/2))
## [1]  1.00000000 +0.50000000  0.16666667  0.00000000 -0.03333333  0.00000000
## [7]  0.02380952  0.00000000 -0.03333333  0.00000000  0.07575758
if(requireNamespace("MASS")) {
  print( MASS::fractions(B.0.10) )
  ## 1  +1/2   1/6    0  -1/30     0  1/42     0 -1/30     0  5/66
}
# }

Run the code above in your browser using DataLab