# 史特靈公式

（重定向自斯特靈公式

n增加时，(ln n!)与o (n ln nn)之比趋于1

${\displaystyle n!}$（藍色）、${\displaystyle {\sqrt {2\pi n}}\left({\frac {n}{e}}\right)^{n}}$（橘色），數字越大${\displaystyle {\sqrt {2\pi n}}\left({\frac {n}{e}}\right)^{n},}$會越趨近${\displaystyle n!}$。但${\displaystyle {\sqrt {2\pi n}}\left({\frac {n}{e}}\right)^{n}}$在負值則會因為出現虛數而無法使用

${\displaystyle n!\approx {\sqrt {2\pi n}}\,\left({\frac {n}{e}}\right)^{n}.}$

${\displaystyle \lim _{n\rightarrow \infty }{\frac {n!}{{\sqrt {2\pi n}}\,\left({\frac {n}{e}}\right)^{n}}}=1}$

${\displaystyle \lim _{n\rightarrow \infty }{\frac {e^{n}\,n!}{n^{n}{\sqrt {n}}}}={\sqrt {2\pi }}.}$

## 历史

${\displaystyle \displaystyle n!\approx cn^{n+{\frac {1}{2}}}e^{-n}}$ ，其中c為常數。

## 推导

${\displaystyle \ln(n!)=\ln 1+\ln 2+\cdots +\ln n.}$

${\displaystyle \ln(n!)-{\frac {\ln n}{2}}=\ln 1+\ln 2+\cdots +\ln n-{\frac {\ln n}{2}}.}$

${\displaystyle \ln(n!)-{\frac {\ln n}{2}}=\ln 1+\ln 2+\cdots +\ln(n-1)+{\frac {\ln n}{2}}=n\ln n-n+1+\sum _{k=2}^{m}{\frac {B_{k}{(-1)}^{k}}{k(k-1)}}\left({\frac {1}{n^{k-1}}}-1\right)+R_{m,n}.}$

${\displaystyle \lim _{n\to \infty }\left(\ln n!-n\ln n+n-{\frac {\ln n}{2}}\right)=1-\sum _{k=2}^{m}{\frac {B_{k}{(-1)}^{k}}{k(k-1)}}+\lim _{n\to \infty }R_{m,n}.}$

${\displaystyle R_{m,n}=\lim _{n\to \infty }R_{m,n}+O\left({\frac {1}{n^{2m-1}}}\right),}$

${\displaystyle \ln n!=n\ln \left({\frac {n}{e}}\right)+{\frac {\ln n}{2}}+y+\sum _{k=2}^{m}{\frac {B_{k}{(-1)}^{k}}{k(k-1)n^{k-1}}}+O\left({\frac {1}{n^{2m-1}}}\right).}$

${\displaystyle n!=e^{y}{\sqrt {n}}~{\left({\frac {n}{e}}\right)}^{n}\left[1+O\left({\frac {1}{n}}\right)\right]}$

${\displaystyle n!={\sqrt {2\pi n}}~{\left({\frac {n}{e}}\right)}^{n}\left[1+O\left({\frac {1}{n}}\right)\right]}$

${\displaystyle \ln(n!)=\sum _{j=1}^{n}\ln j}$

${\displaystyle \sum _{j=1}^{n}\ln j\approx \int _{1}^{n}\ln x\,dx=n\ln n-n+1.}$

## 收敛速率和误差估计

y轴表示截断的斯特林级数的相对误差，x轴表示所使用的项数。

${\displaystyle n!={\sqrt {2\pi n}}\;\left({\frac {n}{e}}\right)^{n}e^{\lambda _{n}}}$

${\displaystyle {\frac {1}{12n+1}}<\lambda _{n}<{\frac {1}{12n}}.}$

${\displaystyle n!={\sqrt {2\pi n}}\left({n \over e}\right)^{n}\left(1+{1 \over 12n}+{1 \over 288n^{2}}-{139 \over 51840n^{3}}-{571 \over 2488320n^{4}}+\cdots \right).}$

${\displaystyle n\to \infty }$ 时，截断级数的误差等于第一个省略掉的项。这是渐近展开式的一个例子。它不是一个收敛级数；对于任何特殊值n，级数的准确性只在取有限个项时达到最大，如果再取更多的项，则准确性将变得越来越差。

${\displaystyle \ln n!=n\ln n-n+{1 \over 2}\ln(2\pi n)+{1 \over 12n}-{1 \over 360n^{3}}+{1 \over 1260n^{5}}-{1 \over 1680n^{7}}+\cdots .}$

## 伽玛函数的斯特林公式

${\displaystyle n!=\Pi (n)=\Gamma (n+1).}$

${\displaystyle \ln \Gamma (z)=\left(z-{\frac {1}{2}}\right)\ln z-z+{\frac {\ln {2\pi }}{2}}+2\int _{0}^{\infty }{\frac {\arctan {\frac {t}{z}}}{\exp(2\pi t)-1}}\,dt.}$

${\displaystyle \ln \Gamma (z)=\left(z-{\frac {1}{2}}\right)\ln z-z+{\frac {\ln {2\pi }}{2}}+\sum _{n=1}^{\infty }{\frac {(-1)^{n-1}B_{n}}{2n(2n-1)z^{2n-1}}}}$

${\displaystyle \Gamma (z)={\sqrt {\frac {2\pi }{z}}}~{\left({\frac {z}{e}}\right)}^{z}\left[1+O\left({\frac {1}{z}}\right)\right].}$

## 斯特林公式的收敛形式

${\displaystyle \int _{0}^{\infty }{\frac {2\arctan {\frac {t}{z}}}{\exp(2\pi t)-1}}\,dt=\ln \Gamma (z)-\left(z-{\frac {1}{2}}\right)\ln z+z-{\frac {1}{2}}\ln(2\pi ).}$

${\displaystyle \int _{0}^{\infty }{\frac {2\arctan {\frac {t}{z}}}{\exp(2\pi t)-1}}\,dt=\sum _{n=1}^{\infty }{\frac {c_{n}}{(z+1)^{\overline {n}}}}}$

${\displaystyle c_{n}={\frac {1}{n}}\int _{0}^{1}x^{\overline {n}}\left(x-{\frac {1}{2}}\right)\,dx.}$

${\displaystyle \ln \Gamma (z)=\left(z-{\frac {1}{2}}\right)\ln z-z+{\frac {\ln {2\pi }}{2}}}$
${\displaystyle {}+{\frac {1}{12(z+1)}}+{\frac {1}{12(z+1)(z+2)}}+{\frac {59}{360(z+1)(z+2)(z+3)}}+{\frac {29}{60(z+1)(z+2)(z+3)(z+4)}}+\cdots }$

## 适用于计算器的形式

${\displaystyle \Gamma (z)\approx {\sqrt {\frac {2\pi }{z}}}\left({\frac {z}{e}}{\sqrt {z\sinh {\frac {1}{z}}+{\frac {1}{810z^{6}}}}}\right)^{z},}$

${\displaystyle 2\ln \Gamma (z)\approx \ln(2\pi )-\ln z+z\left[2\ln z+\ln \left(z\sinh {\frac {1}{z}}+{\frac {1}{810z^{6}}}\right)-2\right],}$

Gergő Nemes在2007年提出了一个近似公式，它的精确度与Windschitl的公式相等，但更加简单：

${\displaystyle \Gamma (z)\approx {\sqrt {\frac {2\pi }{z}}}\left[{\frac {1}{e}}\left(z+{\frac {1}{12z-{\frac {1}{10z}}}}\right)\right]^{z},}$

${\displaystyle \ln \Gamma (z)\approx {\frac {1}{2}}\left[\ln(2\pi )-\ln z\right]+z\left[\ln \left(z+{\frac {1}{12z-{\frac {1}{10z}}}}\right)-1\right]}$

## 参考文献

1. ^ Dutka, Jacques, The early history of the factorial function, Archive for History of Exact Sciences, 1991, 43 (3): 225–249, doi:10.1007/BF00389433
2. ^ Le Cam, L., The central limit theorem around 1935, Statistical Science, 1986, 1 (1): 78–96, JSTOR 2245503, MR 0833276, doi:10.1214/ss/1177013818; see p. 81, "The result, obtained using a formula originally proved by de Moivre but now called Stirling's formula, occurs in his 'Doctrine of Chances' of 1733."
3. ^ Pearson, Karl, Historical note on the origin of the normal curve of errors, Biometrika, 1924, 16 (3/4): 402–404 [p. 403], JSTOR 2331714, doi:10.2307/2331714, I consider that the fact that Stirling showed that De Moivre's arithmetical constant was ${\displaystyle {\sqrt {2\pi }}}$  does not entitle him to claim the theorem, [...]