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?
 A: 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.
A: for comparison your indefinite integral is given by
$$\frac{1}{8} \left(\frac{2 (t+1)}{t^2+1}-\log \left(t^2+1\right)+2 \log (t+1)+4
   \tan ^{-1}(t)\right)$$
A: HINT:
$\cos x+\sin x=\sqrt2\cos\left(x-\dfrac\pi4\right)$
Set  $x-\dfrac\pi4=u$
Now $\cos x=\cos\left(\dfrac\pi4+u\right)=\dfrac{\cos u-\sin u}{\sqrt2}$
Now use $(a-b)^3$ expansion
Finally for $\dfrac{\sin^3 u}{\cos u}=\dfrac{\left(1-\cos^2u\right)\sin u}{\cos u}$ $=\tan u-\cos u\sin u$
and use $\sin2u=2\sin u\cos u$
