JuliaApproximation / DomainSets.jl

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

`RealNumbers` vs `RealLine` #165

Open Vaibhavdixit02 opened 4 months ago

Vaibhavdixit02 commented 4 months ago

I am a little confused about what the difference between the two is meant to be? What tripped me was this subset checking of HalfLine for RealNumbers or RealLine

julia> using DomainSets

julia> d1 = DomainSets.RealNumbers()
RealNumbers()

julia> d2 = DomainSets.HalfLine()
0.0 .. Inf (closed-open) (HalfLine)

julia> issubset(d2, d1)
false

julia> d1 = DomainSets.RealLine()
-Inf .. Inf (open) (RealLine)

julia> issubset(d2, d1)
true
daanhb commented 4 months ago

That's a good point, thanks for raising the issue. I guess the short answer is that these two domains were developed at different times in different contexts. But they should interoperate better.

The technical reason that one works with HalfLine does and the other one doesn't, is that RealLine is implemented as a subtype of an interval and RealNumbers isn't. One improvement may be to implement canonicaldomain for RealNumbers and have it return a RealLine. In that case various fallbacks will start to work and produce better answers.

Yet that wouldn't work for the other sets, i.e., one might also want that the rational numbers are a subset of the real line. Functionality like isequaldomain falls back to issubset, so if the various issubset dependencies are added things should improve. That's probably the way to go: to implement issubset for combinations of the number sets with an interval.

Separately, one can wonder whether the package needs both RealLine and RealNumbers. There are some subtle differences, though. The RealNumbers type really just wraps the isreal function, whereas RealLine is an interval.

daanhb commented 4 months ago

I'll put this on a todo list. Feel free to have a go at it if you like @Vaibhavdixit02. I'm thinking of implementations like the one here: https://github.com/JuliaApproximation/DomainSets.jl/blob/4e36278622df67839cea860a5d0f958c849db988/src/domains/interval.jl#L422

Functions to look at include intersectdomain, setdiffdomain, uniondomain and issubset_domain.

daanhb commented 4 months ago

Coming back to the original question/confusion:

For now, RealLine is better supported.