I often find code that checks for out of range values, as in:

if (x < 5 or x > 6) {
 // do stuff...

I like to rearrange it to get a slightly better visual cue:

if (x < 5 or 6 < x) {
 // do stuff...

My question is whether there is mathematical notation for that. I'm no mathematician; I know about inequality/comparison operators and interval notation for closed and open-ended (between) ranges, but I have yet to stumble upon a good, concise representation for out-of-range.

I'm left with writing the inequalities, or the rather clumsy "all except" interval notation (−∞,5) ∪ (6,∞), So let's say I propose something in the lines of


as new interval notation; how would I go about getting it accepted?

  • 2
    $\begingroup$ How about $x \notin [5,6]$? $\endgroup$ – mhum Apr 6 '18 at 23:21
  • $\begingroup$ Brilliant, negation--of course. Now I feel silly. Thanks! $\endgroup$ – thor2k Apr 9 '18 at 0:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.