perlance has asked for the wisdom of the Perl Monks concerning the following question:

Zero to the power zero as we know is undefined. However perl evaluates 0**0 as 1. Isn't this something abnormal?

Replies are listed 'Best First'.
Re: zero to the power zero
by bart (Canon) on Feb 18, 2007 at 13:26 UTC
It's undefined, because there's more than one solution. 1 is a good answer. But there are others, depending on how you approach the problem: is it x**x, 0**x, x**0 for x approaching 0? You get a different outcome every time.

It's not like the division 1/0, for which there is no finite answer.

I don't see the different answers ... the limit is 1 for both x**x and x**0 as x -> 0 from above. 0**x goes undefined when x falls below 1, but that doesn't prove it stays undefined in the limiting case. So you get two answers agreeing on 1 and one failure to produce an answer out of the three cases. (misread as case of less than zero, as bart supposed, but ... )

Update: I should refine this to: any function from the set of all f(x,y) = g(x)**h(y) that converges on 0**0 will either get a 1 or be discontinuous only at the exact 0,0 point. I used to have to prove that kind of thing as homework, but that's going back nearly 30 yrs!

-M

Free your mind

0**x goes undefined when x falls below 1
Eh? The squareroot of 0 is still 0, AFAIK. And that's where the value of the exponent is 1/2: SQRT(0) == 0**0.5. I see no reason for a change in behaviour when x gets closer to 0.

Perhaps you ment to say "when x falls below 0"? Because 0**x is 0 for any x > 0, and 0**x is infinite for any x < 0.

no all functions of this form converge
Re: zero to the power zero
by jettero (Monsignor) on Feb 18, 2007 at 13:20 UTC
I don't think it's undefined, I think it's indeterminate form. By definition, anything to the 0 power is 1. In calculus it becomes meaningless, but in Perl it doesn't cause an error.

-Paul

The wiki you refer to seems to be bit clumsy there. Rather than be meaningless in calculus, I would argue that calculus, a branch of mathematical analysis, is the only discipline known to be capable of giving such values a meaning.

-M

Free your mind

Re: zero to the power zero
by zentara (Archbishop) on Feb 18, 2007 at 13:21 UTC
I always thought that anything to the power 0 is 1. Googling for "0 power 0" will yield the explanations. You may be confusing power with division by 0.

I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: zero to the power zero
by randyk (Parson) on Feb 18, 2007 at 15:30 UTC
Interpreted as the limit of x**x as x approaches 0, mathematically, 0**0 can be defined in terms of L'H�pital's rule, where it does evaluate to 1.
Even perl hints at this:
```C:\_32\C>perl -e "print 0.5 ** 0.5"
0.707106781186548
C:\_32\C>perl -e "print 0.05 ** 0.05"
0.860891659331735
C:\_32\C>perl -e "print 0.005 ** 0.005"
0.973856237016479
C:\_32\C>perl -e "print 0.0000005 ** 0.0000005"
0.999992745697443
C:\_32\C>perl -e "print 0.00000000005 ** 0.00000000005"
0.99999999881405
C:\_32\C>perl -e "print 0.0000000000001 ** 0.0000000000001"
0.999999999997007
C:\_32\C>perl -e "print 0.0000000000000001 ** 0.0000000000000001"
0.999999999999996
[download]```
When I was at school (which, admittedly, was a long time ago) there was no question about it. Every real number (including 0) raised to the power of 0 was equal to 1.

Not sure about other numbers, however ... eg does i ** 0 == 1 ?

Cheers,
Rob
Update:According to Math::Complex:
```C:\_32\C>perl -MMath::Complex -e "\$z = cplx(0, 1); print \$z ** 0"
1
[download]```
Re: zero to the power zero
by rodion (Chaplain) on Feb 18, 2007 at 13:34 UTC
```   x * (5**1) = x * 5
x * (0**1) = x * 0 = 0
x * (5**0) = x
x * (0**0) = x
[download]```
A useful way to think about it is that the exponent is telling you how many times to multiply by something. If you multiply x by 5 once you get 5x. If you don't multiply it by 5 at all, you just have the x you started with. That's the same as multiplying it by 5 zero times, and the same as multiplying it by 1.

If you don't multiply x by 0 at all, you still have the x you started with. It gives the same as multiplying x by one, so that's why we can say the value of 0**0 is 1.

As bart indicates, 0**0 is a bit of a strange consruct, whith strange relatives, but for simpler operations like the arithmetic most of us normally do in perl, it's really helpful to have it's value be 1, not undefined.

Hope this helps.

Re: zero to the power zero
by klekker (Pilgrim) on Feb 18, 2007 at 13:36 UTC
0^0 is the value of the function x^x when x=0. In fact, x^x is not defined at 0 (not in the domain of definition), therefore 0^0 is not defined. But, we can say that the limit of x^x as x tends to zero equals to 1,yet we can not say that 0^0=1. Programming languages evaluates this limit -not the value- as 1. Finally 0^0 is not defined, but the limit of x^x as x tends to 0 is 1.
Re: zero to the power zero
by talexb (Canon) on Feb 18, 2007 at 22:09 UTC

The counter-argument is where you use logarithms to figure out the answer.

```0 ** 0 = exp ( 0 * ln(0) )
= exp ( 0 * undef )
= exp ( undef )
= undef
[download]```

If you argue that exp(ln(\$anything)) is just \$anything, you still get 1 * 0 and then a zero rseult.

So I would argue against an answer of one .. the value approaches one, but I think the actual point is a singularity.

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

If you interpret 0*ln(0) as a limit of x*ln(x) as x tends to 0, then L'H�pital's rule can be used to infer what this limit is (if it exists):
```  Lim  x ln(x)  = Lim  1/(1/x) ln(x)
x->0            x->0

= Lim  1/(-1/x^2) (1/x)
x->0

= Lim  -x  = 0
x->0
[download]```
Thus, since the limit exists, the limit of x*ln(x) as x approaches 0 is 0.
Re: zero to the power zero
by Moron (Curate) on Feb 19, 2007 at 10:16 UTC
0**0 is undefined according to wikipedia, but 1 is clearly the limit of x**0 as x tends to 0 from above. Limit points are usually left in that form (i.e. as the limit of a Cauchy sequence) or reused in that form (hence the need for something like l'Hopital to take you further) - this being preferable than risking error by trying to reuse the expression in a determinate way.

However, what might be "undefined" in a mathematical sense is rather a different idea from being undefined in Perl. Leaving \$x undefined after \$x = 0**0 isn't reasonable. The only reasonable choices seem to be to return an error or attempt a defined assignment - Perl cannot (yet?) do the ideal(?) thing of leaving it defined as "the limit of x^0 as x tends to 0 from above" and that wouldn't really be useful either!

-M

Free your mind

Re: zero to the power zero
by swampyankee (Parson) on Feb 20, 2007 at 01:04 UTC

From all my math, 00 is not defined. See, for example, "The definition 0^0==1 is sometimes used to simplify formulas, but it should be kept in mind that this equality is a definition and not a fundamental mathematical truth (Knuth 1992; Knuth 1997, p. 56)." from MathWorld. Also, according to here, 00 is undefined. As to why, see here.

00 = 1 is incorrect. Perl should give NaN for 0**0.

emc

Insisting on perfect safety is for people who don't have the balls to live in the real world.

—Mary Shafer, NASA Dryden Flight Research Center
Re: zero to the power zero
by Steve_p (Priest) on Feb 19, 2007 at 14:24 UTC
Hmmmm....
```\$ cat zero.c
#include <stdio.h>

int
main() {
printf("0 ** 0 == %d\n", 0 ^ 0);

}

\$ ./zero
0 ** 0 == 0
[download]```

Test your modules with bleadperl!

```  rsync -avz rsync://public.activestate.com/perl-current/ .
./Configure -des -Dusedevel -Dprefix=/path/to/test/perl
make test
make install
```

Now, please test you modules! If you have test failures that don't happen with Perl 5.8.8, send a simplified test case to

`perlbug at perl.org`

printf("0 ** 0 == %d\n", 0 ^ 0);
That's the xor operator.
Use math
```/* gcc -o zero zero.c -lm */

#include <stdio.h>
#include <math.h>

int main() {

int i = 0;
int j = 0;
int k;

k = pow(i,j);
printf("%d\n",k);
}
[download]```
Output: 1

I'm not really a human, but I play one on earth. Cogito ergo sum a bum