Skip to content
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

Revert throwing an error for non-thin intervals #625

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/intervals/interval_operations/boolean.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
68 changes: 9 additions & 59 deletions src/intervals/real_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading