# Bug: Wrong limit in Mathematica 11.1.1 and current WolframAlpha

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

• MMA 11.3 give a correct answer 1/360 Jun 9, 2018 at 12:12
• Also, the second limit is 139/51840, which is correct. Jun 9, 2018 at 12:18
• I checked WolframAlfa and again give me 1/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 Jun 9, 2018 at 12:22
• @fgrieu MMA 11.3 returns 1/360  and 139/51840 with x! in both cases. Jun 9, 2018 at 12:51
• MMA 10.4.1 returns 1/360 and 139/51840 with Log[x!] and Log[Gamma[x+1]] and LogGamma[x+1].
– JimB
Jun 9, 2018 at 15:06