Solve $\int \limits_{0}^{\infty} \frac{\cos(x)}{\cosh(x)} dx$ without complex integration. Solve $$\int \limits_{0}^{\infty} \frac{\cos(x)}{\cosh(x)} dx$$ without complex integration.
This integral can be very easily solved with contour integration, but how can you solve it without taking a tour in the complex plane?
 A: The integral is equal to
$$\begin{align}2 \int_0^{\infty} dx\, e^{-x} \frac{\cos{x}}{1+e^{-2 x}} &= 2\sum_{k=0}^{\infty} (-1)^k \int_0^{\infty} dx \, e^{-(2 k+1) x} \cos{x} \\ &= 2\operatorname{Re} \sum_{k=0}^{\infty}\frac{(-1)^k}{2 k+1-i}\\ &= 2\sum_{k=0}^{\infty} (-1)^k \frac{2 k+1}{(2 k+1)^2+1}\\ &= \sum_{k=-\infty}^{\infty} (-1)^k \frac{2 k+1}{(2 k+1)^2+1}\\ &=-\pi \sum_{\pm} \operatorname*{Res}_{z=\frac{-1\pm i}{2}}\frac{(2 z+1) \csc{\pi z}}{(2 z+1)^2+1} \\ &= \frac{\pi}{2} \left [ \frac1{\sin{\left ( \frac{\pi}{2} - \frac{\pi i}{2}\right )}} + \frac1{\sin{\left ( \frac{\pi}{2} + \frac{\pi i}{2}\right )}}\right ]\\ &= \frac{\pi}{2 \cosh{(\pi/2)}}\end{align}$$
A: Expand $ \operatorname{sech}{x} $ in an infinite series in $e^{-x}$:
$$ \frac{2}{e^x(1+e^{-2x})} = 2 \sum_{k=0}^{\infty} (-1)^k e^{-(2k+1)x} $$
Interchange the order of integration, and you are left with integrals of the form
$$ \int_0^{\infty} e^{-\alpha x} \cos{x} \, dx, $$
which can be done using integration by parts, to avoid complex numbers totally, with the result $ \alpha/(1+\alpha^2) $. Hence the integral is equal to
$$ \sum_{k=0}^{\infty} (-1)^k \frac{1+2k}{1+2k+2k^2}. $$
Okay, and now it is time once again for "Special Functions and Pray". Using the usual tricks, one can express infinite sums in terms of the digamma function as follows: first, write the summand in partial fractions as
$$ \frac{1+2k}{1+2k+2k^2} = \frac{1}{2} \left( \frac{1}{k+a} + \frac{1}{k+a^*} \right), $$
where $a$ is the complex root of the denominator, $(1+i)/2$. Now we have the identity
$$ \sum_{k=0}^{K} \frac{1}{k+a} = \psi(K+a+1)-\psi(a+1), $$
where $\psi = (\log{\Gamma})'$ as usual. However, this is not good enough: we have to deal with the $(-1)^k$. This we do by splitting into the even and odd cases: some algebra shows the result we want is
$$ \sum_{k=0}^K \frac{(-1)^k}{k+a} = \frac{1}{2} (-1)^K \psi{\left(\frac{a}{2}+\frac{K}{2}+1\right)}
-\frac{1}{2} (-1)^K \psi{\left(\frac{a}{2}+\frac{K}{2}+\frac{1}{2}\right)}
-\frac{1}{2}\psi{\left(\frac{a}{2}\right)}
+\frac{1}{2} \psi{\left(\frac{a}{2}+\frac{1}{2}\right)}. $$
Now, this sum actually converges by comparison with the alternating harmonic series, the details of which I omit. Hence we can take the limit as $k \to \infty$. The problem is what happens to the terms
$$ \frac{1}{2} (-1)^K \left( \psi{\left(\frac{a}{2}+\frac{K}{2}+1\right)}
- \psi{\left(\frac{a}{2}+\frac{K}{2}+\frac{1}{2}\right)} \right), $$
but a slight abuse of Stirling's approximation shows that this term is $O(\log{n}-\log{(n+1/2)})=o(1)$, so in fact we can just ditch it. Hence the answer is
$$ -\frac{1}{4}\psi{\left(\frac{a}{2}\right)}
+\frac{1}{4} \psi{\left(\frac{a}{2}+\frac{1}{2}\right)} + c.c., $$
because we have a half in the partial fractions. Then we need to compute
$$-\frac{1}{4} \psi{\left(\frac{1}{4}+\frac{i}{4}\right)}
+\frac{1}{4} \psi{\left(\frac{3}{4}+\frac{i}{4}\right)}
-\frac{1}{4} \psi{\left(\frac{1}{4}-\frac{i}{4}\right)}
+\frac{1}{4} \psi{\left(\frac{3}{4}-\frac{i}{4}\right)},$$
but staring at this for long enough, you can pair the terms so that you can apply the identity
$$ \psi(z)-\psi(1-z) = -\pi \cot{\pi z}, $$
which gives you
$$ \frac{1}{4} \pi  \cot \left(\left(\frac{1}{4}+\frac{i}{4}\right) \pi \right)+\frac{1}{4} i \pi  \coth \left(\left(\frac{1}{4}+\frac{i}{4}\right) \pi \right), $$
and applying some trigonometric identities eventually settles this into the form
$$ \tfrac{1}{2}\pi \operatorname{sech}{\tfrac{1}{2}\pi}, $$
which is thankfully the right answer.
A: We have
\begin{align}
I & = \int_0^{\infty} \dfrac{\cos(x)}{\left(\dfrac{e^x+e^{-x}}2 \right)}dx = \int_0^{\infty}2e^{-x} \cdot \dfrac{\cos(x)}{1+e^{-2x}}dx = \sum_{k=0}^{\infty}2(-1)^k\int_0^{\infty}e^{-(2k+1)x}\cos(x)dx\\
& = 2\sum_{k=0}^{\infty}(-1)^k f_k
\end{align}
where
\begin{align}
f_k & = \int_0^{\infty}e^{-(2k+1)x}\cos(x)dx = \sum_{l=0}^{\infty}\dfrac{(-1)^l}{(2l)!} \int_0^{\infty} e^{-(2k+1)x}x^{2l}dx = \sum_{l=0}^{\infty}\dfrac{(-1)^l}{(2l)!} \int_0^{\infty} e^{-t}\dfrac{t^{2l}dt}{(2k+1)^{2l+1}}\\
& = \sum_{l=0}^{\infty}\dfrac{(-1)^l}{(2l)!} \cdot \dfrac{\Gamma(2l+1)}{(2k+1)^{2l+1}} = \dfrac1{2k+1} \sum_{l=0}^{\infty} \left(-\dfrac1{(2k+1)^2}\right)^l = \dfrac1{2k+1} \cdot \dfrac1{1+\dfrac1{(2k+1)^2}}\\
& = \dfrac{(2k+1)}{(2k+1)^2+1}
\end{align}
Hence, we have
$$I = 2\sum_{k=0}^{\infty}(-1)^k \dfrac{(2k+1)}{(2k+1)^2+1} = \dfrac{\pi}{2\text{cosh}(\pi/2)}$$
A: You may prove through differential equations that $\frac{1}{\cosh x}$ is almost a fixed point of the Fourier transform, meaning that
$$ \mathscr{F}\left(\frac{1}{\cosh x}\right) = \sqrt{\frac{\pi}{2}}\,\frac{1}{\cosh\frac{\pi s}{2}}$$
according to Mathematica's standard choice of normalization constants. Similarly, in the sense of distributions
$$ \mathscr{F}\left(\cos x\right) = \sqrt{\frac{\pi}{2}}\,\left[\delta(s-1)+\delta(s+1)\right]$$
hence, by parity, it follows that
$$ \int_{0}^{+\infty}\frac{\cos x}{\cosh x}\,dx = \frac{1}{2}\int_{\mathbb{R}}\frac{\cos x}{\cosh x}\,dx = \frac{\pi}{2}\cdot\left.\frac{1}{\cosh\frac{\pi s}{2}}\right|_{s=1} = \frac{\pi}{2\cosh\frac{\pi}{2}} = \frac{\pi e^{\pi/2}}{e^\pi-1}.$$
A: Integration by parts twice yields
$$
\begin{align}
\int_0^\infty\cos(x)e^{-ax}\,\mathrm{d}x
&=a\int_0^\infty\sin(x)e^{-ax}\,\mathrm{d}x\\
&=a-a^2\int_0^\infty\cos(x)e^{-ax}\,\mathrm{d}x\\
&=\frac{a}{a^2+1}\tag{1}
\end{align}
$$
where the last line is mean of the original integral and the third integral weighted by $a^2$ and $1$.
$$
\begin{align}
\int_0^\infty\frac{\cos(x)}{\cosh(x)}\,\mathrm{d}x
&=2\int_0^\infty\cos(x)\sum_{k=0}^\infty(-1)^ke^{-(2k+1)x}\,\mathrm{d}x\tag{2}\\
&=2\sum_{k=0}^\infty(-1)^k\frac{2k+1}{(2k+1)^2+1}\tag{3}\\
&=\sum_{k=1}^\infty(-1)^k\left(\frac1{2k+1+i}+\frac1{2k+1-i}\right)\tag{4}\\
&=\frac12\sum_{k=0}^\infty(-1)^k\left(\frac1{k+\frac{1+i}2}-\frac1{-k-1+\frac{1+i}2}\right)\tag{5}\\
&=\frac12\sum_{k=0}^\infty\frac{(-1)^k}{k+\frac{1+i}2}+\frac12\sum_{k=-\infty}^{-1}\frac{(-1)^k}{k+\frac{1+i}2}\tag{6}\\
&=\frac12\sum_{k=-\infty}^\infty\frac{(-1)^k}{k+\frac{1+i}2}\tag{7}\\
&=\frac\pi2\csc\left(\pi\frac{1+i}2\right)\tag{8}\\[6pt]
&=\frac\pi2\mathrm{sech}\left(\frac\pi2\right)\tag{9}
\end{align}
$$
Explanation:
$(2)$: $\frac2{\large e^x+e^{-x}}=2\sum\limits_{k=0}^\infty(-1)^ke^{-(2k+1)x}$
$(3)$: apply $(1)$
$(4)$: partial fractions
$(5)$: bring the $\frac12$ out front and rewrite the second term
$(6)$: reindex the second sum
$(7)$: combine the sums
$(8)$: use equation $(7)$ from this answer and $\pi\csc(\pi x)=\pi\cot(\pi x/2)-\pi\cot(\pi x)$
$(9)$: $\sin(\frac\pi2+\frac\pi2i)=\sin(\frac\pi2)\cosh(\frac\pi2)+i\cos(\frac\pi2)\sinh(\frac\pi2)=\cosh(\frac\pi2)$
