<s>[INST] Evaluating $\int_0^\pi x\frac{\sin{\frac{x}{2}} - \cos{\frac{x}{2}}}{\sqrt{\sin{x}}} dx$ 
How am I supposed to solve the following definite integral?
$$
\mathcal{I} = \int_0^\pi x \cdot \frac{\sin{\frac{x}{2}} - \cos{\frac{x}{2}}}{\sqrt{\sin{x}}} dx
$$


This definite integral is solved if the minus sign is replaced by a plus sign, and it yields $\pi^2$.
$$
\mathcal{I} = \int_0^\pi x \cdot \frac{\sin{\frac{x}{2}} + \cos{\frac{x}{2}}}{\sqrt{\sin{x}}} dx \text{ 
— (I)} \\
\implies \mathcal{I} = \int_0^\pi (\pi - x) \cdot \frac{\cos{\frac{x}{2} + \sin{\frac{x}{2}}}}{\sqrt{\sin{x}}} dx \text{ 
— (II)}
$$
On (I) + (II), we have,
$$
\mathcal{I} = \frac{\pi}{2}\int_0^\pi \frac{\sin{\frac{x}{2}} + \cos{\frac{x}{2}}}{\sqrt{\sin{x}}} dx = \frac{\pi}{2} \int_0^\pi \frac{\sin{\frac{x}{2}}+\cos{\frac{x}{2}}}{\sqrt{1 - (\sin{\frac{x}{2}-\cos{\frac{x}{2}}})^2}} dx
$$
On substitution,
$$
\sin{\frac{x}{2}} - \cos{\frac{x}{2}} = u \implies \left(\sin{\frac{x}{2}} + \cos{\frac{x} {2}}\right) dx = 2 \cdot du
$$
The upper and lower limits changes to 1 and -1. Now, we have
$$
\mathcal{I} = \frac{\pi}{2} \int_{-1}^1 \frac{2 \cdot du}{\sqrt{1 - u^2}} du = \pi \cdot \left[\arcsin{u}\right]_{-1}^1 = \pi^2
$$

But...

*

*The sign was not supposed to be changed. We get $(2x - \pi)$ instead of $\pi$ in the nominator when adding both integrals. It complicates the problem.


*Using integral-calculator.com or a scientific calculator is helpless.


*The answer to the original problem should be $2\pi \cdot \ln{2}$ (approx 4.35.)
 [/INST] $$I=\int_0^\pi\frac{\sin{\frac{x}{2}} - \cos{\frac{x}{2}}}{\sqrt{\sin{x}}}x dx=2\sqrt2\int_0^\frac{\pi}{2}\Big(\sqrt{\tan x}-\sqrt{\cot x}\Big)xdx=2\sqrt2(I_1-I_2)$$
Both terms converge, so we can evaluate them separately.
Making the substitution $x=\arctan t$ and $\arctan t=\int_0^1\frac{t}{1+t^2x^2}dx$
$$I_1=\int_0^\infty\frac{\sqrt t}{1+t^2}\arctan tdt=\int_0^1\frac{dx}{x^2}\int_0^\infty\frac{t\sqrt t}{(1+t^2)\big(t^2+\frac{1}{x^2}\big)}dt$$
To evaluate the first integral we go in the complex plane and integrate along a keyhole contour. We have four simple poles ($\,\pm i; \,\,\pm\frac{i}{x}\,$).
The straightforward evaluation gives
$$\int_0^\infty\frac{t\sqrt t}{(1+t^2)\big(t^2+\frac{1}{x^2}\big)}dt=\frac{2\pi i}{2}\underset{z=\pm i; z=\pm\frac{i}{x}}{\operatorname{Res}}\frac{z\sqrt z}{(1+z^2)\big(z^2+\frac{1}{x^2}\big)}=\frac{\pi}{\sqrt2}\frac{1-\sqrt x}{\sqrt x(1-x^2)}x^2$$
Therefore,
$$I_1=\frac{\pi}{\sqrt2}\int_0^1\frac{dx}{\sqrt x(1+\sqrt x)(1+x)}=\sqrt2\pi\int_0^1\frac{dt}{(1+t)(1+t^2)}$$
$$=\frac{\pi}{\sqrt2}\int_0^1\Big(\frac{1}{1+t}+\frac{1-t}{1+t^2}\Big)dt$$
Integration is straightforward and gives
$$I_1=\frac{\pi}{2\sqrt2}\Big(\frac{\pi}{2}+\ln2\Big)$$
In the similar way we evaluate $I_2$ (using $\sqrt{\cot x}=\frac{1}{\sqrt{\tan x}}$ and making the same substitution $x=\arctan t\,$)
$$I_2=\int_0^1\frac{dx}{x^2}\int_0^\infty\frac{\sqrt t}{(1+t^2)\big(t^2+\frac{1}{x^2}\big)}dt=\frac{\pi}{\sqrt2}\int_0^1\frac{dx}{(1+\sqrt x)(1+x)}=\frac{\pi}{2\sqrt2}\Big(\frac{\pi}{2}-\ln2\Big)$$
$$\boxed{\,\,I=2\sqrt2(I_1-I_2)=2\pi\ln2\,\,}$$
And, as a bonus,
$$J=2\sqrt2(I_1+I_2)=\pi^2$$
</s>