阶乘有多大?
How Big Are Factorials?

原始链接: https://eli.thegreenplace.net/2026/how-big-are-factorials/

这篇文章探讨了如何在没有计算器辅助的情况下,估算大数阶乘(如 52!)的位数。 作者引入了伽玛函数,将其作为对所有正实数阶乘的一种推广。通过利用斯特林公式——即通过拉普拉斯方法对伽玛函数的积分进行推导——人们可以有效地估算这些巨大数值的量级。 该估算的核心在于计算斯特林公式的以 10 为底的对数。正如作者以 52! 为例所演示的那样,该方法得出的结果与实际值非常接近。尽管该公式包含一项随输入值增大而变得不那么重要的次要项,但作者指出,将其包含在内可以确保更高的精度。总之,这种方法将计算巨大阶乘这一艰巨任务转化为了一种可控的数学练习,为衡量它们的规模提供了一种可靠的途径。

这篇 Hacker News 讨论探讨了阶乘那令人难以理解的规模,并以 52!(一副扑克牌的排列方式总数)作为基准。 主要亮点包括: * **“可理解性”难题:** 用户们分享了各种类比来直观感受巨大的数字,例如:计算 52! 所需的时间跨越了地质年代,将其比作一滴一滴抽干太平洋,或者将纸张堆叠到太阳的高度。 * **数学视角:** 对话涵盖了用于估算阶乘增长的斯特林公式 ($\ln n! \approx n \ln n - n$),并讨论了阶乘在计算机科学、组合数学和统计力学中的基础作用。 * **趣味事实:** 讨论者指出,60! 的数值超过了可观测宇宙中的原子总数,而 24! 与阿伏伽德罗常数惊人地接近。 * **计算:** 技术方面讨论了任意精度算术的效率,指出虽然 Lisp 等语言可以原生处理大数阶乘,但现代库(如 Python)使用优化的分治算法来快速计算它们。 总之,该讨论帖是一次集体沉思,探讨了阶乘的增长速度如何超越直觉,将简单的数列转化为超越宇宙尺度的数字。
相关文章

原文
Tags Math

The other day, I found myself wondering how big 52! (52 factorial) is, and that led me to ponder how these could be estimated without a calculator or a computer.

It turns out there’s some fairly interesting math behind being able to estimate the size (number of digits) of a factorial reasonably accurately. This post will start by stating how to do the estimate, and if you’re curious you can read on for the math background.

Without further ado, the approximation is:

As an example, let’s use my original question, by estimating this for 52!

Well, 52 divided by is... 20-ish? And is about 1.3 ; therefore our estimate comes out to:

The real answer is 68, so this is very close! In estimates like this - when you’re dealing with enormous numbers - being off by a couple of digits usually isn't a big deal.

The Gamma function

The Gamma function for real is defined as:

This integral does not have an analytic expression in the general case, but it does have a very useful property that we can take advantage of. Let’s see what is:

And now use integration by parts with:

Then:

So:

But notice that the last integral is just ; therefore, we’ve shown that:

Let’s also calculate - it’s a special case that has an analytical solution:

This helps establish an induction argument:

In other words - the Gamma function is an interpolation of the factorial over all positive reals. Here’s a plot of the Gamma function over a small range; note that the y axis is log-scale because of the function’s fast growth:

Gamma function plot

Stirling’s approximation

You may have encountered Stirling’s approximation before:

It’s a great approximation that works reasonably well even for small n. This section is a brief overview of how Stirling’s formula is derived from the Gamma function.

Taking:

We’ll start by massaging the integrand a bit:

And making a change of variables , which means that :

These steps make the integral amenable to applying Laplace’s method, which allows us to approximate definite integrals of the form:

Where f(x) is a twice-differentiable function and n some large number. By Laplace’s method, such integrals can be approximated by:

Where x_0 is the global maximum of f(x).

Let’s see how to apply this method to the latest equation we have for (renaming the dummy integration variable back to ):

In our case, . It’s easy to show that this function is twice differentiable and has a global maximum at x_0=1. Moreover:

Substituting these into the proper places in Laplace’s approximation, we get:

Number of digits from Stirling’s approximation

We can calculate the number of digits in by taking the base-10 logarithm of Stirling’s formula:

Note that the first term is not multiplied by n itself; therefore, as n grows, it will become less and less noticeable. That said, it still adds a couple of digits - so you should take it into account if you want a more accurate approximation


联系我们 contact @ memedata.com