Mathematics in Python are not correct

Terry Reedy tjreedy at udel.edu
Mon May 12 02:09:09 EDT 2008


"Mark Dickinson" <dickinsm at gmail.com> wrote in message 
news:6b64d8f4-3f61-4295-9298-4633214d1e94 at m73g2000hsh.googlegroups.com...
On May 11, 9:36 pm, "Terry Reedy" <tjre... at udel.edu> wrote:
|> Do you have in mind any situations in which it is advantageous to have 
0**0
|> undefined?

| (Playing devil's advocate here.) If you regard x**y as exp(y*log(x))

Which, of course, I was not, but for the sake of discussion....

| then it's not at all clear that 0.**0. should be considered well-defined.

Then it seems equally dubious that 0.**y, y>0, should be well-defined.
It seems to me that lim as x goes to 0. exp(y*log(x)) is equally well 
defined whether y is 0 or not, even though there is a discontinuity in the 
limit.
.
...
| The big problem here is that the power operation is really trying
| to combine two subtly different functionalities (integer powers
| and real powers), with quite distinct use-cases, into a single
| function.  Which leads to problems:  witness the mess that's
| C99's pow specification:  why does it make sense for (-2.0)**2.0 to
| return 4.0, while (-2.0)**1.999999999 returns NaN?

2.5 raises an exception.  In 3.0,
>>> (-2)**1.99999999
(3.9999999722741113-1.2566370355167477e-07j)

| Incidentally, the decimal module is slightly schizophrenic about this:

That module follows the IBM-led standard, no matter how crazy.

Terry Jan Reedy






More information about the Python-list mailing list