# Strange integration

Bug introduced in 9.0 or earlier and fixed in 10.1

Note: Beginning with V10.1, this integral returns unevaluated but without error messages.

I tried to evaluate this line

Integrate[((-I/2) (E^((-I) x) - E^(I x)) + ((E^((-I) x) + E^(I x)) x)/
2)/((-1 + E^x) x), {x, 0, Infinity}]


Then I get $14$ lines of

$RecursionLimit::reclim: Recursion depth of 1024 exceeded. >>  After that the anwer is 1/2 (-HarmonicNumber[-I] - HarmonicNumber[I])  After an N[%] is gives -0.671866 + 0. I, but this is an incorrect answer, since the correct numerical value of the integral is -0.39629064109001017515941014. Maybe Mathematica couldn't solve it, it's ok, but from where comes this incorrect closed expression? By the way of turned Off something and because of this the evaluation does not stop after run into some$RecursionLimit, but I don't know what was that and I cannot turn it On. Any idea what was that? I forgot it.

I use Mathematica 9.

• which version are you using? on V10.01, I do not get 1/2 (-HarmonicNumber[-I] - HarmonicNumber[I]), but only Recursion depth. btw, doing NIntegrate[...] works and gives -0.396291 + 1.65436*10^-24 I which is the correct numerical value that you show there. screen shot: !Mathematica graphics Oct 22, 2014 at 11:02
• @Nasser I use Mathematica 9. Yes, but it is strange that NIntegrate[...] and N[Integrate[...]] are different. Oct 22, 2014 at 11:05
• FYI the expression simplifies to: (Cos[x]-Sinc[x])/(Cosh[x]+Sinh[x]-1). Same result on integration though :( Oct 22, 2014 at 15:40
• @george2079 Thank you. I've known it, but Mathematica makes more recursion for this form. Oct 22, 2014 at 15:46
• Definitely a bug. Oct 22, 2014 at 19:16

Here is a way of evaluating your integral analytically.

Series expand the integrand, but hold out a factor x/(-1 + E^x) to ensure that the series can subsequently be integrated term by term — this factor is 1 at x = 0, and x E^-x as x -> Infinity. Keep only the first few terms of the series, which we will use to “spot the pattern”.

ser = Series[(x Cos[x] - Sin[x])/((-1 + E^x) x) ((-1 + E^x)/x), {x, 0, 6}] //
Normal // # x/(-1 + E^x) & // Expand

(* -(x^2/(3 (-1 + E^x))) + x^4/(30 (-1 + E^x)) - x^6/(840 (-1 + E^x)) *)


By integrating each term of this series it is easy to spot that integration of the general term can be done using the following rule:

rule = (x^b_ a_)/(-1+E^x) :> a b! Zeta[b+1];


Feed the (truncated) series through this rule.

ser /. rule

(* -((2 Zeta[3])/3) + (4 Zeta[5])/5 - (6 Zeta[7])/7 *)


The pattern is obvious, so the required integral is given by (this takes a while to evaluate)

int = Sum[(-1)^i (2 i)/(2 i + 1) Zeta[2 i + 1], {i, \[Infinity]}] // FunctionExpand

(* 1/2 I Log[Gamma[1 - I]] - 1/2 I Log[Gamma[1 + I]]
- 1/2 PolyGamma[0, 1 - I] - 1/2 PolyGamma[0, 1 + I] *)


The numerical value of this symbolic result is

N[int] // Chop

(* -0.396291 *)


which is the same as is obtained by direct numerical integration.

• @ Stephen Lutrell: Your final sum does not converge in V8. After regularizing it with Exp(-a i) and taking the limit a->0 of the then converging sum gives the expected result +0. I. The different expansion 1/(E^x - 1) == Sum[E^(x (-k - 1)), {k, 0, [Infinity]}] leads to the Sum[(1 + k)/(2 + k*(2 + k)) - ArcTan[1/(1 + k)], {k, 0, Infinity}] the NSum of which gives the result in no time. Oct 22, 2014 at 21:21
• Based on a ListPlot of the terms in my Sum I had assumed that there must be subtle tricks going on behind the scenes in V10 in order for it to get its result to come out - in fact, I was rather surprised that it worked at all. Oct 22, 2014 at 22:34
• BTW, I like your use of the 1/(1-z) == Sum[z^k, {k, 0, \[Infinity]}] trick. Oct 22, 2014 at 22:48
• @ Stephen Lutrell: things are even more interesting! Your sum is in fact divergent by all criteria. Define the partial sum by s[m_] := Sum[(2*(-1)^kkZeta[1 + 2*k])/(1 + 2*k), {k, 1, m}]. It oscillates between two values, depending on the parity of m: s[10^4] // N -> 0.103684, s[10^4 + 1] // N -> -0.896266 and only the average of these two gives the "correct result". A more simple example is Sum[(-1)^k,{k,0,oo}] which gives 1/2 "on average". Hence the well defined and "innocent" original integral provides de facto a regularized divergent infinite sum. Oct 23, 2014 at 7:17