To subtract a small probability from another, this answer has constraint on log probabilities l1 > l2: Subtracting very small probabilities - How to compute? but I need a function that works for general l1, l2 (l1=log(p1), l2=log(p2)).
If p1-p2<0, that's fine and let's record that.
For instance, I'll need exp(logdiff(-Inf,log(0.01)))=-0.01
which mirrors 0-0.01=-0.01
.
Another case is exp(logdiff(log(0.01),log(0.02)))=-0.01
which mirror 0.01-0.02=-0.01
.
The first equality in the question is true:
> exp(log(0.01))-exp(log(0.02))
[1] -0.01
> exp(log(0.01))*(1-exp(-(log(0.01)-log(0.02))))
[1] -0.01
But the second equality isn't holding:
log(0.01)+log(1-exp(-(log(0.01)-log(0.02))))
[1] NaN
Warning message:
In log(1 - exp(-(log(0.01) - log(0.02)))) : NaNs produced
So I'm not sure if the deductions in the above answer are still valid.