0
$\begingroup$

We are given numerically stable functions exp(x) and expm1(x) computing $e^x$ and $e^{-x}$. How compute numerically stably $\sinh(x)=\frac{e^x-e^{-x}}{2}$ for $x \approx 0$ using exp(x) and expm1(x)?

$\endgroup$
  • 3
    $\begingroup$ Try $\sinh(x) = e^{-x}/2(e^{2x}-1).$ $\endgroup$ – Somos Nov 15 '19 at 1:44
  • $\begingroup$ @Somos How to use the fact that $x \approx 0$? $\endgroup$ – adbeno Nov 15 '19 at 3:47
  • $\begingroup$ @adbeno $(\exp(x) - \exp(-x)) / 2$ suffers from subtractive cancellation for $x \approx 0$. A common approach to fixing this issue is to eliminate the affected subtraction or addition by rewriting the formula as a product or quotient. This approach is exemplified by Somos's suggestion. $\endgroup$ – njuffa Nov 15 '19 at 8:14
  • $\begingroup$ @adbeno The point is that $\text{expm1}(x):=e^x-1$ is computed in a stable way. $\endgroup$ – Somos Nov 15 '19 at 16:05
  • $\begingroup$ You could also insert a zero and compute 0.5*(expm1(x)-expm1(-x)), but use the variant of @Somos if the evaluation of expm1 is much slower than exp. $\endgroup$ – Lutz Lehmann Nov 16 '19 at 9:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.