12

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?

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
Felix
  • 3,871
  • 13
  • 33
  • There seems to be a discontinuity in s[x]. Because when I tried with the additional attribute Exclusions->None, it worked. – Anjan Kumar Feb 13 '17 at 03:03
  • That's very interesting indeed. Another proof that it can plot the data with normal working precision. – Felix Feb 13 '17 at 03:10
  • 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? – Carl Woll Feb 13 '17 at 04:15
  • Version 11.0.1 on Linux, 64 bit. But you are right, I don't have the problem on version 10.4.1 – Felix Feb 13 '17 at 04:39
  • 3
    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. – Szabolcs Feb 13 '17 at 08:54

2 Answers2

15

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 *)
]
Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
8

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} *)
MarcoB
  • 67,153
  • 18
  • 91
  • 189
  • 1
    But why is it that I can evaluate it just fine in a Table and then ListPlot the result? – Felix Feb 13 '17 at 03:08
  • @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.}]. – MarcoB Feb 13 '17 at 03:11
  • 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. – Felix Feb 13 '17 at 03:13
  • 1
    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? – Felix Feb 13 '17 at 03:19
  • @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. – MarcoB Feb 13 '17 at 03:38