6
$\begingroup$

This is a very simple question I suspect but I just cannot seem to nail it...

I have values for $X,Y,Z $, where $X =\log (x)$, $Y = \log (y)$ and $Z = \log (z)$ and I need to calculate $x + y + z$, well actually $\log(x + y + z)$ would suffice. Is there a clever way of doing this other than simply doing $e^X+e^Y+e^Z$?

Its for an algorithm where I am trying to avoid underrun - $x=e^X,y=e^Y,z=e^Z$ likely to be very small.

Any pointers much appreciated.


With answer given by @response I ended up using $\log(x+y+z)=\log(e^R+e^S+e^T)-C$ where $R=X+C$, $S=Y+C$, $T=Z+C$

$\endgroup$
6
$\begingroup$

Suppose, we add a constant $C$ to each one of the values: $X, Y, Z$ which would prevent underflow when they are raised to $e$. Then we get:

$X' = X + C$

$Y' = Y + C$

$Z' = Z + C$

Thus, we have:

$x' = e^{X'}$

$y' = e^{Y'}$

$z' = e^{Z'}$

Adding them, we have:

$x'+y'+z' = e^{X'} + e^{Y'} + e^{Z'}$

But, we know that:

$e^{X'} + e^{Y'} + e^{Z'} = e^{X+C} + e^{Y+C} + e^{Z+C} = e^C (e^{X} + e^{Y} + e^{Z})$

Thus, we have:

$x+y+z = (x'+y'+z') e^{-C}$

$\endgroup$
  • $\begingroup$ Thanks. This is the logic I was looking for. I went a step forwards(backwards?) and using this since I was only after log(x + y + z). See my question edit. $\endgroup$ – Jon May 26 '13 at 4:11

Your Answer

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

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