Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve product of TaylorModelNs #31

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 37 additions & 20 deletions src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,30 +208,47 @@ end
# Multiplication
function *(a::TaylorModelN, b::TaylorModelN)
@assert a.x0 == b.x0 && a.I == b.I

# Polynomial product with extended order
order = max(get_order(a), get_order(b))
@assert 2*order ≤ get_order()
aext = TaylorN(copy(a.pol.coeffs), 2*order)
bext = TaylorN(copy(b.pol.coeffs), 2*order)
res = aext * bext

# Returned polynomial
bext = TaylorN( copy(res.coeffs[1:order+1]) )

# Bound for the neglected part of the product of polynomials
res[0:order] .= zero(eltype(res))
aux = a.I - a.x0
Δnegl = res(aux)

# Remainder of the product
Δa = a.pol(aux)
Δb = b.pol(aux)
Δ = Δnegl + Δb * a.rem + Δa * b.rem + a.rem * b.rem
# Polynomial product with largest order from TaylorSeries._params_TaylorN_
order_a = get_order(a)
order_b = get_order(b)
order_max = max(order_a, order_b)
order_prod = order_a + order_b
orderTS = get_order()

# The returned polynomial has no neglected part
if order_prod ≤ orderTS
apol = TaylorN(a.pol.coeffs, order_prod)
bpol = TaylorN(b.pol.coeffs, order_prod)
res = apol * bpol
Δa = a.pol(aux)
Δb = b.pol(aux)
Δ = Δb * a.rem + Δa * b.rem + a.rem * b.rem
return TaylorModelN(res, Δ, a.x0, a.I)
end

return TaylorModelN(bext, Δ, a.x0, a.I)
end
# The returned polynomial has a neglected part
# Bound the neglected part of the product of polynomials
apol = TaylorN(a.pol.coeffs, orderTS)
lbenet marked this conversation as resolved.
Show resolved Hide resolved
bpol = TaylorN(b.pol.coeffs, orderTS)
res = apol * bpol
Δa = apol(aux)
Δb = bpol(aux)
Δ = Δb * a.rem + Δa * b.rem + a.rem * b.rem

# We evaluate each term of the product of coefficients at `aux`
Δnegl = zero(Δ)
for order = order_max+1:order_prod
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this start at order_max?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am correcting that, it should be orderTS. The idea, as I say above, is to compute the resulting polynomial up to orderTS, and from there bound whatever is not included in the polynomial part.

orderini = order - order_max
for inda = orderini:order_a
indb = order - inda
Δnegl += evaluate(apol[inda], aux) * evaluate(bpol[indb], aux)
end
end

return TaylorModelN(res, Δ+Δnegl, a.x0, a.I)
end

# Multiplication by numbers
function *(b::T, a::TaylorModelN) where {T<:NumberNotSeries}
Expand Down
9 changes: 3 additions & 6 deletions test/TMN.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ function check_containment(ftest, xx::TaylorModelN{N,T,S}, tma::TaylorModelN{N,T
end

const _order = 2
const _order_max = 2*(_order+1)
set_variables(Interval{Float64}, [:x, :y], order=_order_max)
set_variables(Interval{Float64}, [:x, :y], order=_order)

@testset "Tests for TaylorModelN " begin
b0 = Interval(0.0) × Interval(0.0)
Expand Down Expand Up @@ -53,7 +52,7 @@ set_variables(Interval{Float64}, [:x, :y], order=_order_max)
@test_throws BoundsError TaylorModelN(5, _order, b0, ib0) # wrong variable number

# Tests for get_order and remainder
@test get_order() == 6
@test get_order() == 2
@test get_order(xm) == 2
@test remainder(ym) == zi
end
Expand All @@ -79,8 +78,6 @@ set_variables(Interval{Float64}, [:x, :y], order=_order_max)
b = b1[2] * a
@test b == TaylorModelN( b1[2]*a.pol, Δ*b1[2], b1, ib1 )
@test b / b1[2] == a
@test_throws AssertionError TaylorModelN(TaylorN(1, order=_order_max), zi, b1, ib1) *
TaylorModelN(TaylorN(2, order=_order_max), zi, b1, ib1)

remt = remainder(1/(1-TaylorModel1(_order, b1[1], ib1[1])))
@test remainder(1 / (1-xm)) == remt
Expand All @@ -100,7 +97,7 @@ set_variables(Interval{Float64}, [:x, :y], order=_order_max)
@test rpa(x->5*x, ym) == 5*ym
remT = remainder(5*TaylorModel1(2, b1[1], ib1[1])^4)
@test rpa(x->5*x^4, xm) == TaylorModelN(zero(xT), remT, b1, ib1)
remT = 5 * (ib1[1]-b1[1])^2 * (2*(ib1[2]-b1[2])+(ib1[2]-b1[2])^2)
remT = 5 * (ib1[1]-b1[1])^2 *(ib1[2]-b1[2]) * (2+(ib1[2]-b1[2]))
@test rpa(x->5*x^2, xm*ym) == TaylorModelN( 5*xT^2, remT, b1, ib1)

# Testing remainders of an RPA
Expand Down