Search code examples
paripari-gppower-series

How to get the power series G(z^2) from G(z)


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)

Solution

  • 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))