0

I have two small positive real numbers $u, w$ such that $u > w$. Given $\log(u), \log(w)$ I'd like to find a numerically stable way to calculate $\log(u - w)$.

One possible way of transforming the preceding is : $\log (u - w) = \log(u) + \log(1 - \frac{u}{w})$. There are stable methods which calculate $\log(1 - p)$ for small $p,$ and subsequently log-sum-exp trick may be employed. The problem is $\log(\frac{u}{w})$ may be of order of -10000 hence I don't think straightforward exponentiation is an option here. Any suggestions greatly welcomed.

marcusy
  • 33
  • 3
  • When the log is that small, it's hopeless to do this calculation in only double precision: you need over 4000 decimal digits just to distinguish $u-w$ from $u$! Please tell us what kind of arithmetic you are using. And, since such precision is unprecedented in any application, could you tell us how you intend to use this calculation for statistical work? – whuber Feb 05 '20 at 19:44
  • If $u/w$ is $<1$ (as it must be for $\log(u/w)$ to be negative -- you say it's "of order -10000"), then $u-w$ is negative, not positive as initially stated (in which case, how are you taking its log in the first place)? I fear there's some typing error in there – Glen_b Feb 06 '20 at 02:00

0 Answers0