A definite integral with tanh and sin In an old textbook, Thomas John I'Anson Bromwich asks the reader to use the expansion 
$$ \tanh \left(\frac{\pi x}{2} \right) = 1 + 2 \sum_{n=1}^{\infty} (-1)^{n} e^{-n \pi x}$$
to show $$\lim_{t \to 0^{+}} \int_{0}^{\infty} e^{-tx} \tanh \left(\frac{\pi x}{2} \right) \sin (ax) \, dx = \text{csch}(a).$$
The reader is then supposed to assign this value to the divergent integral $$\int_{0}^{\infty} \tanh \left(\frac{\pi x}{2} \right) \sin (ax) \, dx $$
and deduce
$$\int_{0}^{\infty}\frac{\tanh(\frac{\pi x}{2})\sin(ax)}{x^{2}+1} \, dx= \frac{1}{2} \left[e^{-a}\log(e^{2a}-1)-e^{a}\log(1-e^{-2a})\right] \tag{1}.$$
This approach seems quite unusual and not easy to justify.
Can we prove $(1)$ in another way?
 A: Consider the complex function $ \displaystyle f(z) = \tanh \left( \frac{\pi z}{2} \right) \frac{e^{iaz}}{1+z^{2}}$ where $a > 0$.
On the right, top, and left sides of a rectangular contour with vertices at $\pm 2N, \pm 2N + i2N$ (where N is a positive integer), $\tanh \left(\frac{\pi z}{2} \right)$ is uniformly bounded.
So using a slight modification of Jordan's lemma, we can conclude
$$ \int_{-\infty}^{\infty} \tanh \left( \frac{\pi z}{2} \right) \frac{e^{iaz}}{1+z^{2}} \, dx = 2 \pi i \left(\text{Res}[f(z),i] + \sum_{n=1}^{\infty} \text{Res}[f(z),i(2n+1)]\right) .$$
Now since
$$ \begin{align} f(z+i) &= e^{-a} \coth \left(\frac{\pi z}{2} \right) e^{iaz}\frac{1}{z} \frac{1}{z+2i} \\ &= e^{-a} \left(\frac{2 }{\pi z} + \mathcal{O}(z) \right) \left(1+iaz + \mathcal{O}(z^{2}) \right) \frac{1}{z} \left(- \frac{i}{2}+ \frac{z}{4} + \mathcal{O}(z^{2}) \right) \\ &= e^{-a} \left(-\frac{i}{\pi z^{2}} + \frac{2a+1}{2 \pi z} + \mathcal{O}(1) \right) , \end{align}$$
we get
$$ \text{Res}[f(z),i] = \text{Res}[f(z+i), 0] = \frac{e^{-a}(2a+1)}{2 \pi} .$$
And for $n \ge 1$,
$$ \begin{align}\text{Res}[f(z),i(2n+1)] &= \lim_{n \to i(2n+1)} \frac{\sinh (\frac{\pi z}{2}) e^{iaz}}{\frac{d}{dz} \,  \cosh (\frac{\pi z}{2}) (1+z^{2}) } \\ &= - \frac{1}{2 \pi} \frac{e^{-(2n+1)a}}{n(n+1)} . \end{align}$$
Therefore,
$$ \begin{align} \int_{-\infty}^{\infty} \tanh \left(\frac{\pi z}{2} \right) \frac{e^{iax}}{1+x^{2}} \ dx &= i e^{-a} (2a+1) - i \sum_{n=1}^{\infty} \frac{e^{-(2n+1)a}}{n(n+1)} \\ &= i e^{-a} (2a+1) + ie^{-a} \sum_{n=1}^{\infty} \left(\frac{1}{n+1} -\frac{1}{n} \right) e^{-2na} \\ &= 2i a e^{-a} + i e^{-a} + ie^{-a} \sum_{n=1}^{\infty} \frac{e^{-2na}}{n+1} - ie^{-a}\sum_{n=1}^{\infty} \frac{e^{-2na}}{n} \\ &= 2i a e^{-a} + ie^{-a} + i e^{-a} \left(- \frac{\log(1-e^{-2a})}{e^{-2a}} -1\right) + i e^{-a} \log (1-e^{-2a}) \\ &= 2ia e^{-a} - ie^{a} \log(1-e^{-2a})+ie^{-a} \log(1-e^{-2a}) . \end{align}$$
And equating the imaginary parts on both sides of the equation, we get
$$ \begin{align} \int_{0}^{\infty} \tanh \left(\frac{\pi x}{2} \right) \frac{\sin ax}{1+x^{2}} \ dx &= \frac{1}{2} \left( 2a e^{-a} + e^{-a} \log(1-e^{-2a}) - e^{a} \log(1-e^{-2a}) \right) \\ &= \frac{1}{2} \left(e^{-a} \log(e^{2a} (1-e^{-2a})) - e^{a} \log(1-e^{-2a})\right) \\ &= \frac{1}{2} \left(e^{-a}\log(e^{2a}-1)-e^{a}\log(1-e^{-2a})\right) . \end{align}$$
A: Starting with the expansion
$$
\pi\cot(\pi z)=\sum\limits_{k\in\mathbb{Z}}\frac1{z-k}\tag{1}
$$
where the sum is taken in the principal value sense, it is not too difficult to get
$$
\tfrac\pi2\tanh(\tfrac{\pi z}{2})=\sum_{k\text{ odd}}\frac1{z-ik}\tag{2}
$$
Then using $\gamma=[-R,R]\cup Re^{i[0,\pi]}$ as $R\to\infty$ (keeping $R$ even keeps $\frac1{z-ik}$ uniformly bounded since $k$ is odd), we get
$$
\begin{align}
&\int_0^\infty\frac{\tanh(\frac{\pi x}{2})\sin(ax)}{x^2+1}\mathrm{d}x\tag{3}\\[6pt]
&=\frac1{2i}\int_{-\infty}^\infty\frac{\tanh(\frac{\pi x}{2})\,e^{iax}}{x^2+1}\mathrm{d}x\tag{4}\\[6pt]
&=\frac1{\pi i}\sum_{k\text{ odd}}\int_\gamma\frac{e^{iaz}}{(z-ik)(z+i)(z-i)}\mathrm{d}z\tag{5}\\[6pt]
&=\frac1{\pi i}\int_\gamma\frac{2z}{(z^2+1)^2}e^{iaz}\,\mathrm{d}z\tag{6a}\\
&+\frac1{\pi i}\sum_{\substack{k\text{ odd}\\|k|\gt1}}\int_\gamma
\left({\small\color{#C00000}{\frac1{(2k-2)(z+i)}}\color{#00A000}{-\frac1{(2k+2)(z-i)}}\color{#0000FF}{-\frac1{(k^2-1)(z-ik)}}}\right)e^{iaz}\,\mathrm{d}z\tag{6b}\\
&=\frac{a}{\pi}\int_\gamma\frac1{z^2+1}e^{iaz}\,\mathrm{d}z\tag{7a}\\
&+\frac1{\pi i}\left(\color{#C00000}{0}\color{#00A000}{-\sum_{\substack{k\text{ odd}\\|k|\gt1}}\frac{2\pi i\,e^{-a}}{2k+2}}\color{#0000FF}{-\sum_{\substack{k\text{ odd}\\k\gt1}}\frac{2\pi i\,e^{-ka}}{k^2-1}}\right)\tag{7b}\\
&=\frac{a}{2\pi i}\int_\gamma\left(\frac1{z-i}-\frac1{z+i}\right)e^{iaz}\,\mathrm{d}z\tag{8a}\\
&+\color{#C00000}{0}\color{#00A000}{+\frac{e^{-a}}{2}}\color{#0000FF}{-\frac12\left[e^{-a}+(e^a-e^{-a})\log(1-e^{-2a})\right]}\tag{8b}\\[6pt]
&=ae^{-a}-\frac12(e^a-e^{-a})\log(1-e^{-2a})\tag{9}\\[6pt]
&=\frac12e^{-a}\log(e^{2a}-1)-\frac12e^a\log(1-e^{-2a})\tag{10}
\end{align}
$$
Explanation:
$\:\ (4)$: integrand is even; double domain and divide by two. $\sin(ax)$ is the odd part of $\frac1ie^{iax}$
$\:\ (5)$: apply $(2)$
$\text{(6a)}$: isolate the terms with $|k|=1$
$\text{(6b)}$: partial fractions
$\text{(7a)}$: integrate by parts
$\text{(7b)}$: contour integration
$\text{(8a)}$: partial fractions
$\text{(8b)}$: $\color{#00A000}{\text{principal value sum}}$ and $\color{#0000FF}{\text{apply (11)}}$
$\:\ (9)$: contour integration
$(10)$: rearrange
We used the following in $\text{(8b)}$ above:
$$
\begin{align}
\sum_{\substack{k\text{ odd}\\k\gt1}}\frac{x^k}{k^2-1}
&=\sum_{k=1}^\infty\frac{x^{2k+1}}{4k^2+4k}\\
&=\frac x4\sum_{k=1}^\infty\left(\frac1k-\frac1{k+1}\right)x^{2k}\\
&=\frac x4\sum_{k=1}^\infty\frac{x^{2k}}{k}-\frac1{4x}\sum_{k=2}^\infty\frac{x^{2k}}{k}\\
&=-\frac x4\left(\log(1-x^2)\right)+\frac1{4x}\left(\log(1-x^2)+x^2\right)\\
&=\frac x4+\frac{1-x^2}{4x}\log(1-x^2)\tag{11}
\end{align}
$$
A: I actually toyed with this as I was working on my other answer, but since the integrals, without $e^{-tx}$, do not converge, this didn't seem the right way to approach the problem. However, it seems that this is indeed what the hint intends.
For any $t\gt0$, define
$$
f(a)=\int_0^\infty\frac{\tanh(\frac{\pi x}{2})\sin(ax)}{x^2+1}e^{-tx}\,\mathrm{d}x\tag{1}
$$
then
$$
f''(a)=-\int_0^\infty\frac{\tanh(\frac{\pi x}{2})\sin(ax)\,x^2}{x^2+1}e^{-tx}\,\mathrm{d}x\tag{2}
$$
We have
$$
\begin{align}
\tanh(\pi x/2)
&=\frac{e^{\pi x/2}-e^{-\pi x/2}}{e^{\pi x/2}+e^{-\pi x/2}}\\
&=\frac2{1+e^{-\pi x}}-1\\[6pt]
&=1-2e^{-\pi x}+2e^{-2\pi x}-2e^{-3\pi x}+\dots\tag{3}
\end{align}
$$
and
$$
\begin{align}
\int_0^\infty e^{-bx}\sin(ax)\,\mathrm{d}x
&=\frac1{2i}\int_0^\infty\left(e^{-(b-ia)x}-e^{-(b+ia)x}\right)\,\mathrm{d}x\\
&=\frac1{2i}\left(\frac1{b-ia}-\frac1{b+ia}\right)\\
&=\frac{a}{a^2+b^2}\tag{4}
\end{align}
$$
Furthermore, the principal value expansion
$$
\pi\csc(\pi z)=\sum\limits_{k\in\mathbb{Z}}(-1)^k\frac1{z+k}\tag{5}
$$
yields
$$
\begin{align}
\mathrm{csch}(x)
&=\sum_{k\in\mathbb{Z}}(-1)^k\frac1{x+ik\pi}\\
&=\frac1x+\sum_{k=1}^\infty(-1)^k\frac{2x}{x^2+k^2\pi^2}\tag{6}
\end{align}
$$
Combining $(1)-(4)$ and $(6)$, we get
$$
\begin{align}
&f(a)-f''(a)\\
&=\int_0^\infty\tanh(\tfrac{\pi x}{2})\sin(ax)\,e^{-tx}\,\mathrm{d}x\\
&=\int_0^\infty\left(e^{-tx}-2e^{-(\pi+t)x}+2e^{-(2\pi+t)x}-2e^{-(3\pi+t)x}+\dots\right)\sin(ax)\,\mathrm{d}x\\
&=\frac{a}{a^2+t^2}-\frac{2a}{a^2+(\pi+t)^2}+\frac{2a}{a^2+(2\pi+t)^2}-\frac{2a}{a^2+(3\pi+t)^2}+\dots\\
&\stackrel{\!\!t\to0}{\longrightarrow}\frac1a-\frac{2a}{a^2+\pi^2}+\frac{2a}{a^2+4\pi^2}-\frac{2a}{a^2+9\pi^2}+\dots\\[6pt]
&=\mathrm{csch}(a)\tag{7}
\end{align}
$$
We can solve $f-f''=u$ using integrating functions to get
$$
f(x)=e^x\int e^{-2x}\left(\int e^xu(x)\,\mathrm{d}x\right)\mathrm{d}x\tag{8}
$$
Using exponential substitutions, we get
$$
\begin{align}
f(x)
&=e^x\int e^{-2x}\left(\int\mathrm{csch}(x)\,e^x\,\mathrm{d}x\right)\mathrm{d}x\\
&=e^x\int e^{-2x}\left(\log\left(e^{2x}-1\right)-2C_2\right)\mathrm{d}x\\
&=e^x\left(\frac12\log(1-e^{-2x})-\frac12e^{-2x}\log(e^{2x}-1)+C_1+C_2e^{-2x}\right)\\
&=\frac12e^x\log(1-e^{-2x})-\frac12e^{-x}\log(e^{2x}-1)+C_1e^x+C_2e^{-x}\\
&=\frac12e^x\log(1-e^{-2x})-\frac12e^{-x}\log(e^{2x}-1)\tag{9}
\end{align}
$$
where we get $C_1=C_2=0$ since $f(0)=\lim\limits_{x\to\infty}f(x)=0$.
A: Wow, very nice work fellas. It's always nice to see clever solutions to a problem. 
I saw it in an old math book on infinite series as an exercise under 'Harder Examples'.
Here it is verbatim:
"Using the expansion:
$\displaystyle \tanh(\pi x/2)=1-2e^{-\pi x}+2e^{-2\pi x}-\cdot\cdot\cdot $
show that $\displaystyle G\int_{0}^{\infty}\tanh(\pi x/2)\sin(ax)dx=csch(a)....(1)$
and deduce that $\displaystyle \int_{0}^{\infty}\frac{\tanh(\pi x/2)\sin(ax)}{x^{2}+1}dx$
$\displaystyle =1/2\left[e^{-a}\log(e^{2a}-1)-e^{a}\log(1-e^{-2a})\right]$
Well, what is that G in front of the integral sign for?.
Here is what it described:
'If an integral $\displaystyle \int_{a}^{\infty}f(x)dx$ oscillates, then it is called summable if the limit $\displaystyle \lim_{t\to 0}\int_{a}^{\infty}e^{-tx}f(x)dx$ exists. This limit can be indicated by writing a G before the integral sign'. 
EDIT:
Very nice indeed, robjohn, and clever as usual.  
I also played around with it a little and managed to get the first part using their G suggestion. 
By using the expansion they mention: $$\tanh(\pi x/2)=2\sum_{k=1}^{\infty}(-1)^{k}e^{-\pi kx}+1$$
I used $$\int_{0}^{\infty}\tanh(\pi x/2)\sin(ax)dx=\int_{0}^{\infty}\left(2\sum_{k=1}^{\infty}(-1)^{k}e^{-\pi kx}+1\right)\sin(ax)dx$$
$$=\frac{2a}{\pi^{2}}\sum_{k=1}^{\infty}\frac{(-1)^{k}}{k^{2}+(\frac{a}{\pi})^{2}}+G\int_{0}^{\infty}\sin(ax)dx$$
The sum on the left is rather famous and evaluates to $\displaystyle csch(a)-1/a$
According to the book, and they have it as another exercise using the same G logic, $\displaystyle G\int_{0}^{\infty}\sin(x)dx=1$ . Though, this seems rather strange at first.
So, $\displaystyle G\int_{0}^{\infty}\sin(ax)dx=1/a$
Thus, $$csch(a)-1/a+1/a=csch(a)$$.
It is in "An introduction to the theory of infinite series" by Bromwich.
as an aside:
As another exercise they say "prove that $$G\int_{0}^{\infty}x^{n-1}\sin(ax)dx=\frac{\Gamma(n)}{a^{n}}\sin(n\pi/2), \;\ a>0, \;\ n\geq 1$$" and thus $\displaystyle G\int_{0}^{\infty}\sin(x)dx=1$.  
So, I then noticed when $n=1$, $\displaystyle G\int_{0}^{\infty}\sin(ax)dx=1/a$.  This is what I used in the first part.
