<s>[INST] Integrate $\int \frac {\cos^2(x)}{1+\tan(x)} dx$ I have to integrate this :
 $$\int \frac {\cos^2(x)}{1+\tan(x)} dx $$
My attempt: 
I assumed $\tan (x)=t$ and wrote $\cos^2(x)$ as $\frac 1{1+\tan^2(x)}$ 
With this I ended up with 
$$\int \frac {1}{(1+t) (1+t^2)^2} dt $$
How do I solve this integration in a simpler method or do I continue my method and just separate the denominator to simplify further?
 [/INST] We need to calculate
$$
I=\int\frac{\cos^2x}{1+\tan x}\,dx=\int\frac{\cos^3x}{\sin x+\cos x}\,dx.
$$
Consider another integral
$$
J=\int\frac{\sin^3x}{\sin x+\cos x}\,dx
$$
and calculate $I+J$ and $I-J$ using
$$
a^3\pm b^3=(a\pm b)(a^2\mp ab+b^2).
$$
\begin{align}
\color{blue}{I+J}&=\int(\cos^2x-\cos x\sin x+\sin^2x)\,dx=\int\left(1-\frac12\sin 2x\right)\,dx=\color{blue}{x+\frac{\cos 2x}{4}}+C,\\
\color{red}{I-J}&=\int\frac{\cos x-\sin x}{\sin x+\cos x}\cdot(\cos^2x+\cos x\sin x+\sin^2x)\,dx=\\
&=\int\frac{\cos x-\sin x}{\sin x+\cos x}\cdot\frac{(\cos x+\sin x)^2+1}{2}\,dx=\\
&=\frac12\int\cos 2x\,dx+\frac12\int\frac{\cos x-\sin x}{\sin x+\cos x}\,dx=\color{red}{\frac{\sin 2x}{4}+\frac12\ln|\sin x+\cos x|}+C.
\end{align}
Now add $\color{blue}{I+J}$ and $\color{red}{I-J}$ and divide by two.
</s>