Transform $\frac{-2}{\tan\frac{x}{2}+1}$ to $\tan x-\sec x$? I'm learning to integrate and was asked to integrate $\int\frac{1}{1+\sin x}dx$
I get the answer $-\frac{2}{\tan\frac{x}2+1}+c$ which Symbolab confirms is correct, but the textbook says the answer is $\tan x-\sec x+c$.
I can't seem to transform my answer to that one using trig identities. Any idea how/if one can get that result?
Many thanks,
Andrew

You can multiply both the numerator and the denominator by $1 - \sin(x)$, whence you get the desired result:
\begin{align*}
\int\frac{\mathrm{d}x}{1 + \sin(x)} & = \int\frac{1 - \sin(x)}{1-\sin^{2}(x)}\mathrm{d}x\\\\
& = \int\frac{\mathrm{d}x}{\cos^{2}(x)} - \int\frac{\sin(x)}{\cos^{2}(x)}\mathrm{d}x\\\\
& = \tan(x) - \sec(x) + c 
\end{align*}
Alternatively, you can apply the double-angle identity:
\begin{align*}
\tan(x) - \sec(x) & = \frac{\sin(x) - 1}{\cos(x)}\\\\
& = -\frac{1 - 2\sin(x/2)\cos(x/2)}{\cos^{2}(x/2) - \sin^{2}(x/2)}\\\\
& = -\frac{(\cos(x/2) - \sin(x/2))^{2}}{\cos^{2}(x/2) - \sin^{2}(x/2)}\\\\
& = \frac{\sin(x/2) - \cos(x/2)}{\cos(x/2) + \sin(x/2)}\\\\
& = \frac{\sin(x/2) + \cos(x/2)}{\cos(x/2) + \sin(x/2)} - \frac{2\cos(x/2)}{\cos(x/2) + \sin(x/2)}\\\\
& = 1 - \frac{2}{\tan(x/2) + 1}
\end{align*}
Hopefully this helps!
