0

I think it's an easy question, but I can't find how to do it correctly.

substpol works almost as I need, but doubles the polynomial degree.

For example, with :

G(z)=1+2*z+3*z^2+O(z^5)

I got:

substpol(1+2*z^2+3*z^3 + O(z^5),z,z^2)
%20 = 1 + 2*z^4 + 3*z^6 + O(z^10)

but I would like to keep the result in O(z^5):

1 + 2*z^4 + O(z^5)
Andrew
  • 873
  • 4
  • 10
Damien
  • 300
  • 1
  • 8

2 Answers2

2

You can select the precision you want just by adding + O(z^5) to your substpol expression.

> substpol(1+2*'z^2+3*'z^3 + O('z^5),'z,'z^2) + O('z^5)
1 + 2*z^4 + O(z^5)
Piotr Semenov
  • 1,761
  • 16
  • 24
2

I normally handle this situation by having a variable for the desired series length like n and then just tack on + O(x^n)where appropriate. When I am super concerned about performance I will also reduce the length of the power series before substituting.

It is possible to get the precision of a series using serprec. The following function will substitute x for x^2 keeping the same precision:

f(s) = {subst(s, x, x^2) + O(x^serprec(s, x))}
f(1+2*x+3*x^2+O(x^5))
Andrew
  • 873
  • 4
  • 10