1
$\begingroup$

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?

$\endgroup$
1
  • 1
    $\begingroup$ $\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$. $\endgroup$ Commented Apr 10, 2013 at 18:23

4 Answers 4

7
$\begingroup$

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

$\endgroup$
2
  • 1
    $\begingroup$ I like to express it as: $0^0=1$ and $0.0^{0.0}$ is undefined :) $\endgroup$ Commented Apr 10, 2013 at 18:12
  • $\begingroup$ 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. $\endgroup$ Commented Apr 10, 2013 at 18:20
3
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ 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$.” $\endgroup$
    – chharvey
    Commented May 4, 2015 at 23:57
1
$\begingroup$

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

$\endgroup$
2
  • 1
    $\begingroup$ Prove $0^0=1$ : ) $\endgroup$
    – chharvey
    Commented May 2, 2015 at 3:50
  • 2
    $\begingroup$ 0^0 is undefined in mathematics, and log(0^0) is thus undefined. $\endgroup$
    – RK01
    Commented Jul 12, 2016 at 13:37
0
$\begingroup$

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

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .