# Noise near 0 when plotting LerchPhi function

What is happening near 0 when I plot the function LerchPhi?

Plot[LerchPhi[y^2, 1, 9/2], {y, -1, 1}]


• Possible a numeric noise,try Plot[{LerchPhi[y^2, 1, 9/2]}, {y, -1, 1}, WorkingPrecision -> 100, PlotRange -> {Automatic, {0, 1}}] Oct 17, 2017 at 11:22
• Please don't use the bugs tag when posting new questions. See the tag description. Oct 17, 2017 at 13:42
• many thanks, but what if I needs its value for computing? Oct 17, 2017 at 16:39

The problem here, as already noted by Mariusz, is that severe cancellation is happening when evaluating near the origin.

A solution in this case is to use a different representation of your function in terms of Hypergeometric2F1[], which performs better for tiny arguments:

Plot[2/9 Hypergeometric2F1[1, 9/2, 11/2, y^2], {y, -1, 1}]


• May I ask why, under-the-hood, LerchPhi doesn't simply call Hypergeometric2F1 for numerical evaluation? Nov 14, 2017 at 14:31
• I don't know either, honestly. (Probably a good suggestion to send to support.) Note that the same problem happens with HurwitzLerchPhi[]. Nov 14, 2017 at 14:37

"but what if I needs its value for computing?"

LerchPhi[y^2, 1, 9/2]

(* (-2 - (2*y^2)/3 - (2*y^4)/5 -
(2*y^6)/7 + (2*ArcTanh[y])/y)/y^8 *)

LerchPhi[0, 1, 9/2]

(* 2/9 *)


With machine precision near zero you get a bad result

LerchPhi[0.0001, 1., 4.5]

(* 0. *)


Using arbitrary precision

LerchPhi @@ SetPrecision[{0.0001, 1., 4.5}, 20]

(* 0.22 *)

Precision[%]

(* 1.60341 *)


Almost all precision is lost between input and output. It is much better to convert input to exact numbers and then convert exact output to numeric values

N[LerchPhi @@ ({0.0001, 1., 4.5} // Rationalize), 20]

(* 0.22224040557899892396 *)

Precision[%]

(* 20. *)