Why I can't calculate $0*log(0)$ but can $log(0^0)$

8.9k Views Asked by At

I got this doubt after some difficult in programming. In a part of code, i had to calculate:

$$ x = 0 * \log(0) \\ x = 0*(-\infty) $$

and got $x = NaN$ (in R and Matlab). So I changed my computations to $x = Log(0^0)$ and got $x=0$.

I found this question/asnwer about $0*\infty$ getting NaN. But, why the 'log way' does have a result?

2

There are 2 best solutions below

2
On BEST ANSWER

remember that $0^0=1$ so $\log(0^0)=\log(1)=0$. On the other hand $\log(0) = $ undefined and thus so is $0 \log(0)$

2
On

If you need to calculate $0 \log 0$, you're probably either:

  • Doing something wrong
  • Implementing an algorithm that explicitly states that $0 \log 0$ is a fib that doesn't mean "compute zero times the logarithm of zero", but instead something else (e.g. "zero")

If $\log 0^0$ worked in your programming language, it's probably because it used the "wrong" exponentiation convention, and returned $0^0 = 1$.

I say "wrong", because it seems very likely your particular setting is more interested in the continuous exponentiation operator (in which $0^0$ is undefined) than it is in the combinatorial/discrete version (in which $0^0 = 1$).