Skip to content

Commit ee8a685

Browse files
authored
Fix evaluate for mixtures over Intervals (#352)
1 parent b9303b5 commit ee8a685

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "TaylorSeries"
22
uuid = "6aa5eb33-94cf-58f4-a9d0-e4b2c4fc25ea"
33
repo = "https://github.com/JuliaDiff/TaylorSeries.jl.git"
4-
version = "0.17.1"
4+
version = "0.17.2"
55

66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

ext/TaylorSeriesIAExt.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,27 @@ function evaluate(a::TaylorN, dx::IntervalBox{N,T}) where {T<:Real,N}
190190
return suma
191191
end
192192

193+
function evaluate(a::Taylor1{TaylorN{T}}, dx::Interval{S}) where {T<:Real, S<:Real}
194+
order = a.order
195+
uno = one(dx)
196+
dx2 = dx^2
197+
if iseven(order)
198+
kend = order-2
199+
@inbounds sum_even = a[end]*uno
200+
@inbounds sum_odd = a[end-1]*zero(dx)
201+
else
202+
kend = order-3
203+
@inbounds sum_odd = a[end]*uno
204+
@inbounds sum_even = a[end-1]*uno
205+
end
206+
@inbounds for k in kend:-2:0
207+
sum_odd = sum_odd*dx2 + a[k+1]
208+
sum_even = sum_even*dx2 + a[k]
209+
end
210+
return sum_even + sum_odd*dx
211+
end
212+
213+
193214
function evaluate(a::HomogeneousPolynomial, dx::IntervalBox{N,T}) where {T<:Real,N}
194215
@assert N == get_numvars()
195216
dx == IntervalBox(-1..1, Val(N)) && return _evaluate(a, dx, Val(true))

test/intervals.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using TaylorSeries, IntervalArithmetic
55

66
using Test
7-
eeuler = Base.MathConstants.e
7+
# eeuler = Base.MathConstants.e
88

99
@testset "Tests Taylor1 and TaylorN expansions over Intervals" begin
1010
a = 1..2
@@ -100,6 +100,12 @@ eeuler = Base.MathConstants.e
100100
@test string(Taylor1(vc, 5)) ==
101101
" ( [1.5, 2] + [0, 0]im ) - ( [1, 2] + [-1, 1]im ) t + ( [-1, 1.5] + [-1, 1.5]im ) t² + ( [0, 0] + [-1, 1.5]im ) t³ + 𝒪(t⁶)"
102102

103+
# Iss 351 (inspired by a test in ReachabilityAnalysis)
104+
p1 = Taylor1([0 .. 0, (0 .. 0.1) + (0 .. 0.01) * y], 4)
105+
p2 = Taylor1([0 .. 0, (0 .. 0.5) + (0 .. 0.02) * x + (0 .. 0.03) * y], 4)
106+
@test evaluate([p1, p2], 0 .. 1) == [p1[1], p2[1]]
107+
@test typeof(p1(0 .. 1)) == TaylorN{Interval{Float64}}
108+
103109
# Tests related to Iss #311
104110
# `sqrt` and `pow` defined on Interval(0,Inf)
105111
@test_throws DomainError sqrt(ti)

0 commit comments

Comments
 (0)