# Mathematica failing to series expand a simple analytic function

Bug introduced in 5.0 or earlier and persisting in 11.2

Mathematica is doing funky things with the function

f = EllipticPi[z, -z];

f /. z -> 0
(* Pi/2 *)

f /. z -> (x + I y) /. (x + I y) -> 0
(* EllipticK[-x - I y] *)

Series[f, {z, 0, 0}]
(* EllipticPi[z, -z] *)


This function is analytic at the origin, as can be verified by looking at

Plot3D[Evaluate[{Re[f], Im[f], Abs[f]} /. z -> x + I y], {x, -1/2, 1/2}, {y, -1/2, 1/2}]


so there shouldn't be a problem expanding it in series. Is this a bug?

v11.0.1 for Mac OS X x86 (64-bit)

A quick workaround is to re-express the complete elliptic integral of the third kind as an Appell hypergeometric function:

Series[(π/2) AppellF1[1/2, 1, 1/2, 1, z, -z], {z, 0, 10}]
π/2 + (π z)/8 + (21 π z^2)/128 + (45 π z^3)/512 + (3745 π z^4)/32768 + O[z]^5


Wolfram got back to me.

When performing the first substitution in

f /. z -> (x + I y) /. (x + I y) -> 0


, Mathematica is distributing the minus sign, so the result of the first substitution is

EllipticPi[x + I y, -x - I y]


as opposed to

EllipticPi[x + I y, -(x + I y)]


. Therefore, the second argument does not match the pattern x + I y, so the result of the second substitution is

EllipticPi[0, -x - I y]


, which automatically simplifies to

EllipticK[-x - I y]


by a mathematical identity. They suggest

f/.z->(Hold[x+I y])/.(Hold[x+I y])->0


in order to get my desired behavior.

Regarding the series expansion, they just said "it seems that EllipticPi needs to define its arguments separately in order to properly define a Series expansion" without explaining why, or how to implement this in the general case where there might be very complicated expressions inside and/or outside the EllipticPi function. Since the value that Mathematica returns in not actually the correct series expansion and it doesn't throw any error messages, I consider this to be a bug.

• Nevertheless, you can always try re-expressing in terms of AppellF1[], as I noted in my answer. – J. M. is away Apr 18 '17 at 15:02

The function;

 f[z_, m_] := EllipticPi[z, -m];


indeed, looks analytical in z=0, m=0:

Plot3D[f[z, m], {z, -0.5, 0.5}, {m, -0.5, 0.5}]


Try this:

expr1 = Series[f[z, m], {z, 0, 2}] /. m -> z // Normal

(*  EllipticK[-z] + 1/4 π z Hypergeometric2F1[1/2, 3/2, 2, -z] +
3/16 π z^2 Hypergeometric2F1[1/2, 5/2, 3, -z]   *)


and then

expr1A = Series[expr1, {z, 0, 2}] // Normal

(*   π/2 + (π z)/8 + (21 π z^2)/128   *)


Now another way around:

expr2 = Series[f[z, m], {m, 0, 2}] /. z -> m // Normal

(*  π/(2 Sqrt[1 - m]) +
m^2 (-((3 π)/(16 m^2)) + (3 π)/(16 Sqrt[1 - m] m^2) - (
3 π)/(32 m)) + m (π/(4 m) - π/(4 Sqrt[1 - m] m))   *)


and then this:

expr2A = Series[expr2, {m, 0, 2}] /. m -> z // Normal

(*  π/2 + (π z)/8 + (21 π z^2)/128  *)


Evidently:

expr1A == expr2A

(*  True  *)


Have fun!