Skip to content

Commit

Permalink
Replace a.lo with inf(a) and similarly for .hi and sup
Browse files Browse the repository at this point in the history
  • Loading branch information
dpsanders committed May 26, 2024
1 parent 77bda19 commit 3072960
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 31 deletions.
2 changes: 1 addition & 1 deletion examples/examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/IntervalContractors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 12 additions & 12 deletions src/extrema.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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, ∅, ∅)
Expand All @@ -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, ∅, ∅)
Expand Down
8 changes: 4 additions & 4 deletions src/inverse_trig.jl
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/powers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/transformations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions src/trig.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/Non1788tests/exponential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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] ==
Expand Down
2 changes: 1 addition & 1 deletion test/Non1788tests/extrema.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(-∞, ∞)
Expand Down
2 changes: 1 addition & 1 deletion test/Non1788tests/hyperbolic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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], ∅)
Expand Down
2 changes: 1 addition & 1 deletion test/Non1788tests/inv_hyperbolic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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] ==
Expand Down
2 changes: 1 addition & 1 deletion test/Non1788tests/inv_rev.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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] ==
Expand Down
2 changes: 1 addition & 1 deletion test/Non1788tests/inv_trig.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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] ==
Expand Down
2 changes: 1 addition & 1 deletion test/Non1788tests/script.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3072960

Please sign in to comment.