The Fundamental Theorem for Line Integrals
For a gradient field, the work along a path depends only on where the path starts and ends. This is the line-integral version of the Fundamental Theorem of Calculus, and it explains path independence, potential energy and conservation of energy. This lesson proves the theorem, gives the test for whether a field is conservative (and the fine print about holes in the domain), shows how to construct a potential function, and checks everything numerically.
The theorem
Theorem. Let be a smooth curve given by , , and let be a differentiable function whose gradient is continuous on . Then
Proof. By the chain rule, . So
by the ordinary Fundamental Theorem of Calculus. For a piecewise-smooth curve, apply this to each piece; the intermediate values telescope. ∎
Compare with the survey lesson Green's, Stokes' and Divergence Theorems: every theorem of vector calculus has this shape, "", and here the boundary of a curve is its two endpoints.
Path independence and closed curves
Say is independent of path in a region if any two paths in with the same initial and terminal points give the same value. Three statements turn out to be equivalent for a continuous field on an open connected region :
| Statement | Why it follows |
|---|---|
| (1) for some ( is conservative) | assumption |
| (2) is independent of path in | by the theorem |
| (3) for every closed path in | a closed path is two paths with the same ends, one reversed |
is the deeper direction: fix a point and define along any path from to . Path independence makes this well defined, and differentiating along a horizontal final segment gives , along a vertical one .
A test for conservative fields
If with continuous second partials, then by Clairaut's theorem. So
The converse needs a condition on the region: if is simply connected (open, connected, and every simple closed curve in encloses only points of , i.e. no holes) and throughout , then is conservative. The proof uses Green's theorem. Without that condition the converse fails, as the vortex field below shows.
import sympy as sp
import numpy as np
x, y, z = sp.symbols('x y z')
F = sp.Matrix([2*x*y + z, x**2, x + 3*z**2])
curl = [sp.diff(F[2], y) - sp.diff(F[1], z), sp.diff(F[0], z) - sp.diff(F[2], x), sp.diff(F[1], x) - sp.diff(F[0], y)]
print("curl F =", curl)
f = sp.integrate(F[0], x) # x**2*y + x*z, plus g(y, z)
f += sp.integrate(sp.simplify(F[1] - sp.diff(f, y)), y) # nothing new in y
f += sp.integrate(sp.simplify(F[2] - sp.diff(f, z)), z) # adds z**3
print("potential f =", f)
print("f(1,2,1) - f(0,0,0) =", f.subs({x: 1, y: 2, z: 1}) - f.subs({x: 0, y: 0, z: 0}))
t = np.linspace(0, 1, 200_001) # a wiggly path between the same points
r = np.array([t, 2 * t + np.sin(3 * np.pi * t), t**3])
Fn = sp.lambdify((x, y, z), list(F), "numpy")
mid, dr = (r[:, 1:] + r[:, :-1]) / 2, np.diff(r, axis=1)
print("numerical work along the wiggle ≈", round(float(np.sum(np.array(Fn(*mid)) * dr)), 6))curl F = [0, 0, 0]
potential f = x**2*y + x*z + z**3
f(1,2,1) - f(0,0,0) = 4
numerical work along the wiggle ≈ 4.0
The curl is zero on all of (simply connected), SymPy builds the potential step by step (integrate in , then add what is missing in and in ), and the wiggly path gives exactly .
The vortex: curl zero but not conservative
The field is defined on the plane minus the origin. A short computation gives , so the test passes everywhere in its domain. Yet around the unit circle , so . The domain has a hole, and the converse needs simple connectivity. Locally (the polar angle), but cannot be defined continuously all the way around the origin: it jumps by .
import numpy as np
F = lambda x, y: (-y / (x**2 + y**2), x / (x**2 + y**2))
def loop(cx, cy, R, n=100_000):
t = (np.arange(n) + 0.5) * 2 * np.pi / n
x, y = cx + R * np.cos(t), cy + R * np.sin(t)
P, Q = F(x, y)
return float(np.sum(P * -R * np.sin(t) + Q * R * np.cos(t)) * 2 * np.pi / n)
print("circle around the origin :", round(loop(0, 0, 1), 6), " 2π =", round(2 * np.pi, 6))
print("bigger circle, off-centre :", round(loop(0.5, 0, 3), 6))
print("circle NOT around the origin :", round(loop(3, 0, 1), 6) + 0.0) # + 0.0 turns -0.0 into 0.0circle around the origin : 6.283185 2π = 6.283185
bigger circle, off-centre : 6.283185
circle NOT around the origin : 0.0
Every loop that winds once around the hole gives ; a loop that avoids it gives 0. This number divided by is the winding number, used in graphics for point-in-polygon tests.
Conservation of energy
If a force ( the potential energy) moves a particle of mass along from to , Newton's law gives (change in kinetic energy), while the theorem gives . Equating them: . The total energy is constant, which is why such forces are called conservative.
In software
- Game AI and robotics. In a potential-field planner the "cost" of reaching a point is the potential difference, independent of the route taken, as long as the field is a true gradient. Hand-tuned force fields that are not gradients can make agents circle forever.
- Physics engines. A good integrator should keep nearly constant for gravity and springs; energy drift is a standard bug check (integrators).
- Geometry. The winding number () decides point-in-polygon and inside/outside tests, including for the non-zero fill rule in vector graphics.
- Optimization. For a loss , the change is along the training trajectory, regardless of the optimizer's path.
Exercises
Exercise 1: Use the theorem
Show that is conservative and compute along any path from to .
Answer
; the integral is 2.
Solution
Exercise 2: Not conservative
Is conservative on ?
Answer
No.
Solution
and . They differ wherever , and a conservative field must have everywhere, so is not conservative.
Exercise 3: Work done by gravity (code)
With units chosen so that , gravity is with potential (). Find the work done by gravity as an object moves from the point to by hand, then verify numerically along a spiral path.
Answer
(the object moves away, so gravity does negative work).
Solution
import numpy as np
t = np.linspace(0, 1, 200_001)
r = np.array([2 * (1 - t) * np.cos(4 * np.pi * t), 2 * (1 - t) * np.sin(4 * np.pi * t), 4 * t])
mid, dr = (r[:, 1:] + r[:, :-1]) / 2, np.diff(r, axis=1)
F = -mid / np.linalg.norm(mid, axis=0)**3
print(round(float(np.sum(F * dr)), 6))-0.25
Exercise 4: A potential in 3D
Find with and evaluate from to .
Answer
; the integral is 13.
Solution
Test yourself
and runs from to . Then equals…
- 0
On which domain does guarantee that is conservative?
- Any open domain
- A simply connected open domain
- Only on circles
- Only when and are polynomials of degree 1
A field has for every closed curve in a region. What else is true there?
- Line integrals of are path-independent
- is the zero field
- has constant length
- is perpendicular to every curve