惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Jina AI
Jina AI
V
Vulnerabilities – Threatpost
Security Latest
Security Latest
AI
AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
量子位
H
Help Net Security
Attack and Defense Labs
Attack and Defense Labs
The GitHub Blog
The GitHub Blog
L
LINUX DO - 最新话题
A
Arctic Wolf
博客园_首页
S
Securelist
S
Secure Thoughts
Google DeepMind News
Google DeepMind News
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Tailwind CSS Blog
Apple Machine Learning Research
Apple Machine Learning Research
酷 壳 – CoolShell
酷 壳 – CoolShell
Stack Overflow Blog
Stack Overflow Blog
N
Netflix TechBlog - Medium
Cyberwarzone
Cyberwarzone
小众软件
小众软件
T
Threatpost
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Blog — PlanetScale
Blog — PlanetScale
N
News and Events Feed by Topic
NISL@THU
NISL@THU
Forbes - Security
Forbes - Security
博客园 - 聂微东
F
Fortinet All Blogs
Simon Willison's Weblog
Simon Willison's Weblog
H
Heimdal Security Blog
罗磊的独立博客
S
Security @ Cisco Blogs
B
Blog
T
Troy Hunt's Blog
Engineering at Meta
Engineering at Meta
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
The Hacker News
The Hacker News
The Last Watchdog
The Last Watchdog
Hacker News - Newest:
Hacker News - Newest: "LLM"
I
Intezer
T
Threat Research - Cisco Blogs
C
Cybersecurity and Infrastructure Security Agency CISA
The Cloudflare Blog
S
Schneier on Security
月光博客
月光博客
L
LINUX DO - 热门话题
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org

Lex Blog

Proof of the UAT, by Weierstrass Theory - Lex Blog 暗淡蓝点 - Lex Blog ACCESS BLOCK Dimension Curse on Zero and Positive Curvature Space - Lex Blog Introduction of vMF Distribution on Hypersphere - Lex Blog Nonlinearity with Activations - Lex Blog The Lamentable Programmers - Lex Blog ACCESS BLOCK
The Stirling Formula - Lex Blog
Ethan Zhang · 2025-09-18 · via Lex Blog

2025, September, 18

The Stirling Formula

Stirling's formula finds a relationship of n!,nⁿ,eⁿ while n trends to infinity.

Let's start with a definite integral:

∫0π2sin⁡nx dx\int_{0}^{\frac{\pi}{2}} \sin^n x \, dx

We can derive the following result:

∫0π2sin⁡nx dx=−∫0π2sin⁡n−1x d(cos⁡x)\int_{0}^{\frac{\pi}{2}} \sin^n x \, dx = -\int_{0}^{\frac{\pi}{2}} \sin^{n-1} x \, d(\cos x)

Using integration by parts, where ∫u dv=uv−∫v du\int u \, dv = uv - \int v \, du, we get:

−∫0π2sin⁡n−1x d(cos⁡x)=−(sin⁡n−1xcos⁡x)∣0π2+∫0π2cos⁡x d(sin⁡n−1x)-\int_{0}^{\frac{\pi}{2}} \sin^{n-1} x \, d(\cos x) \\ = -\left( \sin^{n-1} x \cos x \right) \Big|_{0}^{\frac{\pi}{2}} + \int_{0}^{\frac{\pi}{2}} \cos x \, d\left(\sin^{n-1} x \right)=∫0π2cos⁡2x⋅(n−1)sin⁡n−2x dx=(n−1)∫0π2(sin⁡n−2x−sin⁡nx) dx= \int_{0}^{\frac{\pi}{2}} \cos^2 x \cdot (n-1) \sin^{n-2} x \, dx \\ = (n-1) \int_{0}^{\frac{\pi}{2}} \left( \sin^{n-2} x - \sin^n x \right) \, dx

Thus:

∫0π2sin⁡nx dx=(n−1)∫0π2(sin⁡n−2x−sin⁡nx) dx\int_{0}^{\frac{\pi}{2}} \sin^n x \, dx = (n-1) \int_{0}^{\frac{\pi}{2}} \left( \sin^{n-2} x - \sin^n x \right) \, dx

We get:

n∫0π2sin⁡nx dx=(n−1)∫0π2sin⁡n−2x dx  ⟹  ∫0π2sin⁡nx dx=n−1n∫0π2sin⁡n−2x dxn \int_{0}^{\frac{\pi}{2}} \sin^n x \, dx = (n-1) \int_{0}^{\frac{\pi}{2}} \sin^{n-2} x \, dx \\ \implies \int_{0}^{\frac{\pi}{2}} \sin^n x \, dx = \frac{n-1}{n} \int_{0}^{\frac{\pi}{2}} \sin^{n-2} x \, dx

Therefore:

For even nn, i.e., n=2kn = 2k:

∫0π2sin⁡2kx dx=2k−12k∫0π2sin⁡2k−2x dx=2k−12k⋅2k−32k−2⋯12∫0π2sin⁡0x dx=2k−12k⋅2k−32k−2⋯12⋅π2\int_{0}^{\frac{\pi}{2}} \sin^{2k} x \, dx = \frac{2k-1}{2k} \int_{0}^{\frac{\pi}{2}} \sin^{2k-2} x \, dx \\ = \frac{2k-1}{2k} \cdot \frac{2k-3}{2k-2} \cdots \frac{1}{2} \int_{0}^{\frac{\pi}{2}} \sin^0 x \, dx \\= \frac{2k-1}{2k} \cdot \frac{2k-3}{2k-2} \cdots \frac{1}{2} \cdot \frac{\pi}{2}

For odd nn, i.e., n=2k+1n = 2k + 1:

∫0π2sin⁡2k+1x dx=2k2k+1∫0π2sin⁡2k−1x dx=2k2k+1⋅2k−22k−1⋯23∫0π2sin⁡1x dx=2k2k+1⋅2k−22k−1⋯23\int_{0}^{\frac{\pi}{2}} \sin^{2k+1} x \, dx \\ = \frac{2k}{2k+1} \int_{0}^{\frac{\pi}{2}} \sin^{2k-1} x \, dx \\ = \frac{2k}{2k+1} \cdot \frac{2k-2}{2k-1} \cdots \frac{2}{3} \int_{0}^{\frac{\pi}{2}} \sin^1 x \, dx \\ = \frac{2k}{2k+1} \cdot \frac{2k-2}{2k-1} \cdots \frac{2}{3}

Here, we need the double factorial:

m!!=m(m−2)(m−4)⋯m!! = m (m-2) (m-4) \cdots

Thus:

∫0π2sin⁡2kx dx=(2k−1)!!(2k)!!⋅π2\int_{0}^{\frac{\pi}{2}} \sin^{2k} x \, dx = \frac{(2k-1)!!}{(2k)!!} \cdot \frac{\pi}{2}∫0π2sin⁡2k+1x dx=(2k)!!(2k+1)!!\int_{0}^{\frac{\pi}{2}} \sin^{2k+1} x \, dx = \frac{(2k)!!}{(2k+1)!!}

Since sin⁡2k+1x<sin⁡2kx<sin⁡2k−1x\sin^{2k+1} x < \sin^{2k} x < \sin^{2k-1} x for x∈(0,π2)x \in (0, \frac{\pi}{2}), we have:

∫0π2sin⁡2k+1x dx<∫0π2sin⁡2kx dx<∫0π2sin⁡2k−1x dx\int_{0}^{\frac{\pi}{2}} \sin^{2k+1} x \, dx < \int_{0}^{\frac{\pi}{2}} \sin^{2k} x \, dx < \int_{0}^{\frac{\pi}{2}} \sin^{2k-1} x \, dx

Substituting the above formulas:

(2k)!!(2k+1)!!<(2k−1)!!(2k)!!⋅π2<(2k−2)!!(2k−1)!!\frac{(2k)!!}{(2k+1)!!} < \frac{(2k-1)!!}{(2k)!!} \cdot \frac{\pi}{2} < \frac{(2k-2)!!}{(2k-1)!!}

We can examine the difference between the bounds for ∫0π2sin⁡2kx dx\int_{0}^{\frac{\pi}{2}} \sin^{2k} x \, dx:

lim⁡k→∞((2k−2)!!(2k−1)!!−(2k)!!(2k+1)!!)=lim⁡k→∞((2k−2)!!(2k−1)!!−2k2k+1⋅(2k−2)!!(2k−1)!!)=lim⁡k→∞12k+1⋅(2k−2)!!(2k−1)!!=0\lim_{k \rightarrow \infty} \left( \frac{(2k-2)!!}{(2k-1)!!} - \frac{(2k)!!}{(2k+1)!!} \right) \\ = \lim_{k \rightarrow \infty} \left( \frac{(2k-2)!!}{(2k-1)!!} - \frac{2k}{2k+1} \cdot \frac{(2k-2)!!}{(2k-1)!!} \right) \\ = \lim_{k \rightarrow \infty} \frac{1}{2k+1} \cdot \frac{(2k-2)!!}{(2k-1)!!} = 0

Note: Here 2k−22k−1<1\frac{2k-2}{2k-1} < 1

For the inequality:

(2k)!!(2k+1)!!<(2k−1)!!(2k)!!⋅π2<(2k−2)!!(2k−1)!!\frac{(2k)!!}{(2k+1)!!} < \frac{(2k-1)!!}{(2k)!!} \cdot \frac{\pi}{2} < \frac{(2k-2)!!}{(2k-1)!!}

Multiply all terms by (2k)!!(2k−1)!!\frac{(2k)!!}{(2k-1)!!}:

(2k)!!2(2k+1)!!(2k−1)!!<π2<(2k−2)!!(2k)!!(2k−1)!!2\frac{(2k)!!^2}{(2k+1)!! (2k-1)!!} < \frac{\pi}{2} < \frac{(2k-2)!! (2k)!!}{(2k-1)!!^2}

We can further examine the difference between the bounds for π2\frac{\pi}{2}:

lim⁡k→∞((2k−2)!!(2k)!!(2k−1)!!2−(2k)!!2(2k+1)!!(2k−1)!!)=lim⁡k→∞(12k−12k+1)⋅(2k)!!2(2k+1)!!(2k−1)!!=lim⁡k→∞12k⋅(2k)!!2(2k+1)!!2=0\lim_{k \rightarrow \infty} \left( \frac{(2k-2)!! (2k)!!}{(2k-1)!!^2} - \frac{(2k)!!^2}{(2k+1)!! (2k-1)!!} \right) \\= \lim_{k \rightarrow \infty} \left( \frac{1}{2k} - \frac{1}{2k+1} \right) \cdot \frac{(2k)!!^2}{(2k+1)!! (2k-1)!!} \\= \lim_{k \rightarrow \infty} \frac{1}{2k} \cdot \frac{(2k)!!^2}{(2k+1)!!^2} = 0

Thus, we obtain Wallis's Formula:

lim⁡k→∞(2k)!!2(2k+1)!!(2k−1)!!=π2\lim_{k \rightarrow \infty} \frac{(2k)!!^2}{(2k+1)!! (2k-1)!!} = \frac{\pi}{2}

This formula introduces Wallis's result in preparation for deriving Stirling's formula.

Stirling's formula reveals a relationship between n!n!, nnn^n, and ene^n.

As nn approaches infinity, n!n! is approximately 2πn(ne)n\sqrt{2 \pi n} \left(\frac{n}{e}\right)^n.

First, introduce a limit:

lim⁡n→∞(n!nn)1n=1e\lim_{n \rightarrow \infty} \left( \frac{n!}{n^n} \right)^{\frac{1}{n}} = \frac{1}{e}

Proof:

lim⁡n→∞(n!nn)1n=lim⁡n→∞e1nln⁡(n!nn)\lim_{n \rightarrow \infty} \left( \frac{n!}{n^n} \right)^{\frac{1}{n}} = \lim_{n \rightarrow \infty} e^{\frac{1}{n} \ln \left( \frac{n!}{n^n} \right)}

which is equivalent to proving:

lim⁡n→∞1nln⁡(n!nn)=−1\lim_{n \rightarrow \infty} \frac{1}{n} \ln \left( \frac{n!}{n^n} \right) = -1

We have:

lim⁡n→∞1nln⁡(n!nn)=lim⁡n→∞1n(ln⁡1n+ln⁡2n+⋯+ln⁡nn)=∫01ln⁡x dx=(xln⁡x−x)∣01=−1\lim_{n \rightarrow \infty} \frac{1}{n} \ln \left( \frac{n!}{n^n} \right) \\ = \lim_{n \rightarrow \infty} \frac{1}{n} \left( \ln \frac{1}{n} + \ln \frac{2}{n} + \cdots + \ln \frac{n}{n} \right) \\ = \int_{0}^{1} \ln x \, dx = (x \ln x - x) \Big|_{0}^{1} = -1

QED.

Thus,

n!nn∼1en\frac{n!}{n^n} \sim \frac{1}{e^n}

We would like to verify:

lim⁡n→∞n!nnen=1\lim_{n \rightarrow \infty} \frac{n!}{n^n} e^n = 1

Let’s test this.

Using the ratio test:

an=n!nnen,an+1=(n+1)!(n+1)n+1en+1a_n = \frac{n!}{n^n} e^n, \quad a_{n+1} = \frac{(n+1)!}{(n+1)^{n+1}} e^{n+1}lim⁡n→∞an+1an=e(1+1n)n>1\lim_{n \rightarrow \infty} \frac{a_{n+1}}{a_n} = \frac{e}{\left(1 + \frac{1}{n}\right)^n} > 1

Although the limit of the expression is ee, it is always approaching ee from below, so it is still greater than 1, indicating that ana_n is divergent.

Mathematicians have attempted various approaches and found:

an=n!nn+12ena_n = \frac{n!}{n^{n + \frac{1}{2}}} e^n

To prove that ana_n converges, use the ratio test again:

an=n!nn+12en,an+1=(n+1)!(n+1)n+32en+1a_n = \frac{n!}{n^{n + \frac{1}{2}}} e^n, \quad a_{n+1} = \frac{(n+1)!}{(n+1)^{n + \frac{3}{2}}} e^{n+1}lim⁡n→∞an+1an=e(1+1n)n+12\lim_{n \rightarrow \infty} \frac{a_{n+1}}{a_n} = \frac{e}{\left(1 + \frac{1}{n}\right)^{n + \frac{1}{2}}}

Compare this with:

(1+1n)n+12=e(n+12)ln⁡(1+1n)\left(1 + \frac{1}{n}\right)^{n + \frac{1}{2}} = e^{(n + \frac{1}{2}) \ln \left(1 + \frac{1}{n}\right)}

and ee.

Thus, compare:

(n+12)ln⁡(1+1n)(n + \frac{1}{2}) \ln \left(1 + \frac{1}{n}\right)

with 1.

Specifically, compare ln⁡n+1n\ln \frac{n+1}{n} with 1n+12\frac{1}{n + \frac{1}{2}}:

Since:

1n+1<ln⁡(1+1n)<1n\frac{1}{n + 1} < \ln \left(1 + \frac{1}{n}\right) < \frac{1}{n}

Note: The right side follows from the inequality ln⁡(1+x)<x\ln(1 + x) < x (for x≠0x \neq 0).

The left side follows from: 1−nn+1<ln⁡(n+1n)1 - \frac{n}{n+1} < \ln \left(\frac{n+1}{n}\right), where nn+1\frac{n}{n+1} is considered as a whole. This is high school knowledge.

Because 1x\frac{1}{x} is a concave function:

∫nn+11x dx=ln⁡n+1n>1n+12\int_{n}^{n+1} \frac{1}{x} \, dx = \ln \frac{n+1}{n} > \frac{1}{n + \frac{1}{2}}

Therefore:

lim⁡n→∞an+1an=e(1+1n)n+12<1\lim_{n \rightarrow \infty} \frac{a_{n+1}}{a_n} = \frac{e}{\left(1 + \frac{1}{n}\right)^{n + \frac{1}{2}}} < 1

Thus, ana_n is monotonically decreasing and an>0a_n > 0, so it must converge, i.e., it has a limit.

Let:

lim⁡n→∞n!nn+12en=a\lim_{n \rightarrow \infty} \frac{n!}{n^{n + \frac{1}{2}}} e^n = a

Then, we need to find this limit.

From the earlier Wallis formula:

lim⁡k→∞(2k)!!2(2k+1)!!(2k−1)!!=π2\lim_{k \rightarrow \infty} \frac{(2k)!!^2}{(2k+1)!! (2k-1)!!} = \frac{\pi}{2}(2n)!!=2n(2n−2)⋯2=2nn!(2n)!! = 2n (2n-2) \cdots 2 = 2^n n!(2n−1)!!=(2n)!(2n)!!=(2n)!2nn!(2n-1)!! = \frac{(2n)!}{(2n)!!} = \frac{(2n)!}{2^n n!}(2n+1)!!=(2n+2)!(2n+2)!!=(2n+2)!2n+1(n+1)!(2n+1)!! = \frac{(2n+2)!}{(2n+2)!!} = \frac{(2n+2)!}{2^{n+1} (n+1)!}

Thus, Wallis' formula becomes:

lim⁡n→∞16n(n!)4(2n+2)(2n)!(2n+2)!=π2\lim_{n \rightarrow \infty} \frac{16^n (n!)^4 (2n+2)}{(2n)!(2n+2)!} = \frac{\pi}{2}

Using:

n!∼ae−nnn+12n! \sim a e^{-n} n^{n + \frac{1}{2}}

Substitute into:

lim⁡n→∞a2e24(n+1n)2n+32=π2\lim_{n \rightarrow \infty} \frac{a^2 e^2}{4 \left(\frac{n+1}{n}\right)^{2n + \frac{3}{2}}} = \frac{\pi}{2}

Solve for:

a=2πa = \sqrt{2 \pi}

Thus, as nn approaches infinity:

n!∼2πe−nnn+12n! \sim \sqrt{2 \pi} e^{-n} n^{n + \frac{1}{2}}

or equivalently:

n!∼2πn(ne)nn! \sim \sqrt{2 \pi n} \left(\frac{n}{e}\right)^n