Length of symmetric difference of two intervals.

interval-arithmeticreal-analysis

I have two intervals characterized by the pairs $a,b$ and $c,d$, all numbers larger than zero:

$$S_1 = (\min(a,b), \max(a,b))$$
$$S_2 = (\min(c,d), \max(c,d))$$

The length $s$ of an interval is defined in the usual way: $s( (x,y)) = y-x$, so that $s(S_1) = |b-a|$ and $s(S_2) = |d-c|$, and the length of a union of disjoint intervals is the sum of lengths. The length does not change when using closed intervals.

My aim is to find a compact form for the length of the symmetric difference $\Delta$ of $S_1$ and $S_2$ (i.e. the union without the intersection; $S_1 \cup S_2 – S_1 \cap S_2$); that is, what is $s(S_1 \Delta S_2)$?


With a little trial and error, I've found the following formula that seems to work pretty generally:

$$s(S_1 \Delta S_2) = |\max(\min(a,b),\max(c,d)) – \max(\max(a,b),\min(c,d))| + |\min(\min(a,b),\max(c,d)) – \min(\max(a,b),\min(c,d))|$$

For example, with $(a,b) = (1,3)$ and $(c,d) = (2,5)$, the symmetric difference is $(1,2]\cup[3,5)$, and the length of the symmetric difference is $1+2 = 3$. The intuition behind this formula is that the first absolute value finds the "right overhang" (length of $[3,5)$, which is $2$) and the second absolute value finds the "left overhang" (length of $[1,2)$, which is $1$).

However, this formula seems more than a little unnecessarily complicated. Is there a simplification, especially one with fewer $\min$ and $\max$?

Best Answer

What about $$ s=\max\{a,b,c,d\}-\min\{a,b,c,d\}-|\max\{a,b,c,d\}-\min\{a,b,c,d\}-s(S_1)-s(S_2)|? $$

Related Question