Check if a given value is out of certain range

Steven D'Aprano steve at pearwood.info
Thu Oct 1 14:59:37 EDT 2015


On Thu, 1 Oct 2015 06:46 am, Ian Kelly wrote:

> On Wed, Sep 30, 2015 at 2:19 PM, alister
> <alister.nospam.ware at ntlworld.com> wrote:

[...]
>> the problem with 1 is the human brain is not particularity good with
>> negatives*.
>> to do not (some function) you first of all have to work out some function
>> & then invert it, a computer does this without difficulty the human brain
>> gets confused which is why I personally consider ii is  more readable
>> (YMMV especially if you are working with Boolean maths regularly) this
>> example is relatively simple as things get more complex they become more
>> error prone error.

In other words, "more complex things are more error prone". Well, sure. That
doesn't tell us much about simple things though.

You are right that there are certain constructs which, when written in terms
of negatives, are harder for people to parse and understand than if written
in more straight-forward positive forms. But others are simpler when
written in the negative:

"No entry to under 18s" versus "Entry to over 18s only"


Ian:
> To me, the negative of one condition (is x in this range) is more
> easily processable than the disjunction of two conditions that
> together compose the real, more easily understood condition (is x
> outside this range). I find it preferable to avoid nested conditions,
> not negated conditions, and (II) has more nesting than (I).
> 
> Thought mirrors language. In English, we typically would say "x is not
> between 0 and 10", not "x is either less than 0 or greater than 10".

I agree with Ian here.


>> *as an example you brain cannot correctly process the following.
>>
>> Not (think of your left toe)
>>
>> you are now thinking about it aren't you?

Actually I'm not, I'm too busy trying to think of a witty reply :-)


> No, it made me think about thinking. I barely even registered the
> phrase "left toe", much less thought about that.

It's a nice trick, but that's all it is -- it's a trick. The problem isn't
that we can't parse and understand the "not", but that few people have
either the mental discipline or the short attention span to not think about
about something once the thought is planted in the mind.

The classic formulation of this idea is the instruction:

Don't think of an elephant!

Sometimes people will use rhinoceros instead.

The more you try to think about *not* thinking of an elephant, the more the
idea of one comes to your consciousness. It takes great discipline, or a
level of flightiness and empty-headedness that is rare even in the post-MTV
and Twitter generation, to consciously think about something else without
going back to the elephant.

Of course, there is a loop-hole. There is always a loop-hole.[1]

In one of Terry Pratchett's Discworld novels, a young witch mentions the
phrase "Don't think of a rhinoceros", and states that it is impossible to
not think of a rhinoceros. The elderly and curmudgeonly, but extremely
powerful, witch Granny Weatherwax confidently dismisses this, and says that
it doesn't work on her, she's not thinking of a rhinoceros. Such is
Granny's reputation for strength of will, and a self-confidence that you
could bend horseshoes on, that her claim is accepted without question.

It's not until quite late in the book that her secret is revealed. Being an
rural witch who has never really travelled much and doesn't hold with book
learning, she has no idea what a rhinoceros is.


> In any case, that's more an issue of being unable to control what
> you're thinking about. If I instruct you, "don't raise your right
> hand", do you then automatically raise your right hand?

I could be wrong, but I seem to recall reading that this is *exactly* what
happens -- the muscles used to raise the right arm trigger
ever-so-slightly. You don't even notice it, but sensitive electrodes can
detect the change in electrical potential in the muscles.




[1] Except when there isn't.



-- 
Steven




More information about the Python-list mailing list