2
$\begingroup$

I want to know summation of some small numbers, such as {e^-1000, -e^1001, e^1002...}

If all numbers are positive, I can use log-sum-exp algorithm. But unfortunately, negative numbers are also included in numbers.

Is there any method to calculate the sum of such numbers?

$\endgroup$
3
  • $\begingroup$ You can (sort of) take the log of a negative number: $\log(-1) = i\pi$ (sort of) $\endgroup$ – ogogmad Dec 11 '20 at 20:35
  • 1
    $\begingroup$ Maybe first all positive numbers can be summed up separately, and all negative summed up separately? $\endgroup$ – Maxim Umansky Dec 11 '20 at 20:38
  • $\begingroup$ Defining $\log(-x) = \log(x) + i\pi$ and $\log(0)= \infty$ should present one solution to your problem $\endgroup$ – ogogmad Dec 11 '20 at 20:41
0
$\begingroup$

In terms of Python, use

from cmath import log, exp

def clog(x):
    if  x == 0:
        return -float('inf')
    else:
        return log(x)

For a negative value of $x$, this gives $\log(x) = \log(-x) + i \pi$, and for $\log(0)$, this gives $\infty$.

$\endgroup$

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.