When is min(a, b) != min(b, a)?

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Fri Jan 25 06:09:39 EST 2008


On Fri, 25 Jan 2008 07:57:13 +0000, Antoon Pardon wrote:

>> But if you consider that having "x is not smaller than y" be equivalent
>> to "x is greater than or equal to y" is more important than forcing a
>> boolean answer in the first place, then you need something to signal
>> Undefined, and an exception is the right solution unless you have
>> multi- valued logic system (True, False, Maybe, Undefined, ...)
> 
> Why should we consider that? 

It's a value judgement. Ask the Apple and IBM engineers and 
mathematicians.

Personally, I think it is more useful to be able to assume that if x is 
not less than y, it must be greater or equal to instead ("completeness"), 
than it is to have a guarantee that x < y will never raise an exception.

Having said that, I think the opposite holds for sorting and calculating 
the min() and max() of floats. Sorting should push the NaNs to one end of 
the list (I don't care which) while min() and max() should ignore NaNs 
and only raise an exception if all the arguments are NaNs.



> The world is full of partial orders. In
> python we have sets and a partial order is perfectly mathematically
> sound.

Sure, we could define floats to have any sort of order we want. We could 
define them to be ordered by their English spelling so that "five million 
point three" would be less than "zero point one". But is it useful?

Putting aside sorting and max/min, what is the use-case for having 
comparisons with NaN succeed? What benefit will it give you?



-- 
Steven



More information about the Python-list mailing list