Would there be support for a more general cmp/__cmp__

Steve Holden steve at holdenweb.com
Mon Oct 24 13:33:19 CEST 2005


Antoon Pardon wrote:
> Op 2005-10-21, Christopher Subich schreef <csubich.spam.block at spam.subich.block.com>:
> 
>>Antoon Pardon wrote:
>>
>>>It would be better if cmp would give an indication it
>>>can't compare two objects instead of giving incorrect
>>>and inconsistent results.
>>
>>If two objects aren't totally comparable, then using 'cmp' on them is 
>>ill-defined to begin with.
> 
> 
> Where is that documented?
> 
> 
>>The Standard Thing To Do is throw an 
>>exception; see the Highly Obscure Case of the Complex Numbers.
>>
>>
>>>>>1 == 1j
>>
>>False
>>
>>>>>1 != 1j
>>
>>True
>>
>>>>>1 < 1j
>>
>>Traceback (most recent call last):
>>   File "<stdin>", line 1, in ?
>>TypeError: cannot compare complex numbers using <, <=, >, >=
> 
> 
> I would say this is the wrong answer. The right answer should
> be False IMO.
> 
Well in that case it's time to declare Principia Mathematica obsolete. 
The real numbers are a two-dimensional field, and you are proposing to 
define an ordering for it.

This is a snail that really shoudn't be salted at all.

> Especially in the following case do I think the TypeError is
> the wrong answer:
> 
> 
>>>>3 + 0j < 2 + 0j
> 
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: cannot compare complex numbers using <, <=, >, >=
> 
Here you seem to be asking for special-case code to detect complex 
numbers that are on the real line. Mathematically speaking this is an 
infintesimal subset of the complex plane, so you are expecting a lot. 
And presumably next you would argue that "since (3+0j) < (2+0j) returns 
False so should (3+1j) < (2+2j)".

I think you should find something more productive to do with our time. 
And mine ;-)
> 
> Look at sets:
> 
> 
>>>>set([1]) <=  set([2])
> 
> False
> 
>>>>set([2]) <= set([1])
> 
> False
> 
Set orderingd are explicitly documented as being based on proper 
subsetting. This is an abuse of the operators to make subset tests more 
convenient rather than a definition of an ordering.
> 
[...]
The rest of your post does highlight one or two inconsistencies, but I 
don't frankly see yor proposed solutions making anything better.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC                     www.holdenweb.com
PyCon TX 2006                  www.python.org/pycon/




More information about the Python-list mailing list