Check if a given value is out of certain range

alister alister.nospam.ware at ntlworld.com
Thu Oct 1 04:33:16 EDT 2015


On Wed, 30 Sep 2015 14:46:48 -0600, Ian Kelly wrote:

> On Wed, Sep 30, 2015 at 2:19 PM, alister
> <alister.nospam.ware at ntlworld.com> wrote:
>> On Wed, 30 Sep 2015 21:06:02 +0300, Marko Rauhamaa wrote:
>>
>>> Grant Edwards <invalid at invalid.invalid>:
>>>
>>>>   not (0 <= x <= 10)         (I)
>>>> [...]
>>>>    (x < 0) or (x > 10)       (II)
>>>> [...]
>>>> IMO, (I) is _more_ readable than (II)
>>>
>>> IMO, they're equally readable (except that you should drop the
>>> redundant parentheses from (II)).
>>>
>>>
>>> Marko
>>
>> both are correct 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.
> 
> 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".
> 
>> *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?
> 
> No, it made me think about thinking. I barely even registered the phrase
> "left toe", much less thought about that.
clearly it did, & you are now consciously aware of you left toe even if 
you try to deny it.
> 
> 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?

Why is it that the Phrase "Don't Panic" is strongly discouraged in 
emergency situations?

answer because the brain parses the statement as follows and focuses on 
Panic instead of calm.

Don't : I must not do somthing what must i not do
	Panic:  what is there to panic about?
		Holly shit the buildings onfire, Raise Panic


The recommended phase is Stay calm

Stay: 	ok dont change anything, whats next
	Calm 
	ok I am calm that's alright then


I may not have raised my right hand but I though about it (& decided no 
thanks)

getting closer to topic, i work on PBX systems where the VM is capable of 
combining multiple conditions into one super condition using Boolean 
Operators.
Invariably this does not happen & engineers are encoraged to check each 
condition separately because:

1) They are less likely to make a mistake
2) It is more obvious to subsequent engineers exactly what is happening
3) it is a lot easier to amend if req.

on the other hand if i was designing an electronic circuit using discreet 
electronics I would use all available techniques to manipulate the 
equation to make best use of components available
the may be reducing the total gate  count, it may actually increase the 
component count so that I could use only Nand gates, or it may get 
strangely complex so that I could make use of spare gates on existing ic's

Although I would have no difficulty reading the final equation it may not 
be obvious at 1st glance  .





-- 
Blue paint today.
		[Funny to Jack Slingwine, Guy Harris and Hal Pierson.  
Ed.]



More information about the Python-list mailing list