<s>[INST] Evaluate $\int \frac{\cos^2x}{1+\tan x}dx$ Evaluate $\int \dfrac{\cos^2x}{1+\tan x}dx$
Here are my various unsuccessful attempts:-
Attempt $1$:
$$\tan x=t$$
$$\sec^2 x=\dfrac{dt}{dx}$$
$$\int \dfrac{dt}{(1+t^2)^2(1+t)}$$
$$\ln(1+t)=y$$
$$\dfrac{1}{1+t}=\dfrac{dy}{dt}$$
$$\int \dfrac{dy}{\left(1+(e^y-1)^2\right)^2}$$
$$\int \dfrac{dy}{(1+e^{2y}+1-2e^y)^2}$$
$$\int \dfrac{dy}{(e^{2y}+2-2e^y)^2}$$
$$\int \dfrac{dy}{e^4y+4+4e^{2y}+4e^{2y}-4e^y(e^{2y}+2)}$$
$$\int \dfrac{dy}{e^4y-4e^{3y}+8e^{2y}-8e^y+4}$$
From here I gave up on this method.
Attempt $2$:
$$\int \dfrac{\cos^3x}{\cos x+\sin x}$$
$$\int\dfrac{3\cos x+\cos 3x}{4(\cos x+\sin x)}$$
$$\dfrac{1}{4}\left(3\cdot\int\dfrac{\cos x}{\cos x+\sin x}+\int \dfrac{\cos 3x}{\cos x+\sin x}\right)$$
Solving the first integral
$$\cos x=A(\cos x+\sin x)+B(-\sin x+\cos x)+C$$
$$A+B=1$$
$$A-B=0$$
$$A=\dfrac{1}{2},B=\dfrac{1}{2}$$
$$\dfrac{1}{4}\left(\dfrac{3}{2}\left(x+\ln|\sin x+\cos x|\right)+\int \dfrac{\cos 3x}{\cos x+\sin x}\right)$$
I was not understanding how to proceed for second integration.
Attempt $3$: 
For @mvpq
$$\tan x=t$$
$$\sec^2 x=\dfrac{dt}{dx}$$
$$\int \dfrac{dt}{(1+t^2)^2(1+t)}$$
Trying to write expression as 
$$\dfrac{1}{(1+t^2)^2(1+t)}=\dfrac{A}{1+t}+\dfrac{B}{1+t^2}+\dfrac{C}{(1+t^2)^2}$$
$$\dfrac{1}{(1+t^2)^2(1+t)}=\dfrac{A(1+t^2)^2+B(1+t^2)+C(1+t)}{(1+t)(1+t^2)^2}$$
$$\dfrac{1}{(1+t^2)^2(1+t)}=(A+B+C)+Ct+(B+2A)t^2+At^4$$
$$A+B+C=1\tag{1}$$
$$A=0$$
$$A+2B=0$$
$$B=0$$
$$C=0$$
But $A+B+C=1$, hence no solution, so cannot be solved by partial fractions.
Attempt $4$: 
For @heropup
$$\tan x=t$$
$$\sec^2 x=\dfrac{dt}{dx}$$
$$\int \dfrac{dt}{(1+t^2)^2(1+t)}$$
Trying to write expression as 
$$\dfrac{1}{(1+t^2)^2(1+t)}=\dfrac{A}{1+t}+\dfrac{Bt+C}{1+t^2}+\dfrac{Dt+E}{(1+t^2)^2}$$
$$\dfrac{1}{(1+t^2)^2(1+t)}=\dfrac{A(1+t^2)^2+(Bt+C)(1+t^2)(1+t)+(Dt+E)(1+t)}{(1+t)(1+t^2)^2}$$
$$1=A(1+t^2)^2+(Bt+C)(1+t^2)(1+t)+(Dt+E)(1+t)$$
Placing $t=-1$ in the equation
$$4A=1, A=\dfrac{1}{4}$$
$$1=(Bt+C)(1+t+t^2+t^3)+(Dt+Dt^2+E+Et)$$
$$1=Bt+Bt^2+Bt^3+Bt^4+C+Ct+Ct^2+Ct^3+Dt+Dt^2+E+Et$$
$$1=Bt^4+(B+C)t^3+(B+C+D)t^2+(B+C+D+E)t+(C+E)$$
$$B=0$$
$$B+C=0$$
$$C=0$$
$$B+C+D=0$$
$$D=0$$
$$B+C+D+E=0$$
$$E=0$$
$$C+E=1$$
$$E=1$$
This is contradiction right?
Any hints?
 [/INST] You may continue and finish the second approach as follows,
$$I=\dfrac{1}{4}\int\dfrac{3\cos x+\cos3x}{\cos x+\sin x}dx$$
Rewrite the term $\cos3x $ in the integrand as
$\cos3x = (\cos2x-\sin2x)(\sin x+ \cos x)+\sin x$ and the integral becomes
$$I=\dfrac{1}{4}\int\left(2+\cos2x-\sin2x+\dfrac{\cos x-\sin x}{\cos x+\sin x}\right)dx$$
$$=\frac x2+\frac18(\sin2x+\cos2x)+\frac14\ln|\sin x+\cos x|+C$$
</s>