# Integrate $\int_{\tan^{-1}1/2}^{\pi/4} \left(\sin x+\cos x-\sqrt{\sin 2x}\right)^2dx$

Encounter the definite integral below while integrating an enclosed area in polar space

$$\int_{\tan^{-1}\frac12}^{\frac\pi4} \left(\sin x+\cos x-\sqrt{\sin 2x}\right)^2dx=\frac15-\tan^{-1}\frac17$$

Figured out the clean result on RHS from the geometric shape involved, but was unable to get it from direct integration. The integral gets unwieldy and the result has too many pieces to resemble $$\frac15-\tan^{-1}\frac17$$.

$$\left(\sin x+\cos x-\sqrt{\sin 2x}\right)^2=1+2\sin(2x)-2(\sin x+\cos x)\sqrt{\sin 2x}$$ The integration of $$1+2\sin(2x)$$ is clear. To integrate $$(\sin x+\cos x)\sqrt{\sin 2x}$$, you can take $$u=\sin x-\cos x$$, so $$\sin 2x=1-u^2$$, and the integral becomes $$\int_{-\frac{1}{\sqrt{5}}}^0 \sqrt{1-u^2}\mathrm{d}u$$ which can be done in many ways.