<s>[INST] 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
 [/INST] 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}
</s>