"Lou Pecora" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| In article <[EMAIL PROTECTED]>,
| "Terry Reedy" <[EMAIL PROTECTED]> wrote:
|
| > "Luis Zarrabeitia" <[EMAIL PROTECTED]> wrote in message
| > news:[EMAIL PROTECTED]
| > | Btw, there seems to be a math problem in python with 
exponentiation...
| > | >>> 0**0
| > | 1
| > | That 0^0 should be a nan or exception, I guess, but not 1.
| >
| > a**b is 1 multiplied by a, b times.  1 multiplied by 0 no times is 1.
| > But there are unenlighted people who agree with you ;-)
| > Wikipedia has a discussion of this.
| >
| > tjr
|
| I like that argument better.  But...
|
| I've also heard the very similar a**b is a multiplied by a b-1 times.

Me too, in school, but *that* definition is incomplete: it excludes b=0 and 
hence a**0 for all a.  It was the best people could do before 0 was known.
But 0 was introduced to Europe just over 800 years ago ;-)

In general, sequence reduction work better if the base case is given 
separately rather that defined as the first member of the sequence (which 
excludes empty sequences!).
ab = [a]*b # b a count
a**b  = reduce(int.__mul__,  ab, 1) # better
a**b = reduce(int.__mul__, ab[1:], a) # crashes for b=0

Consider the equivalent pair of definitions for a*b:
a*b = 0 incremented by a, b times = reduce(int.__add__, ab, 0)
a*b = a incremented by a, b-1 times = reduce(int.__add__, ab[1:] a)

Since we have 0, the second, which excludes (crashes on) a*0 ,
is incomplete.

Terry Jan Reedy



--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to