chooseMpfr(Rmpfr)
chooseMpfr()所属R语言包:Rmpfr
Binomial Coefficients and Pochhammer Symbol aka Rising Factorial
二项式系数和Pochhammer符号又名上升阶乘
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Compute binomial coefficients, chooseMpfr(a,n) being mathematically the same as choose(a,n), but using high precision (MPFR) arithmetic.
计算二项式系数,chooseMpfr(a,n)是数学一样choose(a,n),但采用高精密(MPFR)算术。
chooseMpfr.all(n) means the vector choose(n, 1:n), using enough bits for exact computation via MPFR. However, chooseMpfr.all() is now deprecated in favor of chooseZ from package gmp, as that is now vectorized.
chooseMpfr.all(n)是指向量choose(n, 1:n),使用足够的精确计算通过MPFR位。然而,chooseMpfr.all()现在已经过时赞成chooseZ从包装gmp,因为这是现在量化的。
pochMpfr() computes the Pochhammer symbol or “rising factorial”, also called the &ldquoochhammer function”, &ldquoochhammer polynomial”, “ascending factorial”, “rising sequential product” or “upper factorial”,
pochMpfr()计算Pochhammer符号或“冉冉升起的阶乘”,也被称为“Pochhammer功能”,“Pochhammer多项式”,“升天因子”,“冉冉升起的连续的产品”或“上阶乘”,
用法----------Usage----------
chooseMpfr (a, n)
chooseMpfr.all(n, precBits=NULL, k0=1, alternating=FALSE)
pochMpfr(a, n)
参数----------Arguments----------
参数:a
a numeric or mpfr vector.
一个数字或mpfr向量。
参数:n
an integer vector; if not of length one, n and a are recycled to the same length.
一个整数向量;如果不是一个长度,n和a被再循环到相同的长度。
参数:precBits
integer or NULL for increasing the default precision of the result.
整数或NULL增加默认精度的结果。
参数:k0
integer scalar
整数标
参数:alternating
logical, for chooseMpfr.all(), indicating if alternating sign coefficients should be returned, see below.
逻辑,chooseMpfr.all(),交替的标志系数应返回,见下文。
值----------Value----------
For
为
chooseMpfr(), pochMpfr(): an mpfr vector of length max(length(a),
chooseMpfr(),pochMpfr():mpfr的矢量的长度<CODE>的最大(长度(a),
chooseMpfr.all(n, k0): a mpfr vector of length n-k0+1, of binomial coefficients C[n,m] or, if alternating is true, (-1)^m * C[n,m]
chooseMpfr.all(n, k0):一个mpfr向量的长度n-k0+1,二项式系数C[n,m],alternating是真实的,(-1)^m * C[n,m]
注意----------Note----------
If you need high precision choose(a,n) (or Pochhammer(a,n)) for large n, maybe better work with the corresponding factorial(mpfr(..)), or gamma(mpfr(..)) terms.
如果你需要高精确度choose(a,n)(或Pochhammer(A,N))为大n,也许更好的工作与相应的factorial(mpfr(..)),或gamma(mpfr(..))条款。
参见----------See Also----------
choose(n,m) (base R) computes the binomial coefficient C[n,m] which can also be expressed via Pochhammer symbol as C[n,m] = (n-m+1)^(m) / m!.
choose(n,m)(baseR)的计算的二项式系数C[n,m]这也可以通过Pochhammer符号表示C[n,m] = (n-m+1)^(m) / m!。
chooseZ from package gmp; for now, factorialMpfr.
chooseZ从包装gmp;现在,factorialMpfr。
For (alternating) binomial sums, directly use sumBinomMpfr, as that is potentially more efficient.
对于(交替)二项式款项,直接使用sumBinomMpfr,因为这是潜在的更有效的。
实例----------Examples----------
pochMpfr(100, 4) == 100*101*102*103 # TRUE[TRUE]
a <- 100:110
pochMpfr(a, 10) # exact (but too high precision)[精确的(但过高的精度)]
x <- mpfr(a, 70)# should be enough[应该是足够的]
(px <- pochMpfr(x, 10)) # the same as above (needing only 70 bits)[与上述相同(需要仅70比特)]
stopifnot(pochMpfr(a, 10) == px,
px[1] ==prod(mpfr(100:109, 100)))# used to fail[失败]
(c1 <- chooseMpfr(1000:997, 60)) # -> automatic "correct" precision[ - >自动“正确”的精确度]
stopifnot(all.equal(c1, choose(1000:997, 60), tol=1e-12))
## --- Experimenting & Checking[#---试验和检查]
n.set <- c(1:10, 20, 50:55, 100:105, 200:203, 300:303, 500:503,
699:702, 999:1001)
C1 <- C2 <- numeric(length(n.set))
for(i.n in seq_along(n.set)) {
cat(n <- n.set[i.n],":")
C1[i.n] <- system.time(c.c <- chooseMpfr.all(n) )[1]
C2[i.n] <- system.time(c.2 <- chooseMpfr(n, 1:n))[1]
stopifnot(is.whole(c.c), c.c == c.2,
if(n > 60) TRUE else all.equal(c.c, choose(n, 1:n), tol = 1e-15))
cat(" [Ok]\n")
}
matplot(n.set, cbind(C1,C2), type="b", log="xy",
xlab = "n", ylab = "system.time(.) [s]")
legend("topleft", c("chooseMpfr.all(n)", "chooseMpfr(n, 1:n)"),
pch=as.character(1:2), col=1:2, lty=1:2, bty="n")
## Currently, chooseMpfr.all() is faster only for large n (>= 300)[#目前中,chooseMpfr.all()更快的只有大的n(> = 300)]
## That would change if we used C-code for the *.all() version[#这将改变,如果我们用C代码为*。()版本]
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|