<s>[INST] Evaluate $\int_0^{2\pi} \frac{d\theta}{(1-a\cos(\theta)+a^2)}$ Evaluate $\displaystyle \int_0^{2\pi} \frac{d\theta}{(1-a\cos(\theta)+a^2)}$
Super general. I get to a step: $\displaystyle \frac{2}{i}$ multiplied by Path integral $\displaystyle \frac{z}{[(2-a)z^2 + 2(a^2  z) + a]}.$
No idea if I'm on the right track. Maybe distribute the $i$? Wondering if I can get some help. 
 [/INST] Take a Weierstrass substitution $u = \tan \frac{\theta}{2}$ after reducing the integration range using $\cos(2\pi - \theta) = \cos(\theta)$ in the second integral below:
$$
   \int_0^{2\pi} \frac{\mathrm{d}\theta}{a^2+1-a \cos\theta} = \int_0^{\pi} \frac{\mathrm{d}\theta}{a^2+1-a \cos\theta} + \int_{\pi}^{2\pi} \frac{\mathrm{d}\theta}{a^2+1-a \cos\theta}
$$ 
giving
$$
   \int_0^{2\pi} \frac{\mathrm{d}\theta}{a^2+1-a \cos\theta} = 2 \int_0^{\pi} \frac{\mathrm{d}\theta}{a^2+1-a \cos\theta}
$$
Now apply the substitution, using $\cos\theta = \frac{1-u^2}{1+u^2}$, and $\mathrm{d}\theta = \frac{2\mathrm{d}u}{1+u^2}$:
$$
  2 \int_0^{\pi} \frac{\mathrm{d}\theta}{a^2+1-a \cos\theta} = 4 \int_0^\infty \frac{\mathrm{d}u}{a^2-a+1 + (a^2+a+1) u^2} = 4 \cdot \frac{\pi}{2 \sqrt{(a^2-a+1)(a^2+a+1)}} = \frac{2\pi}{\sqrt{a^4+a^2+1}}
$$
where we used the assumption $a^2-a+1>0$ and $a^2+a+1>0$, valid for all real $a$.
</s>