-
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
Ensure boolean functions error for non-thin intervals #613
Conversation
Naive question: why is it better to return an error rather than simply |
It's definitely not a naive question. Last time @Kolaru and I talked, we thought that using One alternative would be to define the following: function Base.iszero(x::BareInterval)
if isthin(x)
return iszero(inf(x))
else
in_interval(0, x) || return false
@warn "the interval contains 0 but is not thin, this may be ambiguous"
return true
end
end But then again, one may be annoyed to see a bunch of warnings flooding the REPL... An other argument in favour of not throwing an error is that the docstring for |
Thanks for the answer. I would be in favor of having |
Sounds good to me, especially due to Julia's docstring (btw this discussion should also be applicable for @Kolaru you often come up with good corner cases, what's your take on this? |
A typical example that stresses me out would be
Then By breaking all comparisons, we are doing our best to forbid non-continuous functions, that we have no way do detect anyway. |
Indeed; throwing an error gives us a guardrail in this case. That being said, not taking into account the decoration because there is nothing we can do here, such a function does the expected thing according to the docstring It makes me want to have an @safe function foo(x)
if iszero(x)
# return something
elseif x == g(x)
# return something else
elseif 1 < x < 4
# return yet an other thing
end
end to turn it into function foo(x)
if isthinzero(x)
# return something
elseif isequal_interval(x, g(x))
# return something else
elseif isinterior(x, interval(1, 4))
# return yet an other thing
end
end |
If we want to over-engineer, I am still dreaming about function piecewise(x)
if x < 0.2
return f(x)
else
return g(x)
end
end becoming automatically function piecewise(x)
hull(
f(intersect(x, interval(-Inf, 0.2))),
g(intersect(x, interval(0.2, Inf)))
)
end By the way in your example you should have (for full correctness) function foo(x)
if isthinzero(x)
# return something
elseif isthin(x) && inf(x) == g(x)
# return something else
elseif isinterior(x, interval(1, 4))
# return yet an other thing
else
# Probably an error to fall back to
end
end |
Yea that is probably too much to ask 🙂 Actually I did mean that
|
No description provided.