True == 1 weirdness

Michael Schwarz michi.schwarz at gmail.com
Wed Sep 23 12:43:25 CEST 2015


On 2015-09-19, at 09:19, Gregory Ewing <greg.ewing at canterbury.ac.nz> wrote:

> 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.
>> Such as a < b > c or a != b != c  [whereas a may or may not be equal to
>> c]
> 
> I can't remember offhand seeing a != b != c written by a
> mathematician, but if I did, I would suspect that he
> *intended* it to imply a != c, even if that's not a strict
> logical consequence of the notation.

Mathematica interprets a != b != c as "none of a, b or c are equal". See [0]. It does this by parsing it to Unequal[a, b, c] (square brackets are function calls), where Unequal then implements that operation.

Normally I'm used to Mathematica being a very consistent language. But being prepared by this thread, I of course wondered where the inconsistencies start here and whether inequalities mix well with comparisons. They don't:

While b != c != d gets parsed as this:

Unequal[b, c, d]

But a < b != c != d < e gets parsed as this:

And[Less[a, b], Unequal[b, c], Unequal[c, d], Less[d, e]]

Which means that a != b != c is interpreted differently depending on context. I don't think every mathematician would agree which of these interpretations make sense. :)

[0]: https://reference.wolfram.com/language/ref/Unequal.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 842 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://mail.python.org/pipermail/python-list/attachments/20150923/c2dea949/attachment.sig>


More information about the Python-list mailing list