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

Extend boolean functions for intervals to numbers #623

Closed
wants to merge 5 commits into from
Closed
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
55 changes: 52 additions & 3 deletions src/intervals/interval_operations/boolean.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
# Some other (non required) related functions are also present, as well as some
# of the "Recommended operations" (Section 10.6.3)

# used internally, equivalent to `<` but with `(Inf < Inf) == true`
_strictlessprime(x::Real, y::Real) = (x < y) | ((isinf(x) | isinf(y)) & (x == y))
#

_strictlessprime(x::Real, y::Real) = _strictlessprime(default_flavor(), x, y)
_strictlessprime(::Flavor{:set_based}, x::Real, y::Real) =
(x < y) | ((isinf(x) | isinf(y)) & (x == y)) # equivalent to `<` but with `(Inf < Inf) == true`

#

"""
isequal_interval(x, y)
Expand All @@ -28,6 +33,8 @@ isequal_interval(x::Real, y::Complex) = isequal_interval(x, real(y)) & isthinzer

isequal_interval(x) = Base.Fix2(isequal_interval, x)

isequal_interval(x::Number, y::Number) = isequal_interval(interval(x), interval(y))

"""
issubset_interval(x, y)

Expand All @@ -47,6 +54,8 @@ issubset_interval(x::Complex, y::Complex) = issubset_interval(real(x), real(y))
issubset_interval(x::Complex, y::Real) = issubset_interval(real(x), y) & isthinzero(imag(x))
issubset_interval(x::Real, y::Complex) = issubset_interval(x, real(y)) & in_interval(0, imag(y))

issubset_interval(x::Number, y::Number) = issubset_interval(interval(x), interval(y))

"""
isinterior(x, y)

Expand Down Expand Up @@ -78,6 +87,8 @@ isinterior(x::Complex, y::Complex) =
isinterior(x::Complex, y::Real) = isinterior(real(x), y) & isthinzero(imag(x))
isinterior(x::Real, y::Complex) = isinterior(x, real(y)) & in_interval(0, imag(y))

isinterior(x::Number, y::Number) = isinterior(interval(x), interval(y))

"""
isstrictsubset(x, y)

Expand All @@ -100,6 +111,8 @@ isstrictsubset(x::Complex, y::Complex) =
isstrictsubset(x::Complex, y::Real) = isstrictsubset(real(x), y) & isthinzero(imag(x))
isstrictsubset(x::Real, y::Complex) = isstrictsubset(x, real(y)) & in_interval(0, imag(y))

isstrictsubset(x::Number, y::Number) = isstrictsubset(interval(x), interval(y))

"""
isweakless(x, y)

Expand All @@ -115,6 +128,8 @@ function isweakless(x::Interval, y::Interval)
return isweakless(bareinterval(x), bareinterval(y))
end

isweakless(x::Number, y::Number) = isweakless(interval(x), interval(y))

"""
isstrictless(x, y)

Expand All @@ -123,14 +138,16 @@ Test whether `inf(x) < inf(y)` and `sup(x) < sup(y)`, where `<` is replaced by

Implement the `strictLess` function of the IEEE Standard 1788-2015 (Table 10.3).
"""
isstrictless(x::BareInterval, y::BareInterval) = # this may be flavor dependent? Should _strictlessprime be < for cset flavor?
isstrictless(x::BareInterval, y::BareInterval) =
_strictlessprime(inf(x), inf(y)) & _strictlessprime(sup(x), sup(y))

function isstrictless(x::Interval, y::Interval)
isnai(x) | isnai(y) && return false
return isstrictless(bareinterval(x), bareinterval(y))
end

isstrictless(x::Number, y::Number) = isstrictless(interval(x), interval(y))

"""
precedes(x, y)

Expand All @@ -145,6 +162,8 @@ function precedes(x::Interval, y::Interval)
return precedes(bareinterval(x), bareinterval(y))
end

precedes(x::Number, y::Number) = precedes(interval(x), interval(y))

"""
strictprecedes(x, y)

Expand All @@ -159,6 +178,8 @@ function strictprecedes(x::Interval, y::Interval)
return strictprecedes(bareinterval(x), bareinterval(y))
end

strictprecedes(x::Number, y::Number) = strictprecedes(interval(x), interval(y))

"""
isdisjoint_interval(x, y)

Expand All @@ -177,6 +198,8 @@ end
isdisjoint_interval(x::Complex, y::Complex) =
isdisjoint_interval(real(x), real(y)) | isdisjoint_interval(imag(x), imag(y))

isdisjoint_interval(x::Number, y::Number) = isdisjoint_interval(interval(x), interval(y))

"""
in_interval(x, y)

Expand Down Expand Up @@ -207,6 +230,8 @@ in_interval(x::Number, y::Complex) = in_interval(x, real(y)) & in_interval(0, im

in_interval(x) = Base.Fix2(in_interval, x)

in_interval(x::Number, y::Number) = in_interval(interval(x), interval(y))

"""
isempty_interval(x)

Expand All @@ -223,6 +248,8 @@ end

isempty_interval(x::Complex) = isempty_interval(real(x)) & isempty_interval(imag(x))

isempty_interval(x::Number) = isempty_interval(interval(x))

"""
isentire_interval(x)

Expand All @@ -239,6 +266,8 @@ end

isentire_interval(x::Complex) = isentire_interval(real(x)) & isentire_interval(imag(x))

isentire_interval(::Number) = false

"""
isnai(x)

Expand All @@ -250,6 +279,8 @@ isnai(x::Interval) = decoration(x) == ill

isnai(x::Complex) = isnai(real(x)) & isnai(imag(x))

isnai(x::Number) = isnai(interval(x))

"""
isbounded(x)

Expand All @@ -264,6 +295,8 @@ end

isbounded(x::Complex) = isbounded(real(x)) & isbounded(imag(x))

isbounded(x::Number) = isbounded(interval(x))

"""
isunbounded(x)

Expand All @@ -278,6 +311,8 @@ end

isunbounded(x::Complex) = isunbounded(real(x)) | isunbounded(imag(x))

isunbounded(x::Number) = isunbounded(interval(x))

"""
iscommon(x)

Expand All @@ -295,6 +330,8 @@ end

iscommon(x::Complex) = iscommon(real(x)) & iscommon(imag(x))

iscommon(x::Number) = iscommon(interval(x))

"""
isatomic(x)

Expand All @@ -312,6 +349,8 @@ end

isatomic(x::Complex) = isatomic(real(x)) & isatomic(imag(x))

isatomic(x::Number) = isatomic(interval(x))

"""
isthin(x)

Expand All @@ -328,6 +367,8 @@ end

isthin(x::Complex) = isthin(real(x)) & isthin(imag(x))

isthin(x::Number) = isthin(interval(x))

"""
isthin(x, y)

Expand All @@ -347,6 +388,8 @@ isthin(x::Number, y::Complex) = isthin(real(x), real(y)) & iszero(imag(y))

isthin(x::BareInterval, y::Interval) = throw(MethodError(isthin, (x, y)))

isthin(x::Number, y::Number) = isthin(interval(x), y)

"""
isthinzero(x)

Expand All @@ -361,6 +404,8 @@ end

isthinzero(x::Complex) = isthinzero(real(x)) & isthinzero(imag(x))

isthinzero(x::Number) = isthinzero(interval(x))

"""
isthinone(x)

Expand All @@ -375,6 +420,8 @@ end

isthinone(x::Complex) = isthinone(real(x)) & isthinzero(imag(x))

isthinone(x::Number) = isthinone(interval(x))

"""
isthininteger(x)

Expand All @@ -388,3 +435,5 @@ function isthininteger(x::Interval)
end

isthininteger(x::Complex) = isthininteger(real(x)) & isthinzero(imag(x))

isthininteger(x::Number) = isthininteger(interval(x))
Loading
Loading