-
Notifications
You must be signed in to change notification settings - Fork 71
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
Inconsistency with in(x, ::Interval)
and iterate(::Interval)
#425
Comments
in(x, ::Interval)
and iterate(::interval)
in(x, ::Interval)
and iterate(::Interval)
OK, fair point I guess. |
That is the only reasonable definition of I don't propose another definition of |
Thanks for pointing me to https://github.com/gwater/NumberIntervals.jl . I suspected it would have the same inconsistency since julia> using NumberIntervals: NumberInterval
julia> in(0.5, NumberInterval(0.0, 1.0))
true
julia> my_in(element, collection) = any(==(element), collection)
my_in (generic function with 1 method)
julia> my_in(0.5, NumberInterval(0.0, 1.0))
missing |
I was curious about other interval packages, and it seems like the three others I found are not script: import Intervals
import IntervalSets
import ClosedIntervals
import NumberIntervals
import IntervalArithmetic
my_in(element, collection) = any(==(element), collection)
function exception_wrap(f)
function wrapped(args...)
try
return (Some(f(args...)), nothing)
catch e
return (nothing, e)
end
end
return wrapped
end
function test_in(needle, haystack)
_my_in = exception_wrap(my_in)
mi = _my_in(needle, haystack)
i = in(needle, haystack)
return (i, mi)
end
intervals = Any[ # avoid https://github.com/JuliaIntervals/IntervalArithmetic.jl/issues/426
Intervals.Interval(0, 1),
IntervalSets.Interval(0, 1),
ClosedIntervals.ClosedInterval(0, 1),
NumberIntervals.NumberInterval(0, 1),
IntervalArithmetic.Interval(0, 1),
]
println(stdout, "\n-----\n")
show(stdout, "text/plain", test_in.(Ref(0.5), intervals))
println(stdout, "\n-----\n")
show(stdout, "text/plain", test_in.(Ref(1.5), intervals)) |
(originally from JuliaReach/ReachabilityAnalysis.jl#373 (comment))
From doing
?in
To help explain, I'll define
which perhaps is more clear as
and "consistency", and following the documentation of
in
, means that one of two should be the case:my_in
errorsmy_in
returns the same answer asin
Interval
ofIntervalArithmetic.jl
wants to both be set and a<:Number
:and it's a fact of life (unfortunately? fortunately?) that
<:Number
s are singleton collections of themselves: https://github.com/JuliaLang/julia/blob/6614645892f03915e4f10b051df9a228c980abc8/base/number.jl#L233 and soOne possibility is to just document this. I'd be curious to see if it wreaks any havoc to define new methods on
Interval
(iterate
,length
,first
,last
, maybecopy
, ...) that error. This is safer and stricter, and ensures consistency within
.The text was updated successfully, but these errors were encountered: