sumBinomMpfr(Rmpfr)
sumBinomMpfr()所属R语言包:Rmpfr
(Alternating) Binomial Sums via Rmpfr
(交流)二项式和通过Rmpfr
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Compute (alternating) binomial sums via high-precision arithmetic. Such sums appear in different contexts and are typically challenging, i.e., currently impossible, to evaluate reliably as soon as n is larger than around 50--70.
计算(交替)二项式款项通过高精度的算术。这些款项出现在不同的上下文中,通常是具有挑战性的,也就是说,目前是不可能的,以评估可靠作为n是比周围50--70大。
The alternating binomial sum sB(f,n) := sumBinom(n, f, n0=0) is (up to sign) equal to the n-th forward difference operator Δ^n f,
交替的的二项式总和sB(f,n) := sumBinom(n, f, n0=0)是(高达签署)等于n个向前差分算子Δ^n f
where
哪里
is the n-fold iterated forward difference Δ f(x) = f(x+1) - f(x) (for x = 0).
倍n重复差异Δ f(x) = f(x+1) - f(x)(x = 0)。
用法----------Usage----------
sumBinomMpfr(n, f, n0 = 0, alternating = TRUE, precBits = 256,
f.k = f(mpfr(k, precBits=precBits)))
参数----------Arguments----------
参数:n
upper summation index (integer).
上求和指标(整数)。
参数:f
function to be evaluated at k for k in n0:n.
function:评价kk in n0:n。
参数:n0
lower summation index, typically 0 (= default) or 1.
求和指标较低,通常0(=默认值)或1。
参数:alternating
logical indicating if the sum is alternating, see below.
逻辑表明,如果和交替,见下文。
参数:precBits
the number of bits for MPFR precision, see mpfr.
MPFR精度的比特的数目,请参阅mpfr。
参数:f.k
can be specified instead of f and precBits, and must contain the equivalent of its default, f(mpfr(k, precBits=precBits)).
可以指定f和precBits,并且必须包含其默认值,相当于f(mpfr(k, precBits=precBits))。
Details
详细信息----------Details----------
The current implementation might be improved in the future, notably for the case where sB(f,n)=sumBinomMpfr(n, f, *) is to be computed for a whole sequence n = 1,...,N.
显着的情况下,目前的实现可能会在未来得到改善sB(f,n)=“sumBinomMpfr(n, f, *)是计算整个序列n = 1,...,N。
值----------Value----------
an mpfr number of precision precBits, say s. If alternating is true (as per default),
mpfr一些精密precBits,说s。如果alternating是真实的(根据默认的),
if alternating is false, the (-1)^k factor is dropped (or replaced by 1) above.
alternating如果是假的,被丢弃(-1)^k因素(或更换1)以上。
(作者)----------Author(s)----------
Martin Maechler, after conversations with Christophe Dutang.
参考文献----------References----------
The N\"orlund-Rice integral, http://en.wikipedia.org/wiki/Rice_integral
Mellin Transforms and Asymptotics: Finite Differences and Rice's Integrals, Theoretical Computer Science 144, 101–124.
参见----------See Also----------
chooseMpfr, chooseZ from package gmp.
chooseMpfr,chooseZ包gmp。
实例----------Examples----------
## "naive" R implementation:[#“天真”R执行:]
sumBinom <- function(n, f, n0=0, ...) {
k <- n0:n
sum( choose(n, k) * (-1)^k * f(k, ...))
}
## compute sumBinomMpfr(.) for a whole set of 'n' values:[#的计算sumBinomMpfr点(。)一套完整的“N”值:]
sumBin.all <- function(n, f, n0=0, precBits = 256, ...)
{
N <- length(n)
precBits <- rep(precBits, length = N)
ll <- lapply(seq_len(N), function(i)
sumBinomMpfr(n[i], f, n0=n0, precBits=precBits[i], ...))
sapply(ll, as, "double")
}
sumBin.all.R <- function(n, f, n0=0, ...)
sapply(n, sumBinom, f=f, n0=n0, ...)
n.set <- 5:80
system.time(res.R <- sumBin.all.R(n.set, f = sqrt)) ## instantaneous..[#瞬间......]
system.time(resMpfr <- sumBin.all (n.set, f = sqrt)) ## takes ~2 seconds[#~2秒]
matplot(n.set, cbind(res.R, resMpfr), type = "l", lty=1,
ylim = extendrange(resMpfr, f = 0.25), xlab = "n",
main = "sumBinomMpfr(n, f = sqrt) vs. R double precision")
legend("topleft", leg=c("double prec.", "mpfr"), lty=1, col=1:2, bty = "n")
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|