IntervalArithmetic.jl
IntervalArithmetic.jl copied to clipboard
`setdiff` returns a disjoint representation, whereas `union` does not
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]
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).
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".
Yes, that's a good idea.