cosmologicon / pywat

Python wats
1.22k stars 99 forks source link

Minor: 0^0 is not 0 (mathematically) - explanation.md #45

Open tgandor opened 5 years ago

tgandor commented 5 years ago

In your "inverse implication" operator rationale, you say 0^0 is equal to 1. That's not what I've learned. It's actually an undefined symbol: https://www.wolframalpha.com/input/?i=0%5E0 (like 0 * Inf) and so on. So for floats this would be NaN.

However, 1 is the limit of n^n as n->0: https://www.wolframalpha.com/input/?i=lim+n%5En+as+n-%3E0

Given that ints can't represent NaN it was probably proper to return something, in this case the limit value. But saying that the value of 0^0 is actually 1 is like saying 0 / 0 == 1 - it's also the lim(n->0), but for that Python actually returns:

Python 3.7.3 (default, Mar 27 2019, 22:11:17) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 0 / 0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ZeroDivisionError: division by zero
>>> 0 // 0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ZeroDivisionError: integer division or modulo by zero