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?

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.
