3
$\begingroup$

I am trying to understand why the formula

$$ \frac{\log(1+x)}{(1+x)-1} \times x,$$

which simply reduces down to $\log(1+x)$, is considered as more stable to compute than $\log(1+x)$. In my head it doesn't make sense to me as my brain automatically simplifies it to $\log(1+x)$, which I am guessing a computer doesn't do, but then why does adding in "extra" calculations make it more stable for the computer? My intuition would have been the opposite, the more calculations performed, the more error is introduced. Why is this not the case here?

$\endgroup$
0

1 Answer 1

6
$\begingroup$

Consider the case that x is small. (1 + x) has a rounding error; the result that you get is not (1 + x) but (1 + x') for some x' close to x. If x is very small, the relative difference between x' and x can be quite large. Trying to calculate log (1 + x) will calculate log (1 + x') which can have a large relative error. Instead the better formula calculates log (1 + x') / x' * x.

You can just enter both formulas into a spreadsheet and compare with the Taylor polynomial ln (1 + x) = $x - x^2/2 + x^3/3 - x^4/4...$.

Note that it is easy to calculate ln (z) with very high precision when z is close to 1. The damage is done when 1+x is calculated with a small absolute rounding error which turns into a huge relative error, and that's what the modified formula compensates for.

$\endgroup$
3
  • $\begingroup$ But you're still calculating log(1+x'), why does multiplying a factor of x/x' affect the error incurred by the calculation of log(1+x'). Why does it improve it? $\endgroup$
    – Aesir
    Jan 8, 2017 at 20:08
  • 2
    $\begingroup$ @Aesir The error is from (1+x), which actually gives you (1+x'). log(1+x') itself is an accurate calculation. log(1+x') gives you $x'-x'^2/2+...$, so a factor of $x/x'$ makes it closer to $x-x^2/2+...$. $\endgroup$
    – aaaaajack
    Jan 9, 2017 at 6:35
  • $\begingroup$ Thanks, sorry about the delay in accepting the answer, your' explanation really helped me get this. $\endgroup$
    – Aesir
    Feb 16, 2017 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.