My favourite example of this is @SangchulLee's solution to @VladimirReshetnikov's question, which asks to verify
the correctness of the identity
$$\int_0^{\infty} \frac{dx}{\sqrt[4]{7 + \cosh x}}= \frac{\sqrt[4]{6}}{3\sqrt{\pi}} \Gamma\left(\frac14\right)^2 .$$
The other answers indicate the "toughness" of this integral, resorting to all sorts of special functions such as elliptic functions,
hypergeometric functions, or Mathematica.
However, the integral can be brilliantly shown to be a few substitutions away from the form of a beta function integral.
Lee makes a chain of simple substitutions which he desecribes here, to obtain
$$\int_0^{\infty} \frac{dx}{(a+ \cosh x)^s} = \frac1{(a+1)^s} \int_0^1 \frac{v^{s-1}}{\sqrt{(1-v)(1-\frac{a-1}{a+1} v)}} dv.$$
The closed formed of this integral for general $a$ is certainly non-elementary, but our special case $a=7$ and $s=4$ is different
for a very neat reason:
When $a=7,$ $\frac{a-1}{a+1}$ is equal to $\frac34$, but since we have the triple angle formula
$\displaystyle \, \cosh(3 x)=4\cosh^3 x-3 \cosh x,$ the integral can be rewritten (with $v=\operatorname{sech}^2 t$) as
$$2^{5/4} \int_0^{\infty} \frac{\cosh t}{\sqrt{\cosh 3t}} dt$$
which can be easily brought to the form of a beta function.
(Note that we can find a similar closed form (with $a=7$) for $s=3/4$.)
In order to prove that $S=-\frac{\pi^2}{4}$ , where
\begin{equation*}
S=\int_{0}^{1}\dfrac{\sqrt{x-x^3}\log(x)}{x(x^2+1)}\, dx +\int_{0}^{\frac{\pi}{2}}\dfrac{x\sqrt{\cos(x)}}{\sin(x)}\, dx,
\end{equation*}
we will use Cauchy's integral theorem. The integrand will be
\begin{equation*}
f(z)= \dfrac{2i\log(z)\sqrt{\frac{1+z^2}{2}}}{\sqrt{z}(1-z^2)}
\end{equation*}
where
\begin{equation*}
\log(z) = \ln|z| +i\arg(z) \quad \mbox{ with } -\pi<\arg[z)<\pi
\end{equation*}
and
\begin{equation*}
\sqrt{z} =e^{\frac{1}{2}\log(z)}.
\end{equation*}
Let $C$ be the contour of the first quadrant of the unit circle. Then
\begin{equation*}
\int_{C}f(z)\, dz = 0.\tag{1}
\end{equation*}
Some additional justifications are probably needed.
Split $C=C_1+C_2+C_3$ where $C_1$ is the path along the real axis from $0$ to $1$, $C_2$ is the arc from $1$ to $i$ and $C_3$ is the path along the imaginary axis from $i$ to $0$.
The singularity in $1$ is removable.
Close to $0$ we have to slightly modify $C_2$ and $C_3$. At the point $ir$ we leave $C_3$ and follow a small arc $C_r $ with radius $r$ to $r$ on $C_1$. According to the ML inequality
\begin{equation*}
\int_{C_r}f(z)\, dz \to 0 \quad \mbox{ as } r\to 0.
\end{equation*}
The point $i$ can be treated analogously.
We will now study (1).
\begin{equation*}
\int_{C_1}f(z)\, dz = 2i\int_{0}^{1}\dfrac{\ln(x)\sqrt{\frac{1+x^2}{2}}}{\sqrt{x}(1-x^2)}\, dx
\end{equation*}
with real part $= 0$.
The arc $C_2$ can be described as $z=e^{it}, \quad 0 <t< \frac{\pi}{2}$. Then
\begin{gather*}
\int_{C_2}f(z)\, dz = \int_{0}^{\frac{\pi}{2}}\dfrac{2i\log(e^{it})\sqrt{\frac{1+e^{i2t}}{2}}}{\sqrt{e^{it}}(1-e^{i2t})}ie^{it}\, dt =\\[2ex]\int_{0}^{\frac{\pi}{2}}\dfrac{2i^{2}(\ln|e^{it}|+it)\sqrt{\cos(t)}e^{it/2}}{e^{it/2}(e^{-it}-e^{it})}\, dt=
\int_{0}^{\frac{\pi}{2}}\dfrac{t\sqrt{\cos(t)}}{\sin(t)}\, dt.
\end{gather*}
Now we proceed to
\begin{gather*}
\int_{C_3}f(z)\, dz = -\int_{0}^{1}\dfrac{2i\log(iy)\sqrt{\frac{1-y^2}{2}}}{\sqrt{(iy)}(1+y^2)}i\, dy =\\[2ex]
\int_{0}^{1}\dfrac{2\left(\ln(y)+i\frac{\pi}{2}\right)\sqrt{\frac{1-y^2}{2}}}{\frac{1+i}{\sqrt{2}}\sqrt{y}(1+y^2)}\, dy = \int_{0}^{1}\dfrac{(1-i)\left(\ln(y)+i\frac{\pi}{2}\right)\sqrt{1-y^2}}{\sqrt{y}(1+y^2)}\, dy=\\[2ex]
\int_{0}^{1}\dfrac{\left(\ln(y)+\frac{\pi}{2}\right)\sqrt{1-y^2}}{\sqrt{y}(1+y^2)}\, dy+i\cdot\int_{0}^{1}\dfrac{\left(\frac{\pi}{2}-\ln(y)\right)\sqrt{1-y^2}}{\sqrt{y}(1+y^2)}\, dy.
\end{gather*}
Now we extract the real part of (1). We get
\begin{equation*}
\int_{0}^{\frac{\pi}{2}}\dfrac{t\sqrt{\cos(t)}}{\sin(t)}\, dt+\int_{0}^{1}\dfrac{\left(\ln(y)+\frac{\pi}{2}\right)\sqrt{1-y^2}}{\sqrt{y}(1+y^2)}\, dy =0.
\end{equation*}
Thus
\begin{equation*}
S=-\dfrac{\pi}{2}\int_{0}^{1}\dfrac{\sqrt{1-y^2}}{\sqrt{y}(1+y^2)}\, dy =[y=s^2] =-\pi\int_{0}^{1}\dfrac{\sqrt{1-s^4}}{1+s^4}\, ds
\end{equation*}
However,
\begin{equation*}
\dfrac{\sqrt{1-s^4}}{1+s^4} =\dfrac{1}{2}\dfrac{\sqrt{\frac{1}{s^2}-s^2}}{\left(\frac{1}{s^2}-s^2\right)^2+4}\cdot 2\dfrac{1+s^4}{s^3} = \dfrac{1}{2}\dfrac{\sqrt{u}}{u^2+4}\cdot \dfrac{du}{ds}\cdot(-1).
\end{equation*}
where
\begin{equation*}
u=\dfrac{1}{s^2}-s^2.
\end{equation*}
Consequently, if we make the substitution $u=\dfrac{1}{s^2}-s^2$ then
\begin{equation*}
S=-\pi\int_{0}^{\infty}\dfrac{\sqrt{u}}{2(u^2+4)}\, du = [u=2\sqrt{v}]=-\dfrac{\pi}{4\sqrt{2}}\int_{0}^{\infty}\dfrac{v^{\frac{3}{4}-1}}{(1+v)^{\frac{3}{4}+\frac{1}{4}}}\, dv.
\end{equation*}
Here we recognize the beta $\mathrm{B}$ function. See
https://en.wikipedia.org/wiki/Beta_function
If we combine this with Euler's reflection formula we get
\begin{gather*}
S= -\dfrac{\pi}{4\sqrt{2}}B\left(\frac{3}{4},\frac{1}{4}\right)=-\dfrac{\pi}{4\sqrt{2}}\dfrac{\Gamma(\frac{3}{4})\Gamma(\frac{1}{4})}{\Gamma(1)} =\\[2ex] -\dfrac{\pi}{4\sqrt{2}}\Gamma\left(\frac{3}{4}\right)\Gamma\left(1-\frac{3}{4}\right)= -\dfrac{\pi}{4\sqrt{2}}\dfrac{\pi}{\sin(\frac{3\pi}{4})} = -\dfrac{\pi^2}{4}.
\end{gather*}
Best Answer
As suggested, a contour integration technique can be used to evaluate this integral. Notice first that the integrand is an even function of $x$, then \begin{align} I&=- \frac{1}{2\pi}\int_0^\infty \log\left(\frac{(x-s_1)^2+s^2_2}{(x+s_1)^2+s^2_2}\right)\frac{4x\sin\varepsilon}{x^4-2x^2\cos\varepsilon +1}\,dx\\ &=- \frac{1}{4\pi}\int_{-\infty}^\infty \log\left(\frac{(x-s_1)^2+s^2_2}{(x+s_1)^2+s^2_2}\right)\frac{4x\sin\varepsilon}{x^4-2x^2\cos\varepsilon +1}\,dx \end{align}
Considering the integral \begin{equation} J=- \frac{1}{2\pi}\int_{-\infty}^\infty \log\left(\frac{x-s_1+is_2}{x+s_1+is_2}\right)\frac{4x\sin\varepsilon}{x^4-2x^2\cos\varepsilon +1}\,dx \end{equation} where the log function is defined with a branch cut between the points $−s_1−is_2$ and $s_1−is_2$ with $s_2>0$. One can show that it is purely real (see (**)). By expressing the real part (see (*)), we find $J=I$.
The function is holomorphic for $\Im x>0$ except at the poles $x_k$ of the rational fraction with $\Im (x_k)>0$. If the real axis is closed by the upper half-circle $C_R$, the integral can then be evaluated by the residue method. The $C_R$ contribution vanishes as $R\to\infty$.
Assuming $0<\varepsilon<2\pi$, the poles of interest are simple : $x_+=e^{i\varepsilon/2}$ and $x_-=-e^{-i\varepsilon/2}$. The residues are then evaluated as \begin{align} R_{\pm}&=\operatorname{Res}\left[ \log\left(\frac{x-s_1+is_2}{x+s_1+is_2}\right)\frac{4x\sin\varepsilon}{x^4-2x^2\cos\varepsilon +1},x_\pm\right]\\ &= \log\left(\frac{x_\pm-s_1+is_2}{x_\pm+s_1+is_2}\right)\frac{4x_\pm\sin\varepsilon}{\left.\frac{d}{dx}\left[x^4-2x^2\cos\varepsilon +1\right]\right|_{x=x_\pm}}\\ &=\log\left(\frac{x_\pm-s_1+is_2}{x_\pm+s_1+is_2}\right)\frac{\sin\varepsilon}{x_\pm^2-\cos\varepsilon}\\ &=\mp i\log\left(\frac{x_\pm-s_1+is_2}{x_\pm+s_1+is_2}\right) \end{align} and thus \begin{align} I&=-\frac{1}{2\pi}2i\pi \sum_{\pm} R_{\pm}\\ &=-\log\left(\frac{\cos\left(\frac{\varepsilon}{2}\right)-s_1+i(s_2+\sin\left(\frac{\varepsilon}{2}\right))}{\cos\left(\frac{\varepsilon}{2}\right)+s_1+i(s_2+\sin\left(\frac{\varepsilon}{2}\right))}\right)+\log\left(\frac{-\cos\left(\frac{\varepsilon}{2}\right)-s_1+i(s_2+\sin\left(\frac{\varepsilon}{2}\right))}{-\cos\left(\frac{\varepsilon}{2}\right)+s_1+i(s_2+\sin\left(\frac{\varepsilon}{2}\right))}\right)\\ &=-\log\left(\frac{(\cos\left(\frac{\varepsilon}{2}\right)-s_1)^2+(s_2+\sin\left(\frac{\varepsilon}{2}\right))^2}{(\cos\left(\frac{\varepsilon}{2}\right)+s_1)^2+(s_2+\sin\left(\frac{\varepsilon}{2}\right))^2}\right) \end{align} Finally, \begin{equation} I= \log\left(\frac{1+s^2_1+s^2_2+2s_2\sin(\frac{\varepsilon}{2})+2s_1\cos(\frac{\varepsilon}{2})}{1+s^2_1+s^2_2+2s_2\sin(\frac{\varepsilon}{2})-2s_1\cos(\frac{\varepsilon}{2})}\right) \end{equation} as proposed.
(*): using $\log\left( Z \right)=\frac{1}{2}\log\left|Z\right|^2+i\operatorname{Arg}(Z)$
(**): If \begin{equation} J=\int_{-\infty}^\infty \log\left(\frac{x-s_1+is_2}{x+s_1+is_2}\right)f(x)\,dx \end{equation} where $f(-x)=-f(x)$ and $s_{1,2}$ are real, then the complex conjugate \begin{align} J^*&=\int_{-\infty}^\infty \log\left(\frac{x-s_1-is_2}{x+s_1-is_2}\right)f(x)\,dx\\ &=\int_{-\infty}^\infty \log\left(\frac{-x+s_1+is_2}{-x-s_1+is_2}\right)f(x)\,dx\\ &=\int_{-\infty}^\infty \log\left(\frac{y+s_1+is_2}{y-s_1+is_2}\right)f(-y)\,dy\\ &=J \end{align} The integral is thus real.