IntervalArithmetic.jl icon indicating copy to clipboard operation
IntervalArithmetic.jl copied to clipboard

`setdiff` returns a disjoint representation, whereas `union` does not

Open goretkin opened this issue 3 years ago • 3 comments

This strikes me as inconsistent:

julia> union(interval(0, 1), interval(2, 3))
[0, 3]

julia> setdiff(interval(0, 3), interval(1,2))
2-element Array{Interval{Float64},1}:
 [0, 1]
 [2, 3]

goretkin avatar Nov 17 '20 00:11 goretkin

It's true that in some sense it's inconsistent, but it's what is useful. union here really means "interval hull". (There is also the synonym hull.)

If you want union to return a vector of intervals, that's a whole different world (which I have coded somewhere).

dpsanders avatar Nov 17 '20 00:11 dpsanders

I suppose there are two separate issues, one is consistency in which some operations have an implicit "hull" and others do not.

The other issue is about type closure. It would be good if e.g. (even assuming b and c are overlapping to remove the question about whether union should return a hull or a disjoint set)

setdiff(a, union(b,c)) == setdiff(setdiff(a, b), c))

but since setdiff(a, b) returns something that itself cannot carry the semantics of a union of intervals (Unless everywhere Array{Interval} means "union of itnervals", which is almost certainly not tenable).

So probably setdiff should return an object that can only mean "union of intervals".

goretkin avatar Nov 17 '20 01:11 goretkin

Yes, that's a good idea.

dpsanders avatar Nov 17 '20 03:11 dpsanders