The rule for integer arithmetic to subtract two sets of X,Y is
X β Y := {x β y | x β X, y β Y }
but thatβs not what you want as it seems.
You can take ordered sets in your example, which allows you to set any occurrence of x==y as an arbitrary value in a JavaScript array and use it to separate it. But you do not need it.
The set difference {1...7}\{4...5} expands to {1,2,3,4,5,6,7}\{4,5} . As you can easily see, subtraction with the rule of the given arithmetic would leave {1,2,3,0,0,6,7} and with normal subtraction ( \ character) you would get {1,2,3,6,7} .
The established difference {12...14}\{11...20} expands to {12,13,14}\{11,12,13,14,15,16,17,18,19,20} ; given arithm. the difference is {-11,0,0,0, -15, -16, ..., - 20}, but normal addition-subtraction leaves the empty set {} .
Processing operations with an empty set is equivalent to the usual arithmetic {x}-{}={x} and {}-{x} = {-x} for arithmetic rules and {x}\{}={x} , {}\{x}= {} with the usual rules
So, what you should use here, according to your example, are normal typing rules. There is no need to expand the sets; they can be considered dense.
You can use relative differences (you can call them distances).
At {1...7}\{4...5} first start is small, then the second start and the first end are larger than the second end, which led to two different sets.
At {12...14}\{11...20} first start is larger than the second start, and the first end is lower than the second, which led to an empty set.
The third example uses an empty set rule.
Do you need an example fragment?