I would like to understand why evaluation of the expression
1 - Exp[-10.0^12]
causes an out-of-memory error and how can I prevent such errors when calculating numeric integrals with decaying exponents.
For example an attempt to evaluate the following numeric integral:
f[x_Real, y_Real] := (1 - Exp[-x^2]) E^(-x Sqrt[1 + 1/2 (1 - y^2)]);
NIntegrate[f[x, y], {x, 0, Infinity}, {y, -1, 1}]
causes the following error message on Windows:
Throw::sysexc
: UncaughtSystemException
returned to top level. Can be caught withCatch[…, _SystemException]
. >>SystemException["MemoryAllocationFailure"]
while on OSX it causes a kernel restart.
Update: From the discussion in comments it became clear that when Mathematica encounters an exponent of a very large negative number (i.e. when the result cannot be represented as machine precision number) it automatically converts the number to arbitrary precision (see this question). One can prevent this conversion from happening using the command:
SetSystemOptions["CatchMachineUnderflow" -> False];
This trick makes evaluation of the above expressions possible.
What is still interesting to understand is why the evaluation of difference of arbitrary precision numbers causes a memory error.
$MinMachineNumber
and$MaxMachineNumber
, the Wolfram Language will automatically convert the number to arbitrary‐precision form." $\endgroup$NIntegrate[f[x, y], {x, 0, Infinity}, {y, -1, 1}, Method -> "LocalAdaptive"]
runs without problem. It seems that the problem depends on methods specified. $\endgroup$1 - Exp[-10.0^12]
$\endgroup$