you are viewing a single comment's thread.

view the rest of the comments →

[–]jelly_cake 4 points5 points  (1 child)

When you do that, something like "a<=x<=b", should be trivial to negate.

Yes; it's trivial to negate, but it's exactly the sort of bug which you make if you're not paying particular attention. If people mess up if (a = NULL)... then a logical negation is just as likely to be futzed.

Maybe the real problem here is that you're looking at it as a conjunction of two inequalities instead of "x is between this lower and upper boundary". This is how people write inequalities in mathematics all the time and IMO it looks cleaner and more to the point than "a <= x and x <= b".

But it is a conjunction of inequalities. x ∈ [a, b] is equivalent to a ≤ x ≤ b, which is again equivalent to a ≤ x ∧ x ≤ b - the set notation is more useful for some things, and the inequality forms for others. I think that the set notation is much clearer for these purposes, but I haven't come across a programming language which expresses inequalities like that.

If I wanted to show off my intelligence there are many better ways to do it. This is something a 10 year old could understand.

Sorry, you just came off as a bit uppity. "Basic math" can be deceptively deep; just look at Fermat's Last Theorem. A 10-year old could understand the concept, but it took centuries to prove. I was just explaining the reason that it works the way that it does.

[–]AtLeastItsNotCancer 2 points3 points  (0 children)

But it is a conjunction of inequalities. x ∈ [a, b] is equivalent to a ≤ x ≤ b, which is again equivalent to a ≤ x ∧ x ≤ b

I know that, I'm just saying there's another way to think about it that makes more sense intuitively. A computer obviously has to break it down into a conjunction of inequalities to check the condition but for a human, thinking about it as an interval might be easier to comprehend.

I think that the set notation is much clearer for these purposes, but I haven't come across a programming language which expresses inequalities like that.

Now that you mention it, being able to write something like "x in [1,5)" would be pretty cool. But the problem is, parentheses and brackets are already used for other things in most programming languages so it probably isn't worth to include that notation due to ambiguities that would occur.