Integration of $1/(1+\sin x)$ I solved it using $t=\tan(\frac{x}{2})$ substitution and got $-2/(1+\tan(x/2))+C$, but in my math book solution is $\tan(x/2-\pi/4)+C$. Are those the same expressions and if they are, how do I transform from one to another, or are one(or both) solutions incorrect ? 
 A: $\bf{My\; Solution::}$ Let $\displaystyle I = \int\frac{1}{1+\sin x}dx = \int\frac{1}{1+\cos \left(\frac{\pi}{2}-x\right)}dx = \int\frac{1}{2\cos^2 \left(\frac{\pi}{4}-\frac{x}{2}\right)}dx$
So $\displaystyle I = \frac{1}{2}\int \sec^2 \left(\frac{\pi}{4}-\frac{x}{2}\right)dx = -\frac{1}{2}\tan \left(\frac{\pi}{4}-\frac{x}{2}\right)+\mathbf{C} = -\frac{1}{2}\cdot \left(\frac{1-\tan \frac{x}{2}}{1+\tan \frac{x}{2}}\right)+\mathbb{C}$
So $\displaystyle I = \int\frac{1}{1+\sin x} = \frac{1}{2}\left(\frac{\tan \frac{x}{2}-1}{1+\tan \frac{x}{2}}\right)+\mathbb{C} = \left(\frac{-2}{1+\tan \frac{x}{2}}\right)+1+\mathbb{C}$
A: Here is the integral with the Weierstrass substitution:
$$
\begin{align}
\int\frac{\mathrm{d}x}{1+\sin(x)}
&=\int\frac1{1+\frac{2z}{1+z^2}}\frac{2\,\mathrm{d}z}{1+z^2}\\
&=\int\frac{2\,\mathrm{d}z}{1+2z+z^2}\\
&=\frac{-2}{1+z}+C\\
&=\frac{-2}{1+\tan(x/2)}+C
\end{align}
$$
so your answer is correct. Now consider
$$
\begin{align}
\tan(x/2-\pi/4)
&=\frac{\tan(x/2)-1}{1+\tan(x/2)}\\
&=\frac{-2}{1+\tan(x/2)}+1
\end{align}
$$

Here is another approach, without Weierstrass substitution:
$$
\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{\mathrm{d}\cos(x)}{\cos^2(x)}\\[4pt]
&=\tan(x)-\sec(x)+C
\end{align}
$$
and again
$$
\begin{align}
\tan(x)-\sec(x)
&=\frac{\sin(x)-1}{\cos(x)}\\
&=\frac{\frac{2\tan(x/2)}{1+\tan^2(x/2)}-1}{\frac{1-\tan^2(x/2)}{1+\tan^2(x/2)}}\\
&=\frac{-1+2\tan(x/2)-\tan^2(x/2)}{1-\tan^2(x/2)}\\
&=\frac{\tan(x/2)-1}{1+\tan(x/2)}\\
&=\frac{-2}{1+\tan(x/2)}+1
\end{align}
$$
A: To some extent:
$$I=\int \frac{d x}{1+\varepsilon \sin x}=\int \frac{\sin^2 \frac{x}{2}+\cos^2 \frac{x}{2}}{\sin^2 \frac{x}{2}+\cos^2 \frac{x}{2}+2\varepsilon\sin(\frac{x}{2})\cos(\frac{x}{2})}dx\\=2 \int \frac{d t}{(1+t^2)+2\varepsilon t} \quad(t=\tan\frac{x}{2})\\=2\int\frac{dt}{(t+\varepsilon)^2-\varepsilon^2+1}=2\int\frac{d(t+\varepsilon)}{(t+\varepsilon)^2-\varepsilon^2+1}$$
Let $\varepsilon=\pm1$, then
$$I=2\int\frac{dm}{m^2}=-\frac{2}{m}+C=-\frac{2}{t\pm1}+C=-\frac{2}{\pm1+\tan\frac{x}{2}}+C$$
Moreover, for $\varepsilon\in(-1,1)$:
$$I=\int \frac{d x}{1+\varepsilon \sin x}=\frac{2}{\sqrt{1-\varepsilon^2}}\int\frac{dm}{1+m^2}\\=\frac{2}{\sqrt{1-\varepsilon^2}}\arctan m+C=\frac{2}{\sqrt{1-\varepsilon^2}}\arctan(\frac{\tan\frac{x}{2}+\varepsilon}{\sqrt{1-\varepsilon^2}})+C$$
for $\varepsilon>1$ or $\varepsilon<-1$:
$$I=\int \frac{d x}{1+\varepsilon \sin x}=-2\int\frac{d(t+\varepsilon)}{-(t+\varepsilon)^2+\varepsilon^2-1}\\=\frac{1}{\sqrt{\varepsilon^2-1}}\ln |\frac{\tan\frac{x}{2}+\varepsilon-\sqrt{\varepsilon^2-1}}{\tan\frac{x}{2}+\varepsilon+\sqrt{\varepsilon^2-1}}|+C$$
