Skip to content

Commit

Permalink
Improve evaluation (Horner methods) of Taylor1s with intervals (#249)
Browse files Browse the repository at this point in the history
* Improve evaluation of Taylor1 with intervals

* Bump patch version
  • Loading branch information
lbenet authored Sep 18, 2020
1 parent 5044120 commit 6c98fff
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
4 changes: 2 additions & 2 deletions 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.10.6"
version = "0.10.7"

[deps]
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
Expand All @@ -11,7 +11,7 @@ Requires = "ae029012-a4dd-5104-9daa-d747884805df"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[compat]
IntervalArithmetic = "0.15, 0.16"
IntervalArithmetic = "0.15, 0.16, 0.17"
Requires = "0.5.2, 1.0"
julia = "1"

Expand Down
26 changes: 6 additions & 20 deletions src/intervals.jl
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
using .IntervalArithmetic

function evaluate(a::Taylor1, dx::Interval)
dx == (-1..1) && return _evaluate(a, dx, Val(true))
# Usual Horner rule
order = a.order
uno = one(dx)
@inbounds begin
suma = a[end]*uno
for k in a.order-1:-1:0
suma = suma*dx + a[k]
end
end
return suma
end

function _evaluate(a::Taylor1, dx::Interval{T}, ::Val{true}) where {T}
uno = Interval{T}(1, 1)
dx2 = Interval{T}(0, 1)
if iseven(a.order)
kend = a.order-2
dx2 = dx^2
if iseven(order)
kend = order-2
@inbounds sum_even = a[end]*uno
@inbounds sum_odd = a[end-1]*Interval{T}(0, 0)
@inbounds sum_odd = a[end-1]*zero(dx)
else
kend = a.order-3
kend = order-3
@inbounds sum_odd = a[end]*uno
@inbounds sum_even = a[end-1]*uno
end
Expand All @@ -32,8 +20,6 @@ function _evaluate(a::Taylor1, dx::Interval{T}, ::Val{true}) where {T}
return sum_even + sum_odd*dx
end

_evaluate(a::Taylor1, dx::Interval, ::Val{false}) = a(dx)


function evaluate(a::TaylorN, dx::IntervalBox{N,T}) where {N,T}

Expand Down
6 changes: 6 additions & 0 deletions test/intervals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ eeuler = Base.MathConstants.e
@test evaluate(x*y^2, (-1..1)×(-1..1)) == (-1..1)
@test evaluate(x^2*y^2, (-1..1)×(-1..1)) == (0..1)

ii = -1..1
t = Taylor1(1)
@test 0..2 (1+t)(ii)
t = Taylor1(2)
@test 0..4 ((1+t)^2)(ii)

ii = 0..6
t = Taylor1(4)
f(x) = 0.1 * x^3 - 0.5*x^2 + 1
Expand Down

2 comments on commit 6c98fff

@lbenet
Copy link
Member Author

@lbenet lbenet commented on 6c98fff Sep 18, 2020

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

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.10.7 -m "<description of version>" 6c98fff3d746087cb98a5cc09ed062ac9a0112b1
git push origin v0.10.7

Please sign in to comment.