# Is it possible to circumvent a bug inside SeriesCoefficient?

As far as I can tell, there seems to be a bug in SeriesCoefficient:

In:=
f[z_] := (-z + z Sqrt[1 - 4 z^2])/(2 (-1 + z));
SeriesCoefficient[f[z], {z, 0, 10}]
SeriesCoefficient[f[z], {z, 0, n}] /. n -> 10

Out= 9

Out= 93/256


Note that both outputs should be the same, but apparently the application general in n makes a mistake (9 is the correct result). In fact, I know that the coefficients grow exponentially in n but we get:

In:=
SeriesCoefficient[f[z], {z, 0, n},
Assumptions :> Mod[n, 2] == 0 && n >= 2] // FullSimplify

Out= 1/2 (1 - Gamma[n/2]/(Sqrt[\[Pi]] Gamma[(1 + n)/2]))


This quantity,

$\qquad\displaystyle \frac{1}{2} \cdot \biggl(1 - \frac{\Gamma\bigl(\frac{n}{2}\bigr)}{\sqrt{\pi} \cdot \Gamma\bigr(\frac{n+1}{2}\bigr)} \biggr)$,

converges to 1/2 from below (odd n support the same series), so it's not even close to being correct.

Obviously, I can't tell what exactly goes wrong inside SeriesCoefficient.

Since I have an interest in the general form of the coefficient (of the expansions of this and other functions), is there a way to circumvent the bug inside (or the application of SeriesCoefficient) so that it works more reliably? Less power would be acceptable in trade.

• Mathematica 11.0 outputs $\frac{1}{2} \cdot (1 - i \sqrt{3})$ for all $n \geq 1$ -- still wrong, but different. – Raphael Apr 2 '17 at 16:26

As

l = CoefficientList[Series[f[z], {z, 0, 20}], z]
(*
{0, 0, 0, 1, 1, 2, 2, 4, 4, 9, 9, 23, 23, 65, 65, 197, 197, 626, 626, 2056, 2056}
*)


we can calculate only the even terms.

You could do for example:

k = FindSequenceFunction[l[[2 ;; ;; 2]]]

Chop@N@k  (* The tenth coefficient *)
(*
9
*)


Moreover:

FullSimplify[k[n], Element[k, Integers] && k > 0]
(*
(2-2 I Sqrt@3-(4^n Gamma[-1/2+n] Hypergeometric2F1Regularized[1,-1/2+n,1+n, 4])/Sqrt@π)/4
*)


$$k(n) = \frac{1}{4} \left(-\frac{4^n \, _2\tilde{F}_1\left(1,n-\frac{1}{2};n+1;4\right) \Gamma \left(n-\frac{1}{2}\right)}{\sqrt{\pi }}-2 i \sqrt{3}+2\right)$$

• Nice, never knew of these functions. One concern: FindSequenceFunction tries to find a function for which the finite list of coefficients matches, right? Isn't that inherently unsave? – Raphael May 9 '14 at 9:19
• @Raphael Of course! But you may try to "confirm" the result by testing on higher coefficients. I think it's pretty safe in this case (but no, I wont bet my money on it :) ) – Dr. belisarius May 9 '14 at 9:34
• I guess more can't be accepted at this point. (It is possible to prove the result by induction, but that's a mess I'd like to avoid.) Since I kind of have to bet my money on the result, I guess I'll have to wait for the bugfix. Thanks! – Raphael May 9 '14 at 16:59