From 278ff17ac3e961d37e0421443398a241753dc7c5 Mon Sep 17 00:00:00 2001 From: schillic Date: Tue, 5 Mar 2024 19:42:21 +0100 Subject: [PATCH 1/3] fix piracy with in --- src/IntervalMatrices.jl | 3 ++- src/operations/setops.jl | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/IntervalMatrices.jl b/src/IntervalMatrices.jl index 93190a4a..791fb34f 100644 --- a/src/IntervalMatrices.jl +++ b/src/IntervalMatrices.jl @@ -51,11 +51,12 @@ if vIA >= v"0.22" end intersect(a::Interval{T}, b::Interval{S}) where {T,S} = intersect(promote(a, b)...) - Base.in(x::Number, y::Interval) = inf(y) <= x <= sup(y) else import IntervalArithmetic: ±, midpoint_radius issubset_interval(x::Interval, y::Interval) = issubset(x, y) + + in_interval(x::Number, y::Interval) = inf(y) <= x <= sup(y) end # ================================ diff --git a/src/operations/setops.jl b/src/operations/setops.jl index afff5030..7a0fc315 100644 --- a/src/operations/setops.jl +++ b/src/operations/setops.jl @@ -24,7 +24,7 @@ function ∈(M::AbstractMatrix, A::AbstractIntervalMatrix) m, n = size(A) @inbounds for j in 1:n for i in 1:m - if M[i, j] ∉ A[i, j] + if !in_interval(M[i, j], A[i, j]) return false end end From 6c25ca716b53ef9b67ce7459303d9ea92ca12aa5 Mon Sep 17 00:00:00 2001 From: schillic Date: Tue, 5 Mar 2024 19:53:48 +0100 Subject: [PATCH 2/3] fix piracy with intersect --- src/IntervalMatrices.jl | 12 ++---------- src/operations/setops.jl | 2 +- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/IntervalMatrices.jl b/src/IntervalMatrices.jl index 791fb34f..d32fc276 100644 --- a/src/IntervalMatrices.jl +++ b/src/IntervalMatrices.jl @@ -41,22 +41,14 @@ if vIA >= v"0.22" return size(A) == size(B) && all(map((a, b) -> isequal_interval(a, b), A, B)) end - function intersect(a::Interval{T}, b::Interval{T}) where {T} - lo = max(inf(a), inf(b)) - hi = min(sup(a), sup(b)) - if lo > hi - return emptyinterval(T) - end - return interval(lo, hi) - end - intersect(a::Interval{T}, b::Interval{S}) where {T,S} = intersect(promote(a, b)...) - else import IntervalArithmetic: ±, midpoint_radius issubset_interval(x::Interval, y::Interval) = issubset(x, y) in_interval(x::Number, y::Interval) = inf(y) <= x <= sup(y) + + intersect_interval(a::Interval, b::Interval) = intersect(a, b) end # ================================ diff --git a/src/operations/setops.jl b/src/operations/setops.jl index 7a0fc315..e136e09c 100644 --- a/src/operations/setops.jl +++ b/src/operations/setops.jl @@ -78,7 +78,7 @@ function ∩(A::IntervalMatrix, B::IntervalMatrix) @assert size(A) == size(B) "incompatible matrix sizes (A: $(size(A)), B: " * "$(size(B)))" - return IntervalMatrix(map((x, y) -> x ∩ y, A, B)) + return IntervalMatrix(map((x, y) -> intersect_interval(x, y), A, B)) end """ From caf083de9fcd58af4b155f80e5c0ef5a413bb5e0 Mon Sep 17 00:00:00 2001 From: schillic Date: Tue, 5 Mar 2024 20:02:39 +0100 Subject: [PATCH 3/3] =?UTF-8?q?avoid=20defining=20=C2=B1=20for=20Intervals?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/IntervalMatrices.jl | 5 ----- src/exponential.jl | 4 ++-- src/matrix.jl | 8 ++++---- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/IntervalMatrices.jl b/src/IntervalMatrices.jl index d32fc276..1da5c4f4 100644 --- a/src/IntervalMatrices.jl +++ b/src/IntervalMatrices.jl @@ -33,14 +33,9 @@ if vIA >= v"0.22" import Base: intersect export ±, midpoint_radius - function ±(x::Number, y::Number) - return x + interval(-y, y) - end - function Base.:(==)(A::AbstractMatrix{<:Interval}, B::AbstractMatrix{<:Interval}) return size(A) == size(B) && all(map((a, b) -> isequal_interval(a, b), A, B)) end - else import IntervalArithmetic: ±, midpoint_radius diff --git a/src/exponential.jl b/src/exponential.jl index 528ae115..a7d5c22b 100644 --- a/src/exponential.jl +++ b/src/exponential.jl @@ -96,7 +96,7 @@ function _exp_remainder(A::IntervalMatrix{T}, t, p; n=checksquare(A)) where {T} end M = exp(C * t) Y = M - Q - Γ = IntervalMatrix(fill(zero(T) ± one(T), (n, n))) + Γ = IntervalMatrix(fill(interval(-one(T), one(T)), (n, n))) E = Γ * Y return E end @@ -111,7 +111,7 @@ function _exp_remainder_series(A::IntervalMatrix{T}, t, p; n=checksquare(A)) whe @assert c < 1 "the remainder of the matrix exponential could not be " * "computed because a convergence condition is not satisfied: $c ≥ 1 " * "but it should be smaller than 1; try choosing a larger order" - Γ = IntervalMatrix(fill(zero(T) ± one(T), (n, n))) + Γ = IntervalMatrix(fill(interval(-one(T), one(T)), (n, n))) return Γ * ((nA * t)^(p + 1) * (1 / factorial(p + 1) * 1 / (1 - c))) end diff --git a/src/matrix.jl b/src/matrix.jl index a45dc093..d4d22108 100644 --- a/src/matrix.jl +++ b/src/matrix.jl @@ -22,10 +22,10 @@ parametrized in the number field, the interval type, and the matrix type. ### Examples ```jldoctest -julia> A = IntervalMatrix([-0.9±0.1 0±0; 0±0 -0.9±0.1]) +julia> A = IntervalMatrix([-1 .. -0.8 0 .. 0; 0 .. 0 -1 .. -0.8]) 2×2 IntervalMatrix{Float64, Interval{Float64}, Matrix{Interval{Float64}}}: - [-1.00001, -0.7999999] [0.0, 0.0] - [0.0, 0.0] [-1.00001, -0.7999999] + [-1.0, -0.7999999] [0.0, 0.0] + [0.0, 0.0] [-1.0, -0.7999999] ``` An interval matrix proportional to the identity matrix can be built using the @@ -182,7 +182,7 @@ function ±(C::MT, S::MT) where {T,MT<:AbstractMatrix{T}} "radii matrix should match, but they are $(size(C)) " * "and $(size(S)) respectively")) - return IntervalMatrix(map((x, y) -> x ± y, C, S)) + return IntervalMatrix(map((x, y) -> interval(x - y, x + y), C, S)) end for op in (:Adjoint, :Bidiagonal, :Diagonal, :Hermitian,