1

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?

SagarM
  • 1,789
Rcoster
  • 148
  • 1
    $\log 0$ is undefined. $0^0$ is defined and equal to $1$ - although it is a so-called "indeterminate form," which means that when $x,y$ are close to zero, $x^y$ won't necessarily be close to $1$. – Thomas Andrews Apr 10 '13 at 18:23

4 Answers4

7

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$).

  • 1
    I like to express it as: $0^0=1$ and $0.0^{0.0}$ is undefined :) – Thomas Andrews Apr 10 '13 at 18:12
  • Also, if $n\geq 0$ is any integer, and $z$ is any number (or any member of any ring, in fact) we can define $z^n$, and in this context, $z^0=1$ for all $z$. We only are really concerned when the exponent can take continuous values. I still tend to say that $0^0=1$ in all instances, it's just that you have to be careful to not conclude anything about $x^y$ when $x,y$ are close to zero. – Thomas Andrews Apr 10 '13 at 18:20
3

$x=\ln (0)$ does not equal $-\infty$.

The limit approaches $-\infty$ as $x \to 0$ in $\ln(x)$, but it does not equal $-\infty$.

This is because $\ln$ is only defined $x > 0$.

The reason why $\ln(0^0)$ is defined is because your calculator is evaluating $0^0$ first. Any real number raised to the $0$ is $1$, $0^0 = 1$, which is then plugs into $\ln$ and evaluated as $\ln(1)$, which is $0$.

The reason why $0*\ln(0)$ is undefined is that $\ln(0)$ is undefined.

  • Good explanation and answer. However I think the statement “any real number raised to the $0$ is $1$” is about as true as the statement “$0$ raised to any real number is $0$.” – chharvey May 04 '15 at 23:57
1

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)$

Wintermute
  • 3,828
0

Almost every program considers $\frac{1}{0}$ as $+\infty$ and $-\frac{1}{0}$ as $-\infty$ according to the IEEE 754 floating-point standard. Thus $\pm\infty\cdot 0=\pm\frac{1}{0}\cdot 0=\pm\frac{0}{0}=\text{NaN} $.

Some programs also consider $\log(0)$ as $-\infty$ according to: $$ \lim_{x\to 0^+}\log(x)=-\infty $$ For these programs, $0\log(0)=0\cdot -\infty=\text{NaN}$. For those programs which consider $\log(0)$ as $\text{NaN}$, $0\log(0)=0\cdot\text{NaN}=\text{NaN}$.

Then, for $\log(0^0)$, all programs will calculate $x=0^0$ first before calculating $\log(x)$. So the last question is why $0^0=1$, or why calling $\text{pow(0,0)}$ will return $1$. Again, according to the IEEE 754 floating-point standard, the "pow" function is combined with the "pown" function and the "powr" function (Wiki: Zero to the power of zero):

  • pown (whose exponent is an integer, discrete exponent) treats $0^0$ as $1$.
  • powr treats $0^0$ as $\text{NaN}$ due to the indeterminate form.

So which one does the "pow" function use? Well, it depends on implementation.

Some programs will convert float numbers to integers as soon as possible to simplify calculation. In these programs, even if you deliver $0.0$ as the exponent parameter, it will be converted to the integer $0$ first, then the program switch to the "pown" function for calculating. In this situation, you will get $1$ by calculating $0^0$.