Skip to main content

Mathematical Infrastructure

Divergence, Curl, and Line Integrals

The vector-calculus operators that appear in Fokker-Planck, score-based diffusion, and PINN papers. Definitions of divergence, curl, gradient, line integrals, and Green's theorem in the plane. Compact, not encyclopedic.

CoreTier 2Stable~28 min
0

Why This Matters

Open the Fokker-Planck equation page and the first line is tp=(μp)+12(Σp)\partial_t p = -\nabla \cdot (\mu p) + \frac{1}{2}\nabla \cdot (\Sigma \nabla p). Open physics-informed neural networks and the loss is built from PDE residuals like u=0\nabla \cdot u = 0 or ×E=tB\nabla \times E = -\partial_t B. Without the vocabulary of divergence, gradient, curl, and line integral, those expressions are runes.

This page collects the operators with their definitions, the one identity each ML paper actually uses, and Green's theorem in the plane. Stokes' theorem in R3\mathbb{R}^3 and the divergence theorem in Rn\mathbb{R}^n are mentioned for completeness; the full integration-on-manifolds treatment lives in differential-geometry texts and is not redone here.

The Three Operators

Definition

Gradient, Divergence, Curl

Let =(1,,n)T\nabla = (\partial_1, \ldots, \partial_n)^T be the formal vector of partial derivatives. For sufficiently smooth functions on an open set in Rn\mathbb{R}^n:

  • The gradient of a scalar field f:RnRf: \mathbb{R}^n \to \mathbb{R} is the vector field f=(1f,,nf)T\nabla f = (\partial_1 f, \ldots, \partial_n f)^T.
  • The divergence of a vector field F=(F1,,Fn)TF = (F_1, \ldots, F_n)^T is the scalar field F=i=1niFi=tr(JF)\nabla \cdot F = \sum_{i=1}^{n} \partial_i F_i = \mathrm{tr}(J_F).
  • In dimension n=3n = 3, the curl of F=(F1,F2,F3)TF = (F_1, F_2, F_3)^T is the vector field ×F=(2F33F2,  3F11F3,  1F22F1)T\nabla \times F = (\partial_2 F_3 - \partial_3 F_2,\; \partial_3 F_1 - \partial_1 F_3,\; \partial_1 F_2 - \partial_2 F_1)^T.
  • The Laplacian of a scalar field is Δf=f=i=1ni2f\Delta f = \nabla \cdot \nabla f = \sum_{i=1}^{n} \partial_i^2 f.

Three identities are worth memorizing.

Proposition

Divergence is the Trace of the Jacobian

Statement

For a C1C^1 vector field F:RnRnF: \mathbb{R}^n \to \mathbb{R}^n with Jacobian JFJ_F, F=tr(JF)=i=1n(JF)ii.\nabla \cdot F = \mathrm{tr}(J_F) = \sum_{i=1}^{n} (J_F)_{ii}. Consequence: divergence-free fields are exactly those whose Jacobian has trace zero everywhere. The pointwise volume-deformation rate of the flow x˙=F(x)\dot{x} = F(x) equals F\nabla \cdot F at xx.

Intuition

The Jacobian JF(x)J_F(x) is the linear approximation of the flow at xx. Its trace is the sum of eigenvalues, which is the rate of change of volume of an infinitesimal box transported by the flow. When the trace is zero the flow is volume-preserving; when it is positive the flow expands volume. This is exactly Liouville's theorem for the flow x˙=F(x)\dot{x} = F(x).

Why It Matters

The continuity equation tρ+(ρv)=0\partial_t \rho + \nabla \cdot (\rho v) = 0 says mass is locally conserved by the velocity field vv. The Fokker-Planck equation and the probability flow ODE used in score-based diffusion are both continuity equations with specific drift fields. Reading either page assumes you can compute (ρv)\nabla \cdot (\rho v) in coordinates.

A second identity threads through electromagnetism and fluid mechanics: curl of a gradient is zero, ×(f)=0\nabla \times (\nabla f) = 0, and divergence of a curl is zero, (×F)=0\nabla \cdot (\nabla \times F) = 0. Both follow from equality of mixed partials. They are the cohomological reason that "irrotational" and "solenoidal" decompositions (Helmholtz) are well-defined on simply connected domains.

A third identity is the product rule for divergence: (fF)=f(F)+(f)F\nabla \cdot (f F) = f (\nabla \cdot F) + (\nabla f) \cdot F. This is the identity used to derive the integration-by-parts formula in score matching (Hyvärinen 2005), where the gradient log-density logp\nabla \log p replaces f\nabla f inside the divergence.

Line Integrals

Let γ:[a,b]Rn\gamma: [a, b] \to \mathbb{R}^n be a piecewise-C1C^1 curve and F:RnRnF: \mathbb{R}^n \to \mathbb{R}^n a continuous vector field on a region containing the image of γ\gamma.

Definition

Line Integral of a Vector Field

The line integral of FF along γ\gamma is γFdr=abF(γ(t))γ(t)dt.\int_\gamma F \cdot dr = \int_a^b F(\gamma(t)) \cdot \gamma'(t)\, dt. It is independent of orientation-preserving reparametrizations and changes sign under reversal of orientation.

A field FF is conservative on an open set UU if F=ϕF = \nabla \phi for some scalar potential ϕ\phi. The fundamental theorem of line integrals gives, for a conservative field, γϕdr=ϕ(γ(b))ϕ(γ(a))\int_\gamma \nabla \phi \cdot dr = \phi(\gamma(b)) - \phi(\gamma(a)), which depends only on endpoints. Conversely, on a simply connected open set, FF with ×F=0\nabla \times F = 0 is conservative. Outside simply connected domains the converse can fail; the standard counterexample is F(x,y)=(y,x)/(x2+y2)F(x, y) = (-y, x)/(x^2 + y^2) on the punctured plane, which is curl-free yet has nonzero loop integral around the origin.

Green's Theorem in the Plane

Theorem

Green's Theorem

Statement

Let DR2D \subset \mathbb{R}^2 be a bounded region whose boundary D\partial D is a piecewise-C1C^1 simple closed curve, oriented counterclockwise. Let P,Q:DRP, Q: \overline{D} \to \mathbb{R} be C1C^1. Then D(Pdx+Qdy)=D(QxPy)dA.\oint_{\partial D} (P\, dx + Q\, dy) = \iint_D \left(\frac{\partial Q}{\partial x} - \frac{\partial P}{\partial y}\right) dA.

Intuition

The integrand on the right is the scalar curl of the planar field (P,Q)(P, Q). Green's theorem says: the circulation of a planar vector field around a loop equals the integral of its curl over the enclosed region. The divergence form of the same theorem (sometimes called the divergence-in-the-plane theorem) reads DFnds=DFdA\oint_{\partial D} F \cdot n\, ds = \iint_D \nabla \cdot F\, dA, where nn is the outward unit normal.

Why It Matters

Green's theorem is the two-dimensional ancestor of two flagship results: the divergence theorem ΩFndS=ΩFdV\int_{\partial \Omega} F \cdot n\, dS = \int_\Omega \nabla \cdot F\, dV in Rn\mathbb{R}^n, and Stokes' theorem SFdr=S(×F)ndA\oint_{\partial S} F \cdot dr = \iint_S (\nabla \times F) \cdot n\, dA on oriented surfaces in R3\mathbb{R}^3. The integration-by-parts identity underlying Hyvärinen score matching is the divergence theorem applied to logp\nabla \log p with vanishing boundary contributions at infinity. The Helmholtz decomposition used in incompressible fluids and in some neural-PDE solvers is also a Green-type consequence.

Failure Mode

Boundary regularity matters. A region with infinitely many boundary oscillations (a "rough" boundary that is not piecewise-C1C^1) breaks the classical statement. For modern Lipschitz-domain or BV-domain extensions, see Evans-Gariepy. The orientation rule (counterclockwise) is essential; reversing it flips the sign of the right side.

Worked Example: Divergence of an Affine Drift

Let F(x)=Ax+bF(x) = A x + b with ARn×nA \in \mathbb{R}^{n \times n}, bRnb \in \mathbb{R}^n. The Jacobian is constant: JF=AJ_F = A. By the divergence-as-trace identity, F=tr(A)\nabla \cdot F = \mathrm{tr}(A) everywhere. If AA is the negative of a positive-definite matrix (a stable linear drift), then tr(A)<0\mathrm{tr}(A) < 0 and the flow contracts volumes exponentially. This is the linear case of the Fokker-Planck contraction analysis for Ornstein-Uhlenbeck processes.

Common Confusions

Watch Out

Curl is a 3D operator (and a scalar in 2D)

The full ×\nabla \times is defined in R3\mathbb{R}^3 and returns a vector field. In R2\mathbb{R}^2 what is called "curl" is the scalar xQyP\partial_x Q - \partial_y P that appears in Green's theorem; it is the zz-component of the curl of the 3D embedding (P,Q,0)(P, Q, 0). In dimensions n4n \geq 4 the natural object is a 2-form (an antisymmetric matrix), not a vector. ML papers stay in n=2n = 2 or n=3n = 3 for fluid and EM applications, so this confusion rarely bites — but the convention difference matters when reading higher-dimensional differential geometry.

Watch Out

Conservative is a global property

The condition ×F=0\nabla \times F = 0 is local. The condition F=ϕF = \nabla \phi for a global potential ϕ\phi is global and depends on the topology of the domain. On a simply connected open set the two coincide; on the punctured plane they do not. ML rarely cares because most domains are convex or contractible, but in optimal-control and Hamiltonian-flow papers the distinction is real.

Exercises

ExerciseCore

Problem

Let F(x,y)=(y,x)F(x, y) = (-y, x) on R2\mathbb{R}^2. Compute F\nabla \cdot F and the 2D scalar curl xF2yF1\partial_x F_2 - \partial_y F_1. Then evaluate the line integral of FF around the unit circle traversed counterclockwise.

ExerciseAdvanced

Problem

Show that for any C1C^1 vector field F:RnRnF: \mathbb{R}^n \to \mathbb{R}^n and C1C^1 scalar field ρ:RnR\rho: \mathbb{R}^n \to \mathbb{R}, (ρF)=ρ(F)+(ρ)F.\nabla \cdot (\rho F) = \rho (\nabla \cdot F) + (\nabla \rho) \cdot F. This is the product rule for divergence used in deriving the Fokker-Planck drift terms and in Hyvärinen's score-matching integration-by-parts.

References

Related Topics

Last reviewed: April 18, 2026

Prerequisites

Foundations this topic depends on.

Next Topics