# Defining a power series with variable coefficients

It is not difficult to define a multivariate power series; for example, the following works:

R.<a,x,y> = PowerSeriesRing(ZZ,3)
f = a*x + y + x*y + O(a,x,y)^3


But what I would really like is to treat the series f as a series in x and y, with a acting as a variable coefficient, so that, for example, I could instead write f = a*x + y + x*y + O(x,y)^3. I tried the following:

M = PolynomialRing(ZZ,'a')
R.<x,y> = PowerSeriesRing(M,2)
f = a*x + y + x*y + O(x,y)^3
f


This generates the error "name a is not defined." What can I do to get a into the coefficient ring?

edit retag close merge delete

Sort by » oldest newest most voted

To fix this, a needs to be defined as the generator of M.

The code in the question only sets a as the display value for this generator.

So, do one of the following.

M.<a> = PolynomialRing(ZZ)


or

M.<a> = ZZ[]


or

M = PolynomialRing(ZZ, 'a')
a = M.gen()


or

M = PolynomialRing(ZZ, 'a')
M.inject_variables()


Note that there is also a shortcut with [[]] for defining a power series rings.

sage: M.<a> = ZZ[]
sage: M
Univariate Polynomial Ring in a over Integer Ring
sage: R.<x, y> = M[[]]
sage: R
Multivariate Power Series Ring in x, y over Univariate Polynomial Ring in a over Integer Ring
sage: f = a*x + y + x*y + O(x,y)^3
sage: f
a*x + y + x*y + O(x, y)^3

more