Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are "not greater/less" (e.g. "!>" or "!<") operators not used in most programming languages

I understand that you can get the same behavior by using <= or !(x > y) but I usually rather think in terms of not greater instead of less than or equal, so having something like !> and !< would actually be really neat to have for me and would match the != operator perfectly.

The !(x > y) syntax requires more characters and reads: not: x is greater than y, which is unhandy and very unlike natural speech.

I have never seen !< or !> operators anywhere, but have been wondering ever since I started programming why they are not supported. Are there any reasons why not?

like image 722
stimulate Avatar asked Nov 28 '25 03:11

stimulate


1 Answers

Using the least number of logical and comparison operators, and those the most closest to classic math and logic makes it simpler to reason about conditions.

There were programming languages like Natural and COBOL with operators like NOT LESS THAN, but reasoning about (a !< b) when thinking over a complex condition is much more difficult than !(a < b), which is equivalent to (a >= b).

An example:

!(!(a < b) && !(a > c))

Is equivalent to:

!((a >= b) && (a <= c))

which translates to:

(a < b) || (a > c)

There's nothing to gain from !((a !< b) && (a !> c))?

like image 62
Apalala Avatar answered Nov 29 '25 22:11

Apalala



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!