Bug introduced in 11.0 and fixed in 11.1

For some reason I can't plot Log[Gamma[x]] for values of x larger than approximately 170:

Plot[Log[Gamma[x]], {x, 130, 200}, PlotRange -> All]

enter image description here

It works perfectly well with ListPlot (that is, values of this function are defined for x>170:

ListLinePlot[Table[{x, Log[Gamma[x]]}, {x, 130, 200}], PlotRange -> All]

enter image description here

as well as with the internally combined LogGamma:

Plot[LogGamma[x], {x, 130, 200}, PlotRange -> All]

enter image description here

It is also not a problem with the PlotRange. Even if I set the range manually, it will still not plot any points for x>170. What is wrong here?

  • $\begingroup$ There seems to be a discontinuity in s[x]. Because when I tried with the additional attribute Exclusions->None, it worked. $\endgroup$ – Anjan Kumar Feb 13 '17 at 3:03
  • $\begingroup$ That's very interesting indeed. Another proof that it can plot the data with normal working precision. $\endgroup$ – Felix Feb 13 '17 at 3:10
  • $\begingroup$ Works fine for me in M9, 10.3, and M11.1. What version are you using? Or maybe it's an OS thing? Are you using a 32 bit or 64 bit operating system? $\endgroup$ – Carl Woll Feb 13 '17 at 4:15
  • $\begingroup$ Version 11.0.1 on Linux, 64 bit. But you are right, I don't have the problem on version 10.4.1 $\endgroup$ – Felix Feb 13 '17 at 4:39
  • 3
    $\begingroup$ This is a new bug (regression) in 11. I have reported this to Wolfram support a few months ago. As Carl says, the bug is not present in previous versions and will be fixed in the next one. $\endgroup$ – Szabolcs Feb 13 '17 at 8:54

This is a bug specific to version 11.0.

As noted in the comments by @AnjanKumar, the bug seems to be related to exclusion detection. The simple workaround is turning it off:

Plot[Log[Gamma[x]], {x, 130, 200}, PlotRange -> All, 
  Exclusions -> None (* disable exclusions *)
| improve this answer | |

Plot uses machine precision numbers, but Gamma[x] becomes larger than the largest number that can be represented with machine numbers right about $x=170$:

FindRoot[LogGamma[x] == Log@$MaxMachineNumber, {x, 160}]

(* Out: {x -> 171.624} *)

I suspect that to be part of the difficulty. However, something else is going on here. Compare the result above to the following, where Log[Gamma[x]] is "hidden" behind NumericQ, and the plot works fine (!):

lg[x_?NumericQ] := Log[Gamma[x]]
Plot[lg[x], {x, 165., 200.}]

masked log gamma

Also, in comments Anjan noted that adding Exclusions -> None makes the plot work fine. I don't know how exclusions are handled inside plot, but I wonder if the fact that the value of the function exceeds $MaxMachineNumber triggers the exclusion handling and prevents its further plotting. A more authoritative viewpoint on this issue would be welcome.

Notice that other functions gracefully increase the evaluation precision when tasked to evaluate Log@Gamma, but don't need to do so when evaluating LogGamma:

Precision /@ Table[Log@Gamma[x], {x, 165., 185., 5}]
(* Out: {MachinePrecision, MachinePrecision, 15.9546, 15.9546, 15.9546} *)

Precision /@ Table[LogGamma[x], {x, 160., 200., 5}]
(* Out:  {MachinePrecision, MachinePrecision, MachinePrecision, MachinePrecision, 
          MachinePrecision} *)
| improve this answer | |
  • 1
    $\begingroup$ But why is it that I can evaluate it just fine in a Table and then ListPlot the result? $\endgroup$ – Felix Feb 13 '17 at 3:08
  • $\begingroup$ @Felix Table internally switches to arbitrary precision and increases it appropriately to be able to represent the result. See the result of Precision /@ Table[Log@Gamma[x], {x, 160., 210.}]. $\endgroup$ – MarcoB Feb 13 '17 at 3:11
  • $\begingroup$ But in contrast to your example, where with f[x_] := Sin[x^x] I can't evaluate f[150.], here Log[Gamma[200.5]] evaluates just fine. Also, I can generate the table with floating point numbers. $\endgroup$ – Felix Feb 13 '17 at 3:13
  • 1
    $\begingroup$ I am not convinced by this magical increase of precision. For instance, Precision[Log@Gamma[1000000.]]=15.9546. Shouldn't such a large number require much more precision? Also, why does Anjan's suggestion work if it is a working precision issue? $\endgroup$ – Felix Feb 13 '17 at 3:19
  • $\begingroup$ @Felix 1) Precision[Log@Gamma[1000000.]]=15.9546 is the precision of the result, not of the intermediate numbers necessary to arrive at that result. The existence of $MaxExtraPrecision hints at the fact that higher arbitrary precision can be used internally to arrive at a result. 2) I agree; there is something funny connected with Plot that I haven't been able to pinpoint yet. $\endgroup$ – MarcoB Feb 13 '17 at 3:38

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.