# Why can't I plot Log[Gamma[x]] for x > 170?

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]


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]


as well as with the internally combined LogGamma:

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


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?

• 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 3:03
• That's very interesting indeed. Another proof that it can plot the data with normal working precision. – Felix Feb 13 '17 at 3: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 4: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 4:39
• 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 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 *)
]


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.}]  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} *)

• But why is it that I can evaluate it just fine in a Table and then ListPlot the result? – Felix Feb 13 '17 at 3: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 3: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 3:13
• 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 3: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 3:38