The Legendre transform is a mechanism for converting a relationship like
into a relationship like
In other words, by going from a function to its Legendre transform
and vice versa, the roles of
and
in (1) and (2) can be reversed.
In moving from (1) to (2), the required Legendre transform is
because differentiating both sides of (3) with respect to gives
Using (1), we see that the last two terms in (4) cancel, so we get (2). Conversely, the Legendre transform of in (2) can be written
because differentiating both sides with respect to gives (1).
Mainly for teaching purposes, I want to consider a simple example here of applying the Legendre transform to the conversion of a Lagrangian mechanics problem into an equivalent Hamiltonian one. We might want to do this for a number of reasons, not least because it converts the problem of solving second-order ODEs in the case of the Lagrangian formulation into a potentially simpler problem of solving first-order ODEs in the case of the Hamiltonian formulation.
Consider a simple harmonic oscillator consisting of a mass attached to a spring with spring constant
moving backwards and forwards horizontally on a frictionless table. There is a restoring force
that wants to bring the mass back towards its equilibrium position whenever it is displaced either by compressing the spring or stretching it. Newton’s second law,
, then gives us the second-order ODE
with general solution
where is the natural frequency of this system’s oscillations. We could obtain a particular solution (i.e., provide specific values for
and
) given a pair of initial conditions, e.g., the initial conditions
and
would give us the particular solution
The dynamics of this system are now completely determined and we can specify the values of ,
and
at any point in time
.
As is well known, we can arrive at exactly the same result using Lagrangian mechanics, which involves writing the Lagrangian for the problem as
where is kinetic energy and
is potential energy. For the simple harmonic oscillator we have
and
Therefore, the Lagrangian for the harmonic oscillator problem is
We define the action as the functional
and seek the extremal function at which the action is stationary. The extremal is obtained by solving for
the first-order condition for this optimisation problem, known as the Euler-Lagrange equation:
Applying the Euler-Lagrange equation to the Lagrangian for the harmonic oscillator problem in (12) we find
which is the same as the ODE in (6) obtained by Newtonian mechanics.
[To briefly explain how the Euler-Lagrange equation is derived, we begin by constructing a function , where
is the desired extremal,
is a parameter, and
denotes a function which goes through the same two endpoints
and
as the extremal, but has zero value at these endpoints. The new function
then represents the set of all possible varied curves that can joint the two endpoints. Out of all of these curves, we want the one that makes the action stationary, where the action is now treated as the function of
given by
. That is, we want
when
. Noting that
and
and differentiating under the integral sign we get
Setting and
at this point, which is what is required, and remembering that
means
, we obtain
To convert the second term in this integrand into something multiplying instead of
, we can use integration by parts to get
Putting this result into the previous integral we get
from which the Euler-Lagrange equation in (14) follows since is arbitrary.]
We now want to see how this can be transformed into a Hamiltonian mechanics problem using the Legendre transform outlined earlier. We begin by defining a new variable to replace the partial
, which is usually referred to as the generalised momentum in the mechanics literature:
(In the case of the simple harmonic oscillator problem, this will turn out to be the actual linear momentum. The other partial in the Euler-Lagrange equation, , is usually referred to as the generalised force in the mechanics literature, and again will turn out to be the actual force in the case of the simple harmonic oscillator). We now regard (15) as the analogue of equation (1). It follows that the analogue of equation (2) must then be
where is the Legendre transform that takes us from (15) to (16), namely
This is the analogue of (3). This Legendre transform now enables us to write down the Hamiltonian for the harmonic oscillator problem, starting from the Lagrangian in (12). We begin by using (15) to obtain
which allows us to replace by
wherever it occurs. Then using (12) in (17) with
instead of
we get
Therefore, we see that whereas , the Legendre transform has instead given us
. We can also get an equation in terms of
for the Euler-Lagrange equation in (14) above by noting from (17) that
and from (18) that
Therefore, the Euler-Lagrange condition for making the action stationary can be written in terms of as the pair of equations
which is just (16) and represents the act of carrying out the Legendre transform, and
which from (20) and (21) represents the Euler-Lagrange condition expressed in terms of the Hamiltonian. These two first-order ODEs are usually referred to as Hamilton’s equations, and are often more convenient to solve than the second-order ODEs arising in Lagrangian mechanics. The fact that the Hamiltonian is expressed in terms and
and represents the total energy of the system also allows geometric insights to be conveniently obtained, e.g., by plotting constant-energy contours for the system in a x-p phase space. All of this means that, when faced with a mechanics problem, we can usually simply state the Hamiltonian as
, then use Hamilton’s equations as the first-order conditions for making the action stationary, as long as we know the kinetic energy
and the potential energy
for the problem in terms of
and
.
In the case of the simple harmonic oscillator, Hamilton’s equations give us
and
From (22) we get
and equating this with (23) we get
which again is the same as the ODE in (6) obtained from Newtonian mechanics.

Finally, it is obvious from the form of the Hamiltonian in (19) that the level sets of for the simple harmonic oscillator, i.e., the constant-energy contours in x-p phase space, will be circular orbits as shown in the diagram.
