Skip to content
The Lumenary
Early undergraduateUndergraduate (first or second year) 120 min

Multivariable and vector calculus

The derivative becomes a matrix, constraints become multipliers, dx dydx\,dy becomes r dr dθr\,dr\,d\theta — and three great theorems say that what happens inside a region is recorded on its boundary.

Formally verified · 19 LeanComputationally tested · 3 PythonAI-drafted · awaiting human reviewMathematically reviewed: Awaiting human review
MotivationH

Many inputs, many outputs

A hiker on the slopes of Kilimanjaro stands at a point (x,y)(x, y) of a map; her altitude is a function h(x,y)h(x, y). Which way is steepest? How steep is it? A cooperative in Bangladesh wants the largest yield from fields of fixed total perimeter. A hydrologist in the Netherlands wants the total water flowing out through the surface of a region of soil. A physicist wants to know whether a force field can be described by a potential energy.

Each question involves a function of several variables — and each needs a new idea. With one variable, the derivative is a number and the integral is over an interval. With several, the derivative becomes a linear map (a matrix), optimisation must handle constraints, integrals run over regions, curves and surfaces, and the fundamental theorem of calculus grows into a family of theorems — Green's, Stokes's and Gauss's — relating the inside of a region to its boundary.

This lesson assumes calculus of one variable and linear algebra (matrices, determinants, linear maps). We write ∣x∣|x| for the Euclidean length of x∈Rnx \in \R^n and x⋅yx \cdot y for the dot product.

IntuitionH

Slices, tangent planes and boundaries

A function f:R2→Rf : \R^2 \to \R has a graph, a surface z=f(x,y)z = f(x, y) in space, and level curves f(x,y)=cf(x, y) = c, like the contour lines on a map. Freeze yy and you get a function of xx alone, whose slope is the partial derivative ∂f/∂x\partial f/\partial x; freezing xx gives ∂f/∂y\partial f/\partial y. But slices along two directions do not see the whole surface. The right notion is that, near a point, the surface looks like a plane: the derivative is the best linear approximation,

f(a+h)≈f(a)+Df(a) h,f(a + h) \approx f(a) + Df(a)\,h ,

where Df(a)Df(a) is a linear map — for f:Rn→Rmf : \R^n \to \R^m, an m×nm \times n matrix of partial derivatives.

For integrals, the picture is "chop into small pieces and add". The new difficulty is that the natural pieces (polar rectangles, small patches on a curved surface) are distorted copies of squares, and the distortion factor — a Jacobian determinant — must be included. Finally, the one-variable theorem ∫abF′=F(b)−F(a)\int_a^b F' = F(b) - F(a) says the integral of a derivative over an interval is determined by the boundary points a,ba, b. In higher dimensions the same is true for regions, with "derivative" meaning curl or divergence and the boundary a curve or a surface.

DefinitionsH

Definitions

Let U⊆RnU \subseteq \R^n be open (every point of UU has a ball around it inside UU), f:U→Rmf : U \to \R^m and a∈Ua \in U. Limits and continuity are defined as in one variable, with ∣⋅∣|\cdot| the Euclidean length.

Definition— partial and directional derivatives

The partial derivative of ff with respect to xjx_j at aa is ∂f∂xj(a)=lim⁡t→0f(a+tej)−f(a)t\dfrac{\partial f}{\partial x_j}(a) = \lim_{t \to 0} \dfrac{f(a + t e_j) - f(a)}{t}, where eje_j is the jj-th standard basis vector. More generally, for v∈Rnv \in \R^n the directional derivative is Dvf(a)=lim⁡t→0f(a+tv)−f(a)tD_v f(a) = \lim_{t \to 0} \dfrac{f(a + t v) - f(a)}{t}.

Definition— derivative (total or Fréchet derivative)

ff is differentiable at aa if there is a linear map L:Rn→RmL : \R^n \to \R^m such that

lim⁡h→0∣f(a+h)−f(a)−Lh∣∣h∣=0,\lim_{h \to 0} \frac{|f(a + h) - f(a) - L h|}{|h|} = 0 ,

that is, f(a+h)=f(a)+Lh+o(∣h∣)f(a + h) = f(a) + Lh + o(|h|). Then L=Df(a)L = Df(a) is the derivative of ff at aa (it is unique). Its matrix is the Jacobian matrix Jf(a)=(∂fi/∂xj(a))J_f(a) = \big(\partial f_i/\partial x_j(a)\big), an m×nm \times n matrix; when m=nm = n, det⁡Jf(a)\det J_f(a) is the Jacobian determinant.

Definition— gradient

For a real-valued differentiable ff, the gradient ∇f(a)=(∂f/∂x1(a),…,∂f/∂xn(a))\nabla f(a) = \big(\partial f/\partial x_1(a), \dots, \partial f/\partial x_n(a)\big) is the vector with Df(a)h=∇f(a)⋅hDf(a)h = \nabla f(a) \cdot h for all hh.

ff is of class C1C^1 on UU if all partial derivatives exist and are continuous on UU; C2C^2 if the second partials ∂2f/∂xi∂xj\partial^2 f/\partial x_i \partial x_j are too. The Hessian of a C2C^2 function f:U→Rf : U \to \R is the symmetric matrix Hf(a)=(∂2f/∂xi∂xj(a))H_f(a) = \big(\partial^2 f/\partial x_i\partial x_j(a)\big), and aa is a critical point if ∇f(a)=0\nabla f(a) = 0.

Definition— line integral

Let γ:[a,b]→Rn\gamma : [a, b] \to \R^n be a C1C^1 path and FF a continuous vector field on its image. The line integral (work, or circulation if γ\gamma is closed) is

∫γF⋅dr=∫abF(γ(t))⋅γ′(t) dt.\int_\gamma F \cdot d\mathbf r = \int_a^b F(\gamma(t)) \cdot \gamma'(t)\,dt .

FF is conservative on UU if F=∇φF = \nabla \varphi for some C1C^1 function φ:U→R\varphi : U \to \R (a potential; physicists often use V=−φV = -\varphi).

Definition— divergence and curl

For a C1C^1 field F=(F1,…,Fn)F = (F_1, \dots, F_n), the divergence is div⁡F=∇⋅F=∑i∂Fi/∂xi\operatorname{div} F = \nabla \cdot F = \sum_i \partial F_i / \partial x_i. In R3\R^3 the curl is

curl⁡F=∇×F=(∂F3∂y−∂F2∂z,  ∂F1∂z−∂F3∂x,  ∂F2∂x−∂F1∂y),\operatorname{curl} F = \nabla \times F = \Big(\frac{\partial F_3}{\partial y} - \frac{\partial F_2}{\partial z},\; \frac{\partial F_1}{\partial z} - \frac{\partial F_3}{\partial x},\; \frac{\partial F_2}{\partial x} - \frac{\partial F_1}{\partial y}\Big),

and in R2\R^2, for F=(P,Q)F = (P, Q), the scalar curl is ∂Q∂x−∂P∂y\dfrac{\partial Q}{\partial x} - \dfrac{\partial P}{\partial y}.

Definition— surface integral and flux

A parametrised surface is a C1C^1 map Φ:D→R3\Phi : D \to \R^3, D⊆R2D \subseteq \R^2, with Φu×Φv≠0\Phi_u \times \Phi_v \ne 0 in the interior of DD. The flux of a continuous field FF through it, in the direction of the normal Φu×Φv\Phi_u \times \Phi_v, is

∬SF⋅n dS=∬DF(Φ(u,v))⋅(Φu×Φv) du dv,\iint_S F \cdot \mathbf n\,dS = \iint_D F(\Phi(u, v)) \cdot \big(\Phi_u \times \Phi_v\big)\,du\,dv ,

and the area of SS is ∬D∣Φu×Φv∣ du dv\iint_D |\Phi_u \times \Phi_v|\,du\,dv.

Multiple integrals ∬Rf dA\iint_R f\,dA over rectangles are defined by Riemann sums exactly as in one variable, and over a bounded region DD by integrating f⋅1Df \cdot \mathbf 1_D over a rectangle containing DD; a continuous function on a closed bounded region with a reasonable boundary (for example, a piecewise C1C^1 curve) is integrable.

Worked examplesH

Worked examples and a warning

Example— A Jacobian matrix and a directional derivative

Let f(x,y)=(x2y,  x+sin⁡y)f(x, y) = (x^2 y,\; x + \sin y). Then

Jf(x,y)=(2xyx21cos⁡y),Jf(1,0)=(0111).J_f(x, y) = \begin{pmatrix} 2xy & x^2 \\ 1 & \cos y \end{pmatrix}, \qquad J_f(1, 0) = \begin{pmatrix} 0 & 1 \\ 1 & 1 \end{pmatrix}.

For the real-valued g(x,y)=x2yg(x, y) = x^2 y at (1,2)(1, 2): ∇g=(2xy,x2)=(4,1)\nabla g = (2xy, x^2) = (4, 1). In the unit direction u=(3/5,4/5)u = (3/5, 4/5), Dug=4⋅35+1⋅45=165D_u g = 4 \cdot \tfrac35 + 1 \cdot \tfrac45 = \tfrac{16}{5}, while the steepest rate is ∣∇g∣=17≈4.12|\nabla g| = \sqrt{17} \approx 4.12, in the direction (4,1)/17(4, 1)/\sqrt{17}.

Example— Partial derivatives are not enough

Let f(x,y)=xyx2+y2f(x, y) = \dfrac{xy}{x^2 + y^2} for (x,y)≠0(x, y) \ne 0 and f(0,0)=0f(0, 0) = 0. On both axes f=0f = 0, so ∂f/∂x(0,0)=∂f/∂y(0,0)=0\partial f/\partial x(0, 0) = \partial f/\partial y(0, 0) = 0. But on the diagonal f(t,t)=12f(t, t) = \tfrac12 for every t≠0t \ne 0. So ff is not continuous at the origin, and therefore not differentiable there (a differentiable function is continuous, by the same argument as in one variable). The partial derivatives see only two directions; differentiability is a statement about all of them at once, uniformly.

Even existence of every directional derivative is not enough: g(x,y)=x2yx4+y2g(x, y) = \dfrac{x^2 y}{x^4 + y^2} (with g(0)=0g(0) = 0) has a directional derivative Dvg(0)D_v g(0) in every direction vv, but g(t,t2)=12g(t, t^2) = \tfrac12, so gg is discontinuous at 00.

Example— Classifying critical points

f(x,y)=x3−3x+y2f(x, y) = x^3 - 3x + y^2 has ∇f=(3x2−3, 2y)\nabla f = (3x^2 - 3,\, 2y), so the critical points are (±1,0)(\pm 1, 0). The Hessian is (6x002)\begin{pmatrix} 6x & 0 \\ 0 & 2\end{pmatrix}: at (1,0)(1, 0) it is positive definite (a local minimum, f=−2f = -2); at (−1,0)(-1, 0) it has eigenvalues −6-6 and 22 (a saddle point). There is no global minimum: f(x,0)→−∞f(x, 0) \to -\infty as x→−∞x \to -\infty.

ProofH

The derivative and the chain rule

Theorem— Proposition (what differentiability gives)

If ff is differentiable at aa, then ff is continuous at aa, every directional derivative exists and Dvf(a)=Df(a) vD_v f(a) = Df(a)\,v, and the matrix of Df(a)Df(a) is the Jacobian matrix of partial derivatives.

Proof

Write f(a+h)=f(a)+Lh+r(h)f(a + h) = f(a) + Lh + r(h) with ∣r(h)∣/∣h∣→0|r(h)|/|h| \to 0. Then ∣f(a+h)−f(a)∣≤∥L∥ ∣h∣+∣r(h)∣→0|f(a + h) - f(a)| \le \|L\|\,|h| + |r(h)| \to 0, where ∥L∥\|L\| is the operator norm. For v≠0v \ne 0 and t→0t \to 0,

f(a+tv)−f(a)t=Lv+r(tv)t,∣r(tv)t∣=∣r(tv)∣∣tv∣ ∣v∣→0.\frac{f(a + tv) - f(a)}{t} = Lv + \frac{r(tv)}{t}, \qquad \left|\frac{r(tv)}{t}\right| = \frac{|r(tv)|}{|tv|}\,|v| \to 0 .

Taking v=ejv = e_j shows that the jj-th column of the matrix of LL is ∂f/∂xj(a)\partial f/\partial x_j(a).

∎

Theorem— Theorem (continuous partials imply differentiability)

If all partial derivatives of f:U→Rf : U \to \R exist near aa and are continuous at aa, then ff is differentiable at aa. (Apply this to each component when m>1m > 1.)

Proof

We give the proof for n=2n = 2; the general case adds one coordinate at a time in the same way. Write a=(a1,a2)a = (a_1, a_2) and h=(h1,h2)h = (h_1, h_2) small. Change one coordinate at a time:

f(a+h)−f(a)=[f(a1+h1,a2+h2)−f(a1,a2+h2)]+[f(a1,a2+h2)−f(a1,a2)].f(a + h) - f(a) = \big[f(a_1 + h_1, a_2 + h_2) - f(a_1, a_2 + h_2)\big] + \big[f(a_1, a_2 + h_2) - f(a_1, a_2)\big].

By the one-variable mean value theorem, the first bracket is ∂f∂x(ξ) h1\frac{\partial f}{\partial x}(\xi)\,h_1 for a point ξ\xi on the segment from (a1,a2+h2)(a_1, a_2 + h_2) to (a1+h1,a2+h2)(a_1 + h_1, a_2 + h_2), and the second is ∂f∂y(η) h2\frac{\partial f}{\partial y}(\eta)\,h_2 for a point η\eta between (a1,a2)(a_1, a_2) and (a1,a2+h2)(a_1, a_2 + h_2). Hence

∣f(a+h)−f(a)−∇f(a)⋅h∣∣h∣≤∣∂f∂x(ξ)−∂f∂x(a)∣+∣∂f∂y(η)−∂f∂y(a)∣,\frac{\big|f(a + h) - f(a) - \nabla f(a) \cdot h\big|}{|h|} \le \Big|\frac{\partial f}{\partial x}(\xi) - \frac{\partial f}{\partial x}(a)\Big| + \Big|\frac{\partial f}{\partial y}(\eta) - \frac{\partial f}{\partial y}(a)\Big|,

using ∣h1∣,∣h2∣≤∣h∣|h_1|, |h_2| \le |h|. As h→0h \to 0, both ξ\xi and η\eta tend to aa, and the right side tends to 00 by continuity of the partials at aa.

∎

Theorem— Theorem (chain rule)

If f:U→Rmf : U \to \R^m is differentiable at aa and g:V→Rpg : V \to \R^p is differentiable at b=f(a)b = f(a) (with f(U)⊆Vf(U) \subseteq V, VV open), then g∘fg \circ f is differentiable at aa and

D(g∘f)(a)=Dg(f(a))∘Df(a),Jg∘f(a)=Jg(f(a)) Jf(a).D(g \circ f)(a) = Dg(f(a)) \circ Df(a), \qquad J_{g \circ f}(a) = J_g(f(a))\,J_f(a).

Proof

Let A=Df(a)A = Df(a) and B=Dg(b)B = Dg(b), and write f(a+h)=b+Ah+r(h)f(a + h) = b + Ah + r(h) and g(b+k)=g(b)+Bk+s(k)g(b + k) = g(b) + Bk + s(k) with r(h)=o(∣h∣)r(h) = o(|h|), s(k)=o(∣k∣)s(k) = o(|k|) and s(0)=0s(0) = 0. Put k(h)=f(a+h)−b=Ah+r(h)k(h) = f(a + h) - b = Ah + r(h). Then

g(f(a+h))=g(b)+BAh+B r(h)+s(k(h))⏟error.g(f(a + h)) = g(b) + BAh + \underbrace{B\,r(h) + s(k(h))}_{\text{error}} .

First, ∣B r(h)∣≤∥B∥ ∣r(h)∣=o(∣h∣)|B\,r(h)| \le \|B\|\,|r(h)| = o(|h|). Second, for small hh we have ∣r(h)∣≤∣h∣|r(h)| \le |h|, so ∣k(h)∣≤(∥A∥+1)∣h∣|k(h)| \le (\|A\| + 1)|h|. Given ε>0\varepsilon > 0, choose δ\delta with ∣s(k)∣≤ε∣k∣|s(k)| \le \varepsilon |k| for ∣k∣<δ|k| < \delta (this holds for k=0k = 0 too). For hh small enough that ∣k(h)∣<δ|k(h)| < \delta, ∣s(k(h))∣≤ε(∥A∥+1)∣h∣|s(k(h))| \le \varepsilon(\|A\| + 1)|h|. So the error is o(∣h∣)o(|h|), and D(g∘f)(a)=BAD(g \circ f)(a) = BA.

∎

Theorem— Proposition (the gradient)

Let f:U→Rf : U \to \R be differentiable at aa with ∇f(a)≠0\nabla f(a) \ne 0. Among unit vectors uu, the directional derivative Duf(a)=∇f(a)⋅uD_u f(a) = \nabla f(a) \cdot u is largest, with value ∣∇f(a)∣|\nabla f(a)|, exactly for u=∇f(a)/∣∇f(a)∣u = \nabla f(a)/|\nabla f(a)|. If γ\gamma is a differentiable curve in the level set {f=f(a)}\{f = f(a)\} with γ(0)=a\gamma(0) = a, then ∇f(a)⋅γ′(0)=0\nabla f(a) \cdot \gamma'(0) = 0: the gradient is perpendicular to level sets.

Proof

By Cauchy–Schwarz, ∇f(a)⋅u≤∣∇f(a)∣ ∣u∣=∣∇f(a)∣\nabla f(a) \cdot u \le |\nabla f(a)|\,|u| = |\nabla f(a)|, with equality if and only if uu is a positive multiple of ∇f(a)\nabla f(a). For the second claim, f(γ(t))=f(a)f(\gamma(t)) = f(a) for all tt; differentiating with the chain rule gives ∇f(a)⋅γ′(0)=0\nabla f(a) \cdot \gamma'(0) = 0.

∎

For C2C^2 functions, the order of differentiation does not matter: ∂2f∂x ∂y=∂2f∂y ∂x\dfrac{\partial^2 f}{\partial x\,\partial y} = \dfrac{\partial^2 f}{\partial y\,\partial x} (the theorem of Schwarz, or Clairaut; the hypothesis is needed — the function xy(x2−y2)/(x2+y2)xy(x^2 - y^2)/(x^2 + y^2) has unequal mixed partials at the origin). Hence the Hessian is symmetric, and second-order Taylor expansion gives the second derivative test: at a critical point of a C2C^2 function, a positive definite Hessian means a strict local minimum, a negative definite one a strict local maximum, and one with eigenvalues of both signs a saddle point.

ProofH

Constrained optimisation: Lagrange multipliers

To find the extreme values of ff on a constraint set {g=c}\{g = c\}, we cannot simply set ∇f=0\nabla f = 0: the extremum is taken along the constraint. The idea, due to Lagrange (1788), is that at a constrained extremum the level curve of ff must be tangent to the constraint curve.

Maximise xy on the circle x² + y² = 2

Increase c until the hyperbola last touches the circle. At that moment the two curves are tangent.

(1, 1)(−1, −1)
  • level curve xy = c
  • constraint x² + y² = 2
  • constraint (lower half)
  • level curve xy = c: y = 0.5
  • constraint x² + y² = 2: y = 1
  • constraint (lower half): y = −1

Theorem— Theorem (Lagrange multipliers)

Let f,g:U→Rf, g : U \to \R be C1C^1, let aa satisfy g(a)=cg(a) = c and ∇g(a)≠0\nabla g(a) \ne 0, and suppose ff, restricted to {x∈U:g(x)=c}\{x \in U : g(x) = c\}, has a local maximum or minimum at aa. Then there is a number λ\lambda (a Lagrange multiplier) with

∇f(a)=λ ∇g(a).\nabla f(a) = \lambda\,\nabla g(a).

Proof

We use the implicit function theorem (proved in real analysis, from the inverse function theorem): since ∇g(a)≠0\nabla g(a) \ne 0, near aa the set {g=c}\{g = c\} is a C1C^1 hypersurface, and for every vector vv with ∇g(a)⋅v=0\nabla g(a) \cdot v = 0 there is a C1C^1 curve γ\gamma in {g=c}\{g = c\} with γ(0)=a\gamma(0) = a and γ′(0)=v\gamma'(0) = v.

Take such vv and γ\gamma. The function t↦f(γ(t))t \mapsto f(\gamma(t)) has a local extremum at t=0t = 0, so its derivative vanishes there: by the chain rule, ∇f(a)⋅v=0\nabla f(a) \cdot v = 0. Thus ∇f(a)\nabla f(a) is orthogonal to every vector orthogonal to ∇g(a)\nabla g(a); that is, ∇f(a)∈(∇g(a)⊥)⊥=span⁡{∇g(a)}\nabla f(a) \in \big(\nabla g(a)^\perp\big)^\perp = \operatorname{span}\{\nabla g(a)\}.

∎

With several constraints g1=c1,…,gk=ckg_1 = c_1, \dots, g_k = c_k whose gradients at aa are linearly independent, the same argument gives ∇f(a)=∑iλi∇gi(a)\nabla f(a) = \sum_i \lambda_i \nabla g_i(a).

Example— xy on a circle, and the best box

On the circle. Maximise f=xyf = xy on x2+y2=2x^2 + y^2 = 2. The equations (y,x)=λ(2x,2y)(y, x) = \lambda(2x, 2y) give y=2λxy = 2\lambda x and x=2λy=4λ2xx = 2\lambda y = 4\lambda^2 x. If x=0x = 0 then y=0y = 0, which is not on the circle; so λ=±12\lambda = \pm\tfrac12 and y=±xy = \pm x, giving (1,1),(−1,−1)(1, 1), (-1, -1) (value 11) and (1,−1),(−1,1)(1, -1), (-1, 1) (value −1-1). The circle is closed and bounded, so by the extreme value theorem ff has a maximum and a minimum there, and they must be among these candidates: max 1, min −1. (Independently: 2xy≤x2+y2=22xy \le x^2 + y^2 = 2 since (x−y)2≥0(x - y)^2 \ge 0.)

The best box. Maximise the volume xyzxyz of a box with surface area 2(xy+yz+zx)=62(xy + yz + zx) = 6 and x,y,z>0x, y, z > 0. The multiplier equations yz=2λ(y+z)yz = 2\lambda(y + z), xz=2λ(x+z)xz = 2\lambda(x + z), xy=2λ(x+y)xy = 2\lambda(x + y) force x=y=z=1x = y = z = 1 (multiply the first by xx, the second by yy, and compare). Here the constraint set is not compact, so existence needs a separate argument: by the AM–GM inequality, (xy⋅yz⋅zx)1/3≤xy+yz+zx3=1(xy \cdot yz \cdot zx)^{1/3} \le \frac{xy + yz + zx}{3} = 1, so xyz≤1xyz \le 1, with equality for the cube. The multiplier method found the candidate; the inequality proved it optimal.

The multiplier itself has a meaning: if M(c)M(c) is the optimal value as a function of the constraint level cc, then (under mild hypotheses) M′(c)=λM'(c) = \lambda — the "shadow price" of the constraint in economics.

ProofH

Multiple integrals and change of variables

Theorem— Theorem (Fubini, for continuous functions)

If ff is continuous on the rectangle [a,b]×[c,d][a, b] \times [c, d], then

∬[a,b]×[c,d]f dA=∫ab(∫cdf(x,y) dy)dx=∫cd(∫abf(x,y) dx)dy.\iint_{[a,b]\times[c,d]} f\,dA = \int_a^b \left(\int_c^d f(x, y)\,dy\right) dx = \int_c^d \left(\int_a^b f(x, y)\,dx\right) dy.

The proof (via uniform continuity and Riemann sums) belongs to real analysis; the general version for Lebesgue integrals is a cornerstone of measure theory. Without integrability the conclusion can fail: for f(x,y)=x2−y2(x2+y2)2f(x, y) = \frac{x^2 - y^2}{(x^2 + y^2)^2} on (0,1]2(0, 1]^2 the two iterated integrals are π4\frac\pi4 and −π4-\frac\pi4.

Theorem— Theorem (change of variables)

Let T:U→RnT : U \to \R^n be a C1C^1 map that is one-to-one on an open set UU with det⁡JT≠0\det J_T \ne 0 there, and let D⊆UD \subseteq U be a closed bounded region with a reasonable boundary. For ff continuous on T(D)T(D),

∫T(D)f(x) dx=∫Df(T(u)) ∣det⁡JT(u)∣ du.\int_{T(D)} f(x)\,dx = \int_D f(T(u))\,\big|\det J_T(u)\big|\,du .

Why the determinant? A linear map AA multiplies all volumes by ∣det⁡A∣|\det A| (from linear algebra: true for elementary matrices, hence for products). Near a point uu, TT is approximately the affine map u+h↦T(u)+JT(u)hu + h \mapsto T(u) + J_T(u)h, so a tiny box of volume ΔV\Delta V at uu is carried to a region of volume about ∣det⁡JT(u)∣ ΔV|\det J_T(u)|\,\Delta V. Summing over a fine partition gives the formula; making "about" precise is the real work of the proof, done in analysis texts. Points where det⁡JT=0\det J_T = 0 or TT fails to be injective may be ignored if they form a set of volume zero — this is what allows polar coordinates, whose Jacobian vanishes at r=0r = 0.

Polar coordinates. T(r,θ)=(rcos⁡θ,rsin⁡θ)T(r, \theta) = (r\cos\theta, r\sin\theta) has

JT=(cos⁡θ−rsin⁡θsin⁡θrcos⁡θ),det⁡JT=r(cos⁡2θ+sin⁡2θ)=r,J_T = \begin{pmatrix} \cos\theta & -r\sin\theta \\ \sin\theta & r\cos\theta \end{pmatrix}, \qquad \det J_T = r(\cos^2\theta + \sin^2\theta) = r ,

so dx dy=r dr dθdx\,dy = r\,dr\,d\theta. Below, the widget shows JTJ_T at (r,θ)=(2,π/6)(r, \theta) = (2, \pi/6) acting on the plane: the unit square becomes a parallelogram of area 2=r2 = r. A tiny polar rectangle of sides Δr\Delta r and Δθ\Delta\theta is nearly a rectangle with sides Δr\Delta r and r Δθr\,\Delta\theta.

The Jacobian of polar coordinates at r = 2, θ = π/6

Its determinant is r = 2: polar coordinates stretch areas by the factor r.

Your own matrix
Ae₁Ae₂
  • image of the grid
  • image of the unit square
  • image of the flag
  • before the transformation
Entries of the matrix A
A =

The columns of A are the images of e₁ = (1, 0) and e₂ = (0, 1): Ae₁ = (0.866, 0.5), Ae₂ = (−1, 1.732)

det A = ad − bc = 2

The unit square (area 1) becomes a parallelogram of area |det A| = 2. Since det A > 0, orientation is preserved.

Invariant lines (real eigenvectors)

λ = 1.299 ± 0.559i

No real eigenvectors: A turns every direction, so no line through 0 stays put. The eigenvalues are complex.

Theorem— Corollary (the Gaussian integral)

∫−∞∞e−x2 dx=π.\int_{-\infty}^{\infty} e^{-x^2}\,dx = \sqrt{\pi}.

Proof

Let I(R)=∫−RRe−x2dxI(R) = \int_{-R}^{R} e^{-x^2}dx, which increases to a finite limit II (the integrand is at most e−∣x∣e^{-|x|} for ∣x∣≥1|x| \ge 1). By Fubini, I(R)2=∬QRe−(x2+y2) dAI(R)^2 = \iint_{Q_R} e^{-(x^2 + y^2)}\,dA over the square QR=[−R,R]2Q_R = [-R, R]^2. The integrand is positive and the square lies between the discs of radius RR and R2R\sqrt2, so with DρD_\rho the disc of radius ρ\rho,

∬DRe−(x2+y2)dA  ≤  I(R)2  ≤  ∬DR2e−(x2+y2)dA.\iint_{D_R} e^{-(x^2+y^2)}dA \;\le\; I(R)^2 \;\le\; \iint_{D_{R\sqrt2}} e^{-(x^2+y^2)}dA .

In polar coordinates, ∬Dρe−(x2+y2) dA=∫02π ⁣ ⁣∫0ρe−r2r dr dθ=π(1−e−ρ2)\iint_{D_\rho} e^{-(x^2+y^2)}\,dA = \int_0^{2\pi}\!\!\int_0^\rho e^{-r^2} r\,dr\,d\theta = \pi\big(1 - e^{-\rho^2}\big) — the factor rr is exactly what makes e−r2e^{-r^2} integrable in closed form. Both bounds tend to π\pi, so I2=πI^2 = \pi.

∎

This is why the normal density 12πe−x2/2\frac{1}{\sqrt{2\pi}}e^{-x^2/2} has total probability 11.

ProofH

Line integrals and the theorems of Green, Stokes and Gauss

Theorem— Theorem (gradient theorem)

If φ\varphi is C1C^1 on an open set UU and γ:[a,b]→U\gamma : [a, b] \to U is a C1C^1 path, then

∫γ∇φ⋅dr=φ(γ(b))−φ(γ(a)).\int_\gamma \nabla\varphi \cdot d\mathbf r = \varphi(\gamma(b)) - \varphi(\gamma(a)).

In particular the line integral of a conservative field depends only on the endpoints, and is 00 around every closed path.

Proof

By the chain rule, (φ∘γ)′(t)=∇φ(γ(t))⋅γ′(t)(\varphi \circ \gamma)'(t) = \nabla\varphi(\gamma(t)) \cdot \gamma'(t), which is continuous. The one-variable fundamental theorem of calculus gives ∫ab(φ∘γ)′(t) dt=φ(γ(b))−φ(γ(a))\int_a^b (\varphi \circ \gamma)'(t)\,dt = \varphi(\gamma(b)) - \varphi(\gamma(a)).

∎

A test for conservative fields. If F=(P,Q)=∇φF = (P, Q) = \nabla\varphi with φ\varphi of class C2C^2, then ∂P/∂y=∂2φ/∂y ∂x=∂2φ/∂x ∂y=∂Q/∂x\partial P/\partial y = \partial^2\varphi/\partial y\,\partial x = \partial^2\varphi/\partial x\,\partial y = \partial Q/\partial x by Schwarz's theorem: a conservative C1C^1 field has zero curl. The converse holds on a disc, or any star-shaped open set (Poincaré's lemma), but not in general:

Example— The vortex: curl zero, but not conservative

On U=R2∖{0}U = \R^2 \setminus \{0\} let F=(−yx2+y2,xx2+y2)F = \left(\dfrac{-y}{x^2 + y^2}, \dfrac{x}{x^2 + y^2}\right). A quotient-rule computation gives ∂Q∂x=y2−x2(x2+y2)2=∂P∂y\dfrac{\partial Q}{\partial x} = \dfrac{y^2 - x^2}{(x^2 + y^2)^2} = \dfrac{\partial P}{\partial y}, so curl⁡F=0\operatorname{curl} F = 0 on UU. But on the unit circle γ(t)=(cos⁡t,sin⁡t)\gamma(t) = (\cos t, \sin t) we have F(γ(t))=(−sin⁡t,cos⁡t)=γ′(t)F(\gamma(t)) = (-\sin t, \cos t) = \gamma'(t), so

∮γF⋅dr=∫02π(sin⁡2t+cos⁡2t) dt=2π≠0.\oint_\gamma F \cdot d\mathbf r = \int_0^{2\pi} (\sin^2 t + \cos^2 t)\,dt = 2\pi \ne 0 .

By the gradient theorem, FF is not ∇φ\nabla\varphi for any C1C^1 function φ\varphi on UU. Locally it is: F=∇θF = \nabla\theta for the polar angle θ\theta, but θ\theta cannot be defined continuously all the way round the origin. The circulation 2π2\pi detects the hole.

A vortex: circulation without curl

Drag the loop. Around the origin the circulation is 2π while the integrated curl is 0; away from it both vanish.

Examples

F(x, y) = (−y/(x² + y²), x/(x² + y²))

Drag the gold centre (or click anywhere) to move the loop. With the keyboard, focus the centre and use the arrow keys.

Turns so far: 0.09

Circulation
∮ F·dr ≈ 6.2832 | ∬ curl F dA ≈ −0.0322
Flux out
∮ F·n ds ≈ 0 | ∬ div F dA ≈ 0.1043
At the centre
curl F ≈ 0, div F ≈ 0, πr² ≈ 8.042
Index
1

All values are numerical approximations (sums around the loop and over the disc).

The two sides differ: the field must fail to be smooth (or be undefined) somewhere inside the loop, so Green’s theorem does not apply to this loop.

Index 1 ≠ 0: walking once around the loop, the arrow makes 1 net full turns (negative means clockwise). A field that is continuous on the whole disc would have to vanish inside; this one is not (see above), and the point where it breaks down carries the index instead.

Theorem— Theorem (Green's theorem)

Let D⊂R2D \subset \R^2 be a closed bounded region whose boundary ∂D\partial D consists of finitely many piecewise C1C^1 simple closed curves, oriented so that DD lies to the left. If P,QP, Q are C1C^1 on an open set containing DD, then

∮∂DP dx+Q dy=∬D(∂Q∂x−∂P∂y)dA.\oint_{\partial D} P\,dx + Q\,dy = \iint_D \left(\frac{\partial Q}{\partial x} - \frac{\partial P}{\partial y}\right) dA .

Proof

We prove it for a rectangle D=[a,b]×[c,d]D = [a, b] \times [c, d], which already contains the idea; general regions are handled by cutting them into pieces of this kind (or of the form {a≤x≤b, φ1(x)≤y≤φ2(x)}\{a \le x \le b,\ \varphi_1(x) \le y \le \varphi_2(x)\}, where the same computation works), since the line integrals over interior cuts cancel in pairs.

Treat the two terms separately. By Fubini and the one-variable fundamental theorem,

−∬D∂P∂y dA=−∫ab(P(x,d)−P(x,c)) dx=∫abP(x,c) dx−∫abP(x,d) dx.-\iint_D \frac{\partial P}{\partial y}\,dA = -\int_a^b \big(P(x, d) - P(x, c)\big)\,dx = \int_a^b P(x, c)\,dx - \int_a^b P(x, d)\,dx .

On the other hand, ∮∂DP dx\oint_{\partial D} P\,dx runs along the bottom edge from (a,c)(a, c) to (b,c)(b, c), contributing ∫abP(x,c) dx\int_a^b P(x, c)\,dx; along the top edge from right to left, contributing −∫abP(x,d) dx-\int_a^b P(x, d)\,dx; and along the vertical edges, where dx=0dx = 0, contributing nothing. The two expressions agree. In the same way ∬D∂Q∂x dA=∫cd(Q(b,y)−Q(a,y))dy=∮∂DQ dy\iint_D \frac{\partial Q}{\partial x}\,dA = \int_c^d \big(Q(b, y) - Q(a, y)\big)dy = \oint_{\partial D} Q\,dy. Add.

∎

The vortex shows why the hypothesis "C1C^1 on all of DD" matters: for the unit disc the left side is 2π2\pi, the right side would be 00, and indeed FF is undefined at the origin. Green's theorem with P=−y/2P = -y/2, Q=x/2Q = x/2 gives a formula for area, Area⁡(D)=12∮∂Dx dy−y dx\operatorname{Area}(D) = \tfrac12 \oint_{\partial D} x\,dy - y\,dx — the principle of the planimeter, a mechanical instrument that measures areas by tracing boundaries. For the ellipse (acos⁡t,bsin⁡t)(a\cos t, b\sin t) it gives 12∫02πab dt=πab\tfrac12\int_0^{2\pi} ab\,dt = \pi ab.

Applied to the field (−Q,P)(-Q, P) rotated by a right angle, Green's theorem becomes its flux form: the outward flux ∮∂DF⋅n ds\oint_{\partial D} F \cdot \mathbf n\,ds of F=(P,Q)F = (P, Q) equals ∬Ddiv⁡F dA\iint_D \operatorname{div} F\,dA. In three dimensions both forms have analogues.

Theorem— Theorem (divergence theorem of Gauss)

Let V⊂R3V \subset \R^3 be a closed bounded region whose boundary ∂V\partial V is a piecewise smooth closed surface with outward unit normal n\mathbf n, and let FF be C1C^1 on an open set containing VV. Then

∬∂VF⋅n dS=∭Vdiv⁡F dV.\iint_{\partial V} F \cdot \mathbf n\,dS = \iiint_V \operatorname{div} F\,dV .

Theorem— Theorem (Stokes's theorem)

Let SS be a piecewise smooth oriented surface with boundary curve ∂S\partial S, oriented compatibly (walking along ∂S\partial S with your head in the direction of n\mathbf n, the surface is on your left), and let FF be C1C^1 near SS. Then

∮∂SF⋅dr=∬S(curl⁡F)⋅n dS.\oint_{\partial S} F \cdot d\mathbf r = \iint_S (\operatorname{curl} F) \cdot \mathbf n\,dS .

For a box V=[a1,b1]×[a2,b2]×[a3,b3]V = [a_1, b_1] \times [a_2, b_2] \times [a_3, b_3] the divergence theorem is proved exactly like Green's theorem: ∭V∂F3/∂z dV\iiint_V \partial F_3/\partial z\,dV equals, by Fubini and the fundamental theorem, the integral of F3F_3 over the top face minus that over the bottom face — the flux of (0,0,F3)(0, 0, F_3) — and similarly for the other components. The general versions (and Stokes's theorem, which for a graph z=h(x,y)z = h(x, y) reduces to Green's theorem by the chain rule) are proved in texts such as Hubbard and Hubbard, or Marsden and Tromba, and most cleanly as the single theorem ∫∂Mω=∫Mdω\int_{\partial M} \omega = \int_M d\omega of differential forms (see the geometry viewpoint).

Example— Flux out of a sphere, two ways

Let F(x,y,z)=(x,y,z)F(x, y, z) = (x, y, z) and let VV be the ball of radius RR. Directly: on the sphere n=(x,y,z)/R\mathbf n = (x, y, z)/R, so F⋅n=RF \cdot \mathbf n = R, and the flux is R⋅4πR2=4πR3R \cdot 4\pi R^2 = 4\pi R^3. By the divergence theorem: div⁡F=3\operatorname{div} F = 3, so the flux is 3⋅43πR3=4πR33 \cdot \frac43\pi R^3 = 4\pi R^3.

Formal mathematicsF

Multivariable calculus in Lean and Mathlib

Mathlib's derivative for maps between normed spaces is the Fréchet derivative: HasFDerivAt f f' a with f' : E →L[ℝ] F a continuous linear map — precisely the lesson's definition. Euclidean space Rn\R^n is one instance, but the same theorems hold in infinite-dimensional spaces, which is why statements are phrased with E and F rather than matrices.

The chain rule is cited from Mathlib (its proof is the o(∣h∣)o(|h|) argument above). From it we derive directional derivatives: differentiate along the line t↦a+tvt \mapsto a + tv. With an inner product, the derivative is v↦⟨∇f,v⟩v \mapsto \langle \nabla f, v \rangle, and Cauchy–Schwarz gives the steepest-ascent property:

chain_ruleLean 4Applies a library theoremFormally verified
/-- **The chain rule**: `D(g ∘ f)(a) = Dg(f(a)) ∘ Df(a)`, a composite of linear maps (in
coordinates, a product of Jacobian matrices). This applies Mathlib's `HasFDerivAt.comp`. -/
theorem chain_rule {E F G : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
    [NormedAddCommGroup F] [NormedSpace ℝ F] [NormedAddCommGroup G] [NormedSpace ℝ G]
    {f : E → F} {g : F → G} {f' : E →L[ℝ] F} {g' : F →L[ℝ] G} {a : E}
    (hf : HasFDerivAt f f' a) (hg : HasFDerivAt g g' (f a)) :
    HasFDerivAt (g ∘ f) (g'.comp f') a :=
  hg.comp a hf
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MultivariableCalculus.leanTry it in the Lean web editor
directional_derivLean 4Proved here from basic factsFormally verified
/-- If `f` is differentiable at `a` with derivative `f'`, then the directional derivative of `f`
at `a` in the direction `v` exists and equals `f' v`: the derivative of `t ↦ f (a + t v)` at
`t = 0`. Proof: the line `γ t = a + t v` has velocity `v`, and the chain rule
(`HasFDerivAt.comp_hasDerivAt`) gives `(f ∘ γ)'(0) = f'(γ'(0)) = f' v`. -/
theorem directional_deriv {E F : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
    [NormedAddCommGroup F] [NormedSpace ℝ F] {f : E → F} {f' : E →L[ℝ] F} {a : E}
    (hf : HasFDerivAt f f' a) (v : E) :
    HasDerivAt (fun t : ℝ => f (a + t • v)) (f' v) 0 := by
  have hγ : HasDerivAt (fun t : ℝ => a + t • v) v 0 := by
    simpa using ((hasDerivAt_id (0 : ℝ)).smul_const v).const_add a
  have hf0 : HasFDerivAt f f' (a + (0 : ℝ) • v) := by simpa using hf
  exact hf0.comp_hasDerivAt (x := (0 : ℝ)) hγ
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MultivariableCalculus.leanTry it in the Lean web editor
gradient_directionalLean 4Proved here from basic factsFormally verified
/-- With a gradient: if `f : E → ℝ` has gradient `∇f(a) = g` (Mathlib's `HasGradientAt`), the
directional derivative in direction `v` is the inner product `⟪g, v⟫`. This combines
`directional_deriv` with `hasGradientAt_iff_hasFDerivAt`: the derivative is `v ↦ ⟪g, v⟫`. -/
theorem gradient_directional {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]
    [CompleteSpace E] {f : E → ℝ} {g a : E} (hf : HasGradientAt f g a) (v : E) :
    HasDerivAt (fun t : ℝ => f (a + t • v)) (inner ℝ g v) 0 := by
  have := directional_deriv (hasGradientAt_iff_hasFDerivAt.mp hf) v
  simpa using this
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MultivariableCalculus.leanTry it in the Lean web editor
steepest_ascentLean 4Proved here from basic factsFormally verified
/-- **The gradient points uphill fastest.** For a unit vector `v`, the directional derivative
`⟪∇f, v⟫` is at most `‖∇f‖` (Cauchy–Schwarz, `real_inner_le_norm`), and the value `‖∇f‖` is
attained in the direction `∇f / ‖∇f‖` when `∇f ≠ 0`. -/
theorem steepest_ascent {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]
    (g v : E) (hv : ‖v‖ = 1) :
    inner ℝ g v ≤ ‖g‖ ∧ (g ≠ 0 → inner ℝ g (‖g‖⁻¹ • g) = ‖g‖) := by
  constructor
  · calc inner ℝ g v ≤ ‖g‖ * ‖v‖ := real_inner_le_norm g v
      _ = ‖g‖ := by rw [hv, mul_one]
  · intro hg
    have hn : ‖g‖ ≠ 0 := norm_ne_zero_iff.mpr hg
    rw [real_inner_smul_right, real_inner_self_eq_norm_sq]
    field_simp
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MultivariableCalculus.leanTry it in the Lean web editor

The counterexample, formalised as in the lesson: both partials vanish at the origin, the function is not continuous there (look along the diagonal), hence not differentiable. Note how Lean's convention 0/0=00/0 = 0 supplies the value f(0,0)=0f(0, 0) = 0 automatically:

xyQuotLean 4Formally verified
/-- The standard counterexample `f(x, y) = xy / (x² + y²)`. At the origin the formula reads
`0 / 0`, which Lean evaluates to `0` (division by zero is `0` in Mathlib), matching the lesson's
convention `f(0, 0) = 0`. -/
noncomputable def xyQuot (p : ℝ × ℝ) : ℝ := p.1 * p.2 / (p.1 ^ 2 + p.2 ^ 2)
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MultivariableCalculus.leanTry it in the Lean web editor
xyQuot_partialsLean 4Proved here from basic factsFormally verified
/-- Both partial derivatives of `xyQuot` exist at the origin and equal `0`: along each axis the
function is identically zero (`f(t, 0) = 0` and `f(0, t) = 0`), so its derivative there is `0`. -/
theorem xyQuot_partials :
    HasDerivAt (fun t => xyQuot (t, 0)) 0 0 ∧ HasDerivAt (fun t => xyQuot (0, t)) 0 0 := by
  have h1 : (fun t => xyQuot (t, 0)) = fun _ => (0 : ℝ) := by
    funext t; simp [xyQuot]
  have h2 : (fun t => xyQuot (0, t)) = fun _ => (0 : ℝ) := by
    funext t; simp [xyQuot]
  rw [h1, h2]
  exact ⟨hasDerivAt_const 0 0, hasDerivAt_const 0 0⟩
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MultivariableCalculus.leanTry it in the Lean web editor
xyQuot_not_continuousAtLean 4Proved here from basic factsFormally verified
/-- …but `xyQuot` is not even continuous at the origin: on the diagonal, `f(t, t) = 1/2` for
every `t ≠ 0`, while `f(0, 0) = 0`. If `f` were continuous at `0`, then `f(t, t)` would tend to
`f(0, 0) = 0` as `t → 0`, but it is constantly `1/2` near `0`, so `1/2 = 0`. -/
theorem xyQuot_not_continuousAt : ¬ ContinuousAt xyQuot 0 := by
  intro hc
  -- Restrict to the diagonal `t ↦ (t, t)`.
  have hdiag : ContinuousAt (fun t : ℝ => xyQuot (t, t)) 0 := by
    have hγ : ContinuousAt (fun t : ℝ => ((t, t) : ℝ × ℝ)) 0 :=
      (continuous_id.prodMk continuous_id).continuousAt
    have hc' : ContinuousAt xyQuot ((0 : ℝ), (0 : ℝ)) := hc
    exact ContinuousAt.comp (g := xyQuot) (f := fun t : ℝ => ((t, t) : ℝ × ℝ)) hc' hγ
  have hlim0 : Tendsto (fun t : ℝ => xyQuot (t, t)) (𝓝[≠] 0) (𝓝 0) := by
    have := hdiag.tendsto.mono_left (nhdsWithin_le_nhds (s := {(0 : ℝ)}ᶜ))
    simpa [xyQuot] using this
  have hlimhalf : Tendsto (fun t : ℝ => xyQuot (t, t)) (𝓝[≠] 0) (𝓝 (1 / 2)) := by
    refine tendsto_const_nhds.congr' ?_
    filter_upwards [self_mem_nhdsWithin] with t ht
    have ht' : t ≠ 0 := ht
    have : t ^ 2 + t ^ 2 ≠ 0 := by positivity
    simp only [xyQuot]
    field_simp
    ring
  have := tendsto_nhds_unique hlim0 hlimhalf
  norm_num at this
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MultivariableCalculus.leanTry it in the Lean web editor
xyQuot_not_differentiableAtLean 4Proved here from basic factsFormally verified
/-- Hence `xyQuot` is not differentiable at the origin, although both partial derivatives exist
there: differentiability implies continuity (`DifferentiableAt.continuousAt`). -/
theorem xyQuot_not_differentiableAt : ¬ DifferentiableAt ℝ xyQuot 0 :=
  fun h => xyQuot_not_continuousAt h.continuousAt
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MultivariableCalculus.leanTry it in the Lean web editor

Symmetry of second derivatives (Schwarz–Clairaut), cited from Mathlib in its coordinate-free form f′′(v,w)=f′′(w,v)f''(v, w) = f''(w, v):

schwarzLean 4Applies a library theoremFormally verified
/-- **Symmetry of second derivatives** (Schwarz–Clairaut): if `f` is differentiable everywhere and
its derivative `f'` is differentiable at `x` with derivative `f''`, then `f'' v w = f'' w v`; in
coordinates, `∂²f/∂x∂y = ∂²f/∂y∂x`. This applies Mathlib's `second_derivative_symmetric`. -/
theorem schwarz {E F : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
    [NormedAddCommGroup F] [NormedSpace ℝ F] {f : E → F} {f' : E → E →L[ℝ] F}
    {f'' : E →L[ℝ] E →L[ℝ] F} {x : E} (hf : ∀ y, HasFDerivAt f (f' y) y)
    (hx : HasFDerivAt f' f'' x) (v w : E) : f'' v w = f'' w v :=
  second_derivative_symmetric hf hx v w
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MultivariableCalculus.leanTry it in the Lean web editor

Mathlib's Lagrange multiplier theorem is stated without dividing: f′f' and φ′\varphi' are linearly dependent. If f′≠0f' \ne 0 this is the lesson's ∇φ=λ∇f\nabla \varphi = \lambda \nabla f. Beside it, the "certificate" for the circle example:

lagrangeLean 4Applies a library theoremFormally verified
/-- **Lagrange multipliers** (one constraint): if `φ` has a local extremum at `x₀` on the level
set `{x | f x = f x₀}`, and `f`, `φ` are strictly differentiable at `x₀`, then `f'` and `φ'` are
linearly dependent: `a • f' + b • φ' = 0` with `(a, b) ≠ 0`. When `f' ≠ 0` this forces `b ≠ 0`,
i.e. `∇φ = λ ∇f`. This applies Mathlib's `IsLocalExtrOn.exists_multipliers_of_hasStrictFDerivAt_1d`. -/
theorem lagrange {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E]
    {f φ : E → ℝ} {x₀ : E} {f' φ' : StrongDual ℝ E}
    (hextr : IsLocalExtrOn φ {x | f x = f x₀} x₀) (hf' : HasStrictFDerivAt f f' x₀)
    (hφ' : HasStrictFDerivAt φ φ' x₀) : ∃ a b : ℝ, (a, b) ≠ 0 ∧ a • f' + b • φ' = 0 :=
  hextr.exists_multipliers_of_hasStrictFDerivAt_1d hf' hφ'
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MultivariableCalculus.leanTry it in the Lean web editor
circle_max_xyLean 4Proved here from basic factsFormally verified
/-- The answer the multiplier method finds for "maximise `xy` on the circle `x² + y² = 2`":
the maximum is `1`, attained at `(1, 1)`. A certificate: `2xy ≤ x² + y²` because
`(x - y)² ≥ 0`. -/
theorem circle_max_xy :
    (∀ x y : ℝ, x ^ 2 + y ^ 2 = 2 → x * y ≤ 1) ∧ ((1 : ℝ) ^ 2 + 1 ^ 2 = 2 ∧ (1 : ℝ) * 1 = 1) := by
  refine ⟨fun x y h => ?_, by norm_num, by norm_num⟩
  nlinarith [sq_nonneg (x - y)]
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MultivariableCalculus.leanTry it in the Lean web editor

Polar coordinates: the Jacobian determinant is rr, the change of variables formula has the factor rr, and Mathlib proves the Gaussian integral by the lesson's argument:

polar_jacobianLean 4Applies a library theoremFormally verified
/-- The Jacobian determinant of polar coordinates `(r, θ) ↦ (r cos θ, r sin θ)` is `r`:
`det [[cos θ, -r sin θ], [sin θ, r cos θ]] = r (cos² θ + sin² θ) = r`. This applies Mathlib's
`det_fderivPolarCoordSymm`. -/
theorem polar_jacobian (p : ℝ × ℝ) : (fderivPolarCoordSymm p).det = p.1 :=
  det_fderivPolarCoordSymm p
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MultivariableCalculus.leanTry it in the Lean web editor
polar_change_of_variablesLean 4Applies a library theoremFormally verified
/-- **Change of variables to polar coordinates**: `∬ f(x, y) dx dy = ∬ f(r cos θ, r sin θ) r dr dθ`,
the integral on the right over `r > 0`, `-π < θ < π`. The factor `r` is the Jacobian
determinant above. This applies Mathlib's `integral_comp_polarCoord_symm`. -/
theorem polar_change_of_variables (f : ℝ × ℝ → ℝ) :
    ∫ p in polarCoord.target, p.1 * f (polarCoord.symm p) = ∫ p, f p := by
  simpa [smul_eq_mul] using integral_comp_polarCoord_symm f
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MultivariableCalculus.leanTry it in the Lean web editor
gaussian_integralLean 4Applies a library theoremFormally verified
/-- **The Gaussian integral** `∫ e^{-x²} dx = √π` over the whole real line. Mathlib's
`integral_gaussian` proves `∫ e^{-b x²} dx = √(π/b)`, via the square of the integral and polar
coordinates, exactly the lesson's argument; we take `b = 1`. -/
theorem gaussian_integral : ∫ x : ℝ, exp (-x ^ 2) = √π := by
  have := integral_gaussian 1
  simpa using this
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MultivariableCalculus.leanTry it in the Lean web editor

Line integrals. The gradient theorem is proved from the chain rule and the one-variable fundamental theorem, exactly as in the lesson (here ff and γ\gamma are C1C^1 on the whole space, which is what makes the integrand continuous):

gradient_theoremLean 4Proved here from basic factsFormally verified
/-- **The gradient theorem** (fundamental theorem for line integrals): for a `C¹` function
`f : E → ℝ` and a `C¹` path `γ`, the line integral of the derivative of `f` along `γ` from
`t = a` to `t = b` is `f (γ b) - f (γ a)`. Proof: by the chain rule `(f ∘ γ)'(t) = Df(γ t)(γ'(t))`,
which is continuous, so the one-variable fundamental theorem applies. -/
theorem gradient_theorem {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
    {f : E → ℝ} {γ : ℝ → E} (hf : ContDiff ℝ 1 f) (hγ : ContDiff ℝ 1 γ) (a b : ℝ) :
    ∫ t in a..b, fderiv ℝ f (γ t) (deriv γ t) = f (γ b) - f (γ a) := by
  have hderiv : ∀ t ∈ uIcc a b,
      HasDerivAt (f ∘ γ) (fderiv ℝ f (γ t) (deriv γ t)) t := by
    intro t _
    have hfd : HasFDerivAt f (fderiv ℝ f (γ t)) (γ t) :=
      ((hf.differentiable one_ne_zero) (γ t)).hasFDerivAt
    have hγd : HasDerivAt γ (deriv γ t) t :=
      ((hγ.differentiable one_ne_zero) t).hasDerivAt
    exact hfd.comp_hasDerivAt t hγd
  have hcont : Continuous fun t => fderiv ℝ f (γ t) (deriv γ t) :=
    ((hf.continuous_fderiv one_ne_zero).comp hγ.continuous).clm_apply
      (hγ.continuous_deriv le_rfl)
  rw [intervalIntegral.integral_eq_sub_of_hasDerivAt hderiv (hcont.intervalIntegrable a b)]
  rfl
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MultivariableCalculus.leanTry it in the Lean web editor
closed_loop_zeroLean 4Proved here from basic factsFormally verified
/-- Corollary: the line integral of a gradient around a **closed** `C¹` loop (`γ a = γ b`) is
zero. -/
theorem closed_loop_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
    {f : E → ℝ} {γ : ℝ → E} (hf : ContDiff ℝ 1 f) (hγ : ContDiff ℝ 1 γ) {a b : ℝ}
    (hclosed : γ a = γ b) :
    ∫ t in a..b, fderiv ℝ f (γ t) (deriv γ t) = 0 := by
  rw [gradient_theorem hf hγ a b, hclosed, sub_self]
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MultivariableCalculus.leanTry it in the Lean web editor

The vortex: its curl vanishes, and its circulation around the unit circle is 2π2\pi. (The integrand is written out with x=cos⁡tx = \cos t, y=sin⁡ty = \sin t substituted into FF, dotted with γ′(t)=(−sin⁡t,cos⁡t)\gamma'(t) = (-\sin t, \cos t).)

vortex_curl_zeroLean 4Proved here from basic factsFormally verified
/-- The vortex field `F = (P, Q) = (-y/(x² + y²), x/(x² + y²))` has zero curl away from the
origin: `∂Q/∂x = (y² - x²)/(x² + y²)² = ∂P/∂y`. Each partial derivative is computed with the
quotient rule in one variable, the other variable held fixed. -/
theorem vortex_curl_zero {x y : ℝ} (h : x ^ 2 + y ^ 2 ≠ 0) :
    HasDerivAt (fun s => s / (s ^ 2 + y ^ 2)) ((y ^ 2 - x ^ 2) / (x ^ 2 + y ^ 2) ^ 2) x ∧
      HasDerivAt (fun s => -s / (x ^ 2 + s ^ 2)) ((y ^ 2 - x ^ 2) / (x ^ 2 + y ^ 2) ^ 2) y := by
  constructor
  · have hd : HasDerivAt (fun s => s ^ 2 + y ^ 2) (2 * x) x := by
      simpa using (hasDerivAt_pow 2 x).add_const (y ^ 2)
    convert (hasDerivAt_id' x).div hd h using 1
    ring
  · have hd : HasDerivAt (fun s => x ^ 2 + s ^ 2) (2 * y) y := by
      simpa using (hasDerivAt_pow 2 y).const_add (x ^ 2)
    convert (hasDerivAt_neg' y).div hd h using 1
    ring
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MultivariableCalculus.leanTry it in the Lean web editor
vortex_circulationLean 4Proved here from basic factsFormally verified
/-- …yet its circulation around the unit circle `γ(t) = (cos t, sin t)`, `0 ≤ t ≤ 2π`, is `2π`:
on the circle `F(γ t) = (-sin t, cos t) = γ'(t)`, so the integrand `F · γ'` is
`sin² t + cos² t = 1`. By the gradient theorem, `F` is therefore not the gradient of any `C¹`
function on the punctured plane (that step is explained in the lesson, not formalised here). -/
theorem vortex_circulation :
    ∫ t in (0 : ℝ)..2 * π,
      ((-sin t / (cos t ^ 2 + sin t ^ 2)) * (-sin t) +
        (cos t / (cos t ^ 2 + sin t ^ 2)) * cos t) = 2 * π := by
  have h : ∀ t : ℝ, (-sin t / (cos t ^ 2 + sin t ^ 2)) * (-sin t) +
      (cos t / (cos t ^ 2 + sin t ^ 2)) * cos t = 1 := by
    intro t
    rw [cos_sq_add_sin_sq]
    have := sin_sq_add_cos_sq t
    simp only [div_one]
    nlinarith [this]
  simp only [h, intervalIntegral.integral_const, smul_eq_mul, mul_one, sub_zero]
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MultivariableCalculus.leanTry it in the Lean web editor

Finally Green's theorem on a rectangle, in its flux form, as Mathlib states it — the boundary integral written out as four one-variable integrals over the sides:

green_rectangleLean 4Applies a library theoremFormally verified
/-- **Green's theorem on a rectangle**, in its flux (divergence) form: for `F = (f, g)` continuous
on the rectangle `R = [a₁, b₁] × [a₂, b₂]`, differentiable inside, with integrable divergence,
`∬_R (∂f/∂x + ∂g/∂y) = ∮_∂R F · n ds`, written out as four boundary integrals. This applies
Mathlib's `integral_divergence_prod_Icc_of_hasFDerivAt_of_le` (with values in `ℝ`). -/
theorem green_rectangle (f g : ℝ × ℝ → ℝ) (f' g' : ℝ × ℝ → ℝ × ℝ →L[ℝ] ℝ) (a b : ℝ × ℝ)
    (hle : a ≤ b) (Hcf : ContinuousOn f (Icc a b)) (Hcg : ContinuousOn g (Icc a b))
    (Hdf : ∀ x ∈ Ioo a.1 b.1 ×ˢ Ioo a.2 b.2, HasFDerivAt f (f' x) x)
    (Hdg : ∀ x ∈ Ioo a.1 b.1 ×ˢ Ioo a.2 b.2, HasFDerivAt g (g' x) x)
    (Hi : IntegrableOn (fun x => f' x (1, 0) + g' x (0, 1)) (Icc a b)) :
    (∫ x in Icc a b, f' x (1, 0) + g' x (0, 1)) =
      (((∫ x in a.1..b.1, g (x, b.2)) - ∫ x in a.1..b.1, g (x, a.2)) +
          ∫ y in a.2..b.2, f (b.1, y)) - ∫ y in a.2..b.2, f (a.1, y) :=
  integral_divergence_prod_Icc_of_hasFDerivAt_of_le f g f' g' a b hle Hcf Hcg Hdf Hdg Hi
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/MultivariableCalculus.leanTry it in the Lean web editor

What is and is not formalised. Independently proved here: directional derivatives and the gradient formula, steepest ascent, the whole counterexample, the gradient theorem and its closed-loop corollary, the constrained maximum of xyxy, and both vortex computations. Cited from Mathlib: the chain rule, Schwarz's theorem, Lagrange multipliers, the polar Jacobian and change of variables, the Gaussian integral and the divergence theorem on rectangles (Mathlib also has it on boxes in Rn\R^n). Not formalised: "continuous partials imply differentiable" (Mathlib's notion of C1C^1 is defined through the Fréchet derivative, so this coordinate statement is not the form Mathlib uses), the conclusion that the vortex is not conservative on the punctured plane (our gradient theorem assumes φ\varphi is C1C^1 everywhere), Green's theorem for general regions, Stokes's theorem for surfaces, and surface integrals, which in Mathlib are best approached through differential forms and manifolds, still under development.

ComputationC

Computing with multipliers, Jacobians and circulation

The multiplier method turns optimisation into solving equations — something a computer algebra system can do exactly. The first experiment solves the three problems above and one more (the nearest point of a plane):

Lagrange multipliers solved exactlyPythonSymbolic computationExact computationComputationally tested
"""Lagrange multipliers, solved exactly with SymPy.

To find the extreme values of f on the constraint set g = c, solve the
system grad f = lambda grad g, g = c. SymPy solves it exactly for three
problems: xy on the circle x^2 + y^2 = 2, the volume xyz of a box with surface
area 6, and the point of the plane x + 2y + 2z = 9 closest to the origin.
Each candidate is evaluated; the extreme values exist because the constraint
set is compact (first problem) or for a separate reason explained in the
lesson.

Runs in the browser (Pyodide) with the sympy package loaded.
"""

import sympy

x, y, z, lam = sympy.symbols("x y z lambda", real=True)

def lagrange_points(f, g, c, variables):
    """Solve grad f = lambda grad g, g = c; return sorted (point, value) pairs."""
    eqs = [sympy.diff(f, v) - lam * sympy.diff(g, v) for v in variables]
    eqs.append(g - c)
    sols = sympy.solve(eqs, list(variables) + [lam], dict=True)
    out = []
    for s in sols:
        point = tuple(sympy.nsimplify(s[v]) for v in variables)
        out.append((point, sympy.simplify(f.subs(s))))
    return sorted(out, key=lambda pv: (float(pv[1]), [float(p) for p in pv[0]]))

def satisfies_multiplier_rule(f, g, point, variables):
    """True if grad f is a multiple of grad g at the point (2- or 3-vectors)."""
    sub = dict(zip(variables, point))
    gf = sympy.Matrix([sympy.diff(f, v).subs(sub) for v in variables])
    gg = sympy.Matrix([sympy.diff(g, v).subs(sub) for v in variables])
    return sympy.Matrix.hstack(gf, gg).rank() <= 1

PROBLEMS = [
    ("max/min of xy on x^2 + y^2 = 2", x * y, x**2 + y**2, 2, (x, y)),
    ("max of xyz on 2(xy + yz + zx) = 6, x, y, z > 0",
     x * y * z, 2 * (x * y + y * z + z * x), 6, (x, y, z)),
    ("min of x^2 + y^2 + z^2 on x + 2y + 2z = 9",
     x**2 + y**2 + z**2, x + 2 * y + 2 * z, 9, (x, y, z)),
]

def main():
    print(f"Lagrange multipliers with SymPy {sympy.__version__}")
    for title, f, g, c, variables in PROBLEMS:
        print(title)
        points = lagrange_points(f, g, c, variables)
        if len(variables) == 3 and "xyz" in title:
            points = [(p, v) for p, v in points if all(t > 0 for t in p)]
        for point, value in points:
            ok = satisfies_multiplier_rule(f, g, point, variables)
            print(f"   point {str(point):<16} value {str(value):<4} rule holds: {ok}")
    print("Readings: xy ranges over [-1, 1] on the circle; the best box is the")
    print("unit cube (volume 1); the nearest point is (1, 2, 2), at distance 3,")
    print("which is |9| / |(1, 2, 2)|, the point-to-plane distance formula.")
    print()
    print("Epistemic status: exact symbolic solutions of the multiplier")
    print("equations, as reliable as SymPy's solver. The method only lists")
    print("candidates: that a maximum or minimum exists at all is a separate")
    print("argument (compactness of the circle; for the box and the plane, the")
    print("reasoning given in the lesson).")

if __name__ == "__main__":
    main()
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

For the plane, existence of a minimum is easy to see directly: by Cauchy–Schwarz, 9=(1,2,2)⋅(x,y,z)≤3 ∣(x,y,z)∣9 = (1, 2, 2) \cdot (x, y, z) \le 3\,|(x, y, z)|, so every point of the plane has distance at least 33 from the origin, with equality at (1,2,2)(1, 2, 2).

Next, what happens if you forget the Jacobian factor? The second experiment integrates e−(x2+y2)e^{-(x^2+y^2)} over discs three ways:

Polar coordinates and the Jacobian factor rPythonNumerical approximationComputationally tested
"""Change of variables: why the Jacobian factor r matters.

We integrate e^(-(x^2 + y^2)) over discs of radius R three ways: on a
Cartesian grid (the honest but slow way), in polar coordinates with the
Jacobian factor r, and in polar coordinates *forgetting* r. The first two
agree with the exact value pi (1 - e^(-R^2)); the third does not. Letting R
grow gives pi, so (integral of e^(-x^2) over the line)^2 = pi - the Gaussian
integral.

Runs unchanged in the browser (Pyodide) using only the standard library.
"""

import math

def gauss2(x, y):
    """The two-dimensional Gaussian exp(-(x^2 + y^2))."""
    return math.exp(-(x * x + y * y))

def cartesian_disc(f, radius, n=400):
    """Midpoint rule on an n x n grid over [-R, R]^2, keeping cells in the disc."""
    h = 2 * radius / n
    total = 0.0
    for i in range(n):
        x = -radius + (i + 0.5) * h
        for j in range(n):
            y = -radius + (j + 0.5) * h
            if x * x + y * y <= radius * radius:
                total += f(x, y)
    return total * h * h

def polar_disc(f, radius, n_r=400, n_t=64, jacobian=True):
    """Midpoint rule in (r, theta); include the factor r unless jacobian=False."""
    hr, ht = radius / n_r, 2 * math.pi / n_t
    total = 0.0
    for i in range(n_r):
        r = (i + 0.5) * hr
        weight = r if jacobian else 1.0
        for j in range(n_t):
            t = (j + 0.5) * ht
            total += f(r * math.cos(t), r * math.sin(t)) * weight
    return total * hr * ht

def exact_disc(radius):
    """Exact integral of exp(-(x^2 + y^2)) over the disc: pi (1 - e^(-R^2))."""
    return math.pi * (1 - math.exp(-radius * radius))

def gaussian_line(limit=8.0, n=4000):
    """Midpoint-rule approximation of the integral of e^(-x^2) over [-L, L]."""
    h = 2 * limit / n
    return h * sum(math.exp(-((-limit + (i + 0.5) * h) ** 2)) for i in range(n))

def main():
    print("Integral of exp(-(x^2 + y^2)) over the disc of radius R")
    print("  R    exact      Cartesian   polar with r   polar without r")
    for radius in [0.5, 1.0, 2.0, 3.0]:
        exact = exact_disc(radius)
        cart = cartesian_disc(gauss2, radius, n=200)
        good = polar_disc(gauss2, radius)
        bad = polar_disc(gauss2, radius, jacobian=False)
        print(f"  {radius:<4} {exact:.6f}   {cart:.6f}    {good:.6f}       {bad:.6f}")
    print("The Cartesian grid has a jagged edge along the circle, which limits")
    print("its accuracy; polar coordinates with r match the exact value.")
    print("Without r the 'area element' dr dtheta is wrong: it overweights the")
    print("centre, where small r squeezes the polar rectangles together.")
    print()
    big = exact_disc(6.0)
    line = gaussian_line()
    print(f"As R grows the disc integral tends to pi: R = 6 gives {big:.12f}")
    print(f"Integral of e^(-x^2) over [-8, 8] (midpoint rule) = {line:.12f}")
    print(f"sqrt(pi)                                       = {math.sqrt(math.pi):.12f}")
    print()
    print("Epistemic status: numerical quadrature for a few radii - evidence that")
    print("dx dy = r dr dtheta, not a proof. The change of variables theorem and")
    print("the exact Gaussian integral sqrt(pi) are proved in the lesson (and in")
    print("Mathlib, cited in the lesson's Lean file).")

if __name__ == "__main__":
    main()
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

Finally, Green's theorem checked numerically — and its failure for the vortex:

Green's theorem: circulation versus integrated curlPythonNumerical approximationCounterexampleComputationally tested
"""Green's theorem, numerically: circulation around a circle versus curl inside.

Green's theorem says the circulation of a C^1 field F = (P, Q) around the
boundary of a region D equals the double integral of curl F = Q_x - P_y over
D. We compute both sides numerically for circles. For the smooth field
(-y^3, x^3) they agree. For the vortex (-y, x)/(x^2 + y^2) they disagree on a
circle around the origin (2 pi versus 0): the field is singular at the
origin, so the hypothesis "C^1 on all of D" fails - and the circulation
measures the hole.

Runs unchanged in the browser (Pyodide) using only the standard library.
"""

import math

def circulation(P, Q, centre, radius, n=2000):
    """Approximate the circulation of (P, Q) counterclockwise around a circle.

    Uses the trapezoid rule in the angle t, which is very accurate for smooth
    periodic integrands.
    """
    cx, cy = centre
    total = 0.0
    for i in range(n):
        t = 2 * math.pi * i / n
        x, y = cx + radius * math.cos(t), cy + radius * math.sin(t)
        dx, dy = -radius * math.sin(t), radius * math.cos(t)
        total += P(x, y) * dx + Q(x, y) * dy
    return total * 2 * math.pi / n

def disc_integral(g, centre, radius, n_r=200, n_t=200):
    """Approximate the integral of g over a disc, in polar coordinates.

    Midpoint rule in r and t; the factor r is the Jacobian of polar coordinates.
    """
    cx, cy = centre
    hr, ht = radius / n_r, 2 * math.pi / n_t
    total = 0.0
    for i in range(n_r):
        r = (i + 0.5) * hr
        for j in range(n_t):
            t = (j + 0.5) * ht
            total += g(cx + r * math.cos(t), cy + r * math.sin(t)) * r
    return total * hr * ht

def smooth_P(x, y):
    """First component of the smooth field (-y^3, x^3)."""
    return -y**3

def smooth_Q(x, y):
    """Second component of the smooth field (-y^3, x^3)."""
    return x**3

def smooth_curl(x, y):
    """curl (-y^3, x^3) = Q_x - P_y = 3x^2 + 3y^2."""
    return 3 * x**2 + 3 * y**2

def vortex_P(x, y):
    """First component of the vortex field -y / (x^2 + y^2)."""
    return -y / (x**2 + y**2)

def vortex_Q(x, y):
    """Second component of the vortex field x / (x^2 + y^2)."""
    return x / (x**2 + y**2)

def vortex_curl(x, y):
    """curl of the vortex field, which is 0 wherever it is defined."""
    return 0.0

def main():
    rows = [
        ("(-y^3, x^3)", smooth_P, smooth_Q, smooth_curl, (0, 0), 1),
        ("(-y^3, x^3)", smooth_P, smooth_Q, smooth_curl, (1, 0.5), 0.8),
        ("vortex", vortex_P, vortex_Q, vortex_curl, (0, 0), 1),
        ("vortex", vortex_P, vortex_Q, vortex_curl, (0, 0), 0.01),
        ("vortex", vortex_P, vortex_Q, vortex_curl, (2, 0), 1),
    ]
    print("Circulation around a circle versus the integral of curl inside")
    print("field         centre       radius   circulation   integral of curl")
    for name, P, Q, curl, c, r in rows:
        circ = circulation(P, Q, c, r)
        inner = disc_integral(curl, c, r)
        centre = f"({c[0]}, {c[1]})"
        print(f"{name:<13} {centre:<12} {r:<7}  {circ:11.6f}   {inner:11.6f}")
    print(f"For reference: 3 pi / 2 = {1.5 * math.pi:.6f}, 2 pi = {2 * math.pi:.6f}")
    print("Smooth field: the two columns agree, as Green's theorem says.")
    print("Vortex around the origin: circulation 2 pi on every circle, however")
    print("small, but curl 0 wherever the field is defined. Around (2, 0), away")
    print("from the singularity, both sides are 0.")
    print()
    print("Epistemic status: numerical quadrature (trapezoid and midpoint rules),")
    print("accurate here to many digits but not a proof. That the circulation of")
    print("the vortex around the unit circle is exactly 2 pi is a short exact")
    print("computation (formalised in the lesson's Lean file); Green's theorem")
    print("itself is proved in the lesson for rectangles.")

if __name__ == "__main__":
    main()
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

The SymPy computation is exact (within the trust one places in its solver); the other two are numerical evidence for particular fields and regions. The theorems are what make the patterns general.

Exercises

Exercises

1. Multivariable and vector calculus

Warm-upHuman

A hiker's altitude is h(x,y)=3x+2y2h(x, y) = 3x + 2y^2 (in suitable units). What is the greatest rate of increase of hh at the point (0,1)(0, 1), over all unit directions?

2. Multivariable and vector calculus

CoreHuman

Let f(x,y)=xyx2+y2f(x, y) = \dfrac{xy}{x^2 + y^2} for (x,y)≠(0,0)(x, y) \ne (0, 0) and f(0,0)=0f(0, 0) = 0. Which statement is true?

Choose one

3. Multivariable and vector calculus

CoreHuman

Using polar coordinates, ∬x2+y2≤43x2+y2  dA=kπ\displaystyle\iint_{x^2 + y^2 \le 4} 3\sqrt{x^2 + y^2}\;dA = k\pi. Find kk.

4. Multivariable and vector calculus

CoreHuman

Find the maximum value of f(x,y)=x+2yf(x, y) = x + 2y on the circle x2+y2=5x^2 + y^2 = 5.

5. Multivariable and vector calculus

CoreHuman

The vortex field F=(−y,x)/(x2+y2)F = \big(-y, x\big)/(x^2 + y^2) has zero curl on R2∖{0}\R^2 \setminus \{0\}, yet its circulation around the unit circle is 2π2\pi. Which hypothesis of the theorem “a C1C^1 field with zero curl on a domain UU is conservative on UU” fails?

Choose one

6. Multivariable and vector calculus

CoreHuman

For f(x,y)=x3−3x+y2f(x, y) = x^3 - 3x + y^2, which statements are true? (Select all that apply.)

Choose all that apply

7. Multivariable and vector calculus

StretchHuman

Let F(x,y,z)=(x+y2,  y+z2,  z+x2)F(x, y, z) = (x + y^2,\; y + z^2,\; z + x^2). The outward flux of FF through the sphere of radius 22 centred at the origin is kπk\pi. Find kk.

8. Multivariable and vector calculus

StretchFormal

In Lean, xyQuot p = p.1 * p.2 / (p.1 ^ 2 + p.2 ^ 2). Which statement formalises “both partial derivatives exist at the origin, but the function is not differentiable there”?

Choose one

9. Multivariable and vector calculus

StretchComputational

Write circulation(P, Q, r, n) that approximates ∮(P dx+Q dy)\oint (P\,dx + Q\,dy) counterclockwise around the circle of radius r centred at the origin, using the parametrisation (rcos⁡t,rsin⁡t)(r\cos t, r\sin t) and the rectangle (left-point) rule with n equal steps in t∈[0,2π]t \in [0, 2\pi]. Test it on the rotation field (−y,x)(-y, x) (circulation 2πr22\pi r^2), a gradient field (circulation 00) and the vortex (circulation 2π2\pi).

Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.
Common misconceptionsH

Common misconceptions

Misconception

"If the partial derivatives exist, the function is differentiable." Partial derivatives only look along the coordinate axes. f(x,y)=xy/(x2+y2)f(x, y) = xy/(x^2 + y^2) (with f(0)=0f(0) = 0) has both partials at the origin but is not even continuous there. What is true: if the partials exist near aa and are continuous at aa, then ff is differentiable at aa.

Misconception

Forgetting the Jacobian factor. "dx dy=dr dθdx\,dy = dr\,d\theta" is wrong; dx dy=r dr dθdx\,dy = r\,dr\,d\theta. Without the rr, the area of the disc of radius RR would come out as 2πR2\pi R, and the experiment above shows the size of the error for a Gaussian. The factor is ∣det⁡JT∣|\det J_T| — the absolute value, because volumes are positive even when TT reverses orientation.

Misconception

"Zero curl means conservative." Only on simply connected domains (for instance discs, or any star-shaped set). The vortex field has zero curl on the punctured plane but circulation 2π2\pi around the origin.

Misconception

"∇f=λ∇g\nabla f = \lambda \nabla g always finds the maximum." It finds candidates, and only at points where ∇g≠0\nabla g \ne 0. One must also check points where ∇g=0\nabla g = 0 on the constraint, and make sure a maximum exists at all — by compactness, or by a separate inequality, as for the box.

Misconception

"The gradient is just a list of partial derivatives, independent of geometry." The derivative Df(a)Df(a) is defined without any inner product; the gradient is the vector representing it via the dot product. With a different inner product (in curvilinear coordinates, or on a curved surface), the gradient vector changes: in polar coordinates ∇f=fr er+1rfθ eθ\nabla f = f_r\,\mathbf e_r + \frac1r f_\theta\,\mathbf e_\theta, not (fr,fθ)(f_r, f_\theta).

ViewpointsH

Many ways of seeing

Geometry— One theorem: ∫ over the boundary of ω equals ∫ of dω

Green's, Stokes's and Gauss's theorems, and the fundamental theorem of calculus itself, are one theorem in the language of differential forms. A kk-form is something that can be integrated over oriented kk-dimensional surfaces: P dx+Q dyP\,dx + Q\,dy is a 1-form, f dx∧dyf\,dx \wedge dy a 2-form. The exterior derivative dd turns kk-forms into (k+1)(k+1)-forms; in R3\R^3, on 0-, 1- and 2-forms, it is gradient, curl and divergence. The generalised Stokes theorem says ∫∂Mω=∫Mdω\int_{\partial M} \omega = \int_M d\omega for a compact oriented manifold MM with boundary. The wedge product is antisymmetric, dx∧dy=−dy∧dxdx \wedge dy = -dy \wedge dx, which is the geometric reason the Jacobian determinant appears in change of variables: dx∧dy=det⁡JT dr∧dθdx \wedge dy = \det J_T\, dr \wedge d\theta. See differential forms and smooth manifolds.

Topology— Fields that detect holes

The vortex shows that the difference between "curl-free" and "conservative" is topological. Curl-free fields on an open set U⊆R2U \subseteq \R^2, modulo gradients, form a vector space: the first de Rham cohomology HdR1(U)H^1_{dR}(U). Poincaré's lemma says it is zero for a disc; for the punctured plane it is one-dimensional, spanned by the vortex, and the linear map "circulation around the origin, divided by 2π2\pi" identifies it with R\R. For a curl-free field the circulation around a loop depends only on the loop's homotopy class, and for the vortex it is 2π2\pi times the winding number of the loop around the origin. De Rham's theorem (1931) says these analytic invariants agree with the topological ones computed by counting holes. See the fundamental group and algebraic topology.

Algebra— Linearisation, and d² = 0

Multivariable calculus is linear algebra applied locally: the derivative is a linear map, the chain rule is matrix multiplication, the second derivative test is the classification of a symmetric matrix by the signs of its eigenvalues, and the change of variables formula is the multiplicativity of the determinant. The identities curl⁡(∇φ)=0\operatorname{curl}(\nabla \varphi) = 0 and div⁡(curl⁡F)=0\operatorname{div}(\operatorname{curl} F) = 0 are both consequences of the symmetry of second derivatives, and in the language of forms they are the single identity d∘d=0d \circ d = 0: the sequence "functions →∇\xrightarrow{\nabla} fields →curl\xrightarrow{\text{curl}} fields →div\xrightarrow{\text{div}} functions" is a cochain complex, and its failure to be exact measures topology, as in the topological viewpoint.

Physics— Gauss's law, potentials and constraint forces

The theorems of this lesson were developed largely for physics. Gauss's law for the electric field, ∬∂VE⋅n dS=Qinside/ε0\iint_{\partial V} \mathbf E \cdot \mathbf n\,dS = Q_{\text{inside}}/\varepsilon_0, becomes the local equation div⁡E=ρ/ε0\operatorname{div}\mathbf E = \rho/\varepsilon_0 by the divergence theorem applied to small balls; Faraday's law becomes curl⁡E=−∂B/∂t\operatorname{curl}\mathbf E = -\partial\mathbf B/\partial t by Stokes's theorem — Maxwell's equations in their two equivalent forms. A force field is conservative exactly when work is path-independent, and then F=−∇V\mathbf F = -\nabla V for a potential energy VV (see classical mechanics). Lagrange multipliers have a physical reading too: a bead on a wire feels a constraint force λ∇g\lambda\nabla g normal to the wire, and the multiplier measures its strength.

Probability— Densities transform with the Jacobian

If a random point XX in Rn\R^n has density pXp_X and Y=T(X)Y = T(X) for a C1C^1 bijection TT with non-vanishing Jacobian, then YY has density pY(y)=pX(T−1(y)) ∣det⁡JT−1(y)∣p_Y(y) = p_X(T^{-1}(y))\,|\det J_{T^{-1}}(y)| — the change of variables formula read backwards. The Gaussian integral makes the normal distribution a probability distribution, and polar coordinates explain the Box–Muller method for simulating it: if U1,U2U_1, U_2 are independent and uniform on (0,1)(0, 1), then R=−2ln⁡U1R = \sqrt{-2\ln U_1}, Θ=2πU2\Theta = 2\pi U_2 give independent standard normal variables Rcos⁡ΘR\cos\Theta and Rsin⁡ΘR\sin\Theta — the factor rr in r dr dθr\,dr\,d\theta is exactly absorbed by the density of RR. See probability theory.

Category theory— The chain rule is functoriality

Consider pointed open sets (U,a)(U, a) and differentiable maps f:(U,a)→(V,b)f : (U, a) \to (V, b) with f(a)=bf(a) = b. Sending (U,a)(U, a) to the vector space Rn\R^n of directions at aa, and ff to the linear map Df(a)Df(a), respects identities (D(id)(a)=idD(\mathrm{id})(a) = \mathrm{id}) and composition (D(g∘f)(a)=Dg(b)∘Df(a)D(g \circ f)(a) = Dg(b) \circ Df(a)). So the chain rule says precisely that differentiation at a point is a functor from this category to the category of finite-dimensional vector spaces. On manifolds this becomes the tangent functor TT, sending MM to its tangent bundle. See functors.

History & global context

History and global context

  • Partial derivatives and multiple integrals (18th century). Leonhard Euler and Alexis Clairaut used partial derivatives for problems in mechanics and the shape of the Earth (Clairaut's Théorie de la figure de la Terre, 1743, and Euler's work on the symmetry of mixed partials in the 1730s–40s). Euler and Joseph-Louis Lagrange evaluated double and triple integrals by changing variables, and Lagrange introduced multipliers in his Mécanique analytique (1788) for mechanical constraints.
  • Potential theory and the divergence theorem. Lagrange (1762) and Carl Friedrich Gauss (1813, and his 1839–40 papers on potential theory) proved special cases of the divergence theorem; Mikhail Ostrogradsky in St Petersburg gave a general proof in 1826 (published 1831), which is why the theorem is also called the Ostrogradsky–Gauss theorem.
  • Green and Stokes. George Green, a self-taught miller's son from Nottingham, published An Essay on the Application of Mathematical Analysis to the Theories of Electricity and Magnetism privately in 1828; it was rediscovered by William Thomson (Lord Kelvin) in 1845. The theorem now called Stokes's appeared in a letter from Thomson to George Gabriel Stokes in 1850, and Stokes set it as an examination question in Cambridge in 1854.
  • Vector notation and forms. Josiah Willard Gibbs and Oliver Heaviside created vector analysis in the 1880s, in part to write James Clerk Maxwell's equations compactly. Élie Cartan developed differential forms (around 1899–1922), and Vito Volterra, Henri Poincaré and Cartan made the generalised Stokes theorem a single statement; Georges de Rham connected it with topology in 1931.
  • Rigour. Cauchy and later Weierstrass, Jordan and Peano clarified the notion of differentiability in several variables; the definition via the best linear approximation is due to Otto Stolz (1893), William Henry Young (1910) and Maurice Fréchet (1911), the last in infinite-dimensional spaces.
Further reading

Further reading

  • John H. Hubbard and Barbara Burke Hubbard, Vector Calculus, Linear Algebra, and Differential Forms: A Unified Approach (1999; 5th edition 2015) — rigorous, with forms from the start.
  • Jerrold E. Marsden and Anthony Tromba, Vector Calculus (1976; 6th edition 2012).
  • Michael Spivak, Calculus on Manifolds (1965) — a short, classic path from the derivative as a linear map to the generalised Stokes theorem.
  • Tom M. Apostol, Calculus, Volume II (2nd edition 1969).
  • H. M. Schey, Div, Grad, Curl, and All That (1973) — vector calculus through electrostatics.
  • Vladimir A. Zorich, Mathematical Analysis II (2004) — a thorough treatment including the change of variables theorem and differential forms.

Next in the Lumenary: ordinary differential equations, classical mechanics, curves and surfaces, complex analysis and optimisation.