Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump IntervalArithmetic to 0.22 #57

Merged
merged 24 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
fail-fast: false
matrix:
version:
- '1'
- '1.10'
- 'nightly'
os:
- ubuntu-latest
Expand Down
11 changes: 11 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# IntervalContractors.jl NEWS.md

## v0.5.0
- Update to `IntervalArithmetic.jl` v0.22
- Use square versions of intersection and union symbols (available from v0.22.12)
- Some previous functions were removed from `IntervalArithmetic.jl`

- Adds a dependency on the separate `IntervalBoxes.jl` package (to replace the functionality removed from
`IntervalArithmetic.jl`)

- `Interval` now refers to a *decorated* interval
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.5.0"

[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.12"
IntervalBoxes = "0.2"
julia = "1"

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

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::IntervalType, X::IntervalType)` 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.
Functions such as `mul_rev(C::IntervalType, A::IntervalType, B::IntervalType)` 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.

### Contractors

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 ⊓ interval(-1, 1)
y = y ⊓ interval(-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 ⊓ (interval(0, Inf))

y = y (x ^ 3)
x = x ∩ Interval(y.lo ^ (1/3), y.hi^(1/3)) # not rigorous!
y = y (x ^ 3)
x = x ⊓ interval(inf(y) ^ (1/3), sup(y)^(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
29 changes: 20 additions & 9 deletions src/IntervalContractors.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
__precompile__(true)

module IntervalContractors

export plus_rev, minus_rev, inv_rev,
Expand All @@ -15,14 +13,28 @@ 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 IntervalType{T} = Union{Interval{T}, BareInterval{T}}

# @generated
# half_pi(::Type{T}) where {T <: IntervalType} = :(ExactReal(0.5) * convert($T, ExactReal(pi)))
# @generated
# two_pi(::Type{T}) where {T <: IntervalType} = :(ExactReal(2.0) * convert($T, ExactReal(pi)))

@generated function half_pi(x::T) where {T <: IntervalType}
return ExactReal(0.5) * convert(T, ExactReal(pi))
end

@generated function two_pi(x::T) where {T <: IntervalType}
return ExactReal(2.0) * convert(T, ExactReal(pi))
end

const half_pi = IntervalArithmetic.half_pi(Float64) # interval
const two_pi = IntervalArithmetic.two_pi(Float64) # interval
@generated function pi_interval(x::T) where {T <: IntervalType}
return convert(T, ExactReal(pi))
end

#
# 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 +45,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
Loading
Loading