On closed range boundaries

Programmers often need to talk about ranges of values (whether or not the language at hand supports the concept explicitly). For example, given the Java array

String[] streetLines = new String[3];

an index i must satisfy

0 ≤ i < 3 (in normal Mathematical notation)


0 <= i && i < 3 (in Java notation)

to be a valid index on streetLines. But how does one read those expressions aloud?

I learned to read <= and as “at most” and >= and as “at least” from Dijkstra. Those readings have at least two benefits:

  1. They are quite natural. For example, the assertion

    there are at least six eggs left in the carton

    is at least as obvious in normal speech as the equivalent phrase

    there are six or more eggs in the carton

    and is probably much more obvous than other equivalent phrases, such as

    the number of eggs left in the carton is greater than or equal to six


    there are more than five eggs left in the carton

    even though we’ve seen the equivalent of those in code many times.

  2. They avoid introducing extraneous logical operators. The phrasing

    less than or equal to

    seems more complex than

    at most

    because it implies the use of disjunction (logical “or“) in its evaluation. The other equivalent phrase

    not greater than

    introduces negation into a simple comparison.

As a tiny “easter egg”, look for uses of “at least” en passant in the preceding few sentences! If they went by without being obvious, perhaps that serves as evidence of point 1 above. 😉

Trackbacks are closed, but you can post a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: