∫Analysis, Built

Book II · Real and Complex Analysis

Part 7 of 10

Complex Analysis

Graduatestarts at this level28 min of film14 chaptersprerequisites: Part 2, Part 3, Part 4, Part 6

Why is a function with one complex derivative so much better behaved than a differentiable function on the real line?

The part opens with e^(-1/x^2) from Part 2, smooth on the real line with a Taylor series that says nothing, and shows it exploding along the imaginary axis. A complex derivative is a rotation and a scaling, so holomorphic maps keep angles; integrals around closed paths count turns, and Goursat's bisection proves Cauchy's theorem. Cauchy's formula then delivers the three miracles: one derivative gives a power series (the Fibonacci numbers come out as contour integrals), Liouville's theorem gives the fundamental theorem of algebra, and the values on a short arc decide the function everywhere. The global half computes real integrals by residues, counts roots with Rouche's dog on a leash, and uses the maximum principle as a tool in the Schwarz lemma and the three lines theorem. Runge's theorem says when polynomials approximate, Montel's theorem gives compactness, and the Riemann mapping theorem is proved as an extremal problem and computed for an L-shaped hexagon by Schwarz-Christoffel. A tour without proofs ends the part: harmonic functions and Poisson's integral, Weierstrass and Blaschke products, continuation, and the Hardy space H^2 with the shift.

What you need. Complex numbers and power series; for H^2, Fourier series in L^2 from Part 6.

What you will be able to do

Undergraduate

  • Check the Cauchy-Riemann equations and explain why a holomorphic map with nonzero derivative preserves angles.
  • Compute path integrals of powers of z and the winding number of a closed curve around a point.

Graduate

  • Prove Cauchy's theorem for a triangle by Goursat's bisection and derive Cauchy's formula, power series, Liouville's theorem and the fundamental theorem of algebra from it.
  • Prove the open mapping theorem, the maximum modulus principle and the Schwarz lemma, and use Rouche's theorem to count zeros.

Qualifying exam

  • Prove the Riemann mapping theorem from Montel's theorem as an extremal problem, saying where simple connectivity enters.
  • Prove Runge's theorem by pushing poles, and explain why polynomials cannot approximate 1/z on an annulus.

Applications

  • Evaluate real integrals by residues, choosing the contour and bounding the part that fades.
  • Solve the Dirichlet problem on the disk with Poisson's integral, and count the roots of a polynomial in a disk numerically with the argument principle.

Contents

Each chapter has a home level. Choose a track to see what to read and watch: Undergraduate 11 min · Graduate 22 min · Qualifying exam 28 min · Applications 15 min.

  1. 0Why is C so much better behaved than R?Undergraduate2 min
  2. 1Complex derivatives are rotationsUndergraduate2 min
  3. 2Path integrals and winding numbersUndergraduate2 min
  4. 3Cauchy's formula and its miraclesUndergraduate2 min
  5. 4Zeros, open maps, the maximum modulusGraduate2 min
  6. 5The global Cauchy theorem and residuesApplications3 min
  7. 6The Schwarz lemma and three linesGraduate2 min
  8. 7Runge's theoremQualifying exam2 min
  9. 8Normal familiesGraduate2 min
  10. 9The Riemann mapping theoremQualifying exam2 min
  11. 10A tour: harmonic functionsApplications1 min
  12. 11A tour: products and continuationGraduate2 min
  13. 12A tour: H^p and the shiftQualifying exam2 min
  14. The seventh row of the ledgerAll tracks2 min

Also on this page: Lecture · Key results · Try it · Lab · Notes and sources · Build the film.

Lecture

The text of each chapter is the film's narration, as it is spoken, so you can read along or revise without the film. The pictures are in the film.

Why is C so much better behaved than R?Undergraduate2 min

Six rows of the ledger are filled. Part 7 takes a step sideways, into the complex plane. It's the part the rest of the series needs: the spectral theory of Part 10 runs on Cauchy's integral formula.

Part 2 met this function: e to the minus one over x squared. On the real line it's infinitely differentiable, and every derivative at zero vanishes, so its Taylor series is zero, and says nothing about it. Now feed it complex numbers. Here's the same formula on a square of the complex plane, colored by phase, with brightness for size. Along the imaginary axis, minus one over z squared is positive, and the function explodes: at 0.2 i it's already about seven times ten to the ten. The real line hid a catastrophe. In the complex plane a function with a derivative can't behave like this, and that buys three miracles: one derivative gives infinitely many; the function is its own power series; and its values on any tiny arc decide it everywhere.

Rudin begins Real and Complex Analysis with one series: the exponential. On the left, its domain coloring. Moving up, the colors cycle, and the whole picture repeats. From the series alone come the addition law, and the fact that exp never vanishes. Even pi comes out of it: half of pi is the first positive zero of the cosine, the real part of e to the i t. Bisection on the series pins it down to every digit. And the partial sums at two pi i converge to one: the exponential repeats every two pi i, which is the horizontal stripe pattern in the picture.

Here's the plan, following chapters ten through fourteen of Real and Complex Analysis. First the derivative, path integrals, and Cauchy's formula with its miracles. Then the global theorems: residues, the Schwarz lemma, Runge's approximation theorem. Then Arzelà and Ascoli's grandest payoff, the Riemann mapping theorem, computed for a real polygon, and a guided tour of the rest.

1Complex derivatives are rotationsUndergraduate2 min

What it means for a function of a complex variable to have a derivative.

A complex derivative is a limit of difference quotients, where h may approach zero from any direction in the plane. That's a much stronger demand than in two real variables. Take a small square near z zero. Under z squared, it comes out as a square again, turned and enlarged: the derivative is multiplication by the complex number two z zero, which is a rotation by 33.7 degrees and a stretch by 1.44. A real-linear map that isn't complex-linear, like z plus 0.4 i times z bar, turns the square into a rhombus. In coordinates, the Jacobian must be a rotation times a scaling: the Cauchy-Riemann equations.

Since the derivative is a rotation and a scaling, small shapes keep their angles. Here's a grid under z squared: its lines bend, but they still cross at right angles. Under the exponential, the vertical lines become circles and the horizontal ones become rays, still perpendicular. Measured at four points, the angles are ninety degrees to every digit shown. Wherever the derivative isn't zero, a holomorphic map is conformal; at a zero of the derivative, like z squared at the origin, angles get multiplied.

Two first consequences. A power series is holomorphic inside its disk of convergence, and you can differentiate it term by term: one more interchange of limits, made legal. And zeros behave. On the real line, x squared sine one over x is differentiable, and its zeros pile up at zero. A holomorphic function can't do that unless it's zero everywhere: its zeros are isolated, like the integers for sine of pi z, each a dark point with every color around it once.

2Path integrals and winding numbersUndergraduate2 min

Integrals along paths, and the number that counts turns. To integrate along a path, parametrize it and integrate f of gamma times gamma prime. Around the unit circle, the powers of z all give zero, except one. One over z gives two pi i. Every other power has an antiderivative, and around a closed path an antiderivative returns to where it started. One over z would need a logarithm, and no single-valued logarithm exists around the origin. Those two pi i's are the whole story of this part.

Divide by two pi i, shift the singularity to a point a, and the integral of one over z minus a counts how many times the curve winds around a. Follow an arrow from a point inside the small loop to the moving point of the curve. By the time the curve closes, the arrow has turned exactly twice. Compute the integral at twenty points: every answer is an integer, zero, one or two, constant on each piece of the complement, and zero outside the curve.

Cauchy's theorem starts with triangles, and Goursat's proof is bisection, the fourth time in this series that halving has proved a theorem. Cut the triangle into four by its midpoints. The four boundary integrals add up to the whole, so one of them is at least a quarter of it. Keep that one, and repeat: the triangles shrink to a point z zero. Near z zero, f is linear plus a small error, and the linear part integrates to zero around any closed path. So the n-th integral is at most epsilon n times four to the minus n, with epsilon n going to zero, here for the exponential. But bisection kept at least four to the minus n of the original. The only way out: the original integral was zero. For z bar, which isn't holomorphic, the corresponding ratio stays fixed, and the argument fails, as it must. Rudin extends this from triangles to every convex set.

3Cauchy's formula and its miraclesUndergraduate2 min

Cauchy's formula: for a holomorphic function, the value at any point inside a circle is an integral of the values on the circle. The boundary knows the inside. Move a point a around inside. The integral and the value agree, digit for digit. At thirty random points the largest disagreement is a rounding error. At the center the formula says the value is the average over the circle.

Expand the Cauchy kernel, one over z minus a, as a geometric series, and the formula turns into a power series. The coefficients are integrals over a circle. Try it on one over one minus z minus z squared, integrating over the circle of radius one half. The integrals come out as one, one, two, three, five, eight: the Fibonacci numbers. The series converges out to the nearest pole, at 0.618, the golden ratio's reciprocal. That's the first miracle: one complex derivative gives a convergent power series, and so derivatives of every order.

Cauchy's formula also bounds derivatives: on a circle of radius R where f is at most M, the n-th derivative is at most n factorial M over R to the n. A bounded function that's holomorphic on the whole plane can take R as large as it likes, so its derivative is zero: that's Liouville's theorem. If a polynomial had no roots, one over it would be bounded and entire, hence constant. So every polynomial has a root: the fundamental theorem of algebra, the promise from Part 3. The integral of p prime over p counts the roots inside a circle: it's the winding number of the image curve around zero. For five circles it counts zero, one, two, three and five roots, exactly the roots inside.

4Zeros, open maps, the maximum modulusGraduate2 min

What a holomorphic function's zeros and values are allowed to do. Here's the third miracle. Suppose you know a holomorphic function only on this short white arc. Then you know it everywhere it can be continued: the power series at a point of the arc is determined by the values on the arc, and that series decides the next disk, and the next. The identity theorem: two holomorphic functions that agree on a set with a limit point agree on the whole region, because their difference has zeros that aren't isolated. Nothing like it holds on the real line.

Near any point, a nonconstant holomorphic function looks like a power: f of z minus f of z zero is z minus z zero to the m, times a nonvanishing factor. For z cubed, color a small disk in twelve sectors. Each sector opens to three times its angle, and the image disk is covered three times over: every point has three preimages, checked at two hundred random points. Either way, the image of a small disk contains a disk around f of z zero. That's the open mapping theorem: nonconstant holomorphic functions send open sets to open sets.

Here's the size of z squared plus e to the z over the closed unit disk, bright where it's large, with level curves. The largest value is on the boundary, at z equals one, where it's one plus e. Inside, even at radius 0.98, it never gets there. That's the maximum modulus principle, and the open mapping theorem proves it: near an interior point, f covers a whole disk around f of z zero, and that disk contains values of larger size. The landscape of a holomorphic function's size has no peaks, only passes.

5The global Cauchy theorem and residuesApplications3 min

Rudin's global Cauchy theorem says a closed contour only sees what it winds around. If f is holomorphic except at isolated points, its integral is two pi i times the sum of the residues, each counted by its winding number. Use it on a real integral: one over one plus x to the fourth. In the upper half plane it has two poles. Close the interval from minus R to R with a semicircle. As R grows, the arc's contribution fades, but the total around the closed contour never changes, because the contour keeps enclosing the same two poles. Two residues, one over four z cubed at each pole, give pi over root two, and quadrature agrees to nine digits.

Two more classics. The integral of sine x over x is pi: take e to the i z over z, and let the contour step around the pole at zero with a tiny semicircle. And the Gaussian times a cosine needs no poles at all: Cauchy's theorem on a long rectangle shifts the line of integration up to height 0.7, where the integral is easy. Each answer matches quadrature to at least seven digits.

How many roots does z to the fifth plus three z plus one have inside the unit circle? On the circle, it differs from three z by z to the fifth plus one, which is at most two, while three z has size three. Picture a person walking around a tree on the circle of radius three, with a dog on a leash shorter than that. The dog must go around the tree exactly as often as the person: once. So the polynomial has as many roots inside as three z: exactly one. That's Rouché's theorem.

Rudin collects the region's side of the story in one theorem. For a region in the plane, nine conditions are equivalent: topological ones, like having no holes; analytic ones, like Cauchy's theorem for every closed path, or the existence of logarithms and square roots, or approximation by polynomials, which is Runge's theorem, two chapters on. The square roots will build the Riemann mapping.

6The Schwarz lemma and three linesGraduate2 min

The maximum principle, used as a tool. Take a holomorphic map of the unit disk into itself that keeps the center fixed. The Schwarz lemma: it can't move any point farther from the center. Here, three circles and their images: each image stays inside its circle. And the derivative at zero is at most one in size; here it's one half. The proof is one line: f of z over z is holomorphic, and by the maximum principle it's at most one over r on the circle of radius r, so at most one in the limit. Only rotations achieve equality.

The lemma pins down every symmetry of the disk. The map z minus alpha over one minus alpha bar z slides the point alpha to the center, keeps the circle on itself, and bends the polar grid into circles that are no longer concentric. Combined with rotations, these are all the conformal self-maps of the disk: apply Schwarz to any other and it must be a rotation.

The maximum principle has a quantitative cousin on a strip. Let M of x be the largest size of f on the vertical line at x. Hadamard's three lines theorem: the log of M is a convex function of x. Here it lies below its chord, so the size in the middle is at most the geometric mean of the sizes on the two edges. On an unbounded strip some growth condition is needed, which is what Phragmén and Lindelöf made precise. The payoff comes later: Riesz and Thorin turned this into interpolation of operator norms between L p spaces, and Part 9 uses it for the Fourier transform.

7Runge's theoremQualifying exam2 min

Runge's theorem, Weierstrass's approximation theorem for the complex plane. Can polynomials approximate one over z, uniformly on a compact set K that avoids zero? It depends on the shape of K. On a horseshoe, yes. The best fits improve steadily, from 1.5 at degree four to two ten-thousandths at degree one twenty-eight. On the full annulus, never: the error is stuck at 1.33 whatever the degree. The reason is an integral. Around the unit circle, one over z integrates to two pi i and every polynomial integrates to zero, so the difference can't be uniformly small. The pole at zero is trapped in the hole; in the horseshoe it can escape through the gap.

That's Runge's theorem. A function holomorphic near a compact set K is a uniform limit of rational functions, with poles placed anywhere you like, one in each piece of the complement; if the complement is connected, polynomials suffice. The proof: Cauchy's formula on a cycle around K, approximated by a Riemann sum, gives a sum of simple poles. Then push each pole: a pole at a is a convergent series of poles at a nearby b, so it can hop, step by step, along a path in the complement. Out at infinity, a pole becomes a polynomial. Part 10 needs exactly this for its functional calculus.

8Normal familiesGraduate2 min

Montel's theorem, where Arzelà and Ascoli pay off in the complex plane. On the real line, sine n x stays between minus one and one, but gets steeper and steeper: bounded, and not equicontinuous, as Part 3 showed. In the complex plane the same functions aren't even bounded: on the imaginary axis sine becomes hyperbolic sine, and on the disk of radius one half, sine of twelve z reaches two hundred. For holomorphic functions a bound is also a speed limit: Cauchy's estimate bounds the derivative on a smaller disk by the bound on the larger one. So a uniformly bounded family is automatically equicontinuous on compact sets.

Here's a bounded family on the disk: a rotating mixture of z and z squared, plus z to the n, over two. Pick n so that n is nearly a multiple of two pi: six, forty-four, seven hundred and ten. The functions converge to z over two. Brightness shows the error. It retreats to a thinner and thinner rim: on the disk of radius 0.9 it drops to ten to the minus five, but right at the edge, z to the n keeps it at one half. Convergence is uniform on every compact subset, not on the whole disk. Montel's theorem: every uniformly bounded family of holomorphic functions has such a subsequence.

Montel's theorem is Arzelà and Ascoli in the complex plane, with equicontinuity coming for free. And the limits stay holomorphic, by Morera's theorem. In Part 4 the payoff was existence of solutions to differential equations. Here it's the Riemann mapping theorem.

9The Riemann mapping theoremQualifying exam2 min

The Riemann mapping theorem: every simply connected region of the plane, other than the plane itself, can be mapped one-to-one and conformally onto the disk. The proof is an extremal problem. Look at all one-to-one maps of the region into the disk that send a chosen point to zero. There is one, built from a square root, which exists because the region is simply connected. Among them, pick the one with the largest derivative at the point. Montel's theorem guarantees a maximizer. And it must be onto: if it missed a point, another square-root trick would produce a map with a larger derivative. Compactness solves the extremal problem, and the solution is the map.

The theorem says such a map exists; for a polygon we can compute it. Schwarz and Christoffel found its form: the derivative is a product of powers, one for each corner, with exponents set by the angles. The unknowns are the six points on the circle that go to the corners, solved for numerically so that the side lengths come out right. Here's the result. The polar grid of the disk flows onto the L-shaped hexagon: circles become nested loops, rays become curves that bend around the inner corner. Every little square stays a square: the grid lines meet at ninety degrees to within ten to the minus seven, and the center goes to the point 0.8 plus 0.8 i. Nothing about the theorem's proof constructs this map, but the map is really there.

10A tour: harmonic functionsApplications1 min

Chapter ten begins a short tour of the rest of the complex half of Rudin's book, with results stated rather than proved. First, harmonic functions.

The real part of a holomorphic function is harmonic: its Laplacian is zero. Think of it as a steady temperature. Fix the temperature on the boundary circle, here a pattern with three warm and three cool arcs. Then there's exactly one harmonic function inside with those boundary values, given by Poisson's integral. Its Laplacian, checked at random points, is zero to within ten to the minus four, the error of the finite difference. At the center, the temperature is the average around the edge: 0.3. That's the mean value property, the harmonic version of Cauchy's formula.

Poisson's kernel is an old friend: positive, average one, and narrowing as r approaches one, the same bump as the Landau and Fejér kernels. That's why the solution takes the right boundary values. And there's a probabilistic reading, due to Kakutani: the temperature at a point is the average boundary temperature where a random walk started there first hits the circle.

11A tour: products and continuationGraduate2 min

Still on tour: functions built from their zeros, and functions continued along paths. A polynomial is a product over its roots. Euler guessed that sine of pi z should be one too, over the integers. Build the product one pair of zeros at a time: each factor plants two more dark points, and the picture fills in toward the sine. The error shrinks by a factor of ten for every factor of ten in the number of terms. Weierstrass proved that every entire function is such a product, once convergence factors are attached, and that any sequence of points going to infinity is the zero set of some entire function.

In the disk, zeros can pile up toward the edge, but not too densely. Here's a Blaschke product, built from forty zeros spiraling outward. Each factor has size one on the circle, so the product stays bounded. What makes it converge is that the zeros approach the boundary quickly enough: the distances to the circle have a finite sum. For a bounded function, that's also necessary: by Jensen's formula, every zero costs size.

The identity theorem makes continuation unique along any path. Follow the logarithm around the origin twice. Its imaginary part, the angle, climbs without ever returning: two pi after one turn, four pi after two. The continued logarithm lives on a spiral staircase. The monodromy theorem says paths that can be deformed into each other give the same result, and the modular function proves Picard's little theorem: a nonconstant entire function takes every complex value, with at most one exception.

12A tour: H^p and the shiftQualifying exam2 min

The last stop of the tour: Hardy spaces, and the first operator of the series.

Which functions on the circle are boundary values of holomorphic functions on the disk? Expand one in a Fourier series. A power series has only nonnegative frequencies, so on the circle the negative half of the spectrum is empty. The Hardy space H two is exactly that: square-integrable functions on the circle whose negative Fourier coefficients vanish, or equivalently, power series with square-summable coefficients.

Multiply by z. On the coefficients, that moves everything one step to the right and leaves the first slot empty. Do it again, and again. Lengths never change: the shift is an isometry. But it isn't onto: nothing lands on the constant one. An isometry of a space onto a proper part of itself can't happen in finite dimensions. This operator will be the star of Part 10, where its spectrum is the whole closed disk.

Which closed subspaces does the shift map into themselves? Beurling's answer: exactly the multiples of an inner function, a bounded holomorphic function with size one on the circle. This one has no zeros at all, yet it presses everything near the point one down to nothing: an essential singularity on the boundary. It's the first theorem of the series about the invariant subspaces of an operator, and the tour ends here. Part 9 will use the Paley-Wiener theorem from the same part of the book.

The seventh row of the ledgerAll tracks2 min

Let's take stock. Everything grew from one series, the exponential. A complex derivative is a rotation and a scaling, so holomorphic maps preserve angles. Integrals around closed paths count turns, and Goursat's bisection proves Cauchy's theorem. Cauchy's formula then gives power series, Liouville's theorem, and the fundamental theorem of algebra; zeros are isolated, maps are open, and the maximum is on the boundary. Residues compute real integrals. Schwarz's lemma pins down the disk's symmetries, Runge's theorem says when polynomials approximate, and Montel's theorem gives compactness, which builds the Riemann map. Then a tour, ending with the shift operator.

The ledger's seventh row. The space: holomorphic functions on a region, with locally uniform convergence. It's complete, because locally uniform limits of holomorphic functions are holomorphic. Its compact sets are the bounded ones, by Montel. Power series may be differentiated term by term, and the Cauchy integral commutes with limits. And on the Fourier side: H two, the functions with no negative frequencies.

Next time, in Part 8: general Banach spaces. Watch the unit vectors slide off to the right. Each has length one, so they never converge in norm; but against any fixed vector, their inner products go to zero. That's weak convergence, and Part 8 builds the topology where the unit ball becomes compact again, along with Baire's theorem and the Hahn-Banach theorem.

This part followed chapters ten through fourteen of Rudin's Real and Complex Analysis. Thanks for watching, and see you in Part 8.

Where it goes next. Cauchy's formula, Liouville's theorem and Runge's theorem run the spectral theory and the functional calculus of Part 10, where the shift's spectrum is the closed disk; the three lines theorem and Paley-Wiener return with the Fourier transform in Part 9.

Key results

The part's results in one place, for revision.

Cauchy-Riemann equations\(\displaystyle f=u+iv \text{ real-differentiable}:\quad\allowbreak f'(z_0) \text{ exists}\iff u_x=v_y,\ \ u_y=-v_x\)
Cauchy's formula\(\displaystyle f(a)\,\operatorname{Ind}_\gamma(a)=\frac{1}{2\pi i}\int_\gamma\frac{f(z)}{z-a}\,dz,\quad\allowbreak \operatorname{Ind}_\gamma(a)=\frac{1}{2\pi i}\int_\gamma\frac{dz}{z-a}\in\mathbb{Z}\)
Cauchy's estimates, hence Liouville\(\displaystyle |f^{(n)}(a)|\le \frac{n!\,M}{R^n}\ \text{ if } |f|\le M \text{ on } D(a;R)\)
Residue theorem\(\displaystyle \frac{1}{2\pi i}\int_\gamma f\,dz=\sum_k \operatorname{Res}(f;a_k)\operatorname{Ind}_\gamma(a_k)\)
Argument principle\(\displaystyle \frac{1}{2\pi i}\int_{|z|=r}\frac{f'(z)}{f(z)}\,dz=\#\{\text{zeros }\allowbreak \text{of } f \text{ in } |z|<r\}\)
Riemann mapping theorem\(\displaystyle \Omega\ne\mathbb{C} \text{ simply }\allowbreak \text{connected}\implies \Omega \text{ is }\allowbreak \text{conformally }\allowbreak \text{equivalent }\allowbreak \text{to }\allowbreak \text{the }\allowbreak \text{disk}\)

Try it

Lab 7 · What a contour integral knows about the inside

Integrate around circles with the trapezoid rule: Cauchy's formula for the coefficients of 1/(1 - z - z^2) returns the Fibonacci numbers, the integral of p'/p counts the roots of a random polynomial inside each circle, and two residues give the integral of 1/(1 + x^4) over the real line.

Figure produced by Lab 7: What a contour integral knows about the inside
Produced by the lab below, seed 0, in 0.2 s.
python -m videos.analysis.labs 7 needs numpy, scipy, matplotlib · download lab07.py · source on GitHub
coefficients of 1/(1 - z - z^2) by Cauchy      1 1 2 3 5 8 13 21 34 55 89 144   (Fibonacci)
largest imaginary part / error                 2.0e-13 / 4.7e-13
roots of a random degree-7 p inside 8 circles  0.000 1.000 2.000 3.000 4.000 5.000 6.000 7.000
the same counts from numpy.roots               0 1 2 3 4 5 6 7
integral of 1/(1 + x^4): residues              2.2214414691   (pi / sqrt 2 = 2.2214414691)
integral of 1/(1 + x^4): quadrature            2.2214414691
size of the arc's share at R = 2, 5, 20        0.08119  0.00533  0.00008   (closed total fixed)

A contour integral sees only what the contour winds around: Taylor coefficients, the number of zeros, the sum of residues. The trapezoid rule on a circle is exact to rounding here because the integrands are holomorphic in an annulus around the circle.
The code (104 lines; it asserts its own result)
"""Lab 7: read Fibonacci numbers, root counts and a real integral off contour integrals."""

import numpy as np
from scipy.integrate import quad

from videos.coursekit import labs

TITLE = "What a contour integral knows about the inside"
GOAL = ("Integrate around circles with the trapezoid rule: Cauchy's formula for the coefficients of 1/(1 - z - z^2) "
        "returns the Fibonacci numbers, the integral of p'/p counts the roots of a random polynomial inside each "
        "circle, and two residues give the integral of 1/(1 + x^4) over the real line.")
TASKS = [
    "Move the Fibonacci circle from radius 0.5 to 0.7, past the pole at 0.618. What do the integrals return now, and why?",
    "Count the roots of z^5 + 3z + 1 in |z| < 1 with root_count, then explain the answer by Rouche's theorem with 3z.",
    "Put a circle through a root of p (radius abs(roots[0])) and watch the count stop being an integer as m grows.",
]


def circle(radius, m):
    """m equally spaced points of |z| = radius and the factor dz / (2 pi i) for the trapezoid rule."""
    z = radius * np.exp(2j * np.pi * np.arange(m) / m)
    return z, z / m  # dz = i z dtheta, dtheta = 2 pi / m


def taylor_coefficient(f, n, radius=0.5, m=256):
    """a_n = (1 / 2 pi i) * the integral of f(z) / z^(n+1) over |z| = radius."""
    z, w = circle(radius, m)
    return np.sum(f(z) / z ** (n + 1) * w)


def root_count(coef, radius, m=4096):
    """(1 / 2 pi i) * the integral of p'/p over |z| = radius: the number of roots of p inside (argument principle)."""
    z, w = circle(radius, m)
    return np.sum(np.polyval(np.polyder(coef), z) / np.polyval(coef, z) * w)


def run(seed=0):
    rng = np.random.default_rng(seed)
    lab = labs.Lab()

    # 1. Cauchy's formula as a coefficient extractor: the Fibonacci numbers.
    fib = np.array([taylor_coefficient(lambda z: 1 / (1 - z - z * z), n) for n in range(12)])
    exact = [1, 1]
    while len(exact) < 12:
        exact.append(exact[-1] + exact[-2])
    assert np.allclose(fib, exact, atol=1e-8), "the coefficients of 1/(1 - z - z^2) are the Fibonacci numbers"
    lab.row("coefficients of 1/(1 - z - z^2) by Cauchy", " ".join(f"{v.real:.0f}" for v in fib) + "   (Fibonacci)")
    lab.row("largest imaginary part / error", f"{np.abs(fib.imag).max():.1e} / {np.abs(fib - exact).max():.1e}")

    # 2. The argument principle on a random polynomial of degree 7: circles between consecutive root moduli.
    while True:
        coef = rng.normal(size=8) + 1j * rng.normal(size=8)
        roots = np.roots(coef)
        mod = np.sort(np.abs(roots))
        if np.diff(mod).min() > 0.03:  # keep the circles a clear distance from every root
            break
    radii = np.concatenate([[mod[0] / 2], (mod[:-1] + mod[1:]) / 2, [mod[-1] * 1.3]])
    counts = np.array([root_count(coef, r) for r in radii])
    truth = np.array([(np.abs(roots) < r).sum() for r in radii])
    assert np.abs(counts - truth).max() < 1e-6, "the integral of p'/p counts the roots inside"
    lab.row("roots of a random degree-7 p inside 8 circles", " ".join(f"{round(c.real, 3) + 0.0:.3f}" for c in counts))
    lab.row("the same counts from numpy.roots", " ".join(str(t) for t in truth))

    # 3. Residues: the integral of 1/(1 + x^4) over the line is 2 pi i times two residues 1/(4 z^3).
    poles = np.exp(1j * np.pi * np.array([1, 3]) / 4)
    by_residues = 2j * np.pi * np.sum(1 / (4 * poles**3))
    by_quad = 2 * quad(lambda x: 1 / (1 + x**4), 0, np.inf)[0]
    assert abs(by_residues - np.pi / np.sqrt(2)) < 1e-12 and abs(by_quad - by_residues.real) < 1e-8
    lab.row("integral of 1/(1 + x^4): residues", f"{by_residues.real:.10f}   (pi / sqrt 2 = {np.pi / np.sqrt(2):.10f})")
    lab.row("integral of 1/(1 + x^4): quadrature", f"{by_quad:.10f}")
    # the semicircle of radius R encloses the same two poles for every R > 1: the closed integral does not move
    closed = []
    for R in (2.0, 5.0, 20.0):
        t = np.linspace(0, np.pi, 20001)
        arc = R * np.exp(1j * t)
        f_arc = 1 / (1 + arc**4) * 1j * arc
        arc_part = np.sum((f_arc[1:] + f_arc[:-1]) / 2) * (t[1] - t[0])
        closed.append((R, quad(lambda x: 1 / (1 + x**4), -R, R)[0] + arc_part, abs(arc_part)))
    assert all(abs(c - by_residues) < 1e-6 for _, c, _ in closed) and closed[-1][2] < closed[0][2] / 100
    lab.row("size of the arc's share at R = 2, 5, 20", "  ".join(f"{a:.5f}" for _, _, a in closed) + "   (closed total fixed)")
    lab.note = ("A contour integral sees only what the contour winds around: Taylor coefficients, the number of "
                "zeros, the sum of residues. The trapezoid rule on a circle is exact to rounding here because the "
                "integrands are holomorphic in an annulus around the circle.")

    fig, ax = labs.figure(2, size=(11, 4.4))
    t = np.linspace(0, 2 * np.pi, 400)
    for k, (r, c) in enumerate(zip(radii, counts)):
        ax[0].plot(r * np.cos(t), r * np.sin(t), color=labs.BLUE, lw=0.9, alpha=0.8)
        ax[0].text(r * np.cos(0.4 + 0.8 * k), r * np.sin(0.4 + 0.8 * k), f"{abs(round(c.real))}", color=labs.GOLD, fontsize=9,
                   ha="center", va="center", bbox=dict(facecolor=labs.BG, edgecolor="none", pad=1))
    ax[0].plot(roots.real, roots.imag, "o", color=labs.RED, ms=5, label="roots of p (numpy.roots)")
    ax[0].plot([], [], color=labs.BLUE, label="contours, labelled by the integral of p'/p")
    lim = radii[-1] * 1.08
    ax[0].set(title="The argument principle counts roots", xlabel="Re z", ylabel="Im z", xlim=(-lim, lim), ylim=(-lim, lim))
    ax[0].set_aspect("equal")
    ax[0].legend(loc="upper center", bbox_to_anchor=(0.5, -0.14), ncol=1)
    ms = np.array([8, 12, 16, 24, 32, 48, 64, 96, 128])
    for n, color in ((5, labs.GOLD), (11, labs.GREEN)):
        errs = [abs(taylor_coefficient(lambda z: 1 / (1 - z - z * z), n, m=int(m)) - exact[n]) + 1e-17 for m in ms]
        ax[1].semilogy(ms, errs, "o-", color=color, label=f"error of coefficient {n} (Fibonacci {exact[n]})")
    ax[1].set(title="Trapezoid rule on |z| = 1/2: geometric convergence", xlabel="points on the circle", ylabel="absolute error")
    ax[1].legend()
    lab.fig = fig
    return lab

Now change it

  1. Move the Fibonacci circle from radius 0.5 to 0.7, past the pole at 0.618. What do the integrals return now, and why?
  2. Count the roots of z^5 + 3z + 1 in |z| < 1 with root_count, then explain the answer by Rouche's theorem with 3z.
  3. Put a circle through a root of p (radius abs(roots[0])) and watch the count stop being an integer as m grows.

Notes and sources

Sources

W. Rudin, Principles of Mathematical Analysis, 3rd ed. (1976); Real and Complex Analysis, 3rd ed. (1987); Functional Analysis, 2nd ed. (1991). Theorem numbers on screen are those editions'. Each part's credits scene lists the original authors and the companion texts.

About this partfrom its README

Part 7 of a ten-part series that builds mathematical analysis from the holes in the rational numbers to the spectral theorem, following the arc of Walter Rudin's three textbooks. This part covers chapters 10-14 and 17 of Real and Complex Analysis, in a hook, 12 chapters and an outro.

Holomorphic functions as conformal maps, integration and winding numbers, Goursat and Cauchy's formula, power series, the open mapping and maximum modulus theorems, residues and the argument principle, the Schwarz lemma, Runge's theorem, normal families and Montel, the Riemann mapping theorem (with a computed Schwarz-Christoffel map), harmonic functions and the Poisson integral, Weierstrass and Blaschke products, and the Hardy space H^p.

Every number the narration states is computed in compute.py and asserted; most scenes also assert the specific values they display.

What is computed and builtComputations (compute.py)
Item What is computed and asserted
exp e^z from its series: e^(2 pi i) = 1, pi/2 as the first zero of the cosine series, periodicity
conformal grids under z^2 and e^z: angles preserved, Jacobians are rotation-scalings; z + 0.4i conj(z) is not
winding a three-mode closed curve with an inner loop; winding numbers of 20 well-separated points (8 outside, 8 once, 4 twice), from the integral, asserted integers
goursat nested triangles: the remainder bound for e^z shrinks like 8^-n; for conj(z) the ratio is stuck
cauchy Cauchy's formula at random points; the Fibonacci numbers as contour integrals; roots by the argument principle
maxmod
residues three real integrals by residues, against quadrature; Rouche for z^5 + 3z + 1
schwarz a self-map of the disk with f(0) = 0 obeys
runge polynomial approximation of 1/z: on a horseshoe the error goes to 0, on an annulus it never drops below 1
montel sin(nz) blows up on a disk; z^n -> 0 locally uniformly; a subsequence of a bounded family
riemann the Schwarz-Christoffel map of the disk onto an L-shaped hexagon: vertices to 1e-12, angles kept
poisson the Poisson integral of boundary data on the disk, asserted harmonic
products sin(pi z) against its Euler product; a Blaschke product's zeros
Chapter notes
0:00 Why is C so much better behaved than R?
2:06 1. Complex derivatives are rotations
3:59 2. Path integrals and winding numbers
5:56 3. Cauchy's formula and its miracles
7:48 4. Zeros, open maps, the maximum modulus
9:34 5. The global Cauchy theorem and residues
11:46 6. The Schwarz lemma and three lines
13:25 7. Runge's theorem
14:50 8. Normal families
16:32 9. The Riemann mapping theorem
18:04 10. A tour: harmonic functions
19:16 11. A tour: products and continuation
21:01 12. A tour: H^p and the shift
22:33 The seventh row of the ledger
Chapter notes
# Scene Chapter
0 Hook Why is C so much better behaved than R?
1 Holomorphic 1. Complex derivatives are rotations
2 Integration 2. Path integrals and winding numbers
3 CauchyFormula 3. Cauchy's formula and its miracles
4 OpenMapping 4. Zeros, open maps, the maximum modulus
5 Residues 5. The global Cauchy theorem and residues
6 Schwarz 6. The Schwarz lemma and three lines
7 Runge 7. Runge's theorem
8 NormalFamilies 8. Normal families
9 RiemannMapping 9. The Riemann mapping theorem
10 Harmonic 10. A tour: harmonic functions
11 ZerosProducts 11. A tour: products and continuation
12 Hp 12. A tour: H^p and the shift
13 Outro The seventh row of the ledger

Build the film

python -m videos.analysis.analysis7.compute        # the part's numbers, into .cache/analysis7
python tools/build.py analysis7                  # render and assemble the film
EXPLAINER_TTS=silent python tools/qa_scene.py analysis7 Hook   # one chapter, silent, with a contact sheet

Scenes: videos/analysis/analysis7. Setup: see the course page. Source of these notes: the README and the scenes' narration.

Build it

The finished video is not stored in the repository. From the repo root, after the one-time setup in the top-level README:

python -m videos.analysis.analysis7.compute                # once: every computed item (cached in .cache/analysis7)
python tools/build.py analysis7 -q k --fps 60     # the full-quality cut: 2160p60 + subtitles + chapters -> renders/analysis7_2160p.mp4
python tools/build.py analysis7                   # 1080p30 -> renders/analysis7.mp4
python tools/build.py analysis7 -q l              # fast 480p preview
python tools/export_script.py analysis7           # regenerate SCRIPT.md from the code
python tools/check_narration.py analysis7         # Whisper listen test of every narration line

The scenes share the series' instruments in explainer/analysis and helpers from earlier parts (see common.py). The full narration is in SCRIPT.md.