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

Fix sin_rev and cos_rev #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions src/transformations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ Return the integers enclosed in the interval `x`.
"""

function integer_contractor(x::Interval)
a = floor(x.lo)+1

if isinteger(x.lo)
a = x.lo
else
a = floor(x.lo)+1
end
b = floor(x.hi)

a > b && return emptyinterval(x)
Expand Down Expand Up @@ -57,7 +62,7 @@ translate(C, α) = translate(-α) ∘ C ∘ translate(α)
Symmetric part of a Contractor, via an involution `op`
(i.e. such that `inv(op) == op`).
"""
symmetrise(C, op) = op ∘ C ∘ op
symmetrise(C, op) = X -> C(X) ∪ (op ∘ C ∘ op)(X)



Expand Down
10 changes: 7 additions & 3 deletions src/trig.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function sin_main(X::IntervalBox)
end

# TODO: Be careful with the pi constants if using e.g. BigFloats
sin_full = symmetrise(sin_main, reflect_x(half_pi))
sin_reverse = symmetrise(sin_main, reflect_x(half_pi))

"""
Expand All @@ -33,7 +34,8 @@ Contractor for `sin`.
Takes an `IntervalBox` containing the `x` and `y` component intervals.
Returns an `IntervalBox` contracted down to the set ``y = \\sin(x)``.
"""
sin!(X::IntervalBox) = periodise(sin_main, two_pi)(X) ∪ periodise(sin_reverse, two_pi)(X)
sin!(X::IntervalBox) = #periodise(sin_main, two_pi)(X) ∪ periodise(sin_reverse, two_pi)(X)
periodise(sin_full, two_pi)(X)

# Reverse function for sin; does not alter y
"""
Expand Down Expand Up @@ -85,15 +87,17 @@ end
# TODO: Be careful with the pi constants if using e.g. BigFloats
cos_reverse = symmetrise(cos_main, reflect_x(0.0))

cos_full = symmetrise(cos_main, reflect_x(0.0))

"""
cos!(X::IntervalBox)

Contractor for `cos`.
Takes an `IntervalBox` containing the `x` and `y` component intervals.
Returns an `IntervalBox` contracted down to the set ``y = \\cos(x)``.
"""
cos!(X::IntervalBox) = periodise(cos_main, two_pi)(X) ∪ periodise(cos_reverse, two_pi)(X)

cos!(X::IntervalBox) = #periodise(cos_main, two_pi)(X) ∪ periodise(cos_reverse, two_pi)(X)
periodise(cos_full, two_pi)(X)

# Reverse function for cos; does not alter y
"""
Expand Down
5 changes: 5 additions & 0 deletions test/Non1788tests/inv_trig.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ end
@test atan_rev(entireinterval(Float64), entireinterval(Float64))[2] == Interval(-∞, ∞)
@test atan_rev(Interval(-Inf, 0.0), entireinterval(Float64))[2] == Interval(-∞, ∞)
end

@testset "Special cases" begin
@test sin_rev(0..0, 0..0) == (0..0, 0..0)
@test cos_rev(1..1, 0..0) == (1..1, 0..0)
end