Skip to content

Commit f8cccb4

Browse files
dpsanderslucaferranti
authored andcommitted
Fix sin, cos, periodise, symmetrise
Add tests
1 parent 9844021 commit f8cccb4

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

src/transformations.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ Return the integers enclosed in the interval `x`.
66
"""
77

88
function integer_contractor(x::Interval)
9-
a = floor(x.lo)+1
9+
10+
if isinteger(x.lo)
11+
a = x.lo
12+
else
13+
a = floor(x.lo)+1
14+
end
1015
b = floor(x.hi)
1116

1217
a > b && return emptyinterval(x)
@@ -57,7 +62,7 @@ translate(C, α) = translate(-α) ∘ C ∘ translate(α)
5762
Symmetric part of a Contractor, via an involution `op`
5863
(i.e. such that `inv(op) == op`).
5964
"""
60-
symmetrise(C, op) = op C op
65+
symmetrise(C, op) = X -> C(X) (op C op)(X)
6166

6267

6368

src/trig.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function sin_main(X::IntervalBox)
2424
end
2525

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

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

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

90+
cos_full = symmetrise(cos_main, reflect_x(0.0))
91+
8892
"""
8993
cos!(X::IntervalBox)
9094
9195
Contractor for `cos`.
9296
Takes an `IntervalBox` containing the `x` and `y` component intervals.
9397
Returns an `IntervalBox` contracted down to the set ``y = \\cos(x)``.
9498
"""
95-
cos!(X::IntervalBox) = periodise(cos_main, two_pi)(X) periodise(cos_reverse, two_pi)(X)
96-
99+
cos!(X::IntervalBox) = #periodise(cos_main, two_pi)(X) ∪ periodise(cos_reverse, two_pi)(X)
100+
periodise(cos_full, two_pi)(X)
97101

98102
# Reverse function for cos; does not alter y
99103
"""

test/Non1788tests/inv_trig.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,8 @@ end
3232
@test atan_rev(entireinterval(Float64), entireinterval(Float64))[2] == Interval(-∞, ∞)
3333
@test atan_rev(Interval(-Inf, 0.0), entireinterval(Float64))[2] == Interval(-∞, ∞)
3434
end
35+
36+
@testset "Special cases" begin
37+
@test sin_rev(0..0, 0..0) == (0..0, 0..0)
38+
@test cos_rev(1..1, 0..0) == (1..1, 0..0)
39+
end

0 commit comments

Comments
 (0)