TITLE: Indefinite integral with residue theorem
QUESTION [5 upvotes]: I tried to solve the following integral using residue theorem. $$\int_0^\infty\frac{x}{\sinh x} ~\mathrm dx=\int_{-\infty}^\infty\frac{x}{e^x-e^{-x}}~\mathrm dx$$
$e^x-e^{-x}=0$ when $x=n\pi i, n\subset\mathbb Z$
So the residues are (when n is a positive integer)
$$\frac{(-1)^n n\pi i}{2}$$
Thus the value of definite integral will be
$$2\pi i\sum_{n=1}^\infty \frac{(-1)^n n\pi i}{2}=\pi^2(1-2+3-4+5-\ldots)$$
But the series diverges obviously. Here I used the technique that
$$A=1-1+1-1+1-\ldots$$
$$A=1-(1-1+1-1+1-\ldots)$$
$$A=1-A, A=\frac{1}{2}$$
$$B=1-2+3-4+5-6+7-\ldots$$
$$B=(1-1+1-1+1-\ldots)-(1-2+3-4+5-\ldots)$$
$$B=A-B, B=\frac{1}{4}$$
Thus the integral value is $\frac{\pi^2}{4}$.
Although the value itself is correct, I think this method is still controversial. How can this method become justified? Or is there a problem in my residue theorem solution?

REPLY [2 votes]: $\newcommand{\angles}[1]{\left\langle\,{#1}\,\right\rangle}
 \newcommand{\braces}[1]{\left\lbrace\,{#1}\,\right\rbrace}
 \newcommand{\bracks}[1]{\left\lbrack\,{#1}\,\right\rbrack}
 \newcommand{\dd}{\mathrm{d}}
 \newcommand{\ds}[1]{\displaystyle{#1}}
 \newcommand{\expo}[1]{\,\mathrm{e}^{#1}\,}
 \newcommand{\half}{{1 \over 2}}
 \newcommand{\ic}{\mathrm{i}}
 \newcommand{\iff}{\Leftrightarrow}
 \newcommand{\imp}{\Longrightarrow}
 \newcommand{\Li}[2]{\,\mathrm{Li}_{#1}\left(\,{#2}\,\right)}
 \newcommand{\ol}[1]{\overline{#1}}
 \newcommand{\pars}[1]{\left(\,{#1}\,\right)}
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\ul}[1]{\underline{#1}}
 \newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,}
 \newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}}
 \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$


This is another posibility to evaluate the integral along a complex plane contour:
\begin{align}
\color{#f00}{\int_{0}^{\infty}{x \over \sinh\pars{x}}\,\dd x} & =
\half\int_{-\infty}^{\infty}{x \over \sinh\pars{x}}\,\dd x =
\int_{-\infty}^{\infty}{x\expo{x} \over \expo{2x} - 1}\,\dd x\
\stackrel{\expo{x}\ \mapsto\ x}{=}\
\int_{0}^{\infty}{\ln\pars{t} \over t^{2} - 1}\,\dd x
\end{align}
The integral is evaluated along a $\mathit{\mbox{key-hole}}$ contour which takes care of the $\ds{\ln\pars{z}}$ $\mathit{\mbox{branch-cut}}$ along the 'positive real axis'. Namely,
$$
\ln\pars{z} = \ln\pars{\verts{z}} + \,\mathrm{arg}\pars{z}\ic\,,\ 0 < \,\mathrm{arg}\pars{z} < 2\pi\,,\ z \not= 0
$$
Along the above mentioned contour, we evaluate the integral
$$
\int{\ln^{2}\pars{z} \over z^{2} - 1}\,\dd z
$$
which has one  pole $\ds{\pars{= -1}}$  'inside' the contour. The
forthcoming $\ds{\ \ic\,0^{\pm}\ }$ 'factors' will take care of the singularity at $\ds{x = +1}$ along the $\ds{\ln}$ branch-cut.

$$
2\pi\ic\,{\braces{\ln\pars{\verts{-1}} + \pi\ic}^{\, 2} \over -1 - 1} =
\int_{0}^{\infty}
{\bracks{\ln\pars{t} + 0\,\ic}^{\, 2} \over
\pars{t - 1 + \ic 0^{+}}\pars{t + 1}}\,\dd t
+
\int_{\infty}^{0}
{\bracks{\ln\pars{t} + 2\pi\ic}^{\, 2} \over
\pars{t - 1 - \ic 0^{-}}\pars{t + 1}}\,\dd t
$$
\begin{align}
\pi^{3}\,\ic & =
\mathrm{P.V.}\int_{0}^{\infty}{\ln^{2}\pars{t} - \ln^{2}\pars{t} - 4\pi\ic\,\ln\pars{t} - 4\pi^{2} \over t^{2} - 1}\,\dd t
\\[3mm] &\ +\ \overbrace{\int_{0}^{\infty}{\ln^{2}\pars{t} \over t + 1}\,
\bracks{-\pi\ic\,\delta\pars{t - 1}}\,\dd t}^{\ds{=\ 0}}
\\[3mm] & -
\int_{0}^{\infty}{\bracks{\ln\pars{t} + 2\pi\ic}^{\, 2}\over t + 1}\,
\bracks{\pi\ic\,\delta\pars{t - 1}},\dd t
\\[1cm] & =
-4\pi\ic\int_{0}^{\infty}{\ln\pars{t} \over t^{2} - 1}\,\dd t -
4\pi^{2}\,\mathrm{P.V.}\int_{0}^{\infty}{\dd t \over t^{2} - 1} + 2\pi^{3}\ic
\\[1cm] \imp
\int_{0}^{\infty}{\ln\pars{t} \over t^{2} - 1}\,\dd t & =
{\pi^{3}\ic - 2\pi^{3}\ic \over -4\pi\ic} -
{4\pi^{2} \over -4\pi\ic}\,\mathrm{P.V.}\int_{0}^{\infty}{\dd t \over t^{2} - 1}
\\[3mm] & = \color{#f00}{\pi^{2} \over 4} -
\pi\ic\,\mathrm{P.V.}\int_{0}^{\infty}{\dd t \over t^{2} - 1}\tag{1}
\end{align}

Note que
\begin{align}
\mathrm{P.V.}\int_{0}^{\infty}{\dd t \over t^{2} - 1} & =
\lim_{\epsilon \to 0^{+}}\pars{\int_{0}^{1 - \epsilon}{\dd t \over t^{2} - 1} +
\int_{1 + \epsilon}^{\infty}{\dd t \over t^{2} - 1}}
\\[3mm] & =
\lim_{\epsilon \to 0^{+}}\pars{\int_{0}^{1 - \epsilon}{\dd t \over t^{2} - 1} +
\int_{1/\pars{1 + \epsilon}}^{0}{\dd t \over t^{2} - 1}} =
\lim_{\epsilon \to 0^{+}}
\int_{1 - \epsilon}^{1/\pars{1 + \epsilon}}{\dd t \over 1 - t^{2}} = 0
\end{align}
\begin{align}
&\mbox{because}
\\[3mm] &\ 
0 < \verts{\int_{1 - \epsilon}^{1/\pars{1 + \epsilon}}{\dd t \over 1 -t^{2}}}
<\verts{\pars{{1 \over 1 + \epsilon} - 1 + \epsilon}\,{1 \over
1 - 1/\pars{1 + \epsilon}^{2}}} =
\verts{\epsilon\pars{1 + \epsilon} \over 2 + \epsilon} \to
\stackrel{\epsilon\ \to\ 0}{0}
\end{align}

With this result and expression $\pars{1}$:
$$
\color{#f00}{\int_{0}^{\infty}{x \over \sinh\pars{x}}\,\dd x} =
\int_{0}^{\infty}{\ln\pars{t} \over t^{2} - 1}\,\dd t =
\color{#f00}{\pi^{2} \over 4}
$$