<s>[INST] Integration by substitution fail for $\int \frac{1}{(1+\sin x)}\, \mathrm dx$. We tried to do an integral with the universal trigonometric substitution $$\int \frac{1}{(1+\sin x)}\, \mathrm dx$$
Meaning, we substituted: $ t = \tan \frac{x}{2}  \Rightarrow$ 
$$\int \frac{1}{(1+\sin x)}\, \mathrm dx = \int \frac{\frac{2}{1+t^2}}{1+\frac{2t}{1+t^2}}\, \mathrm dt = \int \frac{2}{(1+t)^2}\, \mathrm dt = \frac{-2}{1+t} = \frac{-2}{1+\tan \frac{x}{2}} + C$$
But the answer is:
$$ \tan x - \frac{1}{\cos x} + C $$
What did we do wrong?
 [/INST] $$\begin{align}
\frac{-2}{1+\tan \frac{x}{2}} &= \frac{-2\cos \frac{x}{2}}{\cos\frac{x}{2} + \sin \frac{x}{2}}\\
&= \frac{-2\cos \frac{x}{2}(\cos \frac{x}{2}-\sin\frac{x}{2})}{(\cos \frac{x}{2}+\sin\frac{x}{2})(\cos \frac{x}{2}-\sin\frac{x}{2})}\\
&= \frac{\sin x - 2 \cos^2 \frac{x}{2}}{\cos x}\\
&= \tan x - \frac{\cos x + 1}{\cos x}\\
&= \tan x - \frac{1}{\cos x} - 1
\end{align}$$
You did nothing wrong, you just got another representation of the same family of functions.
</s>