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

Define extrema behaviour

Open omus opened this issue 7 years ago • 2 comments

Currently when running extrema the following behaviour occurs:

julia> x = [Interval(1,3), Interval(2,6), Interval(3,5)]
3-element Array{Intervals.Interval{Int64},1}:
 [1 .. 3]
 [2 .. 6]
 [3 .. 5]

julia> extrema(x)
(Interval{Int64}(1, 3, Inclusivity(true, true)), Interval{Int64}(3, 5, Inclusivity(true, true)))

I would have expected the answer to have the interval with the smallest left-endpoint and the interval with the largest-right endpoint.

omus avatar Jul 13 '18 14:07 omus

I think the behaviour is coming from max:

julia> max(Interval(2,6), Interval(3,5))  # Expecting `Interval(2,6)`
Interval{Int64}(3, 5, Inclusivity(true, true))

julia> max(Interval(3,6), Interval(3,5))  # Expecting `Interval(3,6)`
Interval{Int64}(3, 5, Inclusivity(true, true))

julia> max(Interval(2,6), Interval(3,6))  # Either?
Interval{Int64}(3, 6, Inclusivity(true, true))

omus avatar Jul 13 '18 14:07 omus

julia> max(Interval(2,6), Interval(3,5))  # Expecting `Interval(2,6)`
Interval{Int64}(3, 5, Inclusivity(true, true))

Based solely on the documentation, this one definitely looks like a bug:

The standard < and > operators (which are not explicitly defined, but are derived from isless) simply compare the leftmost endpoint of the intervals, and are used for things like sort, min, max, etc.

(Emphasis mine.)

julia> max(Interval(3,6), Interval(3,5))  # Expecting `Interval(3,6)`
Interval{Int64}(3, 5, Inclusivity(true, true))

This one seems acceptable per the documentation though. Perhaps the documentation should be more specific, in any case.

ararslan avatar Jul 13 '18 19:07 ararslan