For any pair of points \(A,\ B\in\mathbf{R}^n\) consider the space of

paths \(\gamma\colon [0,T]\to\mathbf{R}^n\) between \(A\) and \(B\). Let \(L\)

be a Lagrangian and

\[I(\gamma)=\int_0^TL(t,\gamma(t),\dot{\gamma}(t))dt\] be the action

of that path. A classical path of time \(T\) joining \(A\) and \(B\) is a

solution to the corresponding Euler-Lagrange equation. Let's suppose

we're in an ideal situation: for any \(T\) and any pair of points \(A\),

\(B\) there is a unique classical path \(\gamma_{A,B,T}\) of time \(T\)

joining \(A\) and \(B\).

Fix \(A\), but allow \(B\) and \(T\) to vary. Define the function

\[W(B,T)=I(\gamma_{A,B,T}).\]

The Hamilton-Jacobi equation is a PDE satisfied by this

function. Let's first compute the derivatives of \(W\) with respect to

\(B\). Replace \(B\) by \(B+b\) and suppose that

\(\gamma_{A,B+b,T}(t)=\gamma_{A,B,T}(t)+\eta(t)\). Then, for small \(b\),

writing \(\gamma_{A,B,T}(t)=(x_1(t),\ldots,x_n(t))\), we have

\[I(\gamma_{A,B+b,T})=I(\gamma_{A,B,T})+\int_0^T\left(\frac{\partial

L}{\partial x_i}-\frac{d}{dt}\frac{\partial

L}{\partial\dot{x}_i}\right)dt+\left[\frac{\partial L}{\partial

\dot{x}_i}\eta_i(t)\right]_0^T+\cdots\] by the usual Euler-Lagrange

argument for computing the first variation of \(I\). Since

\(\gamma_{A,B,T}\) is the classical path, the first term vanishes. Since

\(\eta_i(0)=0\) (the point \(A\) is fixed) the only remaining term is

\(\frac{\partial L}{\partial \dot{x}_i}(T)\eta_i(T)\). Since

\(b_i=\eta_i(T)\), this means that the first variation of \(W\) is

\[\frac{\partial W}{\partial B_i}=\frac{\partial

L}{\partial\dot{x}_i}(T)\] By Hamilton's equations, \(\frac{\partial

L}{\partial\dot{x}_i}=p_i\) so this says that \(\partial W/\partial B_i\)

is the ith component of momentum at the endpoint of the path.

Now, by the fundamental theorem of calculus:

\[\frac{dW}{dt}=L(T,B_i,\dot{B}_i)\] but by the chain rule

\[\frac{dW}{dT}=\frac{\partial W}{\partial T}+\sum_i\frac{\partial

W}{\partial B_i}\dot{B}_i\] This gives \[\frac{\partial W}{\partial

T}=L-\sum_ip_i\dot{B}_i\] where \(p_i\) is the momentum at the

endpoint. Since the Hamiltonian \(H\) and Lagrangian \(L\) are related by

a Legendre transform, we have

\[L(T,B_i,\dot{B}_i)-\sum_ip_i\dot{B}_i=-H(T,B_i,p_i)=-H\left(T,B_i,\frac{\partial

W}{\partial B_i}\right)\] so we see that \(W\) satisfies the

Hamilton-Jacobi equation \[\frac{\partial W}{\partial T}=-H(T,B,\nabla

W).\]