Choosing the correct branch in $\int \frac{a-\cos(\theta)}{b-\cos(\theta)} d\theta$ I am interested in the following definite integral:
$$\int_0^{2\pi}\frac{a-\cos\theta}{b-\cos\theta}d\theta$$
for $a>0$ and $b>0$. I asked Wolfram Alpha and it gave me an answer that worried me, so I decided to try the specific case of $a=1$ and $b=2$. It gives me the indefinite version:
$$\int \frac{1-\cos\theta}{2-\cos\theta}d\theta=\theta-\frac{2\tan^{-1}(\sqrt{3}\tan(\theta/2))}{\sqrt{3}}$$
so I can set the limits and get my answer. At $\theta=0$, $\tan(\theta/2)=0$ and $\tan^{-1}(0)=n\pi$. At $\theta=2\pi$, $\tan(\theta/2)=0$ again so $\tan^{-1}(0)=m\pi$ (different integer here for later comparison). My final answer is then
$$\int_0^{2\pi}\frac{a-\cos\theta}{b-\cos\theta}d\theta=2\pi-\frac{2}{\sqrt{3}}n\pi-(0-\frac{2}{\sqrt{3}}m\pi)=2\pi-\frac{2\pi}{\sqrt{3}}(n-m).$$
Which, not knowing what else to do, I might just say the final answer is $2\pi$ (choosing the same branch of the tangent function). Now, along with this indefinite integral, Wolfram also of course gives me its own answer for the definite form,
$$\int_0^{2\pi}\frac{a-\cos\theta}{b-\cos\theta}d\theta=-\frac{2}{3}(\sqrt{3}-3)\pi.$$
Apparently, it has decided that $n-m=1$ is the correct choice for the branches of tangent in the integral. Why?
link to this calculation
 A: I think that you don't really need branch to evaluate the integral. Suppose $b>1$. Noting that $\cos\theta=\frac{1-\tan^2(\frac{\theta}2)}{1+\tan^2(\frac{\theta}2)}$ and letting $u=\tan(\frac{\theta}2)$, then one has
\begin{eqnarray}
\int \frac{a-\cos\theta}{b-\cos\theta}d\theta&=&x+(a-b)\int\frac{1}{b-\cos\theta}d\theta\\
&=&x+(a-b)\int\frac{1+\tan^2(\frac{\theta}2)}{(b-1)+(b+1)\tan^2(\frac{\theta}2)}d\theta\\
&=&x+(a-b)\int\frac{1+u^2}{(b-1)+(b+1)u^2}\frac{2}{1+u^2}du\\
&=&x+2(a-b)\frac{\arctan(\sqrt{\frac{b+1}{b-1}}u)}{\sqrt{b^2-1}}+C\\
&=&x+2(a-b)\frac{\arctan(\sqrt{\frac{b+1}{b-1}}\tan(\frac{\theta}2))}{\sqrt{b^2-1}}+C\\
\end{eqnarray}
A: Note that when one integrates a function of period $2\pi$ one has $\displaystyle\int_0^{2\pi} = \int_{-\pi}^\pi$.
\begin{align}
u & = \tan \frac \theta 2 \\[10pt]
\theta & = 2\arctan u \\[10pt]
\cos\theta & = \cos(2\arctan u) \\
& = \cos^2 \arctan u - \sin^2\arctan u = \frac 1 {u^2 + 1} - \frac {u^2} {u^2+1} \\
& = \frac{u^2-1}{u^2+1}
\end{align}
As $\theta$ increases from $-\pi$ to $\pi$, then $u$ increases from $-\infty$ to $+\infty$. Here we're using just one connected component of the graph of the tangent function.
Now suppose we instead let $\theta$ increase from $0$ to $2\pi$.  Then $u$ first increases from $0$ to $+\infty$ and then increases from $-\infty$ to $0$.  Either way, the definite integral is the same.
Normally I wouldn't bother with changing it back to a function of $\theta$ and going on from there. But suppose we do that.  As $\theta$ goes once around the circle, $c\tan(\theta/2)$ goes once through the whole real line, regardless of the value of $c>0$.  If we follow the "principal branch" of the arctangent function then the arctangent goes from $-\pi/2$ to $+\pi/2$, again regardless of the value of $c>0$.  If we follow a different branch, the indefinite integral changes by a constant, so the definite integral does not change.  So now the question is: Why remain on one branch?  And there the point is that otherwise we have a jump discontinuity in our antiderivative and it fails to be an antiderivative at that point.
A: OK, I am going to seem like I am not answering the question by ignoring the issue posed by the OP altogether.  Why?  Because the whole question about "branches" is an artifice of the (inferior) method of evaluating the integral.  But look at the integrand: no branch points!  And for $b \gt 1$, no poles in the interval of integration.  So really, the whole difficulty posed by the antiderivative should make one question whether that is an appropriate way to evaluate the integral.
A better way to evaluate this integral is via expression as an integral over the unit circle in the complex plane.  Then we can evaluate directly using the residue theorem.  To this effect, consider the case where $b \gt 1$ and let $z=e^{i \theta}$; then the integral is equal to
$$-i \oint_{|z|=1} \frac{dz}{z} \frac{z^2-2 a z+1}{z^2-2 b z+1} $$
The poles of the integrand are at $z=0$ and $z=b \pm \sqrt{b^2-1} $; we can ignore the pole at $z=b+\sqrt{b^2-1}$ as it lies outside the unit circle.  By the residue theorem, the integral is equal to $i 2 \pi$ times the sum of the residues of the poles inside the unit circle.  Leaving the simple computation of the residues to the reader, I get that the integral is equal to
$$\int_0^{2 \pi} d\theta \frac{a-\cos{\theta}}{b-\cos{\theta}} = 2 \pi \left (1-\frac{b-a}{\sqrt{b^2-1}} \right ) $$
This answer was derived without any questions about branches of inverse trig functions, or any other questions at all.  
