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.
 [reply] 

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!
 [reply] 

 [reply] [d/l] 

no all functions of this form converge
 [reply] 
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.
 [reply] 

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.
 [reply] 
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.
 [reply] 
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.
 [reply] 

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
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
 [reply] [d/l] [select] 
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
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.
 [reply] [d/l] 
Re: zero to the power zero
by klekker (Pilgrim) on Feb 18, 2007 at 13:36 UTC

 [reply] 

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.
 [reply] 
Re: zero to the power zero
by talexb (Canon) on Feb 18, 2007 at 22:09 UTC

0 ** 0 = exp ( 0 * ln(0) )
= exp ( 0 * undef )
= exp ( undef )
= undef
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 opensource mentality applied to legal research" ~ Linus Torvalds
 [reply] [d/l] [select] 

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
Thus, since the limit exists, the limit of x*ln(x) as x approaches 0 is 0.  [reply] [d/l] 
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!
 [reply] 
Re: zero to the power zero
by swampyankee (Parson) on Feb 20, 2007 at 01:04 UTC

From all my math, 0^{0} 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, 0^{0} is undefined. As to why, see here.
0^{0} = 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
 [reply] 
Re: zero to the power zero
by Steve_p (Priest) on Feb 19, 2007 at 14:24 UTC

$ cat zero.c
#include <stdio.h>
int
main() {
printf("0 ** 0 == %d\n", 0 ^ 0);
}
$ ./zero
0 ** 0 == 0
Test your modules with bleadperl!
rsync avz rsync://public.activestate.com/perlcurrent/ .
./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
 [reply] [d/l] 

printf("0 ** 0 == %d\n", 0 ^ 0);
That's the xor operator.
 [reply] 

/* 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);
}
Output: 1
 [reply] [d/l] 