swh:1:snp:81eadaa089e8253d8469bcef66aa332632c6c669
Tip revision: fdf16693b000f3e309c56091892c61f0ec9fd670 authored by Hans W. Borchers on 21 November 2017, 16:15:00 UTC
version 2.1.1
version 2.1.1
Tip revision: fdf1669
bernoulli.R
##
## b e r n o u l l i . R Bernoulli numbers and polynomials
##
bernoulli <- function(n, x) {
stopifnot(length(n) == 1, floor(n) == ceiling(n), n >= 0)
if (missing(x)) {
if (n == 0) return(1.0)
bf <- function(n) -n * zeta(1-n)
bx <- c(1.0, sapply(1:n, bf))
bx[2] <- -0.5
} else {
stopifnot(is.numeric(x))
bn <- bernoulli(n)
cn <- choose(n, 0:n)
bx <-polyval(cn*bn, x)
}
bx
}
# euler <- function(n) {
# stopifnot(length(n) >= 1, floor(n) == ceiling(n))
# if (n == 0) return(1)
# en <- numeric(n)
# en[1] <- 0.0
# en[2] <- -1.0
# if (n < 4) return(c(1.0, en[1:n]))
# for (m in 2:floor(n/2)) {
# s <- 1.0
# for (k in 1:(m-1)) {
# r = 1.0
# for (j in 1:(2*k)) {
# r <- r * (2*m - 2*k + j) / j
# }
# s <- s + r*en[2*k]
# }
# en[2*m] <- (-s)
# }
# c(1.0, en)
# }