improper integrals of rational functions
Many integrals over the whole real line, like the integral from minus infinity to infinity of dx / (x^2 + 1) or dx / (x^4 + 1), are perfectly finite but stubborn to evaluate by real antiderivatives, especially for high-degree denominators. The contour method computes them by closing the real line into a loop in the complex plane and harvesting residues.
The strategy: take a real rational function P(x) / Q(x) with Q having no real zeros and the degree of Q at least 2 more than the degree of P (so the integral converges). Form the contour that runs along the real axis from -R to R and then closes with a large semicircle of radius R in the upper half-plane. The residue theorem says the whole loop integral equals 2 pi i times the sum of residues of P(z)/Q(z) at the poles in the upper half-plane. Now let R go to infinity: the semicircle's contribution shrinks to zero (because P/Q decays like 1/R^2 or faster while the arc length grows only like R, so the product vanishes — this is the degree-at-least-2 condition doing its job). What survives is exactly the real integral you wanted.
So the rule comes out clean: the integral from minus infinity to infinity of P(x)/Q(x) dx = 2 pi i times the sum of the residues of P(z)/Q(z) at the poles in the upper half-plane. You could close downward instead, which encircles the lower poles clockwise and introduces a minus sign; the answer is the same. This is the cleanest entry point to contour evaluation of real integrals, and the template generalizes to oscillatory integrands once you add Jordan's lemma.
For the integral from minus infinity to infinity of dx / (x^2 + 1), the only upper-half-plane pole is z = i, with residue 1 / (2 i). So the integral = 2 pi i times 1/(2 i) = pi, matching the known arctangent answer.
Close the real line with an upper semicircle and sum the upper residues.
The degree gap matters: you need deg Q at least deg P + 2 for the arc to vanish. With a gap of only 1 the semicircle does not die on its own and you must invoke Jordan's lemma or a different argument; with Q having a real zero, the bare integral diverges and you need a principal value.