Skip to content

Commit

Permalink
Use \sqcup and \sqcap
Browse files Browse the repository at this point in the history
  • Loading branch information
dpsanders committed May 26, 2024
1 parent 9844021 commit 1746d31
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 115 deletions.
8 changes: 5 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
name = "IntervalContractors"
uuid = "15111844-de3b-5229-b4ba-526f2f385dc9"
version = "0.4.7"
version = "0.4.8"

[deps]
IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"
IntervalBoxes = "43d83c95-ebbb-40ec-8188-24586a1458ed"

[compat]
IntervalArithmetic = "0.16, 0.17, 0.18, 0.19, 0.20"
julia = "1.3, 1.4, 1.5"
IntervalArithmetic = "0.22"
IntervalBoxes = "0.1"
julia = "1"

[extras]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

The reverse function of a function `f` calculates the (interval hull of) its inverse function, `f⁻¹`.

For example, `sin_rev(Y::Interval, X::Interval)` calculates the (interval hull of) those `x ∈ X` such that `sin(x) ∈ Y`. This can also be thought of as an inverse function, calculating `X_new := sin⁻¹(Y) X`.
For example, `sin_rev(Y::Interval, X::Interval)` calculates the (interval hull of) those `x ∈ X` such that `sin(x) ∈ Y`. This can also be thought of as an inverse function, calculating `X_new := sin⁻¹(Y) X`.
The return value is `(Y, X_new)`.

Functions such as `mul_rev(C::Interval, A::Interval, B::Interval)` take three arguments, and correspond to `C = A * B`; they return `(C, A_new, B_new)`, with `A_new` and `B_new` similarly defined to be the corresponding inverse images of the multiplication operator in each component.
Expand Down
28 changes: 14 additions & 14 deletions examples/examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ function sawtooth(X::IntervalBox)

x, y = X

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

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

return IntervalBox(x, y)
end


function constant_contractor(X, y_val)
x, y = X
y = y Interval(y_val)
y = y Interval(y_val)
return IntervalBox(x, y)
end

Expand All @@ -26,8 +26,8 @@ end
function add_one(X) # y = x + 1
x, y = X

y = y (x + 1)
x = x (y - 1)
y = y (x + 1)
x = x (y - 1)

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

x, y = X

x = x (0..∞)
x = x (0..∞)

y = y (x ^ 3)
x = x Interval(y.lo ^ (1/3), y.hi^(1/3)) # not rigorous!
y = y (x ^ 3)
x = x Interval(y.lo ^ (1/3), y.hi^(1/3)) # not rigorous!

return x × y
end
Expand All @@ -53,7 +53,7 @@ odd(X::IntervalBox) = ( (x,y) = X; IntervalBox(-x, -y) )
"""

cube_neg = symmetrise(cube0, odd)
cube = cube0 cube_neg
cube = cube0 cube_neg

ff(x) = x^2 - x^3

Expand All @@ -63,10 +63,10 @@ function ff(X::IntervalBox)
a = x^2
b = x^3

y = y (a - b) # y = a - b
y = y (a - b) # y = a - b

a = a (y + b)
b = b (a - y)
a = a (y + b)
b = b (a - y)

x, a = square(IntervalBox(x, a))
x, b = cube(IntervalBox(x, b))
Expand Down
9 changes: 4 additions & 5 deletions src/IntervalContractors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ export plus_rev, minus_rev, inv_rev,

using IntervalArithmetic

const half_pi = IntervalArithmetic.half_pi(Float64) # interval
const two_pi = IntervalArithmetic.two_pi(Float64) # interval
const half_pi = ExactReal(0.5) * interval(pi)
const two_pi = ExactReal(2.0) * interval(pi)

#
# 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
# 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

include("arithmetic.jl")
include("transformations.jl")
Expand All @@ -33,7 +33,6 @@ include("inverse_trig.jl")
include("hyperbolic.jl")
include("inverse_hyperbolic.jl")
include("extrema.jl")
include("decorated.jl")

"""
Dictionary mapping functions to their reverse functions.
Expand Down
76 changes: 38 additions & 38 deletions src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ The triplet `(a, b_new, c_new)` where
- `c_new` is the interval hull of the set ``{y ∈ c : ∃ x ∈ b, x + y ∈ a}``
"""
function plus_rev(a::Interval, b::Interval, c::Interval) # a = b + c
# a = a (b + c) # add this line for plus contractor (as opposed to reverse function)
b_new = b (a - c)
c_new = c (a - b)
# a = a (b + c) # add this line for plus contractor (as opposed to reverse function)
b_new = b (a - c)
c_new = c (a - b)

return a, b_new, c_new
end
Expand All @@ -37,16 +37,16 @@ The triplet `(a, b_new, c_new)` where
"""
function minus_rev(a::Interval, b::Interval, c::Interval) # a = b - c

b_new = b (a + c)
c_new = c (b - a)
b_new = b (a + c)
c_new = c (b - a)

return a, b_new, c_new
end

minus_rev(a,b,c) = minus_rev(promote(a,b,c)...)

function minus_rev(a::Interval, b::Interval) # a = -b
b_new = b (-a)
b_new = b (-a)
return (a, b_new)
end

Expand All @@ -56,25 +56,25 @@ Reverse multiplication
"""
function mul_rev(a::Interval, b::Interval, c::Interval) # a = b * c

# ((0.0 ∉ a) || (0.0 ∉ b)) && (c = c (a / b))
# ((0.0 ∉ a) || (0.0 ∉ c)) && (b = b (a / c))
# ((0.0 ∉ a) || (0.0 ∉ b)) && (c = c (a / b))
# ((0.0 ∉ a) || (0.0 ∉ c)) && (b = b (a / c))

# a = a (b * c) # ?
# a = a (b * c) # ?

if 0 b
temp = c . extended_div(a, b)
temp = c . extended_div(a, b)
c′ = union(temp[1], temp[2])

else
c′ = c (a / b)
c′ = c (a / b)
end

if 0 c
temp = b . extended_div(a, c)
temp = b . extended_div(a, c)
b′ = union(temp[1], temp[2])

else
b′ = b (a / c)
b′ = b (a / c)
end

return a, b′, c′
Expand All @@ -87,8 +87,8 @@ Reverse division
"""
function div_rev(a::Interval, b::Interval, c::Interval) # a = b / c

b = b (a * c)
c = c (b / a)
b = b (a * c)
c = c (b / a)

return a, b, c
end
Expand All @@ -109,7 +109,7 @@ Pair `(a, b_new)` where
"""
function inv_rev(a::Interval, b::Interval) # a = inv(b)

b_new = b inv(a)
b_new = b inv(a)

return a, b_new
end
Expand All @@ -132,27 +132,27 @@ The triplet `(a, b_new, n)` where
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)

if iszero(n)
1 a && return (a, entireinterval(T) b, n)
1 a && return (a, entireinterval(T) b, n)
return (a, emptyinterval(T), n)
end

if n == 2 # a = b^2
root = a
b1 = b root
b2 = b (-root)
b1 = b root
b2 = b (-root)

elseif iseven(n)
root = a^(1//n)

b1 = b root
b2 = b (-root)
b1 = b root
b2 = b (-root)

elseif isodd(n)
pos_root = (a (0..∞)) ^ (1//n)
neg_root = -( ( (-a) (0..∞) ) ^ (1//n) )
pos_root = (a (0..∞)) ^ (1//n)
neg_root = -( ( (-a) (0..∞) ) ^ (1//n) )

b1 = b pos_root
b2 = b neg_root
b1 = b pos_root
b2 = b neg_root

end

Expand All @@ -170,8 +170,8 @@ function power_rev(a::Interval, b::Interval, c::Interval) # a = b^c
return (temp[1], temp[2], interval(temp[3]))
end

b_new = b ( a^(inv(c) ))
c_new = c (log(a) / log(b))
b_new = b ( a^(inv(c) ))
c_new = c (log(a) / log(b))

return a, b_new, c_new
end
Expand All @@ -193,7 +193,7 @@ The pair `(a, b_new)` where
"""
function sqrt_rev(a::Interval, b::Interval) # a = sqrt(b)

b_new = b (a^2)
b_new = b (a^2)

return a, b_new
end
Expand All @@ -220,8 +220,8 @@ function sqr_rev(c, x) # c = x^2; refine x

root = sqrt(c)

x1 = x root
x2 = x (-root)
x1 = x root
x2 = x (-root)

return (c, hull(x1, x2))
end
Expand All @@ -241,10 +241,10 @@ The pair `(c, x_new)` where
"""
function abs_rev(y, x) # y = abs(x); refine x

y_new = y (0..∞)
y_new = y (0..∞)

x1 = y_new x
x2 = -(y_new (-x))
x1 = y_new x
x2 = -(y_new (-x))

return (y, hull(x1, x2))
end
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 (0..∞)
(a == 0.0) && b = b (0.0..0.0)
(a == -1.0) && b = b (-∞..0.0)
return a, b
end
Expand Down Expand Up @@ -288,7 +288,7 @@ IEEE 1788-2015 standard for interval arithmetic.
- `x_new` the interval hull of the set ``{t ∈ x : ∃ y ∈ b, tʸ ∈ c}
"""
function pow_rev1(b, c, x) # c = x^b
return x c^(1/b) # replace by 1//b
return x c^(1/b) # replace by 1//b
end

"""
Expand All @@ -302,7 +302,7 @@ byt default ``[-∞, ∞]`` is used. See section 10.5.4 of the IEEE 1788-2015 st
- `x_new` the interval hull of the set ``{t ∈ x : ∃ y ∈ b, tʸ ∈ c}
"""
function pow_rev2(a, c, x) # c = a^x
return x (log(c) / log(a))
return x (log(c) / log(a))
end

"""
Expand Down
Loading

0 comments on commit 1746d31

Please sign in to comment.