2
$\begingroup$

Context: I isolated the following minimal working example after getting weird warnings while looking at the limiting behavior of the GumbelDistribution.

Issue: If we try to plot a function that gets doubly exponentially small in the negative direction, we get an underflow warning for sufficient negative values:

Plot[Exp[-Exp[-x]], {x, -6.6, 0}]

General::munfl: Exp[-734.996] is too small to represent as a normalized machine number; precision may be lost.

Unsurprisingly, this warning goes away if we don't try to get too negative:

Plot[Exp[-Exp[-x]], {x, -6.5, 0}]  (* No warning generated *)

(I picked the number 6.6 so we would be right on this threshold.)

At first I thought this issue might have been related to the changes in Mathematica 11.3 related to how precision errors are tracked (see here and links therein). However, increasing the working precision of the original example doesn't help:

Plot[Exp[-Exp[-x]], {x, -6.6, 0}, WorkingPrecision -> 500]

General::munfl: Exp[-734.996] is too small to represent as a normalized machine number; precision may be lost.

And the issue persists even if we eliminate all finite-precision numbers from the input:

Plot[Exp[-Exp[-x]], {x, -7, 0}]

General::munfl: Exp[-1096.48] is too small to represent as a normalized machine number; precision may be lost.

Plot[Exp[-Exp[-x]], {x, -7, 0}, WorkingPrecision -> 500]

General::munfl: Exp[-1096.48] is too small to represent as a normalized machine number; precision may be lost.

Therefore, using Rationalize[], as suggested in answers to other questions, doesn't help. But what does help is setting the precision of x to something finite!

Plot[Exp[-Exp[-SetPrecision[x, 500]]], {x, -7, 0}]    (* No warning generated *) 

Even weirder, the issue also goes away if we just make the substitution x$\to$-x in the original example:

Plot[Exp[-Exp[x]], {x, 0, 6.6}]  (* No warning generated *)

Indeed, this mere reflection in the x variable avoids the error even for extremely small numbers (which in this case corresponds to large x):

Plot[Exp[-Exp[x]], {x, 0, 1000}]  (* No warning generated *) 

Question: What's going on? If I set the option WorkingPrecision -> 500, why is SetPrecision[x, 500] still necessary? And why is all of that that unnecessary under the substitution x$\to$-x?

$\endgroup$
3
$\begingroup$

It seems like Plot always feeds the function a machine number near the left endpoint, and this machine number argument causes the message to be generated:

Plot[Exp[-Exp[-Echo@x]], {x, -7, 0}, WorkingPrecision -> 20]

-7

-6.99986

General::munfl: Exp[-1096.48] is too small to represent as a normalized machine number; precision may be lost.

Charting`Private`pvar$1259378

-6.9999998571428569960

-6.8625993715892867897

-6.7136415004017884200

-6.5745548150089341277

(* snip *)

enter image description here

As is evident above, once the machine number argument is used, Plot is smart enough to always use a higher precision argument (as specified by the WorkingPrecision option). So, other than a possible point that might be wrong due to underflow, the rest of the plotted points are computed at the expected working precision, and the plot output should be correct.

For the example where you use {x, 0, 6.6}, the left endpoint is 0, and evaluation of the function with a machine number near this endpoint is not an issue.

If you don't like this benign error message, you could turn it off, or you can make sure that the plot function artificially enhances precision before evaluation, as you do with your SetPrecision example.

I think you should also report this to Wolfram support.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks! I sent Wolfram a support message, with a link to this page and a pointer your answer. $\endgroup$ – Jess Riedel Dec 30 '19 at 21:27

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.