Skip to content

Commit

Permalink
Fix evaluate for mixtures over Intervals (#352)
Browse files Browse the repository at this point in the history
  • Loading branch information
lbenet authored Mar 15, 2024
1 parent b9303b5 commit ee8a685
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TaylorSeries"
uuid = "6aa5eb33-94cf-58f4-a9d0-e4b2c4fc25ea"
repo = "https://github.com/JuliaDiff/TaylorSeries.jl.git"
version = "0.17.1"
version = "0.17.2"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
21 changes: 21 additions & 0 deletions ext/TaylorSeriesIAExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,27 @@ function evaluate(a::TaylorN, dx::IntervalBox{N,T}) where {T<:Real,N}
return suma
end

function evaluate(a::Taylor1{TaylorN{T}}, dx::Interval{S}) where {T<:Real, S<:Real}
order = a.order
uno = one(dx)
dx2 = dx^2
if iseven(order)
kend = order-2
@inbounds sum_even = a[end]*uno
@inbounds sum_odd = a[end-1]*zero(dx)
else
kend = order-3
@inbounds sum_odd = a[end]*uno
@inbounds sum_even = a[end-1]*uno
end
@inbounds for k in kend:-2:0
sum_odd = sum_odd*dx2 + a[k+1]
sum_even = sum_even*dx2 + a[k]
end
return sum_even + sum_odd*dx
end


function evaluate(a::HomogeneousPolynomial, dx::IntervalBox{N,T}) where {T<:Real,N}
@assert N == get_numvars()
dx == IntervalBox(-1..1, Val(N)) && return _evaluate(a, dx, Val(true))
Expand Down
8 changes: 7 additions & 1 deletion test/intervals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using TaylorSeries, IntervalArithmetic

using Test
eeuler = Base.MathConstants.e
# eeuler = Base.MathConstants.e

@testset "Tests Taylor1 and TaylorN expansions over Intervals" begin
a = 1..2
Expand Down Expand Up @@ -100,6 +100,12 @@ eeuler = Base.MathConstants.e
@test string(Taylor1(vc, 5)) ==
" ( [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⁶)"

# Iss 351 (inspired by a test in ReachabilityAnalysis)
p1 = Taylor1([0 .. 0, (0 .. 0.1) + (0 .. 0.01) * y], 4)
p2 = Taylor1([0 .. 0, (0 .. 0.5) + (0 .. 0.02) * x + (0 .. 0.03) * y], 4)
@test evaluate([p1, p2], 0 .. 1) == [p1[1], p2[1]]
@test typeof(p1(0 .. 1)) == TaylorN{Interval{Float64}}

# Tests related to Iss #311
# `sqrt` and `pow` defined on Interval(0,Inf)
@test_throws DomainError sqrt(ti)
Expand Down

2 comments on commit ee8a685

@lbenet
Copy link
Member Author

@lbenet lbenet commented on ee8a685 Mar 15, 2024

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/102976

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.17.2 -m "<description of version>" ee8a685e3ac9fc2af06ba9e20634e8c33f350b73
git push origin v0.17.2

Please sign in to comment.