ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 01 Aug 2018 10:44:46 -0500Defining a power series with variable coefficientshttp://ask.sagemath.org/question/43222/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?Tue, 31 Jul 2018 12:50:28 -0500http://ask.sagemath.org/question/43222/defining-a-power-series-with-variable-coefficients/Answer by slelievre for <p>It is not difficult to define a multivariate power series; for example, the following works:</p>
<pre><code>R.<a,x,y> = PowerSeriesRing(ZZ,3)
f = a*x + y + x*y + O(a,x,y)^3
</code></pre>
<p>But what I would really like is to treat the series <code>f</code> as a series in <code>x</code> and <code>y</code>, with <code>a</code> acting as a variable coefficient, so that, for example, I could instead write <code>f = a*x + y + x*y + O(x,y)^3</code>. I tried the following:</p>
<pre><code>M = PolynomialRing(ZZ,'a')
R.<x,y> = PowerSeriesRing(M,2)
f = a*x + y + x*y + O(x,y)^3
f
</code></pre>
<p>This generates the error "name <code>a</code> is not defined." What can I do to get <code>a</code> into the coefficient ring?</p>
http://ask.sagemath.org/question/43222/defining-a-power-series-with-variable-coefficients/?answer=43233#post-id-43233To 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)^3Wed, 01 Aug 2018 10:44:46 -0500http://ask.sagemath.org/question/43222/defining-a-power-series-with-variable-coefficients/?answer=43233#post-id-43233