Integration of asymptotic function using Poly.integrate()

35 views
Skip to first unread message

Suchit K

unread,
Feb 26, 2023, 6:34:01 AM2/26/23
to sympy
Why does Poly.integrate() function doesn't give correct answer for asymptotic expressions like O(x**2)?
Example:
from sympy import *
x = Symbol('x')
exp = Poly(O(x**4))
print(exp.integrate()) #prints 1/2*O(x**4)**2 instead of O(x**5)

Oscar Benjamin

unread,
Feb 26, 2023, 8:18:20 AM2/26/23
to sy...@googlegroups.com
A Poly object considers itself to be a polynomial function of some
generator so Poly(O(x**4)) is a polynomial function of O(x**4). Notice
that when you call integrate here you don't specify what variable you
want to integrate with respect to but if you had specified
exp.integrate(x) you would have seen an error because the Poly
considers itself to be a function of O(x**4) rather than x.

There is no way that Poly can do anything sensible with something
O(x**4) so just don't use Poly for this:

>>> O(x**4).integrate(x)
O(x**5)

Calculus with big-O objects is still questionable but SymPy currently
has the behaviour you expect for integration and differentiation.

--
Oscar

Suchit K

unread,
Feb 26, 2023, 9:04:22 AM2/26/23
to sy...@googlegroups.com
Thanks for clarifying.

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAHVvXxS-%2B2dpjfqwi_G2Eg1gVjJJNKoy%2BNX9YKkggV5NUz%3DgTg%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages