# Expanding a bivariate exponential generating function

Expanding an univariate exponential generating function can be done like this:

def egfExpand1(f, size):
x = var('x')
return taylor(f(x), x, 0, size).power_series(SR).egf_to_ogf().list()


For example egfExpand1(sec, 10) returns [1, 0, 1, 0, 5, 0, 61, 0, 1385, 0, 50521].

But how can I expand a bivariate exponential generating function? Say

def f(x, y): return exp(x * y) * sec(x)

def egfExpand2(f, size):
return ...


The expected output is an integer triangle (i.e. a list of integer lists).

The example would return an unsigned version of A119879, which starts:

                           1
0, 1
1, 0, 1
0, 3, 0, 1
5, 0, 6, 0, 1


Edit:

Frédéric suggested the following solution, slightly rewritten here.

def egfExpand2(f, size):
y = polygen(QQ, "y")
x = LazyPowerSeriesRing(y.parent(), "x").gen()
return [list(f(x, y)[n] * factorial(n)) for n in range(size)]

f = lambda x, y: exp(x * y) * sec(x)
egfExpand2(f, 10)


The univariate case can also be written more elegantly with this method:

def egfExpand1(f, size: int):
x = LazyPowerSeriesRing(QQ, "x").gen()
return [f(x)[n] * factorial(n) for n in range(size)]

egfExpand1(sec, 11)

edit retag close merge delete

Sort by » oldest newest most voted Like this

sage: y = polygen(QQ,'y')
sage: x = LazyPowerSeriesRing(y.parent(),'x').gen()
sage: f = exp(x * y) * sec(x)
sage: [list(f[n]*factorial(n)) for n in range(10)]
[,
[0, 1],
[1, 0, 1],
[0, 3, 0, 1],
[5, 0, 6, 0, 1],
[0, 25, 0, 10, 0, 1],
[61, 0, 75, 0, 15, 0, 1],
[0, 427, 0, 175, 0, 21, 0, 1],
[1385, 0, 1708, 0, 350, 0, 28, 0, 1],
[0, 12465, 0, 5124, 0, 630, 0, 36, 0, 1]]

more

This is what I get: "TypeError: cannot coerce arguments: no canonical coercion from Lazy Power Series Ring over Univariate Polynomial Ring in y over Rational Field to Symbolic Ring." Using SageMath 9.6.