Short-circuit Logic
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Fri May 31 04:45:13 EDT 2013
On Fri, 31 May 2013 17:09:01 +1000, Chris Angelico wrote:
> On Fri, May 31, 2013 at 3:13 PM, Steven D'Aprano
> <steve+comp.lang.python at pearwood.info> wrote:
>> What makes you think that the commutative law is relevant here?
>>
>>
> Equality should be commutative. If a == b, then b == a. Also, it's
> generally understood that if a == c and b == c, then a == b, though
> there are more exceptions to that (especially in loosely-typed
> languages).
Who is talking about equality? Did I just pass through the Looking Glass
into Wonderland again? *wink*
We're talking about *approximate equality*, which is not the same thing,
despite the presence of the word "equality" in it. It is non-commutative,
just like other comparisons like "less than" and "greater than or equal
to". Nobody gets their knickers in a twist because the >= operator is non-
commutative.
Approximate equality is not just non-commutative, it's also intransitive.
I'm reminded of a story about Ken Iverson, the creator of APL. Iverson
was a strong proponent of what he called "tolerant equality", and APL
defined the = operator as a relative approximate equal, rather than the
more familiar exactly-equal operator most programming languages use.
In an early talk Ken was explaining the advantages of tolerant
comparison. A member of the audience asked incredulously,
“Surely you don’t mean that when A=B and B=C, A may not equal C?”
Without skipping a beat, Ken replied, “Any carpenter knows that!”
and went on to the next question. — Paul Berry
The intransitivity of [tolerant] equality is well known in
practical situations and can be easily demonstrated by sawing
several pieces of wood of equal length. In one case, use the
first piece to measure subsequent lengths; in the second case,
use the last piece cut to measure the next. Compare the lengths
of the two final pieces.
— Richard Lathwell, APL Comparison Tolerance, APL76, 1976
See also here:
http://www.jsoftware.com/papers/APLEvol.htm
(search for "fuzz" or "tolerance".
--
Steven
More information about the Python-list
mailing list