# An analog to Pari's serlaplace

With PARI I can do this:

f(x) = ((3*x + 8)*sinh(2*x) + (2*x^2 + 16*(x + 1))*cosh(2*x))/16;
serlaplace(f('x + O('x^5)))


PARI returns 1 + 2x + 5x^2 + 16x^3 + 28x^4 + O(x^5).

How to achieve this with Sage? Note that I want the returned value to live in the 'Power Series Ring' over the 'Integer Ring'.

def serlaplace(f, prec):
t = taylor(f, x, 0, prec)
C = [c for c in t.coefficients()]
R.<u> = PowerSeriesRing(QQ)
S.<z> = PowerSeriesRing(ZZ)
return S(R(C).egf_to_ogf())

f(x) = ((3*x + 8)*sinh(2*x) + (2*x^2 + 16*(x + 1))*cosh(2*x))/16
serlaplace(f, 4) returns 1 + 2*z + 5*z^2 + 16*z^3 + 28*z^4.


The question is: Is there a more direct, more efficient way to achieve this?

edit retag close merge delete

Sort by » oldest newest most voted

Here a potential solution:

def as_ogf(f, prec):
S.<z> = PowerSeriesRing(ZZ)
pari.set_series_precision(prec)
C = pari("serlaplace(" + str(f(x)) + ")")
return S(C)

f(x) = ((3*x + 8)*sinh(2*x) + (2*x^2 + 16*(x + 1))*cosh(2*x))/16
as_ogf(f, 4) returns 1 + 2*z + 5*z^2 + 16*z^3 + 28*z^4 and is of the required type.


It seems to me it would be worthwhile to include such a function in Sage.

EDIT: After an edit this now works also with

f(x) = (3*x + 8)*sinh(2*x)/4; as_ogf(f, 4)


and returns 4z + 3z^2 + 16z^3 + 24z^4 + O(z^5), as desired.

more