JuliaDiff/TaylorSeries.jl

Order of returned polynomial for `linear_polynomial()`

Closed this issue · 5 comments

linear_polynomial() currently returns an order-1 polynomial, both for Taylor1 and TaylorN inputs. A problem arises when the result is combined with another polynomial, because the order is silently reduced to the lowest order polynomial; see #225. As an example, consider obtaining the nonlinear part of a polynomial as follows:

julia> using TaylorSeries

julia> p = Taylor1(randn(6))
 0.20079031451576249 - 1.6282576374761404 t - 1.008018078993041- 1.305746635645788+ 1.0012734589392516 t⁴ - 0.5611784209308402 t⁵ + 𝒪(t⁶)

julia> lin = linear_polynomial(p)
 - 1.6282576374761404 t + 𝒪(t²)

julia> non_lin = p - lin   # this is wrong!
 0.20079031451576249 + 𝒪(t²)

Something similar occurs with TaylorN.

I thus propose that linear_polynomial(a) returns a polynomial of the same order of a.

cc: @mforets @dpsanders

I don't understand why the linear polynomial here doesn't contain the constant term?

linear_polynomial only returns the degrere-1 part; so, by design.

The proposed change sounds good to me.

As you know, for more time than I would have liked we had a bug in LazySets by a misuse of linear_polynomial (see here, which fixes it by defining a new function _nonlinear_polynomial for Taylor1 and also for TaylorN).

I am working on this now; a nonlinear_polynomial function would be handy, right?

Yes.