Bug introduced around 11.1.1 and fixed in 11.2
f[x_] := ( (x+1/2) Log[x] - x + Log[2 Pi]/2 - Log[x!] + 1/(12x) ) x^3
Limit[ f[x], x->Infinity ]
Limit[ f[x] - 1/10368, x->Infinity ]
gives (with Mathematica 11.1.1)
1/10368
139/51840
and the two limits are inconsistent. The second is OK, but the first really is $\displaystyle\frac1{360}$, per Richard P. Brent's Asymptotic approximation of central binomial coefficients with rigorous error bounds (arXiv:1608.04834, 2016), OEIS's A046968/A046969, and the Wikipedia article on Stirling's approximation.
There's the very same bug with WolframAlpha as of 2018-06-09:
limit as x goes to infinity of ( (x+1/2) Log[x] - x + Log[2 Pi]/2 - Log[x!] + 1/(12x) ) x^3
yields $\displaystyle\frac1{10368}\approx0.0000964506$ rather than $\displaystyle\frac1{360}\approx0.00277778$ as is should.
What's going on? Is there some way to find the internal cause?
Update: the problem vanishes if we change x!
to Gamma[x+1]
, both for Mathematica and WolframAlpha. Multiple sources confirm that the problem crept in circa version 11.1 of Mathematica and was fixed, since it does not to occur with Mathematica 11.3, nor 11.0.0 or 10.4.1
11.3
give a correct answer1/360
$\endgroup$139/51840
, which is correct. $\endgroup$WolframAlfa
and again give me1/360
.Paste this code to Wolfram Alfa:limit ((x + 1/2)*Ln(x) - x + Ln(2 Pi)/2 - Ln(Gamma(x+1)) + 1/(12 x)) *x^3 x approach to Infinity
$\endgroup$1/360
and139/51840
withx!
in both cases. $\endgroup$1/360
and139/51840
withLog[x!]
andLog[Gamma[x+1]]
andLogGamma[x+1]
. $\endgroup$