# Missing zero in the CoefficientList

The following list has a length only 10 (not 11)

CoefficientList[Series[ArcTan[x]/(1-x^2),{x,0,10}],x]
{0, 1, 0, 2/3, 0, 13/15, 0, 76/105, 0, 263/315}


It should be

{0, 1, 0, 2/3, 0, 13/15, 0, 76/105, 0, 263/315, 0}


Compare with

CoefficientList[Series[ArcTan[x]/(1-x),{x,0,10}],x]
{0, 1, 1, 2/3, 2/3, 13/15, 13/15, 76/105, 76/105, 263/315, 263/315}


(length of the list is 11)

This is important for an exponential generating functions. Correct is

nmax=10; CoefficientList[Series[ArcTan[x]/(1-x), {x, 0, nmax}], x] * Range[0, nmax]!
{0, 1, 2, 4, 16, 104, 624, 3648, 29184, 302976, 3029760}


But from

nmax=10; CoefficientList[Series[ArcTan[x]/(1-x^2), {x, 0, nmax}], x] * Range[0, nmax]!


we get an error:

"Objects of unequal length ... cannot be combined"


Possible solution is add a missing zero manually, for example:

nmax=10; Flatten[{CoefficientList[Series[ArcTan[x]/(1-x^2), {x, 0, nmax}], x] ,0}] * Range[0, nmax]!
{0, 1, 0, 4, 0, 104, 0, 3648, 0, 302976, 0}


Yes, this is a nice solution (and independent on lenght of list), thank you!. For the final sequence we have:

nmax=10; Coefficient[Series[ArcTan[x]/(1-x^2),{x,0,nmax}],x,Range[0,nmax]]*Range[0,nmax]!
{0,1,0,4,0,104,0,3648,0,302976,0}


But question is, if is also efficient. For big "nmax" is much faster

CoefficientList[Series[f[x], {x, 0, nmax}], x] * Range[0, nmax]!


than

Table[n!*SeriesCoefficient[f[x],{x,0,n}], {n,0,nmax}]

• Wait… where is your question here? – J. M.'s ennui May 22 '15 at 10:46
• I report a bug (in this case only a minor bug). I found on this website a lot of similar post, for example mathematica.stackexchange.com/questions/19322 – Vaclav Kotesovec May 22 '15 at 10:56
• @Vaclav In that case you should still include the question "Is this a bug?" Here I don't believe it is one. – Mr.Wizard May 22 '15 at 11:04
• One thing to be aware of is that CoefficientList can take a third argument indicating a total length, and will pad out with zeros to meet that length. This can be used to enforce that the lists being multiplied have the same length. – Daniel Lichtblau May 22 '15 at 18:53
• @Mr. Wizard I guess after I was told to implement it, nobody thought to document it. Which in a way is not so bad-- sometimes the opposite happens. – Daniel Lichtblau May 23 '15 at 22:09

Edit: see the bottom of this post for the best solution.

The documentation for CoefficientList says:

The dimensions of the array returned by CoefficientList are determined by the values of the Exponent[poly, vari].

ser1 = Series[ArcTan[x]/(1 - x^2), {x, 0, 10}];
ser2 = Series[ArcTan[x]/(1 - x), {x, 0, 10}];

Exponent[ser1, x]
Exponent[ser2, x]

9

10


Therefore this is documented behavior, or at least your contention is with Exponent.
It is not looking at the order of the series, only explicit terms:

Exponent[#, x, List] & /@ {ser1, ser2}

{{1, 3, 5, 7, 9}, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}


Each series is represented by a SeriesData expression. I think the fifth parameter is what you need:

ser1[[5]]
ser2[[5]]

11

11

Coefficient[ser1, x, Range[0, 10]]
Coefficient[ser2, x, Range[0, 10]]

{0, 1, 0, 2/3, 0, 13/15, 0, 76/105, 0, 263/315, 0}

{0, 1, 1, 2/3, 2/3, 13/15, 13/15, 76/105, 76/105, 263/315, 263/315}


## Proposed solution

You expressed concern over performance. Please try this:

seriesCoefficientList[ser_SeriesData] :=
ser ~CoefficientList~ ser[[1]] ~PadRight~ ser[[5]]


Test:

big = Series[ArcTan[x]/(1 - x^2), {x, 0, 1000}];

seriesCoefficientList[big] // Length // AbsoluteTiming

{0.0010, 1001}


Daniel Lichtblau revealed an undocumented third parameter of CoefficientList that specifies the length to pad to as implemented above, allowing us to define:

seriesCoefficientList[ser_SeriesData] := CoefficientList[ ser, ser[[1]], ser[[5]] ]