integrate giving wrong result

Bug introduced in 7.0 or earlier, fixed as of 11.3

A question with the same title has been asked many times, but I can't find the solution of my problem in their answers. The integral I am trying to calculate is

Integrate[Sin[q ]^2 / Sinh[q]^2, {q, 0, ∞}]

which gives me

1/4 (-1 + 2 π Coth[π])

The correct result is

1/4 (-2 + 2 π Coth[π])

This is a tabulated integral, see for instance Gradshteyn and Ryzhik, 3.982.3

Why is Mathematica wrong here? Most issues I have seen were due to variables in the integral, which I don't have (at least not in this example, in the actual integral that I am computing I have variables).

• Wolfram Alpha is wrong as well ... wolframalpha.com/input/… – Young Jul 11 '16 at 22:58
• In the meantime: take the Laplace transform of your integrand, and let the transform variable go to zero. – J. M. will be back soon Jul 11 '16 at 23:21
• Or use GenerateConditions -> False, gives correct answer, makes you feel ucky... – ciao Jul 12 '16 at 3:37
• Why does GenerateConditions -> False change the result (or even the algorithm behind it) if there are no parameters that possibly could cause conditions? – Felix Jul 12 '16 at 14:32
• The bug has been confirmed by Mathematica developers. – Felix Jul 12 '16 at 20:16

You get the right result, if you first solve the indefinite integral and then take the upper and lower limit (using MMA version 8.0)

int[q_] = Integrate[Sin[q]^2/Sinh[q]^2, q, Assumptions -> q > 0]

(*     1/8 E^(-2 I q) (-4 E^(2 I q) Coth[q] + 2 (1 + E^(4 I q)) Coth[q] +
2 Hypergeometric2F1[-I, 1, 1 - I, E^(2 q)] +
2 E^(4 I q) Hypergeometric2F1[I, 1, 1 + I, E^(2 q)] + (1 - I) E^(
2 q) Hypergeometric2F1[1, 1 - I, 2 - I, E^(
2 q)] + (1 + I) E^((2 + 4 I) q)
Hypergeometric2F1[1, 1 + I, 2 + I, E^(2 q)])     *)

lim0 = Limit[int[q], q -> 0, Direction -> -1] // FullSimplify

(*     1/2 \[Pi] Coth[\[Pi]]     *)

liminf = Limit[int[q], q -> \[Infinity]] // FullSimplify

(*     -(1/2) + \[Pi] Coth[\[Pi]]     *)

{buf = liminf - lim0, N[buf]}

(*     {-(1/2) + 1/2 \[Pi] Coth[\[Pi]], 1.07667}     *)