Note
Go to the end to download the full example code or to run this example in your browser via JupyterLite.
Cauchy’s integral theorem: the integral of a holomorphic function around a closed contour is zero#
For \(f\) holomorphic inside and on a closed contour \(\gamma\), \(\oint_\gamma f(z)\,dz = 0\), whatever the shape of \(\gamma\). \(1/z\) shows what happens when the hypothesis fails: its integral is \(2\pi i\) times the number of times \(\gamma\) winds around the singularity at 0.
import matplotlib.pyplot as plt
import numpy as np
from mathematicskit.complex_analysis import circle_contour, contour_integral, polygon_contour, winding_number
from mathematicskit.complex_analysis.visualizers import plot_contour
Three contours, two integrands#
contours = {
"unit circle": circle_contour(0.0, 1.0),
"star around 0": polygon_contour([1.5 * np.exp(2j * np.pi * k / 10) * (1 if k % 2 == 0 else 0.5) for k in range(10)]),
"triangle missing 0": polygon_contour([0.5 + 0.5j, 2 + 0.5j, 1 + 2j]),
}
entire = lambda z: np.exp(z) * np.cos(z) + z**4
fig, axes = plt.subplots(1, 3, figsize=(12, 4))
for ax, (name, contour) in zip(axes, contours.items(), strict=False):
plot_contour(contour, marked_points=[0], ax=ax)
ax.set_title(name)
print(
f"{name:20s} oint entire = {contour_integral(entire, contour):.1e} "
f"oint 1/z = {contour_integral(lambda z: 1 / z, contour):.6f} "
f"winding number about 0 = {winding_number(contour, 0)}"
)

unit circle oint entire = -1.8e-16-6.7e-16j oint 1/z = 0.000000+6.283185j winding number about 0 = 1
star around 0 oint entire = 8.9e-16+1.0e-15j oint 1/z = -0.000000+6.283185j winding number about 0 = 1
triangle missing 0 oint entire = 8.9e-16+2.0e-15j oint 1/z = 0.000000+0.000000j winding number about 0 = 0
Total running time of the script: (0 minutes 0.197 seconds)