2

As x goes to 0, the limits of x^0 and 0^x go to 1 and 0, respectively. Some say that the best value for 0^0 depends on context, others say that the value of 0^0 should be 1. I'm interested in knowing what your language implementers say. There doesn't seem to be a consensus. For example, in ActiveState Perl 5.12.0:

C:\>perl -e "print 0**0"
1

While in Mathematica 6.0:

In[1]:= 0^0
        During evaluation of In[1]:= Power::indet:
        Indeterminate expression 0^0 encountered. >>
Out[1]= Indeterminate

I'm also interested in knowing your opinion on the matter: What should 0^0 be? And also whether you have ever introduced a bug into a program you were writing (or had a hard time debugging a program) because of the way your language handles indeterminate forms?

  • 2
    What is the actual question? There is consensus as to what 0^0 means; it's indeterminate. Languages that don't flag it as such are wrong. What's to discuss? It's no different than if a language returned anything other than undefined for 1/0. – user8 Oct 5 '10 at 23:27
  • 1
    @Mark: actually, for 1/0 it can return 'infinity', if it has such a thing available. A better example would be '0/0', which really is indeterminate. – Jerry Coffin Oct 6 '10 at 0:11
  • Jerry: fair enough. I was thinking more of the "division by zero" assertion/exception/error most languages have that would produce an undefined value. Such behavior is more or less uncontroversial; 0^0 should be, too. – user8 Oct 6 '10 at 0:15
  • 2
    @Mark: I don't agree that there's a consensus. According to Donald Knuth, 0^0 "has to be 1." August Mobius agrees that its 1. See en.wikipedia.org/wiki/Exponentiation#Zero_to_the_zero_power – A. N. Other Oct 6 '10 at 1:28
  • @Mark: There are three related questions. Let me restate them succinctly: 1- Which languages implement 0^0=1 and which implement it as "Indeterminate" (or something else?) 2- Does it matter to you which way its implemented? 3- Has the way its implemented ever caused you practical issues? – A. N. Other Oct 6 '10 at 1:32
4

According to this Wikipedia article,

"Most programming language with a power function are implemented using the IEEE pow function and therefore evaluate 0^0 as 1. The later C and C++ standards describe this as the normative behavior. The Java standard mandates this behavior. The .NET Framework method System.Math.Pow also treats 0^0 as 1."

  • Good insight. So clearly, Mathematica isn't IEEE-compliant, since it returns 0^0=Indeterminate rather than 0^0=1. Perhaps, then, the first part of my question should be rephrased as, "Which programming languages aren't IEEE-compliant, and return something other than 1 for 0^0?" – A. N. Other Oct 6 '10 at 3:04
3

Python:

>>> for t in [int, float, complex, fractions.Fraction, decimal.Decimal]:
...     print(t, t(0)**0)
... 
<type 'int'> 1
<type 'float'> 1.0
<type 'complex'> (1+0j)
<class 'fractions.Fraction'> 1
Traceback (most recent call last):
  ...
decimal.InvalidOperation: 0 ** 0
  • 2
    This is very, very interesting: So, in Python, the value of 0^0 depends on the numeric type of the base! Bravo and +1 for taking the trouble to find this out!!! – A. N. Other Oct 6 '10 at 21:01
  • 1
    Elisha: well, it also depends on each type's intended purpose. Most of the above types follow the convention to return 1, as seems generally more convenient. The decimal module/type, on the other hand, is intended to be a standards-compliant implementation of the IBM/IEEE decimal floating point specifications, which might be more conservative about 0**0. (I'm not sure, though.) – Pi Delport Oct 6 '10 at 22:01
1

Google says:

0^0 = 1

0

Delphi's got 2 float values: NaN and Infinity. That get returned in case of weirdness.

But it doesn't have a built in exponentiation function.

^ is for pointers, as in "hey you up there, I'm pointing at you!"

  • I always heard ^ pronounced "hat". – Jesse C. Slicer Oct 6 '10 at 14:14
  • Makes more sense than carrot, or carat... – Peter Turner Oct 6 '10 at 14:37
  • Standard Pascal has no exponentiation operator either. Timo Salmi contributed an exponentiation function to the Pascal FAQ here midnightbeach.com/jon/pubs/clp-faq.htm#exponentiation which looks as if it makes 0^0=1 rather than NaN. Do you agree with this implementation? – A. N. Other Oct 6 '10 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.