How can log(exp(1000)+exp(1001)) be computed without overflow?
MathematicsLevel: IntermediateDerivative and probability numerics
How can log(exp(1000)+exp(1001)) be computed without overflow?
Hints
- Factor out the largest exponential.
- Work with nonpositive exponents.
Answer
Subtract the maximum: 1001+log(exp(−1)+1), about 1001.3133. Use a stable logsumexp implementation rather than direct exponentials.
Source and licence: SciPy — logsumexp and softmax numerics · BSD-3-Clause · answer: Quantoros editorial