Integrate $\int\frac{\cos^2x}{1+\tan x}dx$ Integrate $$I=\int\frac{\cos^2x}{1+\tan x}dx$$

$$I=\int\frac{\cos^3xdx}{\cos x+\sin x}=\int\frac{\cos^3x(\cos x-\sin x)dx}{\cos^2x-\sin^2x}=\int\frac{\cos^4xdx}{1-2\sin^2x}-\int\frac{\cos^3x\sin xdx}{2\cos^2x-1}$$
Let $t=\sin x,u=\cos x,dt=\cos xdx,du=-\sin xdx$
$$I=\underbrace{\int\frac{-u^4du}{(2u^2-1)\sqrt{1-u^2}}}_{I_1}+\underbrace{\int\frac{u^3du}{2u^2-1}}_{I_2}$$
I have found(using long division): $$I_2=\frac{u^2}2+\frac18\ln|2u^2-1|+c=\frac12\cos^2x+\frac18\ln|\cos2x|$$
I have converted $I_1$ into this:
$$I_1=\frac12\left(\int(-2)\sqrt{1-u^2}du+\int\frac{du}{\sqrt{1-u^2}}\right)+\frac14\underbrace{\int\frac{du}{(2u^2-1)\sqrt{1-u^2}}}_{I_3}$$
Now I have took $v=1/u$ in $I_3$ so that $du=-(1/v^2)dv$:
$$I_3=\int\frac{vdv}{(v^2-2)\sqrt{v^2-1}}$$
Now I took $w^2=v^2-1$ or $wdw=vdv$ to get:
$$I_3=\int\frac{dw}{w^2-1}=\frac12\ln\left|\frac{w-1}{w+1}\right|$$
I have not yet formulated the entire thing;



*

*Is this correct?

*This is very long, do you have any "shorter" method?

 A: We have $$I=\int\dfrac{\cos^3x}{\cos x+\sin x}dx=\dfrac1{\sqrt2}\int\dfrac{\cos^3x}{\cos\left(\dfrac\pi4-x\right)}dx$$
Setting $\dfrac\pi4-x=y\iff x=\dfrac\pi4-y,dx=-dy$
$$-\sqrt2I=\int\dfrac{\cos^3\left(\dfrac\pi4-y\right)}{\cos y}dy=\dfrac1{2\sqrt2}\int\dfrac{(\cos y+\sin y)^3}{\cos y}dy$$
The rest is pretty easy.
A: The integral is equivalent to $ \displaystyle{\int\frac{\cos^3 x}{\sin x + \cos x}\,\mathrm{d}x}. $ Now, consider
$$ \mathcal{I}_{1} = \int\frac{\cos^3 x}{\sin x + \cos x}\,\mathrm{d}x \qquad\text{and}\qquad\mathcal{I}_{2}=\int\frac{\sin^3 x}{\sin x + \cos x}\,\mathrm{d}x. $$
Observe that
$$
\begin{aligned}
\mathcal{I}_{1}+\mathcal{I}_{2} &= \int\frac{\cos^3 x + \sin^3 x}{\sin x + \cos x}\,\mathrm{d}x\\
&=\int\frac{(\cos x + \sin x)(\cos^2 x - \sin x\cos x + \sin^2 x)}{\cos x + \sin x}\,\mathrm{d}x\\
&=x - \frac{\sin^2 x}{2}+C_{1},
\end{aligned}
$$
and
$$
\begin{aligned}
\mathcal{I}_{1}-\mathcal{I}_{2}&=\int\frac{(\cos x - \sin x)(1 + \sin x \cos x)}{\cos x + \sin x}\,\mathrm{d}x\\
&=\int\frac{(\cos x - \sin x)(\cos x + \sin x)(1 + \sin x\cos x)}{(\cos x + \sin x)^2}\,\mathrm{d}x\\
&=\int\frac{1 +\frac{\sin 2x}{2}}{1 + \sin 2x}\cos 2x\,\mathrm{d}x\\
&=\underbrace{\frac{1}{4}\int\left(1 + \frac{1}{1+\sin 2x}\right)2\cos 2x\,\mathrm{d}x}_{t = \sin 2x\implies\mathrm{d}t=2\cos 2x\,\mathrm{d}x}\\
&=\frac{1}{4}\int1+\frac{1}{1+t}\,\mathrm{d}t\\
&=\frac{t}{4}+\frac{1}{4}\log|t+1|+C_{2}\\
&=\frac{\sin2x}{4}+\frac{1}{4}\log(1+\sin2x)+C_{2}
\end{aligned}
$$.
Thus,
$$
\begin{aligned}
(\mathcal{I}_{1}+\mathcal{I}_{2})+(\mathcal{I}_{1}-\mathcal{I}_{2})&=2\mathcal{I}_{1}\\
&=x+\frac{\sin2x}{4}+\frac{1}{4}\log(1+\sin2x)-\frac{\sin^2 x}{2} + C_{3},
\end{aligned}
$$
which yields
$$
\begin{aligned}
\mathcal{I}_{1}&=\int\frac{\cos^3x}{\sin x + \cos x}\,\mathrm{d}x\\
&=\int\frac{\cos^2 x}{1+\tan x}\,\mathrm{d}x\\
&=\frac{x}{2}+\frac{\sin 2x}{8}+\frac{1}{8}\log(1+\sin2x)-\frac{\sin^2 x}{4} + C,
\end{aligned}
$$
or, in an equivalent manner,
$$
\int\frac{\cos^2 x}{1+\tan x}\,\mathrm{d}x=\frac{x}{2}+\frac{\sin x\cos x}{4}+\frac{1}{4}\log\left|\cos\!\left(x-\frac{\pi}{4}\right)\right|-\frac{\sin^2 x}{4}+\mathcal{C}.
$$
A: Setting $\tan x=u,I=\int\dfrac{\sec^2x}{\sec^4x(1+\tan x)}dx$
$I=\int\dfrac{du}{(1+u^2)^2(1+u)}=\int\dfrac1{u(1+u)}\cdot\dfrac u{(1+u^2)^2}du$
Integrating by parts, $I=\dfrac1{u(1+u)}\int\dfrac u{(1+u^2)^2}\ du-\int\left(\dfrac{d\dfrac1{u(1+u)}}{du}\int\dfrac u{(1+u^2)^2}\ du\right)du$
$I=-\dfrac1{2u(1+u)(1+u^2)}-\int\dfrac{2u+1}{2u^2(1+u)^2(1+u^2)}du$
Now use Partial Fraction Decomposition,
$\dfrac{2u+1}{u^2(1+u)^2(1+u^2)}=\dfrac Au+\dfrac B{u^2}+\dfrac C{1+u}+\dfrac D{(1+u)^2}+\dfrac E{1+u^2}$
A: Decompose the integrand as follows\begin{align}
\frac{\cos^2x}{1+\tan x}&= \frac{\cos^3 x \ (\cos x +\sin x)}{(\cos x+\sin x)^2}\\
&=\frac{(1+\cos2x)\ (\cos 2x + 1+ \sin2x)}{4(1+\sin 2x)}\\
&=\frac14\left( 1+\cos2x + \frac{\cos^2 2x+\cos2x}{1+\sin2x}\right)\\
 &=\frac14\left( 2+\cos2x -\sin 2x +\frac{\cos2x}{1+\sin2x}\right)
\end{align}
Then
$$\int\frac{\cos^2x}{1+\tan x}dx
=\frac12x+\frac18\left[\sin 2x+ \cos 2x+\ln (1+\sin2x) \right]
$$
