Skip to content

Commit

Permalink
Tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
dpsanders committed Jul 28, 2024
1 parent 844f13e commit 18cf52d
Show file tree
Hide file tree
Showing 19 changed files with 180 additions and 230 deletions.
8 changes: 4 additions & 4 deletions examples/examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ function sawtooth(X::IntervalBox)

x, y = X

x = x (-1..1)
y = y (-2..2)
x = x interval(-1, 1)
y = y interval(-2, 2)

y = y (2x)
x = x (y/2)
x = x (y / 2)

return IntervalBox(x, y)
end
Expand Down Expand Up @@ -38,7 +38,7 @@ function cube0(X::IntervalBox) # contractor for y=x^3, x>=0

x, y = X

x = x (0..)
x = x (interval(0, Inf))

y = y (x ^ 3)
x = x interval(inf(y) ^ (1/3), sup(y)^(1/3)) # not rigorous!
Expand Down
2 changes: 0 additions & 2 deletions src/IntervalContractors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ 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
30 changes: 15 additions & 15 deletions src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ function power_rev(a::Interval{T}, b::Interval{T}, n::Integer) where T # a = b^
b2 = b (-root)

elseif isodd(n)
pos_root = (a (0..)) ^ (1//n)
neg_root = -( ( (-a) (0..) ) ^ (1//n) )
pos_root = (a interval(0, Inf)) ^ (1//n)
neg_root = -( ( (-a) (interval(0, Inf)) ) ^ (1//n) )

b1 = b pos_root
b2 = b neg_root
Expand Down Expand Up @@ -207,7 +207,7 @@ sqrt_rev(a,b) = sqrt_rev(promote(a,b)...)
sqr_rev(c::Interval[, x::Interval])
Reverse square. Calculates the preimage of `a = x²`. If `x` is not provided, then
byt default ``[-∞, ∞]`` is used. See section 10.5.4 of the IEEE 1788-2015 standard for interval arithmetic.
byt default ``[-Inf, Inf]`` is used. See section 10.5.4 of the IEEE 1788-2015 standard for interval arithmetic.
### Output
Expand All @@ -230,7 +230,7 @@ end
abs_rev(c::Interval[, x::Interval])
Reverse absolute value. Calculates the preimage of `a = |x|`. If `x` is not provided, then
byt default ``[-∞, ∞]`` is used. See section 10.5.4 of the IEEE 1788-2015 standard for interval arithmetic.
byt default ``[-Inf, Inf]`` is used. See section 10.5.4 of the IEEE 1788-2015 standard for interval arithmetic.
### Output
Expand All @@ -241,7 +241,7 @@ The pair `(c, x_new)` where
"""
function abs_rev(y, x = entireinterval(y)) # y = abs(x); refine x

y_new = y (0..)
y_new = y (interval(0, Inf))

x1 = y_new x
x2 = -(y_new (-x))
Expand All @@ -254,9 +254,9 @@ Reverse sign
"""
function sign_rev(a::Interval, b::Interval) # a = sqrt(b)
(a == 1.0) && b = b ⊓ (0..∞)
(a == 0.0) && b = b ⊓ (0.0..0.0)
(a == -1.0) && b = b ⊓ (-∞..0.0)
(a == 1.0) && b = b ⊓ (interval(0, Inf))
(a == 0.0) && b = b ⊓ (0.interval(0, 0).0)
(a == -1.0) && b = b ⊓ (-interval(Inf, 0).0)
return a, b
end
Expand All @@ -269,7 +269,7 @@ sign_rev(a,b) = sign_rev(promote(a,b)...)
mul_rev_IEEE1788(b::Interval, c::Interval[, x::Interval])
Reverse multiplication. Computes the preimage of ``c = x * b`` with respect to `x`.
If `x` is not provided, then by default ``[-∞, ∞]`` is used.
If `x` is not provided, then by default ``[-Inf, Inf]`` is used.
See section 10.5.4 of the IEEE 1788-2015 standard for interval arithmetic.
### Output
Expand All @@ -282,7 +282,7 @@ mul_rev_IEEE1788(b, c, x = entireinterval(b)) = mul_rev(c, x, b)[2]
pow_rev1(b::Interval, c::Interval[, x::Interval])
Reverse power 1. Computes the preimage of ``c=xᵇ`` with respect to `x`. If `x` is not provided,
then byt default ``[-∞, ∞]`` is used.. See section 10.5.4 of the
then byt default ``[-Inf, Inf]`` is used.. See section 10.5.4 of the
IEEE 1788-2015 standard for interval arithmetic.
### Output
Expand All @@ -297,7 +297,7 @@ end
pow_rev2(b::Interval, c::Interval[, x::Interval])
Reverse power 2. Computes the preimage of ``c = aˣ`` with respect to `x`. If `x` is not provided, then
byt default ``[-∞, ∞]`` is used. See section 10.5.4 of the IEEE 1788-2015 standard for interval arithmetic.
byt default ``[-Inf, Inf]`` is used. See section 10.5.4 of the IEEE 1788-2015 standard for interval arithmetic.
### Output
Expand All @@ -319,11 +319,11 @@ See section 10.5.5 of the IEEE 1788-2015 standard for interval arithmetic.
### Example
```jldoctest
julia> mul_rev_to_pair(-1..1, 1..2)
([-, -1], [1, ])
julia> mul_rev_to_pair(-interval(1, 1), interval(1, 2))
([-Inf, -1], [1, Inf])
julia> mul_rev_to_pair(1..2, 3..4)
([1.5, 4], )
julia> mul_rev_to_pair(interval(1, 2), interval(3, 4))
([1.5, 4], emptyinterval())
"""
mul_rev_to_pair(b::Interval, c::Interval) = extended_div(c, b)
8 changes: 4 additions & 4 deletions src/exponential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ end
Reverse function for `exp`.
"""
function exp_rev(y::Interval, x::Interval)
y_new = y (0..)
y_new = y (interval(0, Inf))
x_new = x log(y)
return y_new, x_new
end
Expand All @@ -20,7 +20,7 @@ end
Reverse function for `exp2`.
"""
function exp2_rev(y::Interval, x::Interval)
y_new = y (0..)
y_new = y (interval(0, Inf))
x_new = x log2(y)

return y_new, x_new
Expand All @@ -30,7 +30,7 @@ end
Reverse function for `exp10`.
"""
function exp10_rev(y::Interval, x::Interval)
y_new = y (0..)
y_new = y (interval(0, Inf))
x_new = x log10(y)

return y_new, x_new
Expand All @@ -40,7 +40,7 @@ end
Reverse function for `expm1`.
"""
function expm1_rev(y::Interval, x::Interval)
y_new = y (-1.0..)
y_new = y (interval(-1, Inf))
x_new = x log1p(y)

return y_new, x_new
Expand Down
12 changes: 6 additions & 6 deletions src/extrema.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ function max_rev(a::Interval, b::Interval, c::Interval) # a = max(b,c)
(sup(b) < sup(c)) && (C_hi = min(sup(c),sup(a)))

if isempty_interval(b)
isempty_interval(c) && (return a, ∅, ∅)
return a, , interval(C_lo,C_hi)
isempty_interval(c) && (return a, emptyinterval(), emptyinterval())
return a, emptyinterval(), interval(C_lo,C_hi)
else
isempty_interval(c) && (return a, interval(B_lo,B_hi), )
isempty_interval(c) && (return a, interval(B_lo,B_hi), emptyinterval())
return a, interval(B_lo,B_hi), interval(C_lo,C_hi)
end
end
Expand All @@ -35,10 +35,10 @@ function min_rev(a::Interval, b::Interval, c::Interval)
(sup(b) < sup(c)) && (C_hi = min(sup(b),sup(a)))

if isempty_interval(b)
isempty_interval(c) && (return a, ∅, ∅)
return a, , interval(C_lo,C_hi)
isempty_interval(c) && (return a, emptyinterval(), emptyinterval())
return a, emptyinterval(), interval(C_lo,C_hi)
else
isempty_interval(c) && (return a, interval(B_lo,B_hi), )
isempty_interval(c) && (return a, interval(B_lo,B_hi), emptyinterval())
return a, interval(B_lo,B_hi), interval(C_lo,C_hi)
end
end
Expand Down
8 changes: 4 additions & 4 deletions src/hyperbolic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
sinh_rev(c::Interval[, x::Interval])
Reverse hyperbolic sine. Calculates the preimage of `a = sinh(x)`. If `x` is not provided, then
byt default ``[-∞, ∞]`` is used. See section 10.5.4 of the IEEE 1788-2015 standard for interval arithmetic.
byt default ``[-Inf, Inf]`` is used. See section 10.5.4 of the IEEE 1788-2015 standard for interval arithmetic.
### Output
Expand All @@ -21,7 +21,7 @@ end
cosh_rev(c::Interval[, x::Interval])
Reverse square root. Calculates the preimage of `a = cosh(x)`. If `x` is not provided, then
byt default ``[-∞, ∞]`` is used. See section 10.5.4 of the IEEE 1788-2015 standard for interval arithmetic.
byt default ``[-Inf, Inf]`` is used. See section 10.5.4 of the IEEE 1788-2015 standard for interval arithmetic.
### Output
Expand All @@ -31,7 +31,7 @@ The pair `(c, x_new)` where
- `x_new` is the interval hull of the set ``{x ∈ b : cosh(x) ∈ a}``
"""
function cosh_rev(y::Interval, x::Interval = entireinterval(y))
y_new = y interval(1.,)
y_new = y interval(1.,Inf)
x = (x acosh(y)) (x -acosh(y))

return y_new, x
Expand All @@ -41,7 +41,7 @@ end
tanh_rev(c::Interval[, x::Interval])
Reverse square root. Calculates the preimage of `a = tanh(x)`. If `x` is not provided, then
byt default ``[-∞, ∞]`` is used. See section 10.5.4 of the IEEE 1788-2015 standard for interval arithmetic.
byt default ``[-Inf, Inf]`` is used. See section 10.5.4 of the IEEE 1788-2015 standard for interval arithmetic.
### Output
Expand Down
8 changes: 4 additions & 4 deletions src/inverse_hyperbolic.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Reverse function for `asinh`.
"""
function asinh_rev(y::Interval,x::Interval)
function asinh_rev(y::Interval, x::Interval = entireinterval(y))
x = x sinh(y)

return y, x
Expand All @@ -10,8 +10,8 @@ end
"""
Reverse function for `acosh`.
"""
function acosh_rev(y::Interval,x::Interval)
y_new = y interval(0.0,)
function acosh_rev(y::Interval, x::Interval = entireinterval(y))
y_new = y interval(0.0,Inf)
x = x cosh(y)

return y_new, x
Expand All @@ -20,7 +20,7 @@ end
"""
Reverse function for `atanh`.
"""
function atanh_rev(y::Interval,x::Interval)
function atanh_rev(y::Interval, x::Interval = entireinterval(y))
x = x tanh(y)

return y, x
Expand Down
2 changes: 1 addition & 1 deletion src/inverse_trig.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ end
Reverse `acos`.
"""
function acos_rev(y::Interval, x::Interval)
y_new = y interval(0.0,sup(two_pi))
y_new = y interval(0.0, sup(two_pi))
x_new = x cos(y_new)

return y_new, x_new
Expand Down
4 changes: 2 additions & 2 deletions src/powers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function square_pos(X::IntervalBox)

x, y = X

x = x (0..)
x = x (interval(0, Inf))

y = y (x^2)
x = x y
Expand All @@ -27,7 +27,7 @@ function cube_pos(X::IntervalBox) # contractor for y=x^3, x>=0

x, y = X

x = x (0..)
x = x (interval(0, Inf))

y = y (x ^ 3)
x = x interval(inf(y) ^ (1/3), sup(y)^(1/3)) # not rigorous!
Expand Down
6 changes: 3 additions & 3 deletions src/transformations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ function periodise(C, period)
X -> begin
x, y = X

x2 = -..
x2 = entireinterval()
x2, y = C(IntervalBox(x2, y))

isempty(IntervalBox(x2, y)) && return(IntervalBox(∅, ∅))
isempty(IntervalBox(x2, y)) && return(IntervalBox(emptyinterval(), emptyinterval()))

# periods where the periodization of x intersects with x2:
periods = integer_contractor((x - x2) / period)

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

x3 = x2 + periods*period
x = x x3
Expand Down
10 changes: 5 additions & 5 deletions src/trig.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function sin_main(X::IntervalBox)
x, y = X

x_range = interval(-sup(half_pi), sup(half_pi))
y_range = -1..1
y_range = interval(-1, 1)

x = x x_range
y = y y_range
Expand Down Expand Up @@ -40,7 +40,7 @@ sin!(X::IntervalBox) = periodise(sin_main, two_pi)(X) ⊔ periodise(sin_reverse,
sin_rev(c::Interval[, x::Interval])
Reverse sine. Calculates the preimage of `a = sin(x)`. If `x` is not provided, then
byt default ``[-∞, ∞]`` is used. See section 10.5.4 of the IEEE 1788-2015 standard for interval arithmetic.
byt default ``[-Inf, Inf]`` is used. See section 10.5.4 of the IEEE 1788-2015 standard for interval arithmetic.
### Output
Expand Down Expand Up @@ -68,7 +68,7 @@ function cos_main(X::IntervalBox)
x, y = X

x_range = interval(0, inf(interval(π)))
y_range = -1..1
y_range = interval(-1, 1)

x = x x_range
y = y y_range
Expand Down Expand Up @@ -100,7 +100,7 @@ cos!(X::IntervalBox) = periodise(cos_main, two_pi)(X) ⊔ periodise(cos_reverse,
cos_rev(c::Interval[, x::Interval])
Reverse cosine. Calculates the preimage of `a = cos(x)`. If `x` is not provided, then
byt default ``[-∞, ∞]`` is used. See section 10.5.4 of the IEEE 1788-2015 standard for interval arithmetic.
byt default ``[-Inf, Inf]`` is used. See section 10.5.4 of the IEEE 1788-2015 standard for interval arithmetic.
### Output
Expand Down Expand Up @@ -145,7 +145,7 @@ tan!(X::IntervalBox) = periodise(tan_main, interval(π))(X)
tan_rev(c::Interval[, x::Interval])
Reverse tangent. Calculates the preimage of `a = tan(x)`. If `x` is not provided, then
byt default ``[-∞, ∞]`` is used. See section 10.5.4 of the IEEE 1788-2015 standard for interval arithmetic.
byt default ``[-Inf, Inf]`` is used. See section 10.5.4 of the IEEE 1788-2015 standard for interval arithmetic.
### Output
Expand Down
Loading

0 comments on commit 18cf52d

Please sign in to comment.