From 30729606f9c3cfae0101200e35c33369ef71f34b Mon Sep 17 00:00:00 2001 From: David Sanders Date: Sun, 26 May 2024 18:42:31 -0500 Subject: [PATCH] Replace a.lo with inf(a) and similarly for .hi and sup --- examples/examples.jl | 2 +- src/IntervalContractors.jl | 4 +++- src/arithmetic.jl | 2 +- src/extrema.jl | 24 ++++++++++++------------ src/inverse_trig.jl | 8 ++++---- src/powers.jl | 2 +- src/transformations.jl | 4 ++-- src/trig.jl | 4 ++-- test/Non1788tests/exponential.jl | 2 +- test/Non1788tests/extrema.jl | 2 +- test/Non1788tests/hyperbolic.jl | 2 +- test/Non1788tests/inv_hyperbolic.jl | 2 +- test/Non1788tests/inv_rev.jl | 2 +- test/Non1788tests/inv_trig.jl | 2 +- test/Non1788tests/script.jl | 2 +- 15 files changed, 33 insertions(+), 31 deletions(-) diff --git a/examples/examples.jl b/examples/examples.jl index 049ab3e..ef3dcf0 100644 --- a/examples/examples.jl +++ b/examples/examples.jl @@ -41,7 +41,7 @@ function cube0(X::IntervalBox) # contractor for y=x^3, x>=0 x = x ⊓ (0..∞) y = y ⊓ (x ^ 3) - x = x ⊓ Interval(y.lo ^ (1/3), y.hi^(1/3)) # not rigorous! + x = x ⊓ Interval(inf(y) ^ (1/3), sup(y)^(1/3)) # not rigorous! return x × y end diff --git a/src/IntervalContractors.jl b/src/IntervalContractors.jl index 0dc70ea..3346acc 100644 --- a/src/IntervalContractors.jl +++ b/src/IntervalContractors.jl @@ -15,11 +15,13 @@ export plus_rev, minus_rev, inv_rev, mul_rev_IEEE1788, mul_rev_to_pair, pow_rev1, pow_rev2 -using IntervalArithmetic +using IntervalArithmetic, IntervalArithmetic.Symbols +using IntervalBoxes const half_pi = ExactReal(0.5) * interval(pi) const two_pi = ExactReal(2.0) * interval(pi) +const ∞ = Inf # # Base.:⊔(f::Function, g::Function) = X -> ( f(X) ⊔ g(X) ) # Base.:⊓(f::Function, g::Function) = X -> ( f(X) ⊓ g(X) ) # or f(g(X)) for contractors diff --git a/src/arithmetic.jl b/src/arithmetic.jl index 5c77203..41e883d 100644 --- a/src/arithmetic.jl +++ b/src/arithmetic.jl @@ -129,7 +129,7 @@ The triplet `(a, b_new, n)` where - `a` and `n` are unchanged - `b_new` is the interval hull of the set ``{x ∈ b : xⁿ ∈ a}`` """ -function power_rev(a::Interval{T}, b::Interval{T}, n::Integer) where T # a = b^n, log(a) = n.log(b), b = a^(1/n) +function power_rev(a::Interval{T}, b::Interval{T}, n::Integer) where T # a = b^n, log(a) = inf(n)g(b), b = a^(1/n) if iszero(n) 1 ∈ a && return (a, entireinterval(T) ⊓ b, n) diff --git a/src/extrema.jl b/src/extrema.jl index abc51a2..abcc78f 100644 --- a/src/extrema.jl +++ b/src/extrema.jl @@ -3,13 +3,13 @@ Reverse max """ function max_rev(a::Interval, b::Interval, c::Interval) # a = max(b,c) - B_lo = b.lo; B_hi = b.hi; - C_lo = c.lo; C_hi = c.hi; + B_lo = inf(b); B_hi = sup(b); + C_lo = inf(c); C_hi = sup(c); - (b.lo > c.lo) && (B_lo = max(b.lo,a.lo)) - (b.lo < c.lo) && (C_lo = max(c.lo,a.lo)) - (b.hi > c.hi) && (B_hi = min(b.hi,a.hi)) - (b.hi < c.hi) && (C_hi = min(c.hi,a.hi)) + (inf(b) > sup(c)) && (B_lo = max(inf(b),inf(a))) + (inf(b) < inf(c)) && (C_lo = max(inf(c),inf(a))) + (sup(b) > sup(c)) && (B_hi = min(sup(b),sup(a))) + (sup(b) < sup(c)) && (C_hi = min(sup(c),sup(a))) if isempty(b) isempty(c) && (return a, ∅, ∅) @@ -26,13 +26,13 @@ Reverse min """ function min_rev(a::Interval, b::Interval, c::Interval) - B_lo = b.lo; B_hi = b.hi; - C_lo = c.lo; C_hi = c.hi; + B_lo = inf(b); B_hi = sup(b); + C_lo = inf(c); C_hi = sup(c); - (b.lo > c.lo) && (B_lo = max(c.lo,a.lo)) - (b.lo < c.lo) && (C_lo = max(b.lo,a.lo)) - (b.hi > c.hi) && (B_hi = min(c.hi,a.hi)) - (b.hi < c.hi) && (C_hi = min(b.hi,a.hi)) + (inf(b) > inf(c)) && (B_lo = max(inf(c),inf(a))) + (inf(b) < inf(c)) && (C_lo = max(inf(b),inf(a))) + (sup(b) > sup(c)) && (B_hi = min(sup(c),sup(a))) + (sup(b) < sup(c)) && (C_hi = min(sup(b),sup(a))) if isempty(b) isempty(c) && (return a, ∅, ∅) diff --git a/src/inverse_trig.jl b/src/inverse_trig.jl index 8bcd938..85e944e 100644 --- a/src/inverse_trig.jl +++ b/src/inverse_trig.jl @@ -1,7 +1,7 @@ function asin!(X::IntervalBox) x, y = X - h = half_pi.lo + h = inf(half_pi) y_new = y ⊓ Interval(-h, h) # range of asin x_new = sin(y_new) @@ -13,7 +13,7 @@ Reverse `asin`. """ function asin_rev(y::Interval, x::Interval) # y = asin(x) - h = half_pi.lo + h = inf(half_pi) y_new = y ⊓ Interval(-h, h) # range of asin x_new = sin(y_new) @@ -25,7 +25,7 @@ end Reverse `acos`. """ function acos_rev(y::Interval, x::Interval) - y_new = y ⊓ Interval(0.0,two_pi.hi) + y_new = y ⊓ Interval(0.0,sup(two_pi)) x_new = x ⊓ cos(y_new) return y_new, x_new @@ -38,7 +38,7 @@ Inverse of `y = atan(x)`. Returns the new `y` and `x`. """ function atan_rev(y::Interval, x::Interval) - y_new = y ⊓ Interval(-half_pi.hi, half_pi.hi) + y_new = y ⊓ Interval(-sup(half_pi), sup(half_pi)) x_new = x ⊓ tan(y_new) return y_new, x_new diff --git a/src/powers.jl b/src/powers.jl index 58a743a..31d022b 100644 --- a/src/powers.jl +++ b/src/powers.jl @@ -30,7 +30,7 @@ function cube_pos(X::IntervalBox) # contractor for y=x^3, x>=0 x = x ⊓ (0..∞) y = y ⊓ (x ^ 3) - x = x ⊓ Interval(y.lo ^ (1/3), y.hi^(1/3)) # not rigorous! + x = x ⊓ Interval(inf(y) ^ (1/3), sup(y)^(1/3)) # not rigorous! return x × y end diff --git a/src/transformations.jl b/src/transformations.jl index aefd68a..a03cfa7 100644 --- a/src/transformations.jl +++ b/src/transformations.jl @@ -6,8 +6,8 @@ Return the integers enclosed in the interval `x`. """ function integer_contractor(x::Interval) - a = floor(x.lo)+1 - b = floor(x.hi) + a = floor(inf(x))+1 + b = floor(sup(x)) a > b && return emptyinterval(x) diff --git a/src/trig.jl b/src/trig.jl index fe60047..dcde8fe 100644 --- a/src/trig.jl +++ b/src/trig.jl @@ -8,7 +8,7 @@ function sin_main(X::IntervalBox) x, y = X - x_range = Interval(-half_pi.hi, half_pi.hi) + x_range = Interval(-sup(half_pi), sup(half_pi)) y_range = -1..1 x = x ⊓ x_range @@ -126,7 +126,7 @@ function tan_main(X::IntervalBox) x, y = X - x_range = Interval(-half_pi.hi, half_pi.hi) + x_range = Interval(-sup(half_pi), sup(half_pi)) x = x ⊓ x_range diff --git a/test/Non1788tests/exponential.jl b/test/Non1788tests/exponential.jl index 783b942..1873273 100644 --- a/test/Non1788tests/exponential.jl +++ b/test/Non1788tests/exponential.jl @@ -11,7 +11,7 @@ setprecision(Interval, Float64) # Using approximate checks for validaty update later? import Base.isapprox -isapprox(x::Interval,y::Interval) = isapprox(x.lo,y.lo,atol=1E-4) && isapprox(x.hi,y.hi,atol=1E-4) +isapprox(x::Interval,y::Interval) = isapprox(inf(x),inf(y),atol=1E-4) && isapprox(sup(x),sup(y),atol=1E-4) @testset "exp2_rev_test" begin @test exp2_rev(∅, entireinterval(Float64))[2] == ∅ diff --git a/test/Non1788tests/extrema.jl b/test/Non1788tests/extrema.jl index 0b59d78..6d23c29 100644 --- a/test/Non1788tests/extrema.jl +++ b/test/Non1788tests/extrema.jl @@ -10,7 +10,7 @@ setprecision(Interval, Float64) # Using approximate checks for validaty update later? import Base.isapprox -isapprox(x::Interval,y::Interval) = isapprox(x.lo,y.lo,atol=1E-4) && isapprox(x.hi,y.hi,atol=1E-4) +isapprox(x::Interval,y::Interval) = isapprox(inf(x),inf(y),atol=1E-4) && isapprox(sup(x),sup(y),atol=1E-4) @testset "max_rev_test" begin @test max_rev(∅, entireinterval(Float64),entireinterval(Float64))[2] == Interval(-∞, ∞) diff --git a/test/Non1788tests/hyperbolic.jl b/test/Non1788tests/hyperbolic.jl index d098581..7754ed1 100644 --- a/test/Non1788tests/hyperbolic.jl +++ b/test/Non1788tests/hyperbolic.jl @@ -11,7 +11,7 @@ setprecision(Interval, Float64) # Using approximate checks for validaty update later? import Base.isapprox -isapprox(x::Interval,y::Interval) = isapprox(x.lo,y.lo,atol=1E-4) && isapprox(x.hi,y.hi,atol=1E-4) +isapprox(x::Interval,y::Interval) = isapprox(inf(x),inf(y),atol=1E-4) && isapprox(sup(x),sup(y),atol=1E-4) @testset "sinh_rev_test" begin @test isapprox(sinh_rev(∅, -∞..∞)[2], ∅) diff --git a/test/Non1788tests/inv_hyperbolic.jl b/test/Non1788tests/inv_hyperbolic.jl index 703793a..eecd2ee 100644 --- a/test/Non1788tests/inv_hyperbolic.jl +++ b/test/Non1788tests/inv_hyperbolic.jl @@ -11,7 +11,7 @@ setprecision(Interval, Float64) # Using approximate checks for validaty update later? import Base.isapprox -isapprox(x::Interval,y::Interval) = isapprox(x.lo,y.lo,atol=1E-4) && isapprox(x.hi,y.hi,atol=1E-4) +isapprox(x::Interval,y::Interval) = isapprox(inf(x),inf(y),atol=1E-4) && isapprox(sup(x),sup(y),atol=1E-4) @testset "asinh_rev_test" begin @test asinh_rev(∅, -∞..∞)[2] == ∅ diff --git a/test/Non1788tests/inv_rev.jl b/test/Non1788tests/inv_rev.jl index 2492a86..d6faf69 100644 --- a/test/Non1788tests/inv_rev.jl +++ b/test/Non1788tests/inv_rev.jl @@ -12,7 +12,7 @@ setprecision(Interval, Float64) # Using approximate checks for validaty update later? import Base.isapprox -isapprox(x::Interval,y::Interval) = isapprox(x.lo,y.lo,atol=1E-4) && isapprox(x.hi,y.hi,atol=1E-4) +isapprox(x::Interval,y::Interval) = isapprox(inf(x),inf(y),atol=1E-4) && isapprox(sup(x),sup(y),atol=1E-4) @testset "inv_rev_test" begin @test inv_rev(∅, entireinterval(Float64))[2] == ∅ diff --git a/test/Non1788tests/inv_trig.jl b/test/Non1788tests/inv_trig.jl index 87f833e..74164a4 100644 --- a/test/Non1788tests/inv_trig.jl +++ b/test/Non1788tests/inv_trig.jl @@ -12,7 +12,7 @@ setprecision(Interval, Float64) # Using approximate checks for validaty update later? import Base.isapprox -isapprox(x::Interval,y::Interval) = isapprox(x.lo,y.lo,atol=1E-4) && isapprox(x.hi,y.hi,atol=1E-4) +isapprox(x::Interval,y::Interval) = isapprox(inf(x),inf(y),atol=1E-4) && isapprox(sup(x),sup(y),atol=1E-4) @testset "acos_rev_test" begin @test acos_rev(∅, entireinterval(Float64))[2] == ∅ diff --git a/test/Non1788tests/script.jl b/test/Non1788tests/script.jl index e229dfa..2cda868 100644 --- a/test/Non1788tests/script.jl +++ b/test/Non1788tests/script.jl @@ -12,7 +12,7 @@ setprecision(Interval, Float64) # Using approximate checks for validaty update later? import Base.isapprox -isapprox(x::Interval,y::Interval) = isapprox(x.lo,y.lo,atol=1E-4) && isapprox(x.hi,y.hi,atol=1E-4) +isapprox(x::Interval,y::Interval) = isapprox(inf(x),inf(y),atol=1E-4) && isapprox(sup(x),sup(y),atol=1E-4) c = ∅ d = entireinterval(Float64)