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)


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

  • 2
    $\begingroup$ MMA 11.3 give a correct answer 1/360 $\endgroup$ Jun 9 '18 at 12:12
  • 1
    $\begingroup$ Also, the second limit is 139/51840, which is correct. $\endgroup$
    – Michael E2
    Jun 9 '18 at 12:18
  • 1
    $\begingroup$ 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 $\endgroup$ Jun 9 '18 at 12:22
  • 2
    $\begingroup$ @fgrieu MMA 11.3 returns 1/360 and 139/51840 with x! in both cases. $\endgroup$
    – roman465
    Jun 9 '18 at 12:51
  • 1
    $\begingroup$ MMA 10.4.1 returns 1/360 and 139/51840 with Log[x!] and Log[Gamma[x+1]] and LogGamma[x+1]. $\endgroup$
    – JimB
    Jun 9 '18 at 15:06

Daniel Lichtblau said in the comments

@Halirutan (and Francois) I think it is simply a BTGF (bug that got fixed) or maybe a BTFI (I'll let you guess). Okay with me if a bug header is added. I had no issue with the question, and I voted to close mostly because there is really no good response since it appears to be working in the current version.

Therefore, we will keep this Q&A open as a reference for future visitors. The issue described above seems to be a bug that is only present in Mathematica 11.1.1 or a minor version away from it.

It is fixed in 11.2 and later versions.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.