The Stirling Formula

    18 Sep, 2024

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

    Wallis's Formula

    Let's start with a definite integral:

    0π2sinnxdx\int_{0}^{\frac{\pi}{2}} \sin^n x \, dx

    We can derive the following result:

    0π2sinnxdx=0π2sinn1xd(cosx)\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 udv=uvvdu\int u \, dv = uv - \int v \, du, we get:

    0π2sinn1xd(cosx)=(sinn1xcosx)0π2+0π2cosxd(sinn1x)-\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π2cos2x(n1)sinn2xdx=(n1)0π2(sinn2xsinnx)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π2sinnxdx=(n1)0π2(sinn2xsinnx)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:

    n0π2sinnxdx=(n1)0π2sinn2xdx    0π2sinnxdx=n1n0π2sinn2xdxn \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π2sin2kxdx=2k12k0π2sin2k2xdx=2k12k2k32k2120π2sin0xdx=2k12k2k32k212π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π2sin2k+1xdx=2k2k+10π2sin2k1xdx=2k2k+12k22k1230π2sin1xdx=2k2k+12k22k123\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(m2)(m4)m!! = m (m-2) (m-4) \cdots

    Thus:

    0π2sin2kxdx=(2k1)!!(2k)!!π2\int_{0}^{\frac{\pi}{2}} \sin^{2k} x \, dx = \frac{(2k-1)!!}{(2k)!!} \cdot \frac{\pi}{2} 0π2sin2k+1xdx=(2k)!!(2k+1)!!\int_{0}^{\frac{\pi}{2}} \sin^{2k+1} x \, dx = \frac{(2k)!!}{(2k+1)!!}

    Since sin2k+1x<sin2kx<sin2k1x\sin^{2k+1} x < \sin^{2k} x < \sin^{2k-1} x for x(0,π2)x \in (0, \frac{\pi}{2}), we have:

    0π2sin2k+1xdx<0π2sin2kxdx<0π2sin2k1xdx\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)!!<(2k1)!!(2k)!!π2<(2k2)!!(2k1)!!\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π2sin2kxdx\int_{0}^{\frac{\pi}{2}} \sin^{2k} x \, dx:

    limk((2k2)!!(2k1)!!(2k)!!(2k+1)!!)=limk((2k2)!!(2k1)!!2k2k+1(2k2)!!(2k1)!!)=limk12k+1(2k2)!!(2k1)!!=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 2k22k1<1\frac{2k-2}{2k-1} < 1

    For the inequality:

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

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

    (2k)!!2(2k+1)!!(2k1)!!<π2<(2k2)!!(2k)!!(2k1)!!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}:

    limk((2k2)!!(2k)!!(2k1)!!2(2k)!!2(2k+1)!!(2k1)!!)=limk(12k12k+1)(2k)!!2(2k+1)!!(2k1)!!=limk12k(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:

    limk(2k)!!2(2k+1)!!(2k1)!!=π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

    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:

    limn(n!nn)1n=1e\lim_{n \rightarrow \infty} \left( \frac{n!}{n^n} \right)^{\frac{1}{n}} = \frac{1}{e}

    Proof:

    limn(n!nn)1n=limne1nln(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:

    limn1nln(n!nn)=1\lim_{n \rightarrow \infty} \frac{1}{n} \ln \left( \frac{n!}{n^n} \right) = -1

    We have:

    limn1nln(n!nn)=limn1n(ln1n+ln2n++lnnn)=01lnxdx=(xlnxx)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!nn1en\frac{n!}{n^n} \sim \frac{1}{e^n}

    We would like to verify:

    limnn!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} limnan+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} limnan+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 lnn+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 x0x \neq 0).

    The left side follows from: 1nn+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+11xdx=lnn+1n>1n+12\int_{n}^{n+1} \frac{1}{x} \, dx = \ln \frac{n+1}{n} > \frac{1}{n + \frac{1}{2}}

    Therefore:

    limnan+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:

    limnn!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:

    limk(2k)!!2(2k+1)!!(2k1)!!=π2\lim_{k \rightarrow \infty} \frac{(2k)!!^2}{(2k+1)!! (2k-1)!!} = \frac{\pi}{2} (2n)!!=2n(2n2)2=2nn!(2n)!! = 2n (2n-2) \cdots 2 = 2^n n! (2n1)!!=(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:

    limn16n(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!aennn+12n! \sim a e^{-n} n^{n + \frac{1}{2}}

    Substitute into:

    limna2e24(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πennn+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