Skip to content

Commit

Permalink
Bump IntervalArithmetic to 0.22 (#57)
Browse files Browse the repository at this point in the history
* Use \sqcup and \sqcap

* Comment out stuff with DecoratedIntervals

* Replace a.lo with inf(a) and similarly for .hi and sup

* More updates

* Bump minor version

* Replace == and === in tests with isequal_interval

* Fix CI to 1.10

* Bump IntervalBoxes version

* Replace Interval() with interval()

* Add eq function for testing bareinterval equality

* Add single-argument sqr_rev

* Add single-arg abs_rev

* Add NEWS.md

* Add single-argument versions of sin_rev and cos_rev

* Typo

* Remove usage of member symbol

* Fix mulrev_to_pair tests

* Add more single-variable versions

* Fix another isempty

* Correct fix for mul_rev_to_pair tests

* Tests passing

* Working for bare intervals

* Fix tests

* Fix test
  • Loading branch information
dpsanders authored Aug 24, 2024
1 parent 9844021 commit 2da7077
Show file tree
Hide file tree
Showing 29 changed files with 2,369 additions and 2,370 deletions.
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

2 comments on commit 2da7077

@dpsanders
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/113792

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.0 -m "<description of version>" 2da707754d84857419a1bbbae082faf999084ab1
git push origin v0.5.0

Please sign in to comment.