Solving $\int\frac{dx}{1+\tan x}$ How do we solve $$\int\frac{dx}{1+\tan x}$$? I found two ways to solve it, one with the Weierstrass substitution ($t=\tan(\dfrac x2)$) and one with simply substituting $u=\tan x$ (which is better in my opinion). To solve it with the Weierstrass substitution, we get $$\int\dfrac{\frac{2}{1+t^2}}{1+\dfrac{2t}{1-t^2}}dt$$ Which is very complicated. But if we do $u=\tan x$ we would need to solve $$\int\frac{1}{(u+1)\left(u^2+1\right)}du$$Which is easier. Are there any other ways to solve this problem?
 A: Alternatively, you can spot that
\begin{align*}
\frac{1}{1+\tan x}&=\frac{\cos x}{\cos x+\sin x}
=\frac12\Big(1+\frac{\cos x-\sin x}{\cos x+\sin x}\Big),
\end{align*}
and noting that the latter term is of the form $f'/f$,
$$\int \frac{dx}{1+\tan x}=\frac 12\Big(x+\log(\cos x+\sin x)\Big)+c.$$
A: We can multiply by conjugate: $$\int \frac{dx}{1+\tan \left(x\right)} =\int \frac{1-\tan x}{1-\tan^2x}dx =\frac{1}{2}\int \frac{1+\cos 2x-\sin 2x}{\cos 2x}dx=\frac{1}{2}\int (1+\sec 2x -\tan 2x) dx$$ Secant is the most problematic integral here but similar to partial fraction or tangent substitution
A: Another possible approach: multiply the top and bottom by $\cos(x)$ to get
$$
\int\frac{\cos(x)}{\sin(x) + \cos(x)}\,dx.
$$
With the substitution $u = x + \pi/4$, this becomes
$$
\int\frac{\cos(u - \pi/4)}{\sin(u - \pi/4) + \cos(u - \pi/4)}\,du
\\=
\frac 12 \int\frac{\cos(u) + \sin(u)}{\sin(u)}\,du
\\ = 
\frac 12 \int\cot(u)\,du
+ \frac 12 \int du.
$$
A: $$\int \frac{dx}{1+\tan \left(x\right)} =\int \frac{1}{\left(1+u^2\right)\left(1+u\right)}du$$ applying the substitution $u=\tan x$, $x=\arctan u$ and $dx=\dfrac{du}{1+u^2}$; take the partial fraction of
$$\int \frac{1}{\left(1+u^2\right)\left(1+u\right)}=\int \frac{-u+1}{2\left(u^2+1\right)}du+\int \frac{1}{2\left(u+1\right)}du$$
Hence the two integrals have as primitive
$$=\frac{1}{2}\left(-\frac{1}{2}\ln \left|u^2+1\right|+\arctan \left(u\right)\right)+\frac{1}{2}\ln \left|u+1\right|+K$$
Substitute back $u=\tan \left(x\right)$ and you have the thesis.
A: Solution using Euler substitution, provided $\cos(x)>0$:
$$\begin{align*}
& \int \frac{dx}{1+\tan(x)} \\
&= \int \frac{\cos(x)}{\sin(x)+\cos(x)} \, dx \\
&= \int \frac{du}{u+\sqrt{1-u^2}} & u=\sin(x) \\
&= -2 \int \frac{1-t^2}{(1+t^2) \left(1-2t -t^2\right)}\,dt & u=-\frac{2t}{1+t^2}\\
&= \int \left(\frac{-1-t}{1-2t-t^2} - \frac{1}{1+t^2} - \frac t{1+t^2}\right) \, dt \\
&= \frac12 \ln\left|1-2t-t^2\right| - \arctan(t) - \frac12 \ln\left(1+t^2\right) + C \\
&= \frac12 \ln\left|\frac{(1-u)\left(1-\sqrt{1-u^2}\right)-u^2}{1-\sqrt{1-u^2}}\right| - \arctan\left(\frac{\sqrt{1-u^2}-1}u\right) + C \\
&= \frac12 \ln\left|\cos(x)+\sin(x)\right| + \arctan\left(\frac{1-\cos(x)}{\sin(x)}\right) + C \\
\end{align*}$$
and we recall
$$\arctan\left(\frac{1-\sqrt{1-z^2}}z\right) = \arctan\left(\frac{z}{1+\sqrt{1-z^2}}\right) = \frac12 \arcsin(z)$$
A: Note that
$$\sin x+\cos x=\sqrt{2}\sin\left(x+\frac{\pi}{4}\right)$$
Therefore you have:
$$I=\frac{1}{\sqrt{2}}\int\frac{\cos x}{\sin\left(x+\frac{\pi}{4}\right)}dx$$
Now let $x+\pi/4=t$
$$I=\frac{1}{\sqrt{2}}\int\frac{\cos \left(t-\frac{\pi}{4}\right)}{\sin t}dt=\frac{1}{2}\int\frac{\sin t + \cos t}{\sin t}dt=\frac{1}{2}\left(t+\ln {\left|\sin t\right|}\right)+c\\=\frac{1}{2}\left(x+\frac{\pi}{4}+\ln {\left|\sin x+\cos x\right|}\right)+c=\frac{1}{2}\left(x+\ln {\left|\sin x+\cos x\right|}\right)+k$$
