[Math] Intervals: examples of open intervals; fencepost errors

Open intervals in programming are rare.

For example, if it's impossible to divide by 0 and infinity, the valid intervals for divisor are: (-inf, 0) and (0, +inf). Hence we include however small numbers but not zero. And however large numbers, but not infinity.


The major source of fencepost errors is a confusion between closed and half-open intervals.

If you're aware what intervals do you use in each loop, you'll reduce number of errors significantly.

Also, note that Edsger W. Dijkstra was a famous proponent of half-open intervals and arrays starting at zero index.

In his famous paper, he enumerates half-open, half-closed, closed and open intervals and offers to choose best suited for programming:

a) 		2 ≤ i < 13
b) 		1 < i ≤ 12
c) 		2 ≤ i ≤ 12
d) 		1 < i < 13

(the post first published at 20251219.)


List of my other blog posts. Subscribe to my news feed,
If you enjoy my work, you can support it on patreon.
Some time ago (before 24-Mar-2025) there was Disqus JS script for comments. I dropped it --- it was so motley, distracting, animated, with too much ads. I never liked it. Also, comments din't appeared correctly (Disqus was buggy). Also, my blog is too chamberlike --- not many people write comments here. So I decided to switch to the model I once had at least in 2020 --- send me your comments by email (don't forget to include URL to this blog post) and I will copy&paste it here manually.
Let's party like it's ~1993-1996, in this ultimate, radical and uncompromisingly primitive pre-web1.0-style blog and website. This website is best viewed under lynx/links/elinks/w3m.
Or use my zulip for feedback.