# Why did the contour integration for $\int_0^{\pi/2}\frac{1}{1+\sin x}\,\mathrm{d}x$ fail

complex-analysiscontour-integrationintegrationlogarithms

$$\newcommand{\d}{\,\mathrm{d}}$$Integrals of the titular form can be successfully contour-integrated, e.g.: $$\int_0^{2\pi}\frac{1}{4\cos x-5}\d x=-\frac{2}{3}\pi$$Follows from a complex substitution very similar to what I've done here.

However:

$$\int_0^{\pi/2}\frac{1}{1+\sin x}\d x=1$$

Is easily evaluated with Weierstrass's substitution, but out of curiosity I attempted to form a contour integration approach, which failed:

First translate by $$\pi/4$$:

$$\int_{-\pi/4}^{\pi/4}\frac{1}{1+\sin(x+\pi/4)}\d x=\sqrt{2}\int_{-\pi/4}^{\pi/4}\frac{1}{\sqrt{2}+\sin x+\cos x}\d x$$

Let $$\Bbb T=\{z\in\Bbb C:|z|=1\}$$. Let $$\log$$ be the principal branch, and put $$x=\frac{1}{4i}\log z$$, $$z=e^{4ix}$$ and $$[-\pi/4,\pi/4)\mapsto\Bbb T$$:

\begin{align}\frac{\sqrt{2}}{4i}\oint_{\Bbb T}\frac{1}{\sqrt{2}+\sin\left(\frac{1}{4i}\log z\right)+\cos\left(\frac{1}{4i}\log z\right)}\frac{\d z}{z}&=\frac{\sqrt{2}}{4i}\oint_{\Bbb T}\frac{1}{\sqrt{2}+z^{1/4}}\frac{\d z}{z}\\&=\pi\frac{\sqrt{2}}{2}\sum\mathrm{Res}\end{align}

We have a pole at $$z=0$$ which is contained by $$\Bbb T$$. The other pole is when $$\exp\frac{1}{4}\log z=-2^{1/2}$$:

$$\exp\frac{1}{4}\log z=\exp(\pi i+\frac{1}{2}\ln 2),\,\log z=4\pi i+2\ln 2+8\pi i\cdot k$$

But this doesn't really make sense, since the principal $$\log z$$ should have imaginary part contained in $$(-\pi,\pi]$$, but this expression clearly does not satisfy this for any $$k$$. I will infer from this that no principal solutions exist, and then that $$z=0$$ is the only pole, with residue $$\frac{1}{\sqrt{2}}$$. We then arrive at the incorrect answer:

$$\int_0^{\pi/2}\frac{1}{1+\sin x}\d x=\frac{\pi}{2}$$

What did I do wrong?

When you go from the real integral to the complex integral you have made a mistake, for the final result (after accounting for the Jacobian) is more like $$e^{-i\pi/4}\int_{\mathbb T}\frac1{(\sqrt2+(1+i)z^{1/4})^2z^{3/4}}\,dz$$ so contour integration is not suitable for the integrand in that form (branch cuts get introduced with the fractional powers!). The original bounds are another minus, since the method requires a closed loop in the complex plane, usually corresponding to a whole-period $$[0,2\pi]$$ integral.