Equivalence of Stirling's approximations for $n!$ and $\Gamma(z)$ In this Wikipedia article for Stirling's approximation,
it is first shown that
$$ n!=\sqrt{2\pi n}\left(\frac{n}{e}\right)^n\left(1+O\left(\frac{1}{n}\right)\right)$$
for $n\in \mathbb N$,
and then it also shows that for complex $z$, the gamma funtion is approximated as
$$ \Gamma(z)=\sqrt{\frac{2\pi}{z}}\left(\frac{z}{e}\right)^z\left(1+O\left(\frac{1}{z}\right)\right)$$
and mentioned that these two asymtotic expressions are identical.
I thought if I just simply substitute $z=n+1$ in the second formula, then I get the first formula. But apparently this is not the case.
What I really don't get is why in the first formula we have $n^{n+1/2}$ and in the second formula $z^{z-1/2}$?  How these two formula can be identical?
 A: No, what you said actually works, and I show it here.
To save the space, I omit the $O\left(\frac{1}z\right)$ terms
$$\sqrt{\frac{2\pi}{z}}\left(\frac{z}{e}\right)^z$$
Let $z=n+1$, and note $\lim_{n\to\infty}(1+1/n)^n=e$
$$\sqrt{\frac{2\pi}{z}}\left(\frac{z}{e}\right)^z
=\sqrt{\frac{2\pi}{n+1}}\left(\frac{n+1}{e}\right)^{n+1}=\sqrt{2\pi(n+1)}\frac{(n+1)^n}{e^{n+1}}\sim\sqrt{2\pi n}\frac{(n+1)^n}{e^{n+1}}$$
$$=\sqrt{2\pi n}\frac{n^n(1+\frac{1}{n})^n}{e^{n+1}}\sim \sqrt{2\pi n}\frac{n^n\cdot e}{e^{n+1}}=\sqrt{2\pi n}\frac{n^n}{e^{n}}=\sqrt{2\pi n}\left(\frac{n}{e}\right)^n$$
So you get Stirling's formula.
A: Just for a future reference, I post a full proof (without omiting $O(1/n)$ term).
$$
n! = \Gamma(n+1) = \sqrt{\frac{2\pi}{n+1}}\left(\frac{n+1}{e}\right)^{n+1}\left(1+O\left(n^{-1}\right)\right) \\
=\sqrt{2\pi (n+1)}\left(\frac{n+1}{e}\right)^{n}e^{-1}\left(1+O\left(n^{-1}\right)\right) \\
=\sqrt{2\pi}\sqrt{n+1}\left(\frac{n}{e}\right)^{n}\left(1+\frac{1}{n}\right)^{n}e^{-1}\left(1+O\left(n^{-1}\right)\right) \quad \dots\quad\ast
$$
We have
$$
\left(n+1\right)^{1/2}=n^{1/2}+O\left(n^{-1/2}\right)=n^{1/2}\left(1+O\left(n^{-1}\right)\right)
$$
by binomial series and
$$
e^{-1}\left(1+\frac{1}{n}\right)^{n}=1+O\left(n^{-1}\right) \quad \dots\quad\ast\ast
$$
Hence
$$
\ast=\sqrt{2\pi}n^{1/2}\left(1+O\left(n^{-1}\right)\right)\left(\frac{n}{e}\right)^{n}\left(1+O\left(n^{-1}\right)\right)\left(1+O\left(n^{-1}\right)\right)\\
=\sqrt{2\pi n}\left(\frac{n}{e}\right)^{n}\left(1+O\left(n^{-1}\right)\right)^3\\
=\sqrt{2\pi n}\left(\frac{n}{e}\right)^{n}\left(1+O\left(n^{-1}\right)\right)
$$
For $\ast\ast$, see N. G. De Bruijn, Asymtotic methods in analysis, ch$1$ ex$1$.
