[Python-3000] None in Comparisons: None vs. float("inf")
Antoine Pitrou
solipsis at pitrou.net
Wed Nov 12 16:10:29 CET 2008
M.-A. Lemburg <mal <at> egenix.com> writes:
>
> The difference is that None is a singleton, so the set of all
> None type instances is {None}. You always have an intuitive total order
> relation on one element sets: the identity relation.
But it's not what you are asking for. You are asking for None to support ordered
comparison with objects of other types, which is completely different.
Having None be comparable with itself for ordered comparisons is certainly
possible, but it's also completely useless if None doesn't compare with other
types, which is what we are talking about.
> Right, but you're taking the view of a CPython developer. You
> need to view this as Python user.
No, I'm taking the view of an user. inf is usable as a float object and as such
supports many of the same operations as other float objects. None obviously
doesn't and doesn't claim to. I don't see how this is a CPython-centric point of
view.
> In real (math) life, inf is a different type of number than regular floats,
> ints or complex numbers and has a special meaning depending on the context
> in which you use it.
Well, in real life, inf isn't a number at all. It is a notation to indicate the
behaviour of certain sequences or functions when some of their arguments tends
to a certain "value" (either infinite, or a singular point for which the
function or sequence is not defined). Making inf usable as a number is a way to
make more accessible some useful properties of limits, at the price of
notational abuse. (*)
But there's still no analogy with None. None has nothing to do with algebra,
limits, neighbourings or closures. It cannot be defined as the limit of a
particular function when of its arguments approaches either infinity or a
singular point. None is a independent discrete value, not something at the outer
boundary of a continuous set of values.
(*) e.g.:
>>> f = float("inf")
>>> f * f
inf
>>> math.exp(f)
inf
>>> math.log(f)
inf
>>> math.tanh(f)
1.0
>>> math.exp(-f)
0.0
>>> 1 ** f
1.0
>>> 0 ** f
0.0
It is not complete though :
>>> 2 ** f
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: (34, 'Numerical result out of range')
>>> f ** 2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: (34, 'Numerical result out of range')
Regards
Antoine.
More information about the Python-3000
mailing list