Skip to content

Commit de1cc11

Browse files
dpsanderslbenet
authored andcommitted
Add "in" for IntervalBox (#244)
* Add explicit definition for ∈ of IntervalBox * Import alias for 'in' * Throw ArgumentError for for IntervalBox * Fix test * Allow general AbstractVector for membership of IntervalBox; add tests * Make X in Y an error for X and Y intervals * Add tests * Add explicit definition for subseteq of two complex intervals
1 parent f67c819 commit de1cc11

File tree

6 files changed

+26
-1
lines changed

6 files changed

+26
-1
lines changed

src/IntervalArithmetic.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import Base:
2828
union, intersect, isempty,
2929
convert, promote_rule, eltype, size,
3030
BigFloat, float, widen, big,
31-
, , , , eps,
31+
, , , , , eps,
3232
floor, ceil, trunc, sign, round,
3333
expm1, log1p,
3434
precision,

src/intervals/complex.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2+
(x::Complex{Interval{T}}, y::Complex{Interval{T}}) where T = real(x) real(y) && imag(x) imag(y)
3+
14
function ^(x::Complex{Interval{T}}, n::Integer) where {T}
25
if n < 0
36
return inv(x)^n

src/intervals/set_operations.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ function in(x::T, a::Interval) where T<:Real
1313
a.lo <= x <= a.hi
1414
end
1515

16+
in(x::Interval, y::Interval) = throw(ArgumentError("$x$y is not defined"))
17+
1618
in(x::T, a::Complex{<:Interval}) where T<:Real = x real(a) && 0 imag(a)
1719
in(x::Complex{T}, a::Complex{<:Interval}) where T<:Real = real(x) real(a) && imag(x) imag(a)
1820

src/multidim/intervalbox.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ big(X::IntervalBox) = big.(X)
6767
(X::IntervalBox{N,T}, Y::IntervalBox{N,T}) where {N,T} =
6868
IntervalBox(X.v .∪ Y.v)
6969

70+
(X::AbstractVector, Y::IntervalBox{N,T}) where {N,T} = all(X .∈ Y)
71+
(X, Y::IntervalBox{N,T}) where {N,T} = throw(ArgumentError("$X$Y is not defined"))
72+
73+
7074
#=
7175
On Julia 0.6 can now write
7276
∩{N,T}(X::IntervalBox{N,T}, Y::IntervalBox{N,T}) = IntervalBox(NTuple{N, Interval{Float64}}( (X[i] ∩ Y[i]) for i in 1:N))

test/interval_tests/consistency.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ setprecision(Interval, Float64)
8383
@test 0.1 in @interval(0.1)
8484
@test !(-Inf entireinterval())
8585
@test !(Inf entireinterval())
86+
87+
@test_throws ArgumentError (3..4) (3..4)
8688
end
8789

8890
@testset "Inclusion tests" begin

test/multidim_tests/multidim.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,18 @@ end
218218
@test diam.(X) == SVector(diam(X[1]), diam(X[2]))
219219
end
220220

221+
@testset "" begin
222+
X = IntervalBox(3..4, 5..6)
223+
@test mid(X) X
224+
@test mid(X, 0.75) X
225+
226+
@test (zero(mid(X)) X) == false
227+
@test zero(mid(X)) X
228+
229+
@test_throws ArgumentError (3..4) X
230+
231+
@test_throws ArgumentError [3..4, 5..6] X
232+
233+
end
234+
221235
end

0 commit comments

Comments
 (0)