Skip to content

Instantly share code, notes, and snippets.

@CMCDragonkai
Created June 12, 2016 13:25
Show Gist options
  • Save CMCDragonkai/55515bbab9ed274d3069110a9f3f5da4 to your computer and use it in GitHub Desktop.
Save CMCDragonkai/55515bbab9ed274d3069110a9f3f5da4 to your computer and use it in GitHub Desktop.
Math: Interval Notation (in histograms, programming.. etc)

Interval Notation

(0,1) = 0 < x < 1
[0,1) = 0 <= x < 1
(0,1] = 0 < x <= 1
[0,1] = 0 <= x <= 1

The problem with the open (x,y) and closed [x,y], is that when used in a sequence or a list (which happens in histograms), they don't allow you to represent a continuous unique interval mapping of a real number function. By continuous I mean that the intervals capture every real number, and by unique, I mean that every number is captured by 1 and only 1 interval.

For an sequence of open intervals: (0,1) (1,2)..., it gives us 0 < _ < 1 < _ < 2. The list of intervals can't represent 1. If you tried (0,1) (0.9999999... it still won't work, since it's no longer a unique mapping.

For a sequence of closed intervals: [0,1] [2,3]..., it doesn't represent anything between 1 and 2. But also even if you tried [0,1] [1.0000000..., it wouldn't work because you'll never finish writing down the first number of the second interval.

Finally, the semi-open intervals can do this easily, but there does seem to be a preference of left inclusive instead of the right inclusive version. This might be because certain groups of people have left to right bias in their written language. An infinite sequence can be done simply by doing [0,1) [1,2)....

So it turns out that the left inclusive right inclusive form appears in many programming languages, and in my opinion should be the default standard for any expressions of intervals for graphs and specifically histograms.

Note that Haskell uses closed form in its [1..10], while SQL uses closed form in its BETWEEN operator, but Python uses left inclusive right exclusive in its range and xrange procedures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment