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.)

Here is a solution using real analysis. First, denote the two integrals as
\begin{align*}
J & \equiv\int\limits_0^{\pi}\frac {x\left(\sin\frac x2\color{red}-\cos\frac x2\right)}{\sqrt{\sin x}}\,\mathrm dx\\K & \equiv\int\limits_0^{\pi}\frac {x\left(\sin\frac x2\color{red}+\cos\frac x2\right)}{\sqrt{\sin x}}\,\mathrm dx
\end{align*}
And from your post, recall that $K=\pi^2$. Adding the two integrals together removes the $\cos\frac x2$ factor inside the integrand, leaving only
\begin{align*}
J+K & =2\int\limits_0^{\pi}\frac {x\sin\frac x2}{\sqrt{\sin x}}\,\mathrm dx\\ & =\sqrt 2\int\limits_0^{\pi}x\sqrt{\tan\frac x2}\,\mathrm dx\\ & =4\sqrt{2}\int\limits_0^{+\infty}\frac {\sqrt t}{1+t^2}\arctan t\,\mathrm dt
\end{align*}
Where a double angle identity was utilized in the second equation and the half-angle tangent substitution in the third equation. The last integral has been evaluated here before using Complex Analysis, Feynman's Trick, etc. Here is an alternative approach using double integrals. First, enforce the substitution $x=\sqrt t$ so that the integral becomes
$$\int\limits_0^{+\infty}\frac {\sqrt t}{1+t^2}\arctan t\,\mathrm dt=2\int\limits_0^{+\infty}\frac {x^2}{1+x^4}\arctan x^2\,\mathrm dx$$
Next, use the identity
$$\arctan x^2=\int\limits_0^1\frac {x^2}{1+x^4 y^2}\,\mathrm dy$$
Swapping the order of integration and using partial fraction decomposition, then we get
\begin{align*}
2\int\limits_0^{+\infty}\,\int\limits_0^1\frac {x^4}{(1+x^4)(1+x^4y^2)}\,\mathrm dy\,\mathrm dx & =2\int\limits_0^1\frac 1{y^2-1}\int\limits_0^{+\infty}\frac 1{1+x^4}-\frac 1{1+x^4y^2}\,\mathrm dx\,\mathrm dy\\ & =\frac {\pi}{\sqrt 2}\int\limits_0^1\frac 1{y^2-1}\left(1-\frac 1{\sqrt y}\right)\,\mathrm dy\\ & =\frac {\pi^2}{4\sqrt 2}+\frac {\pi\log 4}{4\sqrt 2}
\end{align*}
To recap, we have the equation
$$J+\pi^2=4\sqrt{2}\int\limits_0^{+\infty}\frac {\sqrt t}{1+t^2}\arctan t\,\mathrm dt=\pi^2+\pi\log 4$$
Subtracting a $\pi^2$ from both sides, then
$$\int\limits_0^{\pi}\frac {x\left(\sin\frac x2-\cos\frac x2\right)}{\sqrt{\sin x}}\,\mathrm dx\color{blue}{=\pi\log 4}$$
