[Python-Dev] PyObject_RichCompareBool identity shortcut
Rob Cliffe
rob.cliffe at btinternet.com
Thu Apr 28 15:59:07 CEST 2011
I am not a specialist in this area (although I call myself a
mathematician). But they say that sometimes the outsider sees most of
the game, or more likely that sometimes the idiot's point of view is useful.
To me the idea of non-reflexive equality (an object not being equal to
itself) is abhorrent. Nothing is more likely to put off new Python
users if they happen to run into it. And I bet even very experienced
programmers will be tripped up by it a good proportion of the time they
hit it.
Basically it's deferring to a wart, of dubious value, in floating point
calculations and/or the IEEE754 standard, and allowing it to become a
monstrous carbuncle disfiguring the whole language.
I think implementations of equal/not-equal which are make equality
non-reflexive (and thus break "identity implies equality") should be
considered broken.
On 27/04/2011 15:53, Guido van Rossum wrote:
> Maybe we should just call off the odd NaN comparison behavior?
Right on, Guido. (A pity that a lot of people don't seem to be listening.)
On 27/04/2011 17:05, Isaac Morland wrote:
> Python could also provide IEEE-754 equality as a function (perhaps in
> "math"), something like:
>
> def ieee_equal (a, b):
> return a == b and not isnan (a) and not isnan (b)
>
Quite. If atypical behaviour is required in specialised areas, it can
be coded for. (Same goes for specialised functions for comparing lists,
dictionaries etc. in non-standard ways. Forced explicit is better than
well-hidden implicit.)
> Of course, the definition of math.isnan cannot then be by checking its
> argument by comparison with itself
Damn right - a really dirty trick if ever I saw one (not even proof
against the introduction of new objects which also have the same
perverse non-reflexive equality).
> - it would have to check the appropriate bits of the float representation.
So it should.
On 28/04/2011 11:11, Nick Coghlan wrote:
> After all, why discard centuries of mathematical experience based on a
> decision that the IEEE754 committe can't clearly recall the rationale
> for, and didn't clearly document?
Sorry Nick, I have quoted you out of context - you WEREN'T arguing for
the same point of view. But you express it much better than I could.
It occurred to me that the very length of this thread [so far!]
perfectly illustrates how controversial non-reflexive "equality" is.
(BTW I have read, if not understood, every post to this thread and will
continue to read them all.)
And then I came across:
On 28/04/2011 09:43, Alexander Belopolsky wrote:
> If nothing else, annual reoccurrence of long threads on this topic is
> a reason enough to reconsider which standard to follow.
Aha, this is is a regular, is it? 'Nuff said!
Best wishes
Rob Cliffe
More information about the Python-Dev
mailing list