From f8cccb48f1911c8ab9e675552a8522349b5cb320 Mon Sep 17 00:00:00 2001 From: David Sanders Date: Thu, 13 Jun 2019 15:45:59 -0500 Subject: [PATCH] Fix sin, cos, periodise, symmetrise Add tests --- src/transformations.jl | 9 +++++++-- src/trig.jl | 10 +++++++--- test/Non1788tests/inv_trig.jl | 5 +++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/transformations.jl b/src/transformations.jl index 5c0198e..4d42458 100644 --- a/src/transformations.jl +++ b/src/transformations.jl @@ -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) @@ -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) diff --git a/src/trig.jl b/src/trig.jl index 77ab181..5d1a80b 100644 --- a/src/trig.jl +++ b/src/trig.jl @@ -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)) """ @@ -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 """ @@ -85,6 +87,8 @@ 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) @@ -92,8 +96,8 @@ 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 """ diff --git a/test/Non1788tests/inv_trig.jl b/test/Non1788tests/inv_trig.jl index 87f833e..ed84b3e 100644 --- a/test/Non1788tests/inv_trig.jl +++ b/test/Non1788tests/inv_trig.jl @@ -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