binomfactors

版本 1.0.0.0 (3.2 KB) 作者: John D'Errico
Returns a factored form for very large binomial coefficients
325.0 次下载
更新时间 2010/2/16

查看许可证

Every once in a while someone wishes to compute a VERY large binomial coefficient. While I'll admit that most of the time the proper solution is to compute the log of the coefficient. The best solution for this is to use gammaln.

n = 20000000;
k = 5000000;
gammaln(n+1) - gammaln(k+1) - gammaln(n-k+1)
ans =
11246694.4048045

Once in a rare while someone might wish to compute the integer factors of this coefficient. I've now had two recent occasions to look for such a factorization, so I assume there must be someone else in the world who has a use for them too.

tic,[facs,count] = binomfactors(20000000,5000000);toc
Elapsed time is 43.071204 seconds.

We can verify the result by computing the log of the binomial coefficient from the factors. See that it is identical to that returned from gammaln above.

sum(log(facs).*count)
ans =
11246694.404804

How many digits are in this number?

sum(log(facs).*count)/log(10)
ans =
4884377.31965857

I did say it was large, with approximately 4.8 million digits.

So, for that rare person who wishes to compute the factors of a binomial coefficient, binomfactors does exactly that. Or, if all you wish to see are some ideas on how one might design a prime sieve for such a computation in MATLAB, this might be of some interest.

(Note that while this tool is used in my vpi toolbox, it does not require vpi to run.)

引用格式

John D'Errico (2024). binomfactors (https://www.mathworks.com/matlabcentral/fileexchange/26702-binomfactors), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2007b
兼容任何版本
平台兼容性
Windows macOS Linux
标签 添加标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.0.0.0