# Why does merely writing SeriesData[] with zeros give an error, even if it is never called?

Bug introduced in 8.0 or earlier and fixed in 11.0.0

Why does the code

Function[t, SeriesData[t, 0, {0}, 0, 1, 1]]


give me the following error?

First::nofirst: {} has zero length and no first element.


First, why in the world is SeriesData even evaluated inside the Function?

Second, what exactly is the error? Can't a series be zero?

• Have you tried to click on the >> sign?
– user9660
Mar 11 '16 at 8:16
• @Louis: Yes I have, and it was completely irrelevant. Have you found it relevant? Mar 11 '16 at 8:19
• (continued), but both of those SeriesData expressions have the same InputForm, that is InputForm[SeriesData[t, 0, {}, 1, 2, 1]] === InputForm[SeriesData[t, 0, {0}, 1, 2, 1]] evaluates to True Mar 11 '16 at 8:51
• @Dr.belisarius - but Hold@SeriesData[t, 0, {}, 0, 1, 1] does not give the error. Something about the internal representation of SeriesData when the coefficients are zero Mar 11 '16 at 8:52
• I believe the more general question is why Hold@SeriesData[t, 0, {0}, 0, 1, 1] reports an error. The Function[ ] thing is holding it, hence the error Mar 11 '16 at 9:02

This is a formatting issue, that I think should be reported to WRI.

Quick and dirty workaround could be something like this:

Unprotect[SeriesData];
SeriesData /: MakeBoxes[
ser : SeriesData[
x_, x0_,
{__?(Function[Null, MiscDumpeffectiveSign@HoldComplete[#] === "0", HoldAllComplete])},
nmin_Integer, nmax_Integer, den_Integer
],
fmt_
] :=
MakeBoxes[SeriesData[x, x0, {}, nmin, nmax, den], fmt]
Protect[SeriesData];


Now outputting held series data doesn't result in error messages.

SeriesData[t, 0, {0}, 0, 1, 1] // Hold
SeriesData[t, 0, {0.}, 0, 1, 1] // Hold
SeriesData[t, 0, {0 a}, 0, 1, 1] // Hold
SeriesData[t, 0, {Print["leak"] 0}, 0, 1, 1] // Hold
SeriesData[t, 0, {0, 0., 0 a, Print["leak"] 0}, 0, 1, 1] // Hold
(* Hold[O[t]^1]  (in all cases) *)


In Function[t, SeriesData[t, 0, {0}, 0, 1, 1]] expression SeriesData[t, 0, {0}, 0, 1, 1] is not evaluated, but when this expression is outputted in the FrontEnd it is formatted.

Rules used for formatting of SeriesData can be found in FormatValues[SeriesData]. We can see there two rules: first for empty list of coefficients, second for non-empty. In second rule we can find DeleteCases[MiscDumpsignsAndTerms, {"0", _}] code followed by First[MiscDumpsignsAndTerms], where MiscDumpsignsAndTerms is list containing certain special representation of series terms. Above DeleteCases removes terms corresponding to 0 coefficients.

It seems that possibility that there will be only 0 coefficients was overlooked and in such case First[MiscDumpsignsAndTerms] receives empty list which results in First::nofirst error.

Formatting of non-held SeriesData expression with zero-only coefficients does not result in error, because such expression evaluates to SeriesData with empty list of coefficients which is covered by first formatting rule.

SeriesData[t, 0, {0}, 0, 1, 1] // InputForm
(* SeriesData[t, 0, {}, 1, 1, 1] *)

• Interesting, thanks! It's funny that I've only been seriously coding in Mathematica for a week or so and I've run into bugs already. Mar 11 '16 at 18:08
• Perhaps this question should have the bugs tag; what does everyone think? Mar 11 '16 at 20:45
• An easy bug to fix. One comment: it would be better to write {0 ..} instead of {(zero_ /; zero == 0) ..}. The latter allows the arguments to evaluate (which may have bad consequences--onsider {Print[foo}), and its much slower. Mar 15 '16 at 19:27
• One other minor point: Series would never produce a list only containing zeroes--the canonical form is an empty list--which is probably how this bug snuck through. Mar 15 '16 at 19:35
• Another refinement: you don't need Repeated, i.e. _?test .., as __?test` will do the same thing. Mar 16 '16 at 10:44