One of the great difficulties with contour integration is choosing an appropriate contour. Like integration itself, there are few rules and choosing the right contour is a matter of intuition, experience, and trial and error. A member of math stack exchange provided some useful rules of thumb.

‘When analyzing real integrals with contour integrals, how does one choose a proper contour integral?

Many cases can be solved by integrating around the top half of a circle with radius of infinity and then integrating along the entire real line.

I understand how when integrating one would avoid the branch cuts, but how would one know to use a rectangle or a quarter of a circle as a contour?‘

‘In response to the comment, I will do my best to attempt to explain how I choose contours for integration.

I first look at the bounds of integration. If it is over \([0,\infty)\) and even, make it over \((−\infty,-\infty)\).

Next, I look at how the function behaves around infinity in the top half of the plane. If it decreases fast enough (e.g. \( \frac{\exp(ix)}{x^{2}+1} \), we can integrate with a semicircle contour. If not, find a value \(a\) such that when you integrate a rectangle with vertices at \(−R,R,R+ia,−R+ia−R,R,R+ia,−R+ia (as R \to \infty) \), the vertical sides disappear and the horizontal integrals are equal when multiplied by a constant.

If the function cannot be made even, there is still some hope left to contour integrate. If the function has a branch cut (e.g. \( \frac{\sqrt{x}}{x^{2}+1}\)), try a keyhole contour if the function decays fast enough around \(\infty\). Otherwise, try a rectangle.

Other contours exist and can be used (e.g. the trapezoid contour for integrating the gaussian integral), though I’ve found the above contours work for most standard integrals.

If the contour travels through a pole, indent it with a semicircle – with a simple pole, \(z_{0}\), the contributed value from that integral equals \( i\theta Res f_{z=z_{0}} \) where \(\theta\) equals the angle traversed around the pole.

It is often convenient to change sine or cosine in the numerator to \(e^{ix}\) (which is better behaved for integration around the top half of the plane) and take the real or imaginary part after integration – this can even be done if the other part diverges.‘