edgepedia

物质世界与数学 / 数学与统计学 / 逻辑与离散数学 / General discrete mathematics and discrete structures / Combinatorics / Enumerative combinatorics / Counting techniques and recurrences / Recurrence relations

综合 · Edgepedia阅读需 7 分钟

阶乘

阅读英文原文

非负整数 n 的阶乘,记作 n!,是所有从 n 到 1 的正整数的乘积,即 n × (n−1) × … × 2 × 1,并约定 0! = 1。1 例如,5! = 120。1 阶乘计数的是将 n 个不同物体排成顺序的方式数,它贯穿于组合数学、概率论以及初等函数的级数展开之中。

关键事实细节
定义对整数 n ≥ 0,n! = n × (n−1) × … × 2 × 1,且 0! = 11
递推关系当 n > 1 时,n! = n × (n−1)!,不过在代码中一个简单的循环通常更快,也同样清晰1
计数用途n 个物体的 r-排列数为 n!/(n−r)!;r-组合数为 n!/(r!(n−r)!)2
连续延拓n! = Γ(n+1),其中 Γ 为 gamma 函数,对一切数有定义,而阶乘则严格说来只对非负整数有定义3
记号记号 n! 由克里斯蒂安·克兰普(Christian Kramp)引入;“factorial”一词则由阿尔博加斯特(Arbogast)提出4
增长当 n 很大时,(n/e)^n √(2nπ) < n! < (n/e)^n (1 + 1/(12n−1)) √(2nπ)(斯特林公式)5
快速计算借助快速乘法,n! 可在 O(n(log n log log n)²) 位复杂度内算出6

定义与基本性质

阶乘对每个非负整数都有定义。0! = 1 这一取值可由 gamma 函数的定义推出:0! = Γ(0+1) = ∫₀^∞ e^(−x)x^(1−1) dx = ∫₀^∞ e^(−x) dx = 1。1 令 0! = 1 也使计数公式得以成立:将 n 个物体全部排列,方式数为 n!/(n−n)! = n!/0! = n!。7

阶乘满足递推关系 n! = n × (n−1)!(n > 1)。算法教科书常把它用作递归的例子,但一个简单的循环通常更快,也同样清晰。1 迭代实现与递归实现的增长阶相同。8

在计数中的作用

阶乘是排列数与组合数计数的基础。n 个物体的 r-排列数,即从 n 个中有序选取 r 项的方式数,为 n!/(n−r)!。r-组合数,即无序选取的方式数,为二项式系数 (nr)=n!r!(n−r)! \binom{n}{r} = \frac{n!}{r!(n-r)!} 。2 二项式定理用这些量来表达 (a+b)^n 的系数。2

阶乘也直接出现在概率公式中。泊松分布刻画给定时间区间内发生的事件数,其概率质量函数为 p(x;λ)=e−λλxx! p(x;\lambda) = \frac{e^{-\lambda}\lambda^{x}}{x!} ,其中 x = 0, 1, 2, …,λ 为该区间内事件的平均发生次数。9 在微积分中,函数的泰勒级数将第 n 阶导数项除以 n 的阶乘。10

向非整数变元的延拓

非整数的阶乘不能由乘积公式定义,但 gamma 函数提供了标准的延拓。n 的 gamma 函数为 Γ(n) = ∫₀^∞ e^(−x)x^(n−1) dx,且对非负整数有 Γ(n+1) = n!。3 gamma 函数对复数 z 满足递推关系 Γ(z+1) = zΓ(z),这与阶乘所服从的函数方程相同。11 gamma 函数对一切数有定义,而阶乘则严格说来只对非负整数有定义。3

一个凸性条件唯一地确定了这一延拓:玻尔–莫勒鲁普定理(Bohr–Mollerup theorem)指出,若 (0, ∞) 上的正函数 f(x) 满足 f(x+1) = x f(x)、f(1) = 1,且 ln f(x) 为凸函数,则 f(x) = Γ(x)。11 软件同时反映了该函数的这两种视角:SciPy 的阶乘例程在 exact=False 时用 gamma 函数近似取值,即 n! = Γ(n+1),这也正是其复数延拓的定义;而在 exact=True 时则用整数算术算出结果。12

记号的历史

用 n! 表示从 n 递减到 1 的各数之积,这一记号出自法国数学家克里斯蒂安·克兰普(Christian Kramp,1760–1826)之手,他是一位数学教授,曾任斯特拉斯堡理学院院长,研究分析与组合数学。4 在 1798 年前后关于此题的早期工作中,他把这些乘积称为“faculty”(facultés analytiques,分析阶乘),但在其《万有算术要义》(Éléments d'arithmétique universelle,1808)的序言中,他采用了同乡阿尔博加斯特(Arbogast)提出的“factorial”一名,并写道,他很高兴以此向亡友致意。4 在同一部著作中,他解释说,自己在组合分析中不断使用这一概念,使得简洁的记号 n! 成为必要。4

克兰普与贝塞尔(Bessel)、勒让德(Legendre)、高斯(Gauss)一样,将阶乘的概念推广到非整数变元,并于 1812 年发表了一份这些数值的数值表,寄给了贝塞尔。13 这一函数更深层的历史属于詹姆斯·斯特林(James Stirling),他于 1730 年发现了阶乘的著名渐近公式;也属于莱昂哈德·欧拉(Leonhard Euler),他引入 gamma 函数作为阶乘在非整数变元上的自然延拓。14

增长与近似

阶乘的增长快于任何固定的幂,也快于几何序列,这一事实例如被用于证明指数函数泰勒级数的收敛性。15 斯特林公式使这一增长变得精确。当 n 很大时,5

(ne)n2nπ<n!<(ne)n(1+112n−1)2nπ. \left(\frac{n}{e}\right)^{n} \sqrt{2n\pi} < n! < \left(\frac{n}{e}\right)^{n} \left(1 + \frac{1}{12n-1}\right) \sqrt{2n\pi}.

DLMF 将 gamma 函数相应的展开称为斯特林级数,其首项即称为斯特林公式;当该展开对实的正 z 在 n 项后截断时,余项的绝对值以第一个被舍弃的项为界,且符号与之相同。16 用 gamma 函数表示,一般的渐近形式为:对固定的 a > 0,Γ(az+b) ∼ √(2π) e^(−az) (az)^(az+b−1/2)。16

计算

对于精确的整数值,朴素的循环或递归对小 n 足够,但对大 n 则很浪费。真正严肃的算法利用 n! 的素因数分解:《算法杂志》(Journal of Algorithms)上的一项分析表明,结合快速乘法,这可以得到一个计算 n! 的 O(n(log n log log n)²) 复杂度算法。6 素数摆动法(prime swing method)在假定快速乘法的前提下把问题的位复杂度降到大约 O(n log n),至今仍属已知最高效的阶乘算法之列。17 彼得·卢施尼(Peter Luschny)维护着素数摆动算法在 SageMath、Python、Julia、Java、C#、Go 和 C++ 中的实现。18

主流软件采用了这些思路。Python 的 math.factorial(n) 以整数返回 n 的阶乘,若 n 不是整数或为负数则抛出 ValueError。19 对于近似值,各库则退回到 gamma 函数,正如 SciPy 在 exact=False 时所做的那样。12

浮点存储限制了精确序列所能表示的范围:在 32 位无符号整数下,按递归方案中每次函数调用约 16 字节的常见估计,计算 13! 就已溢出。20

推广

阶乘有一族亲属。波赫哈默尔符号(Pochhammer symbol),也称移位阶乘,为 (a)_n = a(a+1)(a+2)⋯(a+n−1) = Γ(a+n)/Γ(a)。21 双阶乘 n!! 可用 gamma 函数表示,偶数 n 与奇数 n 的因子不同。22 在 q-模拟中,q-阶乘定义为 n!_q = 1(1+q)⋯(1+q+⋯+q^(n−1)) = (q;q)_n (1−q)^(−n),其中 (q;q)_n 为 q-波赫哈默尔符号。23 多重 gamma 函数是欧拉 gamma 函数由递推函数方程定义的推广,由金克林(Kinkelin)、格莱舍(Glaisher)和巴恩斯(Barnes)于 1900 年前后引入。24

References

  1. Paul E. Black, "factorial", NIST Dictionary of Algorithms and Data Structures
  2. Permutations, Combinations, and the Binomial Theorem, University of Lethbridge open text
  3. Paul E. Black, "gamma function", NIST Dictionary of Algorithms and Data Structures
  4. Christian Kramp (1760–1826), MacTutor History of Mathematics
  5. Paul E. Black, "Stirling's formula", NIST Dictionary of Algorithms and Data Structures
  6. On the complexity of calculating factorials, Journal of Algorithms
  7. 7.2 Permutations, Contemporary Mathematics, OpenStax
  8. Efficiency of recursive implementations, COL100 lecture notes, IIT Delhi
  9. 1.3.6.6.19. Poisson Distribution, NIST/SEMATECH e-Handbook of Statistical Methods
  10. Lecture 38: Taylor's Series, MIT OpenCourseWare 18.01
  11. DLMF §5.5 Functional Relations, NIST Digital Library of Mathematical Functions
  12. scipy.special.factorial, SciPy v1.18.0 Manual
  13. Kramp, Chrétien or Christian, Complete Dictionary of Scientific Biography
  14. Factorial: Introduction to the factorials and binomials, Wolfram Functions
  15. Math Tutor – Series: function series, Czech Technical University
  16. DLMF §5.11 Asymptotic Expansions, NIST Digital Library of Mathematical Functions
  17. Fast Factorial & Binomial Computation for Arbitrary Precision
  18. PeterLuschny/Fast-Factorial-Functions, GitHub
  19. math — Mathematical functions, Python 3.11 documentation
  20. Recursive algorithm for factorial function, PlanetMath
  21. DLMF §5.2 Definitions, NIST Digital Library of Mathematical Functions
  22. DLMF §5.4 Special Values and Extrema, NIST Digital Library of Mathematical Functions
  23. DLMF §5.18 q-Gamma and q-Beta Functions, NIST Digital Library of Mathematical Functions
  24. Multiple Gamma Function and Its Application to Computation of Series, arXiv:math/0308074

Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026

© 2026 Biostate AI。依据 Edgepedia Community License,注明出处即可免费使用。 嵌入参考卡片。

报告错误

阶乘

请至少选择一个原因。