Skip to content

Commit

Permalink
More updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dpsanders committed May 26, 2024
1 parent 3072960 commit 2fd4b4e
Show file tree
Hide file tree
Showing 19 changed files with 1,388 additions and 1,388 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(inf(y) ^ (1/3), sup(y)^(1/3)) # not rigorous!
x = x interval(inf(y) ^ (1/3), sup(y)^(1/3)) # not rigorous!

return x × y
end
Expand Down
6 changes: 3 additions & 3 deletions src/decorated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ for op in (:sqr_rev, :abs_rev, :sin_rev, :cos_rev, :tan_rev, :cosh_rev, :sinh_re
function $op(a::DecoratedInterval{T}, x::DecoratedInterval{T}) where T
( isnai(a) || isnai(x) ) && return nai(T)
bare = $op(interval(a), interval(x))
return (DecoratedInterval(bare[1], trv), DecoratedInterval(bare[2], trv))
return (Decoratedinterval(bare[1], trv), DecoratedInterval(bare[2], trv))
end
end
@eval $op(a::Interval{T}) where T = $op(a, entireinterval(T))
Expand All @@ -15,7 +15,7 @@ end
function power_rev(a::DecoratedInterval{T}, x::DecoratedInterval{T}, n::Integer) where T
( isnai(a) || isnai(x) ) && return nai(T)
bare = power_rev(interval(a), interval(x), n)
return (DecoratedInterval(bare[1], trv), DecoratedInterval(bare[2], trv), n)
return (Decoratedinterval(bare[1], trv), DecoratedInterval(bare[2], trv), n)
end

power_rev(a::DecoratedInterval{T}, n::Integer) where T = power_rev(a, entiredecorated(T), n)
Expand All @@ -25,7 +25,7 @@ for op in (:mul_rev_IEEE1788, :pow_rev1, :pow_rev2)
function $op(b::DecoratedInterval{T}, c::DecoratedInterval{T}, x::DecoratedInterval{T}) where T
(isnai(b) || isnai(c) || isnai(x) ) && return nai(T)
bare = $op(interval(b), interval(c), interval(x))
return DecoratedInterval(bare, trv)
return Decoratedinterval(bare, trv)
end
end

Expand Down
16 changes: 8 additions & 8 deletions src/extrema.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ function max_rev(a::Interval, b::Interval, c::Interval) # a = max(b,c)
(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, ∅, ∅)
if isempty_interval(b)
isempty_interval(c) && (return a, ∅, ∅)
return a, ∅, Interval(C_lo,C_hi)
else
isempty(c) && (return a, Interval(B_lo,B_hi), ∅)
return a, Interval(B_lo,B_hi), Interval(C_lo,C_hi)
isempty_interval(c) && (return a, interval(B_lo,B_hi), ∅)
return a, interval(B_lo,B_hi), Interval(C_lo,C_hi)
end
end
max_rev(a,b,c) = max_rev(promote(a,b,c)...)
Expand All @@ -34,12 +34,12 @@ function min_rev(a::Interval, b::Interval, c::Interval)
(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, ∅, ∅)
if isempty_interval(b)
isempty_interval(c) && (return a, ∅, ∅)
return a, ∅, Interval(C_lo,C_hi)
else
isempty(c) && (return a, Interval(B_lo,B_hi), ∅)
return a, Interval(B_lo,B_hi), Interval(C_lo,C_hi)
isempty_interval(c) && (return a, interval(B_lo,B_hi), ∅)
return a, interval(B_lo,B_hi), Interval(C_lo,C_hi)
end
end

Expand Down
6 changes: 3 additions & 3 deletions src/inverse_trig.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function asin!(X::IntervalBox)
x, y = X

h = inf(half_pi)
y_new = y Interval(-h, h) # range of asin
y_new = y interval(-h, h) # range of asin
x_new = sin(y_new)

return IntervalBox(x_new, y_new)
Expand All @@ -14,7 +14,7 @@ Reverse `asin`.
function asin_rev(y::Interval, x::Interval) # y = asin(x)

h = inf(half_pi)
y_new = y Interval(-h, h) # range of asin
y_new = y interval(-h, h) # range of asin

x_new = sin(y_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(-sup(half_pi), sup(half_pi))
y_new = y interval(-sup(half_pi), sup(half_pi))
x_new = x tan(y_new)

return y_new, x_new
Expand Down
4 changes: 2 additions & 2 deletions src/pave.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ function outer_pave{N,T}(C, working::Vector{IntervalBox{N,T}}, ϵ)

outer_list = SubPaving{N,T}()

while !isempty(working)
while !isempty_interval(working)

X = pop!(working)

contracted = C(X)

if isempty(contracted)
if isempty_interval(contracted)
continue
end

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(inf(y) ^ (1/3), sup(y)^(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 @@ -11,7 +11,7 @@ function integer_contractor(x::Interval)

a > b && return emptyinterval(x)

return Interval(a, b)
return interval(a, b)
end


Expand Down Expand Up @@ -76,7 +76,7 @@ function periodise(C, period)
# periods where the periodization of x intersects with x2:
periods = integer_contractor((x - x2) / period)

isempty(periods) && return(IntervalBox(∅, ∅))
isempty_interval(periods) && return(IntervalBox(∅, ∅))

x3 = x2 + periods*period
x = x x3
Expand Down
6 changes: 3 additions & 3 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(-sup(half_pi), sup(half_pi))
x_range = interval(-sup(half_pi), sup(half_pi))
y_range = -1..1

x = x x_range
Expand Down Expand Up @@ -67,7 +67,7 @@ function cos_main(X::IntervalBox)

x, y = X

x_range = Interval(0, Interval{Float64}(π).lo)
x_range = interval(0, Interval{Float64}(π).lo)
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(-sup(half_pi), sup(half_pi))
x_range = interval(-sup(half_pi), sup(half_pi))

x = x x_range

Expand Down
72 changes: 36 additions & 36 deletions test/Non1788tests/exponential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,60 +15,60 @@ isapprox(x::Interval,y::Interval) = isapprox(inf(x),inf(y),atol=1E-4) && isappro

@testset "exp2_rev_test" begin
@test exp2_rev(∅, entireinterval(Float64))[2] ==
@test exp2_rev(Interval(0.0, 1.0), ∅)[2] ==
@test exp2_rev(∅, Interval(0.0, 1.0))[2] ==
@test exp2_rev(Interval(-2.0, -1.0), entireinterval(Float64))[2] ==
@test exp2_rev(Interval(1.0, 1.0), entireinterval(Float64))[2] == Interval(0.0, 0.0)
@test exp2_rev(entireinterval(Float64), entireinterval(Float64))[2] == Interval(-∞, ∞)
@test exp2_rev(Interval(-Inf, 0.0), entireinterval(Float64))[2] ==
@test exp2_rev(interval(0.0, 1.0), ∅)[2] ==
@test exp2_rev(∅, interval(0.0, 1.0))[2] ==
@test exp2_rev(interval(-2.0, -1.0), entireinterval(Float64))[2] ==
@test exp2_rev(interval(1.0, 1.0), entireinterval(Float64))[2] == Interval(0.0, 0.0)
@test exp2_rev(entireinterval(Float64), entireinterval(Float64))[2] == interval(-∞, ∞)
@test exp2_rev(interval(-Inf, 0.0), entireinterval(Float64))[2] ==
end

@testset "exp10_rev_test" begin
@test exp10_rev(∅, entireinterval(Float64))[2] ==
@test exp10_rev(Interval(0.0, 1.0), ∅)[2] ==
@test exp10_rev(∅, Interval(0.0, 1.0))[2] ==
@test exp10_rev(Interval(-2.0, -1.0), entireinterval(Float64))[2] ==
@test exp10_rev(Interval(1.0, 1.0), entireinterval(Float64))[2] == Interval(0.0, 0.0)
@test exp10_rev(entireinterval(Float64), entireinterval(Float64))[2] == Interval(-∞, ∞)
@test exp10_rev(Interval(-Inf, 0.0), entireinterval(Float64))[2] ==
@test exp10_rev(interval(0.0, 1.0), ∅)[2] ==
@test exp10_rev(∅, interval(0.0, 1.0))[2] ==
@test exp10_rev(interval(-2.0, -1.0), entireinterval(Float64))[2] ==
@test exp10_rev(interval(1.0, 1.0), entireinterval(Float64))[2] == Interval(0.0, 0.0)
@test exp10_rev(entireinterval(Float64), entireinterval(Float64))[2] == interval(-∞, ∞)
@test exp10_rev(interval(-Inf, 0.0), entireinterval(Float64))[2] ==
end

@testset "expm1_rev_test" begin
@test expm1_rev(∅, entireinterval(Float64))[2] ==
@test expm1_rev(Interval(0.0, 1.0), ∅)[2] ==
@test expm1_rev(∅, Interval(0.0, 1.0))[2] ==
@test expm1_rev(Interval(-2.0, -1.0), entireinterval(Float64))[2] ==
@test isapprox(expm1_rev(Interval(1.0, 1.0), entireinterval(Float64))[2],Interval(0.693147, 0.693148))
@test expm1_rev(entireinterval(Float64), entireinterval(Float64))[2] == Interval(-∞, ∞)
@test expm1_rev(Interval(-Inf, -1.0), entireinterval(Float64))[2] ==
@test expm1_rev(interval(0.0, 1.0), ∅)[2] ==
@test expm1_rev(∅, interval(0.0, 1.0))[2] ==
@test expm1_rev(interval(-2.0, -1.0), entireinterval(Float64))[2] ==
@test isapprox(expm1_rev(interval(1.0, 1.0), entireinterval(Float64))[2],Interval(0.693147, 0.693148))
@test expm1_rev(entireinterval(Float64), entireinterval(Float64))[2] == interval(-∞, ∞)
@test expm1_rev(interval(-Inf, -1.0), entireinterval(Float64))[2] ==
end

@testset "log2_rev_test" begin
@test log2_rev(∅, entireinterval(Float64))[2] ==
@test log2_rev(Interval(0.0, 1.0), ∅)[2] ==
@test log2_rev(∅, Interval(0.0, 1.0))[2] ==
@test log2_rev(Interval(-2.0, -1.0), entireinterval(Float64))[2] == Interval(0.25, 0.5)
@test log2_rev(Interval(1.0, 1.0), entireinterval(Float64))[2] == Interval(2.0, 2.0)
@test log2_rev(entireinterval(Float64), entireinterval(Float64))[2] == Interval(0.0, Inf)
@test log2_rev(Interval(-Inf, 0.0), entireinterval(Float64))[2] == Interval(0.0, 1.0)
@test log2_rev(interval(0.0, 1.0), ∅)[2] ==
@test log2_rev(∅, interval(0.0, 1.0))[2] ==
@test log2_rev(interval(-2.0, -1.0), entireinterval(Float64))[2] == Interval(0.25, 0.5)
@test log2_rev(interval(1.0, 1.0), entireinterval(Float64))[2] == Interval(2.0, 2.0)
@test log2_rev(entireinterval(Float64), entireinterval(Float64))[2] == interval(0.0, Inf)
@test log2_rev(interval(-Inf, 0.0), entireinterval(Float64))[2] == Interval(0.0, 1.0)
end

@testset "log10_rev_test" begin
@test log10_rev(∅, entireinterval(Float64))[2] ==
@test log10_rev(Interval(0.0, 1.0), ∅)[2] ==
@test log10_rev(∅, Interval(0.0, 1.0))[2] ==
@test isapprox(log10_rev(Interval(-2.0, -1.0), entireinterval(Float64))[2], Interval(0.00999999, 0.100001))
@test log10_rev(Interval(1.0, 1.0), entireinterval(Float64))[2] == Interval(10.0, 10.0)
@test log10_rev(entireinterval(Float64), entireinterval(Float64))[2] == Interval(0.0, Inf)
@test log10_rev(Interval(-Inf, 0.0), entireinterval(Float64))[2] == Interval(0.0, 1.0)
@test log10_rev(interval(0.0, 1.0), ∅)[2] ==
@test log10_rev(∅, interval(0.0, 1.0))[2] ==
@test isapprox(log10_rev(interval(-2.0, -1.0), entireinterval(Float64))[2], Interval(0.00999999, 0.100001))
@test log10_rev(interval(1.0, 1.0), entireinterval(Float64))[2] == Interval(10.0, 10.0)
@test log10_rev(entireinterval(Float64), entireinterval(Float64))[2] == interval(0.0, Inf)
@test log10_rev(interval(-Inf, 0.0), entireinterval(Float64))[2] == Interval(0.0, 1.0)
end

@testset "log1p_rev_test" begin
@test log1p_rev(∅, entireinterval(Float64))[2] ==
@test log1p_rev(Interval(0.0, 1.0), ∅)[2] ==
@test log1p_rev(∅, Interval(0.0, 1.0))[2] ==
@test isapprox(log1p_rev(Interval(-2.0, -1.0), entireinterval(Float64))[2], Interval(-0.864665, -0.63212))
@test isapprox(log1p_rev(Interval(1.0, 1.0), entireinterval(Float64))[2], Interval(1.71828, 1.71829))
@test log1p_rev(entireinterval(Float64), entireinterval(Float64))[2] == Interval(-1.0, Inf)
@test log1p_rev(Interval(-Inf, 0.0), entireinterval(Float64))[2] == Interval(-1.0, 0.0)
@test log1p_rev(interval(0.0, 1.0), ∅)[2] ==
@test log1p_rev(∅, interval(0.0, 1.0))[2] ==
@test isapprox(log1p_rev(interval(-2.0, -1.0), entireinterval(Float64))[2], Interval(-0.864665, -0.63212))
@test isapprox(log1p_rev(interval(1.0, 1.0), entireinterval(Float64))[2], Interval(1.71828, 1.71829))
@test log1p_rev(entireinterval(Float64), entireinterval(Float64))[2] == interval(-1.0, Inf)
@test log1p_rev(interval(-Inf, 0.0), entireinterval(Float64))[2] == Interval(-1.0, 0.0)
end
28 changes: 14 additions & 14 deletions test/Non1788tests/extrema.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ import Base.isapprox
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(-∞, ∞)
@test max_rev(Interval(0.0, 1.0), ∅,Interval(-2.0, -1.0))[2] ==
@test max_rev(∅, Interval(0.0, 1.0),Interval(-2.0, -1.0))[2] ==
@test max_rev(Interval(-2.0, -1.0), entireinterval(Float64),Interval(-3.0, -2.0))[2] == Interval(-∞, -1.0)
@test isapprox(max_rev(Interval(1.0, 1.0), entireinterval(Float64),Interval(-2.0, -1.0))[2], Interval(-∞, 1))
@test max_rev(entireinterval(Float64), Interval(-2.0, -1.0), Interval(-3.0, -2.0))[2] == Interval(-2.0, -1.0)
@test max_rev(Interval(-Inf, 0.0), entireinterval(Float64),Interval(-3.0, -2.0))[2] == Interval(-∞, 0.0)
@test max_rev(∅, entireinterval(Float64),entireinterval(Float64))[2] == interval(-∞, ∞)
@test max_rev(interval(0.0, 1.0), ∅,Interval(-2.0, -1.0))[2] ==
@test max_rev(∅, interval(0.0, 1.0),Interval(-2.0, -1.0))[2] ==
@test max_rev(interval(-2.0, -1.0), entireinterval(Float64),Interval(-3.0, -2.0))[2] == Interval(-∞, -1.0)
@test isapprox(max_rev(interval(1.0, 1.0), entireinterval(Float64),Interval(-2.0, -1.0))[2], Interval(-∞, 1))
@test max_rev(entireinterval(Float64), interval(-2.0, -1.0), Interval(-3.0, -2.0))[2] == Interval(-2.0, -1.0)
@test max_rev(interval(-Inf, 0.0), entireinterval(Float64),Interval(-3.0, -2.0))[2] == Interval(-∞, 0.0)
end

@testset "min_rev_test" begin
@test min_rev(∅, entireinterval(Float64),entireinterval(Float64))[2] == Interval(-∞, ∞)
@test min_rev(Interval(0.0, 1.0), ∅,Interval(-2.0, -1.0))[2] ==# should return empty?
@test min_rev(∅, Interval(0.0, 1.0),Interval(-2.0, -1.0))[2] ==
@test min_rev(Interval(-2.0, -1.0), entireinterval(Float64),Interval(-3.0, -2.0))[2] == Interval(-∞, -2.0)
@test isapprox(min_rev(Interval(1.0, 1.0), entireinterval(Float64),Interval(-2.0, -1.0))[2], Interval(-∞, -1.0))
@test min_rev(entireinterval(Float64), Interval(-2.0, -1.0), Interval(-3.0, -2.0))[2] == Interval(-3.0, -2.0)
@test min_rev(Interval(-Inf, 0.0), entireinterval(Float64),Interval(-3.0, -2.0))[2] == Interval(-∞, -2.0)
@test min_rev(∅, entireinterval(Float64),entireinterval(Float64))[2] == interval(-∞, ∞)
@test min_rev(interval(0.0, 1.0), ∅,Interval(-2.0, -1.0))[2] ==# should return empty?
@test min_rev(∅, interval(0.0, 1.0),Interval(-2.0, -1.0))[2] ==
@test min_rev(interval(-2.0, -1.0), entireinterval(Float64),Interval(-3.0, -2.0))[2] == Interval(-∞, -2.0)
@test isapprox(min_rev(interval(1.0, 1.0), entireinterval(Float64),Interval(-2.0, -1.0))[2], Interval(-∞, -1.0))
@test min_rev(entireinterval(Float64), interval(-2.0, -1.0), Interval(-3.0, -2.0))[2] == Interval(-3.0, -2.0)
@test min_rev(interval(-Inf, 0.0), entireinterval(Float64),Interval(-3.0, -2.0))[2] == Interval(-∞, -2.0)
end
28 changes: 14 additions & 14 deletions test/Non1788tests/hyperbolic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ isapprox(x::Interval,y::Interval) = isapprox(inf(x),inf(y),atol=1E-4) && isappro

@testset "sinh_rev_test" begin
@test isapprox(sinh_rev(∅, -..∞)[2], ∅)
@test isapprox(sinh_rev(Interval(-10.0, -1.0), -..∞)[2], Interval(-2.99823, -0.881373))
@test isapprox(sinh_rev(Interval(0.0, Inf), -..∞)[2], Interval(0.0, ∞))
@test isapprox(sinh_rev(Interval(0.0, 1.0), -..∞)[2], Interval(0, 0.881374))
@test isapprox(sinh_rev(Interval(-0.5, 1.0), -..∞)[2], Interval(-0.481212, 0.881374))
@test isapprox(sinh_rev(Interval(-1000.0, 1.0), -..∞)[2], Interval(-7.60091, 0.881374))
@test isapprox(sinh_rev(Interval(0.0, 25.0), -..∞)[2], Interval(0.0, 3.91243))
@test isapprox(sinh_rev(Interval(-1.0, 25.0), -..∞)[2], Interval(-0.881374, 3.91243))
@test isapprox(sinh_rev(interval(-10.0, -1.0), -..∞)[2], Interval(-2.99823, -0.881373))
@test isapprox(sinh_rev(interval(0.0, Inf), -..∞)[2], Interval(0.0, ∞))
@test isapprox(sinh_rev(interval(0.0, 1.0), -..∞)[2], Interval(0, 0.881374))
@test isapprox(sinh_rev(interval(-0.5, 1.0), -..∞)[2], Interval(-0.481212, 0.881374))
@test isapprox(sinh_rev(interval(-1000.0, 1.0), -..∞)[2], Interval(-7.60091, 0.881374))
@test isapprox(sinh_rev(interval(0.0, 25.0), -..∞)[2], Interval(0.0, 3.91243))
@test isapprox(sinh_rev(interval(-1.0, 25.0), -..∞)[2], Interval(-0.881374, 3.91243))
end

@testset "tanh_rev_test" begin
@test tanh_rev(∅, -..∞)[2] ==
@test tanh_rev(Interval(-10.0, -1.0), -..∞)[2] ==
@test isapprox(tanh_rev(Interval(0.0, Inf), -..∞)[2], Interval(0.0, ∞))
@test isapprox(tanh_rev(Interval(0.0, 1.0), -..∞)[2], Interval(0.0, ∞))
@test isapprox(tanh_rev(Interval(-0.5, 1.0), -..∞)[2], Interval(-0.549307, ∞))
@test isapprox(tanh_rev(Interval(-1000.0, 1.0), -..∞)[2], Interval(-∞, ∞))
@test isapprox(tanh_rev(Interval(0.0, 25.0), -..∞)[2], Interval(0, ∞))
@test isapprox(tanh_rev(Interval(-1.0, 25.0), -..∞)[2], Interval(-∞, ∞))
@test tanh_rev(interval(-10.0, -1.0), -..∞)[2] ==
@test isapprox(tanh_rev(interval(0.0, Inf), -..∞)[2], Interval(0.0, ∞))
@test isapprox(tanh_rev(interval(0.0, 1.0), -..∞)[2], Interval(0.0, ∞))
@test isapprox(tanh_rev(interval(-0.5, 1.0), -..∞)[2], Interval(-0.549307, ∞))
@test isapprox(tanh_rev(interval(-1000.0, 1.0), -..∞)[2], Interval(-∞, ∞))
@test isapprox(tanh_rev(interval(0.0, 25.0), -..∞)[2], Interval(0, ∞))
@test isapprox(tanh_rev(interval(-1.0, 25.0), -..∞)[2], Interval(-∞, ∞))
end
Loading

0 comments on commit 2fd4b4e

Please sign in to comment.