True == 1 weirdness

Steven D'Aprano steve at pearwood.info
Fri Sep 18 09:14:52 EDT 2015


On Fri, 18 Sep 2015 10:47 pm, Random832 wrote:

> On Fri, Sep 18, 2015, at 08:30, Steven D'Aprano wrote:
>> On Fri, 18 Sep 2015 07:26 am, Random832 wrote:
>> 
>> > I don't even think chaining should
>> > work for all *actual* comparison operations.
>> 
>> I don't see why. Mathematicians chain comparisons all the time. If the
>> language implements the same semantics as mathematicians already use, why
>> do you dislike that?
> 
> Please provide a citation for this claim.

Really? You're disputing that chained comparisons are a standard maths
notation?

https://en.wikipedia.org/wiki/Inequality_(mathematics)#Chained_notation

Mathworld, for example, says:

    Solutions to the inequality |x-a|<b consist of the set {x:-b<x-a<b},
    or equivalently {x:a-b<x<a+b}.

http://mathworld.wolfram.com/Inequality.html


>> Only if the comparisons are transitive, which they may not be.
> 
> My *entire point* is that it *shouldn't be used* for non-transitive
> comparisons!!!

And my point is that there is no good reason for such a restriction, even if
it were technically possible to enforce (which it is not).

The mathematical chained notation doesn't rely on, or imply, transitivity.
Given a < b < c, *if* the operator is transitive, then AND ONLY THEN can
you conclude that a < c, but that's not implied by the chaining. It happens
to be true for real numbers, but it isn't necessarily true.


-- 
Steven




More information about the Python-list mailing list