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.Tue, 29 Nov 2016 05:18:52 -0600Coefficients of serieshttp://ask.sagemath.org/question/35774/coefficients-of-series/Consider the sequence of polynomials:
g = lambda x, n: ((1 + x^2)^n + n*x*(1 + x^2)^(n - 1))
for n in (0..4):
print g(x,n).series(x,3*n)
1
1 + 1*x + 1*x^2
1 + 2*x + 2*x^2 + 2*x^3 + 1*x^4
1 + 3*x + 3*x^2 + 6*x^3 + 3*x^4 + 3*x^5 + 1*x^6
1 + 4*x + 4*x^2 + 12*x^3 + 6*x^4 + 12*x^5 + 4*x^6 + 4*x^7 + 1*x^8
for n in (0..4):
print g(x,n).list()
[1]
[1, 1, 1]
[1, 2, 2, 2, 1]
[1, 3, 3, 6, 3, 3, 1]
[1, 4, 4, 12, 6, 12, 4, 4, 1]
These are obviously the coefficients of the polynomials.
So I expected that I could also write instead
for n in (0..4):
print g(x,n).series(x,3*n).coefficients()
But this is not the case. What I get is:
[]
[[1, 0], [1, 1]]
[[1, 0], [2, 1], [2, 2], [2, 3]]
[[1, 0], [3, 1], [3, 2], [6, 3], [3, 4], [3, 5]]
[[1, 0], [4, 1], [4, 2], [12, 3], [6, 4], [12, 5], [4, 6], [4, 7]]
Here the term 1*x^(2*n) is missing. Is this a bug?Tue, 29 Nov 2016 04:10:51 -0600http://ask.sagemath.org/question/35774/coefficients-of-series/Answer by slelievre for <p>Consider the sequence of polynomials:</p>
<pre><code>g = lambda x, n: ((1 + x^2)^n + n*x*(1 + x^2)^(n - 1))
for n in (0..4):
print g(x,n).series(x,3*n)
1
1 + 1*x + 1*x^2
1 + 2*x + 2*x^2 + 2*x^3 + 1*x^4
1 + 3*x + 3*x^2 + 6*x^3 + 3*x^4 + 3*x^5 + 1*x^6
1 + 4*x + 4*x^2 + 12*x^3 + 6*x^4 + 12*x^5 + 4*x^6 + 4*x^7 + 1*x^8
for n in (0..4):
print g(x,n).list()
[1]
[1, 1, 1]
[1, 2, 2, 2, 1]
[1, 3, 3, 6, 3, 3, 1]
[1, 4, 4, 12, 6, 12, 4, 4, 1]
</code></pre>
<p>These are obviously the coefficients of the polynomials. </p>
<p>So I expected that I could also write instead</p>
<pre><code>for n in (0..4):
print g(x,n).series(x,3*n).coefficients()
</code></pre>
<p>But this is not the case. What I get is:</p>
<pre><code>[]
[[1, 0], [1, 1]]
[[1, 0], [2, 1], [2, 2], [2, 3]]
[[1, 0], [3, 1], [3, 2], [6, 3], [3, 4], [3, 5]]
[[1, 0], [4, 1], [4, 2], [12, 3], [6, 4], [12, 5], [4, 6], [4, 7]]
</code></pre>
<p>Here the term 1<em>x^(2</em>n) is missing. Is this a bug?</p>
http://ask.sagemath.org/question/35774/coefficients-of-series/?answer=35777#post-id-35777I think it is a bug.
A workaround for now is to use `coeffs` instead of `coefficients`.
Here is what you get then.
sage: for n in (0..4):
....: print g(x,n).series(x,3*n).coeffs()
....:
/opt/s/sage-7.4/src/bin/sage-ipython:2: DeprecationWarning: coeffs is deprecated. Please use coefficients instead.
See http://trac.sagemath.org/17438 for details.
# -*- coding: utf-8 -*-
[[1, 0]]
[[1, 0], [1, 1], [1, 2]]
[[1, 0], [2, 1], [2, 2], [2, 3], [1, 4]]
[[1, 0], [3, 1], [3, 2], [6, 3], [3, 4], [3, 5], [1, 6]]
[[1, 0], [4, 1], [4, 2], [12, 3], [6, 4], [12, 5], [4, 6], [4, 7], [1, 8]]
Note however that `coeffs` is deprecated, so it might disappear in a future version of Sage.
I'll edit later today with more on the bug.Tue, 29 Nov 2016 05:18:52 -0600http://ask.sagemath.org/question/35774/coefficients-of-series/?answer=35777#post-id-35777