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?
The stability of log(1+x)
algorithms;numerical algorithms;numerical analysis;error estimation
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. 