Decimals and other numbers

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Jan 9 13:24:35 CET 2015


I want to emphasis that I'm not really arguing that 0**0 should evaluate as
0. That's probably the least useful thing we can have out of the four
possibilities:

- return 1
- return NAN
- raise an exception
- return 0

But in the spirit of the Devil's Advocate, I mentioned that there was an
argument to be made for having integer 0**0 return 0. Intuitively, we have:

0**5 = 0
0**4 = 0
0**3 = 0
0**2 = 0
0**1 = 0
0**0 = ?

It's not hard to see that 0**n = 0 for every n except 0, so why make an
exception for 0? I stress that there are *better* arguments for making that
exception and having 0**0 defined as 1. My argument is merely that there is
*an argument* for having 0**0 return 0.

I could put it this way:

If you start with nothing and raise it to the power of nothing, then there
is nothing to exponentiate and you're left with nothing.

More below.

Chris Angelico wrote:

> On Fri, Jan 9, 2015 at 9:20 PM, Steven D'Aprano
> <steve+comp.lang.python at pearwood.info> wrote:
>> On the basis that m**n means m multiplied by itself n times:
>>
>> 5**4 = 5*5*5*5 = 625
>>
>> that gives us:
>>
>> 0**0 = zero multiplied by itself zero times.
>>
>> You can multiply 0 by any number you like, and the answer will always be
>> 0, not 1. Even if that other number is 0, the answer is still 0.
> 
> 5 * 0 * 0 * 0 * 0 = 0

Where did the 5 come from?

You're effectively saying that 0**0 becomes 5*0**0, then cancelling the 0**0
because they're all zeroes and so don't matter, leaving 5. And that simply
doesn't work. If it did work, there's nothing special about 5, we could use
18 instead:

0**0 = 5*0**0 => 5

but 0**0 = 18*0**0 => 18
therefore 5 = 18.

Yay maths! :-)


> You can multiply 5 by 0 any number of times you like, and the answer 
> will always be 0... unless you never multiply it by 0 at all, in which
> case it'll be 5. Multiplying 0 by any number, including 0, is 0... but 
> *not* multiplying 0 by 0 doesn't have to give 0. 0**0 is the result of
> not multiplying any zeroes together, so it doesn't follow the rules of
> multiplying zeroes together.

If you want to be vigorous, we're both talking nonsense. Exponentiation in
terms of repeated multiplication only works for non-zero powers. Talking
about "multiplication by itself zero times" raises the question "what the
hell do you mean by multiplication by itself zero times?"

There are ways to make this vigorous. The problem is, with 0**0, you get a
different answer depending on how you make it vigorous. Hence 0**0 is
indeterminate.


> Look at it another way. 6**x modulo 10 will always be 6, right? 6, 36, 
> 216... the rules for multiplying mean that the last digit will be
> consistent. (That's how we can know what the last digits of Graham's
> Number are, despite having no way to even comprehend its scale.) 

Oh, after going through some of the discussions on Python-ideas, I'm pretty
sure I comprehend its scale...


> So 
> what's 6**0? Is that going to end with 6, too, to be consistent? No,
> because we're not multiplying any sixes in, so the answer's simply 1.

Why 1? Why not 3? Or 0?

The answer is, it needs to be 1 to be consistent with the Index Laws such as
a**(b-c) = a**b / a**c. That's a good answer, and it works great for a=6:

6**0 = 6**(2-2) = 6**2 / 6**2 = 36/36 = 1

(There's nothing special about 2, I could have used 0 = 97-97, or any other
positive value.)

But it doesn't work when the base is zero:

0**0 = 0**(2-2) = 0**2 / 0**2 = 0/0 = ????

Oops. There's that pesky indeterminate result again.



-- 
Steven




More information about the Python-list mailing list