On this page
You meet the Legendre transform twice in physics: when the Lagrangian becomes the Hamiltonian, and when internal energy becomes enthalpy or Gibbs energy. Both times it does the same job: it swaps the variable a function depends on for the slope of that function.
What is the Legendre transform?
For a convex function f(x), the Legendre transform is f*(p) = max over x of (px − f(x)), a new function of the slope p instead of the point x (Legendre transformation, Wikipedia). The same article records that Adrien-Marie Legendre introduced it in 1787 while studying the minimal surface problem.
To compute it, differentiate px − f(x) with respect to x and set the result to zero: f′(x) = p. So you find the point where the curve's slope equals p, then evaluate px − f(x) there. Strict convexity makes that point unique, because the slope of a strictly convex function keeps increasing (see Jensen's inequality and convex functions for a refresher).
What does the Legendre transform mean geometrically?
The diagram above shows two pictures for f(x) = x²/2 with p = 1.5.
The gap. px − f(x) is the vertical gap between the line y = px and the curve. f*(p) is the largest gap, reached exactly where the curve runs parallel to the line.
The intercept. The tangent to the curve with slope p crosses the y-axis at −f*(p), as the Wikipedia article shows.
So f* is a catalogue of tangent lines, labelled by slope. A convex curve is traced out by its tangents, which is why nothing is lost in the swap.
Worked examples: x²/2 and eˣ
Example 1: f(x) = x²/2.
Maximise px − x²/2. The derivative is p − x = 0, so x = p.
Substitute: f*(p) = p·p − p²/2 = p²/2.
This function is its own transform. Keep that in mind for mechanics: kinetic energy ½mv² and p²/2m are the same pair.
Example 2: f(x) = eˣ.
The derivative of px − eˣ is p − eˣ = 0, so x = ln p. This needs p > 0, because eˣ never has a zero or negative slope.
Substitute: f*(p) = p ln p − p, defined for p > 0.
Now go back. Maximise xp − (p ln p − p) over p: x − ln p = 0 gives p = eˣ, and the value is xeˣ − xeˣ + eˣ = eˣ, matching the Wikipedia article.
Why is the Legendre transform its own inverse?
Differentiate f*(p) = px − f(x), remembering that x depends on p. The terms involving dx/dp cancel because f′(x) = p, leaving (f*)′(p) = x. The slope of f* at p is the point where f had slope p. Slopes and points have traded places, so a second transform trades them back: for convex f, f** = f (Legendre transformation, Wikipedia).
Convexity matters. Without it, two points can share a slope and the swap is ambiguous. The general version, called the convex conjugate or Legendre–Fenchel transform, still works, and the same article notes it can be used to build a function's convex hull: the curve with its dents filled in.
How is the Legendre transform used in mechanics and thermodynamics?
Mechanics. Take L(q, v) = ½mv² − V(q). The momentum is p = ∂L/∂v = mv. The Legendre transform in v gives the Hamiltonian H = pv − L = p²/2m + V(q), the total energy written in terms of momentum (Legendre transformation, Wikipedia). The Lagrangian side comes from the Euler–Lagrange equation, worked step by step.
Thermodynamics. Internal energy U depends on entropy S and volume V, and entropy in particular is hard to control directly in a lab. Swapping V for pressure gives enthalpy H = U + PV; swapping S for temperature gives the Helmholtz energy F = U − TS and the Gibbs energy G = H − TS. Per Wikipedia, enthalpy suits controlled pressure, Helmholtz controlled temperature and volume, Gibbs controlled temperature and pressure. Signs here differ from the maths definition, so follow your book's convention.
In Making sense of the Legendre transform (American Journal of Physics, 2009), R. K. P. Zia, Edward Redish and Susan McKay present the transform as a way of choosing independent variables that are more easily controlled. That is the idea behind the Gibbs energy, and our post on why reactions stop at the Gibbs energy minimum shows it at work.
A four-step recipe you can reuse
Check strict convexity: f′(x) keeps increasing (f″ > 0, allowing isolated zeros like x⁴/4 at 0).
Solve f′(x) = p for x, and note which values of p are allowed.
Substitute: f*(p) = p·x − f(x) at that x.
Check that (f*)′(p) equals your x, then transform back.
Try it on f(x) = x⁴/4. Step 2 gives x = p^(1/3), and step 3 gives f*(p) = (3/4)|p|^(4/3). Do step 4 yourself before reading on.
If the derivative or convexity steps feel uncertain, the Fermi Concept Library covers every concept in physics, chemistry, biology, mathematics and computing. For practice, the Fermi Problem Library has a step-by-step solver that explains the reasoning rather than printing an answer.



