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

Order behavior of integrate and derivative for univariate Taylor series #230

Closed
AnderMuruaUria opened this issue Oct 28, 2019 · 10 comments · Fixed by #248 or #274
Closed

Order behavior of integrate and derivative for univariate Taylor series #230

AnderMuruaUria opened this issue Oct 28, 2019 · 10 comments · Fixed by #248 or #274

Comments

@AnderMuruaUria
Copy link

I don't like the way integrate and derivative deal with the order of univariate series in TaylorSeries.jl.

I've checked that, integrate( 1. + O(t) ) gives on output 0. + O(t).
In my opinion, integrate( 1 + O(t)) should give t + O(t^2).

Similarly, derivative( t + O(t^2) ) gives 1 + O(t^2). In my opinion, derivative( t + O(t^2) ) should result in 1 + O(t).

Is there some reason for integrate and derivative behave in that (in my opinion, mathematically unnatural) way in TaylorSeries.jl?

@lbenet
Copy link
Member

lbenet commented Oct 28, 2019

Thanks for reporting. Let me first say that, the convention we have is to have the same (fixed) order as the initial polynomial.

Then, for integrate, I think the issue is related to the maximal order you are defining initially for your Taylor1 polynomial. I'll try to reproduce what I think you did. Below, I define an "order 0" Taylor1 polynomial, and then integrate it, which results in what you are reporting:

julia> a = Taylor1([1.0], 0)  # zero-th order Taylor1 polynomial
 1.0 + 𝒪(t¹)

julia> integrate(a)
 0.0 + 𝒪(t¹)

If, however, you do the following, you get what is expected:

julia> b = Taylor1([1.0], 1)  # order-1 Taylor1 polynomial
 1.0 + 𝒪(t²)

julia> integrate(b)
 1.0 t + 𝒪(t²)

Note that, if you further integrate the last answer, i.e., integrate(integrate(b)) you get again zero,
0.0 + 𝒪(t²), because the result is an order-2 Taylor polynomial but you are truncating the computations in order 1 (the coefficients of the resulting order-1 Taylor1 polynomial are all zero.

Regarding the derivative, your comment is well taken: we should probably "lower" the order of the resulting Taylor polynomial, instead of returning the same order with the last coefficient equal to zero. As I said above, we have the convention of fixing the order of the result. Note that similar things also occur when multiplying, or computing certain functions, such as exp.

A recent, somewhat related issue, is #226.

@dpsanders
Copy link
Contributor

Derivative seems to be a special case that is different from any other function, since it reduces the order, instead of increasing it. It really is true that you are losing information (number of known coefficients of the polynomial) so probably that should really reduce the order.

@AnderMuruaUria
Copy link
Author

Thanks a lot for the quick answers.

Yes, I agree that integrate and derivative are different in that

  • integrate(Taylor1([1.], 0)) = 0. + O(t) is mathematically correct

  • derivative(Taylor1([1., 0.], 1) = 0. + O(t^2) is mathematically incorrect

The convention of giving to the resulting series the same order as the input series should perhaps have some exceptions so that to guarantee that the results are mathematically correct. By the way, I've checked that
Taylor1([0.,1.],1)/Taylor1([0.,1.],1) == Taylor1([1.,0.],1)
gives true, which I think is mathematically incorrect as well.

@lbenet
Copy link
Member

lbenet commented Oct 28, 2019

I've checked that Taylor1([0.,1.],1)/Taylor1([0.,1.],1) == Taylor1([1.,0.],1) gives true, which I think is mathematically incorrect as well.

Why? Don't you expect that t/t == 1? Or, do you mean that the order of the answer is again 1? If so, again, it is the convention mentioned above.

@lbenet
Copy link
Member

lbenet commented Oct 28, 2019

@dpsanders I agree that derivative is a special case, and in that sense, we should lower the order. Yet, to change this may have other consequences due to #226.

@AnderMuruaUria
Copy link
Author

The convention on the order adopted in TaylorSeries.jl is not what I expected. I find the big Oh notation misleading. I interpret s = a0 + a1t + a2t^2+O(t^3) as s = a0 + a1t +a2t^2+a3t^3+a4t^4+... with unknown coefficients a3, a4, ...

Going back to the example I mentioned in my latest comment: consider sin(t), which can be Taylor-expanded at t0=0 as s = t + O(t^2). If we divide s by t (or by anything that can be expanded as t + O(t^2)), I would expect s/t = 1 + O(t). Indeed, sin(t)/t = 1 + O(t). Clearly, sin(t)/t = 1 + O(t^2) is wrong.

I understand that with the order convention adopted in TaylorSeries.jl, the elements of type Taylor1 are interpreted on input as polynomials, not as series. The order field of the object of type Taylor1 is only used on output: The result of evaluating a function f on an object p of type Taylor1 with order=n is the polynomial obtained by truncating at order n the series expansion of f(p). Is that right?

@lbenet
Copy link
Member

lbenet commented Oct 29, 2019

Yes, you are right. To be explicit, we consider the Taylor expansions as polynomials, which are truncated to certain order, which is kept fixed.

@lbenet
Copy link
Member

lbenet commented Jul 9, 2020

@AnderMuruaUria Sorry to address this issue with such a delay!

I just pushed a few changes in #248 which address some of the issues pointed out here. With them, we have:

julia> derivative(Taylor1([1., 0.], 1))
 0.0 + 𝒪(t¹)

There are still few things to do, e.g., that if t = t + O(t^2) and s = sin(t) = t + O(t^2), then s/t == 1 + O(t^1), as well as other cases involving powers; I am checking how breaking these changes are in other projects which are somewhat related to TaylorIntegration.jl.

cc @PerezHz

@lbenet
Copy link
Member

lbenet commented Apr 7, 2021 via email

@lbenet
Copy link
Member

lbenet commented Apr 7, 2021

@dpsanders What about the integration? Should we increase the order?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants