TITLE: Why $\int_0^{2\pi} \frac{dx}{2-\sin x}=0$?
QUESTION [7 upvotes]: Of course this is not true, because the integrand is always greater than zero. However, when using Mathematica to do an indefinite integral of the general form
$$
\int\frac{dx}{\xi-\sin x} = -\frac{2\arctan\left[\frac{1-\xi\tan\frac{x}{2}}{\sqrt{\xi^2-1}}\right]}{\sqrt{\xi^2-1}}
$$
Now if you plug into the limit in the result, i.e. $0$ to $2\pi$, the result is zero. What's wrong with this argument? I must miss something very basic...
I don't need another way to do the integral, just need someone tell me why this doesn't work...

REPLY [5 votes]: The $\arctan$ function is multi-valued. When it appears in formulae for indefinite integrals you have to be careful when using it to calculate definite integrals, since in practice you use the principal branch ${\rm Arctan} : {\Bbb R} \cup {\infty}\to (-\pi/2,\pi/2]$ to evaluate the expression.
Let me illustrate by a simplified example:
$$ x = \int dx = 2\arctan(\tan(x/2)).$$
Again, calculating $\int_0^{2\pi} dx = 2\pi$ leads to the same paradoxe as yours if you evaluate using ${\rm Arctan}$ on the RHS. To solve the paradoxe note that there is a constant of integration which was omitted in the formula. You may change this constant when $\tan$ goes through a singularity $x=(2k+1)\pi$, $k\in {\Bbb Z}$ so as to make the result a continuous function.
Thus for my integral, if I want a continuous indefinite integral I should split ${\Bbb R}$ into intervals between these singularities:
$$ x =\int dx = 2{\rm Arctan} (\tan(x/2)) +  2\pi k,  \ \ \ \ \ \ {\rm when } \ \ x\in  \left((2k-1) \pi, (2k+1) \pi\right], k\in {\Bbb Z}.$$
which now is continuous and an identity for all $x\in {\Bbb R}$.
A drawback is, of course, that the formula becomes somewhat indigestible to read.