From 1754eecfb4b61e1a8833bcb4c845c5451ea6f51d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20H=C3=A9not?= <38465572+OlivierHnt@users.noreply.github.com> Date: Mon, 5 Feb 2024 08:39:16 -0600 Subject: [PATCH] Revert throwing an error for non-thin intervals (#625) --- src/intervals/interval_operations/boolean.jl | 3 +- src/intervals/real_interface.jl | 68 +++----------------- 2 files changed, 11 insertions(+), 60 deletions(-) diff --git a/src/intervals/interval_operations/boolean.jl b/src/intervals/interval_operations/boolean.jl index 5bcb391eb..a64978c75 100644 --- a/src/intervals/interval_operations/boolean.jl +++ b/src/intervals/interval_operations/boolean.jl @@ -348,7 +348,8 @@ Test whether `x` contains only `y`. """ isthin(x::BareInterval, y::Number) = inf(x) == sup(x) == y isthin(x::BareInterval, y::Complex) = isthin(x, real(y)) & iszero(imag(y)) -isthin(x::BareInterval, y::Interval) = throw(MethodError(isthin, (x, y))) +isthin(::BareInterval, ::Interval) = + throw(ArgumentError("`isthin` is purposely not supported for intervals. See instead `isequal_interval`")) function isthin(x::Interval, y::Number) isnai(x) && return false diff --git a/src/intervals/real_interface.jl b/src/intervals/real_interface.jl index bb0abfe8f..682e8c7ea 100644 --- a/src/intervals/real_interface.jl +++ b/src/intervals/real_interface.jl @@ -137,71 +137,21 @@ end ==(::Number, ::Interval) Test whether an interval is the singleton of a given number. In other words, the -result is true if and only if the interval contains only that number. This -function errors whenever the input interval is not a singleton. +result is true if and only if the interval contains only that number. !!! note Comparison between intervals is purposely disallowed. Indeed, equality between non-singleton intervals has distinct properties, notably ``x = y`` does not imply ``x - y = 0``. See instead [`isequal_interval`](@ref). """ -function Base.:(==)(x::BareInterval, y::Number) - isthin(x) || return throw(ArgumentError("`==` is only supported between thin intervals and numbers")) - return inf(x) == y -end -Base.:(==)(x::Number, y::BareInterval) = y == x -function Base.:(==)(x::Interval, y::Number) - isnai(x) && return false - return bareinterval(x) == y -end -Base.:(==)(x::Number, y::Interval) = y == x -Base.:(==)(x::BareInterval, y::Interval) = throw(MethodError(==, (x, y))) -Base.:(==)(x::Interval, y::BareInterval) = throw(MethodError(==, (x, y))) +Base.:(==)(x::Union{BareInterval,Interval}, y::Number) = isthin(x, y) +Base.:(==)(x::Number, y::Union{BareInterval,Interval}) = y == x -""" - iszero(::BareInterval) - iszero(::Interval) +# follows docstring of `Base.iszero` +Base.iszero(x::Union{BareInterval,Interval}) = isthinzero(x) -Test whether an interval is the singleton of zero. This function errors whenever -the input interval is not a singleton. -""" -function Base.iszero(x::BareInterval) - isthin(x) || return throw(ArgumentError("`iszero` is only supported for thin intervals")) - return iszero(inf(x)) -end -function Base.iszero(x::Interval) - isnai(x) && return false - return iszero(bareinterval(x)) -end - -""" - isone(::BareInterval) - isone(::Interval) +# follows docstring of `Base.isone` +Base.isone(x::Union{BareInterval,Interval}) = isthinone(x) -Test whether an interval is the singleton of one. This function errors whenever -the input interval is not a singleton. -""" -function Base.isone(x::BareInterval) - isthin(x) || return throw(ArgumentError("`isone` is only supported for thin intervals")) - return isone(inf(x)) -end -function Base.isone(x::Interval) - isnai(x) && return false - return isone(bareinterval(x)) -end - -""" - isinteger(::BareInterval) - isinteger(::Interval) - -Test whether an interval is the singleton of an integer. This function errors -whenever the input interval is not a singleton. -""" -function Base.isinteger(x::BareInterval) - isthin(x) || return throw(ArgumentError("`isinteger` is only supported for thin intervals")) - return isinteger(inf(x)) -end -function Base.isinteger(x::Interval) - isnai(x) && return false - return isinteger(bareinterval(x)) -end +# follows docstring of `Base.isinteger` +Base.isinteger(x::Union{BareInterval,Interval}) = isthininteger(x)