Deforming contours let us replace a big contour by small circles around each point inside where $f$ fails to be analytic. Each small circle contributes $2\pi i$ times a residue. Put together, that is the residue theorem, the main computing tool of the course.
Key idea
Residue theorem. If $f$ is analytic on and inside a simple closed contour $C$ (counterclockwise) except at finitely many isolated singularities $a_1, \ldots, a_k$ inside $C$, then
$$\oint_C f(z)\,dz = 2\pi i\sum_{j = 1}^{k}\operatorname{Res}(f, a_j).$$
Singularities outside $C$ do not count.
Why it works
Draw a small circle $c_j$ around each $a_j$. Cutting slits from $C$ to each $c_j$, as in the deformation argument, shows that $\oint_C f\,dz = \sum_j \oint_{c_j} f\,dz$, because $f$ is analytic in the region between them. On $c_j$, integrate the Laurent series about $a_j$ term by term: only the $(z - a_j)^{-1}$ term survives, giving $2\pi i\operatorname{Res}(f, a_j)$.
Worked examples
Worked example: Two poles, one inside
Compute $\displaystyle\oint_{|z| = 2}\frac{z}{(z - 1)(z - 3)}\,dz$.
- Poles at $1$ (inside) and $3$ (outside).
- $\operatorname{Res}(f, 1) = \frac{1}{1 - 3} = -\frac{1}{2}$.
- $2\pi i\left(-\frac{1}{2}\right) = -\pi i$.
Answer: $-\pi i$
Worked example: Three poles
Compute $\displaystyle\oint_{|z| = 3/2}\frac{dz}{z(z - 1)(z + 2)}$.
- Inside: $0$ and $1$. Outside: $-2$.
- $\operatorname{Res}(f, 0) = \frac{1}{(0 - 1)(0 + 2)} = -\frac{1}{2}$ and $\operatorname{Res}(f, 1) = \frac{1}{1 \cdot 3} = \frac{1}{3}$.
- $2\pi i\left(-\frac{1}{2} + \frac{1}{3}\right) = -\frac{\pi i}{3}$.
Answer: $-\frac{\pi i}{3}$
Worked example: With a double pole
Compute $\displaystyle\oint_{|z| = 2}\frac{e^z}{z^2(z - 3)}\,dz$.
- Inside: the double pole at $0$. Outside: $3$.
- $\operatorname{Res}(f, 0) = \frac{d}{dz}\frac{e^z}{z - 3}\Big|_{0} = \frac{e^z(z - 3) - e^z}{(z - 3)^2}\Big|_{0} = \frac{-3 - 1}{9} = -\frac{4}{9}$.
- $2\pi i\left(-\frac{4}{9}\right) = -\frac{8\pi i}{9}$.
Answer: $-\frac{8\pi i}{9}$
- Find all singular points of $f$.
- Decide which lie inside $C$ (compare distances from the center with the radius, or sketch).
- Compute the residue at each inside point, using the simple-pole or higher-order formulas.
- Multiply the sum by $2\pi i$.
The residue theorem contains the earlier results: with no singular points inside it is Cauchy's theorem, and for $\frac{f(z)}{z - a}$ the residue at $a$ is $f(a)$, giving Cauchy's integral formula. For a rational function whose bottom has degree at least two more than the top, the residues at all its poles add up to $0$, which can save work.
Orientation matters: a clockwise contour gives $-2\pi i$ times the sum of the residues inside.
Common mistake
Including residues of poles outside the contour. The theorem sums over the singularities inside $C$ only. Before computing any residue, list all singular points with their distances from the center of $C$ and cross out the ones outside. That also saves work: there is no need to compute residues you will not use.