# How to include negative number in the log-sum-exp?

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?

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

from cmath import log, exp

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