<s>[INST] Calculation of $\int \sin^2 x\frac{\sin x-\cos x}{\sin x+\cos x}dx$ 
Calculation of $\displaystyle \int\frac{\sin^2 x\cos x}{
\sin x+\cos x}dx$ and $\displaystyle \int^{\pi}_{0}\frac{1}{1-2a\cos x+a^2}dx, ,0<a<1$

$\bf{Attempt}$ For (a) $\displaystyle \frac{1}{2}\int\frac{\sin^2 x\bigg[(\sin x+\cos x)+(\sin x-\cos x)\bigg]}{\sin x+\cos x}dx $
$\displaystyle =\frac{1}{4}\int (1+\cos 2x)dx+\frac{1}{2}\int \sin^2 x\frac{\sin x-\cos x}{\sin x+\cos x}dx$
could some help me how to solve $\displaystyle \int \sin^2 x\frac{\sin x-\cos x}{\sin x+\cos x}dx$
For (b) Can we solve it any geometrical way like taking unit circle . thanks
 [/INST] For (a), 
\begin{eqnarray}
&&\int\frac{\sin^2 x\cos x}{\sin x+\cos x}dx\\
&=&\int \frac{\sin^2x(\cos^2x-\sin x\cos x)}{\cos^2x-\sin^2x}dx\\
&=&\frac14\int \frac{(1-\cos(2x))(1+\cos(2x)-\sin(2x))}{\cos(2x)}dx\\
&=&\frac14\int\frac{1-\cos^2(2x)-(1-\cos(2x))\sin(2x)}{\cos(2x)}dx\\
&=&\frac14\int(\sec(2x)-\cos(2x)-\tan(2x)+\sin(2x))dx\\
&=&\frac14(\frac12\ln(\frac{\cos x+\sin x}{\cos x-\sin x})-\frac12\sin(2x)+\frac12\ln(\cos (2x))-\frac12\cos(2x))+C\\
&=&\frac18(\ln(\frac{\cos x+\sin x}{\cos x-\sin x})-\sin(2x)+\ln(\cos(2 x))-\cos(2x))+C\\
&=&\frac18(2\ln(\cos x+\sin x)-\sin(2x)-\cos(2x))+C.
\end{eqnarray}
For (b), let $t=\tan\frac{x}{2}$ and then
\begin{eqnarray}
&&\int^{\pi}_{0}\frac{1}{1-2a\cos x+a^2}dx\\
&=&\int^{\pi}_{0}\frac{1}{1-2a\frac{1-\tan^2\frac x2}{1+\tan^2\frac x2}+a^2}dx\\
&=&\int_0^\infty\frac{1}{1-2a\frac{1-t^2}{1+t^2}+a^2}\frac{2}{1+t^2}dt\\
&=&\int_0^\infty\frac{1}{(1+a)^2t^2+(1-a)^2}dt\\
&=&\frac{2}{(1+a)^2}\int_0^\infty\frac1{t^2+(\frac{(1-a}{1+a})^2}dt\\
&=&\frac{2}{(1+a)^2}\frac{1+a}{1-a}\arctan\frac{t}{\frac{1-a}{1+a}}\bigg|_{0}^\infty\\
&=&\frac{\pi}{1-a^2}.
\end{eqnarray}
</s>