Problem: Compute $\int_{|z|=2} \frac{4z^7 - 1}{z^8 - 2z + 1}dz$.
Attempt: I notice that if $w = z^8 - 2z + 1$ then $dw = 2 (4z^8 - 1) dz$ so $$I=\int_{|z|=2} \frac{4z^7 - 1}{z^8 - 2z + 1}dz = \frac{1}{2}\int_C \frac{1}{w}dw$$ over the closed curve $C = \{ (2e^{i \theta})^8 - 2 (2e^{i \theta}) + 1 \in \mathbb{C} : 0 \leq \theta \leq 2 \pi \}$.
At this point, I know that $\int_C \frac{1}{w} dw = 2\pi i \cdot (\text{winding number of }C\text{ around w = 0})$ so $I = \frac{1}{2} 2\pi i \cdot 8 = 8 \pi i$. Is this not correct?
When I try to verify my answer using Wolfram Alpha, I can get a complex number with nonzero real part: Wolfram link
Maybe Wolfram Alpha is just approximating this integral up to some error bound so their approximation terminates without realizing the real part is actually $0$?
The residue at infinity serves as a sort of "dual" to the residue at zero. Namely,
$$\mathrm{Res}(f(z), \infty) = - \mathrm{Res}\left(\frac{1}{z^2}f\left(\frac{1}{z} \right), 0 \right). $$
Recall that the residue theorem looks at the contributions of singularities inside the contour. But $\infty$ is outside of our contour. How do we fix this? Easy - reverse the orientation. That's where the minus sign comes in.
Let $f(z) = \frac{4z^7 - 1}{z^8 - 2z + 1}.$ Then
\begin{align*} f\left(\frac{1}{z} \right) &= \frac{\frac{4}{z^7} - 1}{\frac{1}{z^8} - \frac{2}{z} + 1} \\ &= \frac{4z - z^8}{1 - 2z^7 + z^8} \end{align*}
Computing the needed value is easy. Thanks to some nice cancellation,
$$ \lim_{z \to 0} z\cdot \frac{1}{z^2} f\left(\frac{1}{z} \right) = 4 $$
and $\mathrm{Res}(f(z), \infty) = -4.$
Let $\gamma$ be the circle of radius $2$ centered at the origin (our contour). Now since $\infty$ is outside $\gamma$, we instead integrate over $-\gamma$ by reversing orientation so that $\infty$ is inside $-\gamma.$ So,
\begin{align*} \oint\limits_{\gamma} f(z) \ dz &= -\oint\limits_{-\gamma} f(z) \ dz \\ &= -2\pi i \mathrm{Res}(f(z), \infty) \\ &= 8\pi i \end{align*}
as needed!