True == 1 weirdness

Terry Reedy tjreedy at udel.edu
Fri Sep 18 14:24:14 EDT 2015


On 9/18/2015 9:40 AM, Random832 wrote:

> I'm disputing that chained comparisons are used for the particular
> combinations that I am actually arguing should not be used in python.

You are free to dislike certain combinations, not use them yourself, and 
even request others not to use them (all in Python code).  But claiming 
that they have never been used in math is quite different.

> Such asa < b > c

If a, b, c are members of a totally ordered set, so that < is 
transitive, this is equivalent to max(a,c) < b.  But the latter makes an 
irrelevant comparison between a and c.

If they are only partially ordered, so that a and c are not necessarily 
comparable, then the above is the most concise way to way what it says. 
  I believe I have seen such.

> or a != b != c [whereas a may or may not be equal to c]

a != b != c != a says that all three are unequal to any of the other 
two.  I believe I have seen such, with '!=' replaced with the single 
'not equal' character.

or a in b in c.

If b and c are collections, such as sets, this is perfectly sensible. 
With 'in' replaced with the epsilon 'set membership' character, I may 
have seen such.  If 'a in b in c', then 'a in Union(c)', where Union is 
the union of all collections in c.  One might call this 
quasi-transitive.  In reverse, 'a in Union(c)' implies 'exists b, a in b 
in c'. Similarly, if 'a in b for all b in c' is equivalent to 'a in 
Intersection(c)'.

> Your claim seemed to be that these combinations *are*
> used, since you claimed that python implements the *same* semantics.

The semantics Python copies from math is "a op b op c == a op b and b op 
c", where 'op' is a binary predicate or comparison operator. I also 
happen to believe you are wrong in the specific examples. But the 
semantic copying would apply even if a particular combination had not 
yet ever been used.

-- 
Terry Jan Reedy




More information about the Python-list mailing list