2

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}

Added after an answer by Mr.Wizard:

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}]
Vaclav Kotesovec
  • 2,949
  • 1
  • 11
  • 22
  • 1
    Wait… where is your question here? – J. M.'s missing motivation 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 http://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
  • Please see my updated answer with my proposal seriesCoefficientList. – Mr.Wizard May 22 '15 at 11:37
  • Yes, this is faster: {0., 1001}

    I tried also (each with a restart of Mathematica)

    Timing[nmax = 1000; Coefficient[Series[ArcTan[x]/(1 - x^2), {x, 0, nmax}], x, Range[0, nmax]]*Range[0, nmax]!;]
    {0.904806, Null}
    Timing[nmax = 1000; Flatten[{CoefficientList[Series[ArcTan[x]/(1 - x^2), {x, 0, nmax}], x], 0}]*Range[0, nmax]!;]
    {0.140401, Null}
    
    – Vaclav Kotesovec May 22 '15 at 11:56
  • Exactly, I used seriesCoefficientList[big]*Range[0, 1000]! // Length // AbsoluteTiming. But CoefficientList was really much faster than Coefficient. – Vaclav Kotesovec May 22 '15 at 12:00
  • 3
    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
  • @Daniel Thank you. That appears to be undocumented; do you know why? – Mr.Wizard May 23 '15 at 09:54
  • @Daniel: Great! nmax=10; CoefficientList[Series[ArcTan[x]/(1-x^2),{x,0,nmax}],x,11] * Range[0,nmax]! The output is now correct: {0,1,0,4,0,104,0,3648,0,302976,0} – Vaclav Kotesovec May 23 '15 at 10:01
  • Only note that third argument in CoefficientList can be added in version 10.0, but not in versions 7 or 8 (not tested in version 9). – Vaclav Kotesovec May 23 '15 at 10:05
  • In general, in my program above please replace 11-> nmax+1, for example nmax=20; CoefficientList[Series[ArcTan[x]/(1-x^2),{x,0,nmax}],x,nmax+1]*Range[0,nmax]! – Vaclav Kotesovec May 23 '15 at 10:15
  • 1
    @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
  • @Mr. Wizard I've now filed a suggestion that this third arg to CoefficientList be documented. – Daniel Lichtblau May 23 '15 at 22:48

1 Answers1

3

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]] ]
Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371