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
 A: 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!
A: Let $$f(x) = \frac{-2}{\tan \frac{x}{2} + 1}, \quad g(x) = \tan x - \sec x.$$
Then the first thing to note is that $f(0) = -2$, whereas $g(0) = -1$.  So if $f$ and $g$ differ by a constant, this difference must satisfy $g(x) - f(x) = 1$.  Consequently,
$$\begin{align}
f(x) + 1 &= 1 - \frac{2}{\tan \frac{x}{2} + 1} \\
&= \frac{\tan \frac{x}{2} - 1}{\tan \frac{x}{2} + 1} \\
&= \frac{\sin \frac{x}{2} - \cos \frac{x}{2}}{\sin \frac{x}{2} + \cos \frac{x}{2}} \\
&= \frac{(\sin \frac{x}{2} - \cos \frac{x}{2})^2}{\sin^2 \frac{x}{2} - \cos^2 \frac{x}{2}} \\
&= \frac{\sin^2 \frac{x}{2} - 2 \sin \frac{x}{2} \cos \frac{x}{2} + \cos^2 \frac{x}{2}}{-\cos x} \\
&= \frac{\sin x - 1}{\cos x} \\
&= \tan x - \sec x \\
&= g(x).
\end{align}$$
A: Using $\tan \frac x2 = \frac{1-\cos x}{\sin x}$, simply note that
\begin{align*}
\tan x -\sec x +\frac 2{\tan \frac x2 +1}&=
\frac{\sin x -\sin x \cos x + \sin^2-1+\cos x - \sin x + 2\sin x \cos x}{\cos x(1+\sin x -\cos x)} =\\
&= \frac{\cos x (1+\sin x -\cos x)} {\cos x(1+\sin x -\cos x)} =1.
\end{align*}
