JuliaApproximation / DomainSets.jl

A Julia package for describing domains as continuous sets of elements
MIT License
72 stars 12 forks source link

Why is a union of disjoint sets (intervals) not supported? #40

Closed vincentcp closed 4 years ago

vincentcp commented 5 years ago
julia> union(Interval(-1.0,-0.5),Interval(-0.2,0.5))
ERROR: ArgumentError: Cannot construct union of disjoint sets.

julia> DomainSets.UnionDomain(Interval(-1.0,-0.5),Interval(-0.2,0.5))
a union of 2 domains:
    1.  : -1.0..-0.5
    2.  : -0.2..0.5
dlfivefifty commented 5 years ago

Because it’s inherited from IntervalSets.jl, where type stability is necessary. It’s not clear what the best solution is: the alternatives would be to always return a UnionDomain

daanhb commented 4 years ago

Right, IntervalSets.jl has chosen to remain type-stable by only ever returning a single interval when using union. We can't really change that behaviour in DomainSets.jl, otherwise behaviour depends on whether users loaded our package or not. This does mean, unfortunately, that one can not rely on union always working. The UnionDomain constructor does always work, but it doesn't simplify (i.e. it won't fuse overlapping intervals into one).

This leaves room for a uniondomain function which attempts to simplify before falling back to UnionDomain. But that won't map to the infix operator for unions.

Unfortunately, I don't think the list of domains for which union can be both simplifying and type-stable is very long (overlapping intervals is one... anything else?). So, not ideal, leaving the issue open :-)

daanhb commented 4 years ago

The situation has not changed, it seems clear we are not going to diverge from what IntervalSets does. Closing this for now.