-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for unbounded intervals #123
Comments
What was wrong with just using |
Note also |
|
The topics in this issue and #122(#121) are totally different. We just want unbounded intervals, and non-promoted |
Ah, I see the issue with Regarding
Is that not the desired behavior? |
It's okay to have |
Overall, I'd also favour having more and simpler concrete types over having a more complicated interval type that supports everything (like a swiss army knife of intervals). Code will be easier to write and easier to read. It does indeed require some thought about a good choice of abstract types to make it easy to write generic implementations at the right level. (I did not think about the suggestions.) |
Also, I'm beginning to wonder why being open and closed are type parameters, since it seems to lead to quite a few type-instabilities of set operations. I guess it is an optimization, to save on memory (storing two booleans) and possibly saving some if-else statements in set operations by using dispatch. |
The subtypes of I don't have use cases that require high-performance (with type-stability) with set operations, so the current implementation is enough for me. |
@dlfivefifty Is there any update on this? |
No |
Hmm, I wonder if rather than handling this in the type structure we could just support it through duck typing? Basically something like requiring methods for Pros:
Cons:
|
As discussed in #67 (comment), we currently don't support unbounded intervals.
This issue is a proposal for adding types such as
LeftUnboundedInterval{R,T}
RightUnboundedInterval{L,T}
ComplementInterval{L,R,T}
Define new concrete types, or allow a new type parameter?
We have the following two choices to implement unbounded intervals.
LeftUnboundedInterval{R, T}
andRightUnboundedInterval{L, T}
.:unbounded
. (This is the same approach as Intervals.jl)I prefer the first, because:
leftendpoint
andrightendpoint
seems verbose.in
method withInterval{:unbounded, :unbounded}
will cause some confusion.Where the proposed type
LeftUnboundedInterval{L,R,T}
is a subtype ofAbstractInterval{T}
.I think we need another abstract type just like
IntervalSets.TypedEndpointsInterval
.What should the set operator return?
i1 = RightUnboundedInterval{:open, Int}(3)
is a intervali2 = LeftUnboundedInterval{:closed, Int}(5)
is a intervalThen, what should
i1 ∪ i2
be? Should we define a new type forI prefer not to define the new type because:
2..1
is an example of an empty intervalin(::Interval{Int64, Unbounded, Unbounded})
method, already discussed abobe.Here, I propose adding a new type with$\{x \ | \ x < a \ \text{or} \ x > b\}$ , then the
ComplementInterval{L,R,T}
which represents sets such asComplementInterval(2,1)
represents the whole real numbers.With these methods and types, the following methods can be defined:
complement(::Interval)
type-stablecomplement(::LeftUnboundedInterval)
type-stablecomplement(::RightUnboundedInterval)
type-stalbeunion(::LeftUnboundedInterval, ::LeftUnboundedInterval)
type-stability depends on the boundariesunion(::RightUnboundedInterval, ::LeftUnboundedInterval)
type-stableunion(::LeftUnboundedInterval, ::RightUnboundedInterval)
type-stableunion(::RightUnboundedInterval, ::RightUnboundedInterval)
type-stability depends on the boundariesintersection(::LeftUnboundedInterval, ::LeftUnboundedInterval)
type-stability depends on the boundariesintersection(::RightUnboundedInterval, ::LeftUnboundedInterval)
type-stableintersection(::LeftUnboundedInterval, ::RightUnboundedInterval)
type-stableintersection(::RightUnboundedInterval, ::RightUnboundedInterval)
type-stability depends on the boundariesintersection(::Interval, ::LeftUnboundedInterval)
type-stability depends on the boundariesintersection(::Interval, ::LeftUnboundedInterval)
type-stability depends on the boundariesintersection(::Interval, ::RightUnboundedInterval)
type-stability depends on the boundariesintersection(::Interval, ::RightUnboundedInterval)
type-stability depends on the boundariesintersection(::LeftUnboundedInterval, ::Interval)
type-stability depends on the boundariesintersection(::RightUnboundedInterval, ::Interval)
type-stability depends on the boundariesintersection(::LeftUnboundedInterval, ::Interval)
type-stability depends on the boundariesintersection(::RightUnboundedInterval, ::Interval)
type-stability depends on the boundariesThe following methods might throw
ArgumentError
just likeunion(1..2, 3..4)
.union(::Interval, ::LeftUnboundedInterval)
type-stability depends on the boundariesunion(::Interval, ::LeftUnboundedInterval)
type-stability depends on the boundariesunion(::Interval, ::RightUnboundedInterval)
type-stability depends on the boundariesunion(::Interval, ::RightUnboundedInterval)
type-stability depends on the boundariesunion(::LeftUnboundedInterval, ::Interval)
type-stability depends on the boundariesunion(::RightUnboundedInterval, ::Interval)
type-stability depends on the boundariesunion(::LeftUnboundedInterval, ::Interval)
type-stability depends on the boundariesunion(::RightUnboundedInterval, ::Interval)
type-stability depends on the boundariesQuestions
ComplementInterval <: AbstractInterval
?complement(::ComplementInterval{:open,:closed})
be?Interval{:open,:closed}
; this impliesComplementInterval{:open,:closed}
is a complement ofInterval{:open,:closed}
Interval{:closed,:open}
; this implies the endpoints ofComplementInterval
are specified directly.TypedRightUnboundedInterval
,TypedLeftUnboundedInterval
, andTypedEndpointsComplementInterval
RightUnboundedInterval{L,T} <: TypedRightUnboundedInterval{L,T} <: AbstractInterval{T}
LeftUnboundedInterval{R,T} <: TypedLeftUnboundedInterval{R,T} <: AbstractInterval{T}
ComplementInterval{L,R,T} <: TypedEndpointsComplementInterval{L,R,T} <: AbstractInterval{T}
UnboundedInterval
UnboundedInterval{T} <: AbstractInterval{T}
RightUnboundedInterval{L,T} <: TypedRightUnboundedInterval{L,T} <: UnboundedInterval{T}
LeftUnboundedInterval{R,T} <: TypedLeftUnboundedInterval{R,T} <: UnboundedInterval{T}
ComplementInterval{L,R,T} <: TypedEndpointsComplementInterval{L,R,T} <: UnboundedInterval{T}
AbstractOrderedSet{T}
AbstractInterval{T} <: AbstractOrderedSet{T} <: Domain{T}
TypedEndpointsComplementInterval{L,R,T} <: AbstractOrderedSet{T} <: Domain{T}
Any feedback is welcomed!
(cc: @timholy @dlfivefifty @daanhb @omus)
The text was updated successfully, but these errors were encountered: