Ask Your Question
0

Expanding a bivariate exponential generating function

asked 2023-03-09 22:38:21 +0100

Peter Luschny gravatar image

updated 2023-03-10 23:32:14 +0100

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 flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
3

answered 2023-03-10 09:29:28 +0100

FrédéricC gravatar image

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)]
[[1],
 [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]]
edit flag offensive delete link more

Comments

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.

Peter Luschny gravatar imagePeter Luschny ( 2023-03-10 15:50:19 +0100 )edit

Your sage is too old. Use sage 9.8.

FrédéricC gravatar imageFrédéricC ( 2023-03-10 18:58:13 +0100 )edit

Yes, this is quite nice. Thank you.

Peter Luschny gravatar imagePeter Luschny ( 2023-03-10 23:32:46 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2023-03-09 22:38:21 +0100

Seen: 276 times

Last updated: Mar 10 '23