Legendre Transform
Convex Conjugate · Fenchel Transform
Advanced (graduate level)
1. Introduction
The Legendre transform is a transformation that re-describes a convex function in terms of a different variable — the dual variable corresponding to its slope. By focusing not on the values of the function themselves but on the relationship between the slope and intercept of its tangent lines, one can naturally interchange the independent variable. Introduced in the eighteenth century by Adrien-Marie Legendre, this transform is today a foundation of a wide range of fields, including Hamiltonian mechanics, thermodynamics, and convex optimization.
In this article we first give the definition for a convex function of one variable and clarify its geometric meaning, and then establish basic properties such as the involution property and the preservation of convexity. We further treat the generalization to several variables and applications in physics and optimization.
2. Definition
Legendre Transform (Convex Conjugate)
For a function $f: \mathbb{R} \to \mathbb{R} \cup \{+\infty\}$, its Legendre transform (convex conjugate, or Fenchel conjugate) is defined by
$$f^*(p) = \sup_{x \in \mathbb{R}} \bigl( px - f(x) \bigr)$$Here $p$ is called the dual variable (or conjugate variable).
Throughout this article we use "Legendre transform" in the generalized sense of the convex conjugate (the Legendre–Fenchel transform) defined by the supremum above. Strictly speaking, the classical "Legendre transform" refers to the case where $f$ is differentiable and strictly convex, so that $p = f'(x)$ can be solved to write $f^*(p) = px - f(x)$ explicitly; the extension to general convex functions via the supremum is sometimes distinguished as the Legendre–Fenchel transform (convex conjugate). The two coincide in the smooth, strictly convex case.
The supremum ($\sup$) rather than a maximum ($\max$) is used because for a general convex function the maximum need not exist.
When $f$ is a differentiable strictly convex function, the supremum is attained, as a genuine maximum, at the point $x = x(p)$ satisfying $p = f'(x)$. In this case
$$f^*(p) = p\, x(p) - f\bigl(x(p)\bigr)$$holds. That is, the relation $p = f'(x)$ puts $x$ and $p$ in one-to-one correspondence, and the independent variable is switched from $x$ to $p$.
3. Geometric Interpretation
The geometric meaning of the Legendre transform is transparent. Maximizing the difference $px - f(x)$ between the line $y = px$ of slope $p$ and the function $y = f(x)$ is nothing other than finding (the sign-reversed) $y$-intercept of the line of slope $p$ that is tangent to the graph of $f$.
Figure 1: Geometric interpretation
The $y$-intercept of the tangent line of slope $p$ is $f(x_0) - p x_0 = -f^*(p)$. That is, $f^*(p)$ equals the sign reversal of the tangent line's intercept. The essence of the Legendre transform is to describe the function $f$ by "the intercepts of its family of tangent lines" instead of by "its pointwise values."
From the line $px$ to the tangent line — why the intercept appears
The term $px$ appearing in the definition is the line $y = px$ of slope $p$ through the origin. For each point $x$, the quantity $px - f(x)$ is nothing other than the vertical difference (gap) obtained by subtracting the height $f(x)$ of the curve from the height $px$ of this line. Therefore $f^*(p) = \sup_{x}\,\bigl( px - f(x) \bigr)$ measures "how wide, at most, the vertical gap between the line $y = px$ and the curve $y = f(x)$ opens up as $x$ varies."
At the point $x_0$ where the gap is maximal, the derivative of $px - f(x)$ with respect to $x$, namely $\dfrac{d}{dx}\bigl( px - f(x) \bigr) = p - f'(x)$, vanishes. That is,
$$ f'(x_0) = p $$holds, and the gap is maximal at the point where the slope of the tangent to the curve coincides exactly with $p$. That maximal gap is precisely $f^*(p) = p\,x_0 - f(x_0)$.
It should be noted here that the red dashed line in Figure 1 is not the line $y = px$ of the definition itself. As one translates the line $y = px$ straight downward while keeping its slope, it eventually becomes tangent to the convex curve from below. Stopping it at the very moment it touches yields the tangent line in the figure, and the amount by which it was lowered is exactly the maximal gap $f^*(p)$. Hence the equation of the tangent line is
$$ y = px - f^*(p) $$Thus $y = px$ and the tangent line are two parallel lines with the same slope $p$, and the constant vertical separation between them is $f^*(p)$. Consequently the $y$-intercept of the tangent line (its height at $x = 0$) is $-f^*(p)$, shifted below the origin. This is the reason "the line in the figure does not pass through the origin." Indeed, substituting $x = 0$ into the tangent line $y = f(x_0) + p(x - x_0)$ confirms that the intercept is $f(x_0) - p\,x_0 = -\bigl( p\,x_0 - f(x_0) \bigr) = -f^*(p)$.
In summary, the Legendre transform $f^*(p)$ can be understood as three restatements of the same quantity.
- The maximal vertical gap between the line $y = px$ and the curve $y = f(x)$.
- The distance by which the line $y = px$ of slope $p$ is lowered until it becomes tangent to the curve.
- The sign-reversed $y$-intercept of the tangent line of slope $p$.
4. Involution
Fenchel-Moreau Theorem (Involution)
If $f: \mathbb{R}^n \to \mathbb{R} \cup \{+\infty\}$ is a lower semicontinuous proper convex function, then
$$f^{**} = f$$holds. That is, the Legendre transform is an involution.
Sketch of proof (one-variable case)
By definition,
$$f^{**}(x) = \sup_{p} \bigl( px - f^*(p) \bigr) = \sup_{p} \Bigl( px - \sup_{y}\bigl(py - f(y)\bigr) \Bigr)$$For all $p, y$ we have $px - (py - f(y)) = p(x-y) + f(y) \geq f(x)$ (by convexity), so $f^{**}(x) \leq f(x)$. On the other hand, substituting $p = f'(x)$ attains equality, hence $f^{**}(x) = f(x)$.
This is only the sketch for a differentiable, strictly convex function. A complete proof for a general lower semicontinuous proper convex function (without assuming differentiability) requires the separating hyperplane theorem of convex analysis, used to show that the epigraph of $f$ is the upper envelope of its supporting (affine minorant) lines.
Figure 2: Involution $f \to f^* \to f$
Applying the transform $\mathcal{L}$ twice returns the original function. This corresponds to decomposing the function into its family of tangent lines and then recovering the function as the envelope of that family.
5. Properties
Preservation of Convexity
$f^*(p)$ is always a convex function (regardless of whether $f$ is convex or not).
Proof
For each $x$, the function $g_x(p) = px - f(x)$ is an affine function of $p$ (both convex and concave). Since $f^*(p) = \sup_x g_x(p)$ is a supremum of convex functions, and the pointwise supremum of convex functions is convex, $f^*$ is convex.
Duality of Variables
When $f$ is a differentiable strictly convex function, the following duality relation holds:
$$p = f'(x) \quad \Longleftrightarrow \quad x = (f^*)'(p)$$That is, the derivatives of $f$ and $f^*$ are inverse functions of each other.
Proof
Since $f$ is a differentiable strictly convex function, the point $x$ attaining the supremum $f^*(p) = \sup_x\bigl(px - f(x)\bigr)$ satisfies $\dfrac{d}{dx}\bigl(px - f(x)\bigr) = p - f'(x) = 0$, that is,
$$p = f'(x)$$and it is the unique point $x = x(p)$ satisfying this (by strict convexity $f'$ is strictly increasing, hence bijective, and $x(p) = (f')^{-1}(p)$). Using this $x(p)$, differentiating $f^*(p) = p\,x(p) - f\bigl(x(p)\bigr)$ with respect to $p$ and noting that $f'\bigl(x(p)\bigr) = p$ gives
$$(f^*)'(p) = x(p) + p\,x'(p) - f'\bigl(x(p)\bigr)\,x'(p) = x(p) + \bigl(p - f'(x(p))\bigr)x'(p) = x(p)$$Since $x(p) = x$, we have $x = (f^*)'(p)$. The converse follows in the same way, so $p = f'(x) \Leftrightarrow x = (f^*)'(p)$ holds. This means that $(f^*)' = (f')^{-1}$, i.e., $f'$ and $(f^*)'$ are inverse functions of each other. $\blacksquare$
Young's Inequality
For all $x, p$,
$$f(x) + f^*(p) \geq px$$holds. Equality holds if and only if $p = f'(x)$.
Proof
Since the definition $f^*(p) = \sup_{y}\bigl(py - f(y)\bigr)$ is a supremum over $y$, it is in particular at least the value at $y = x$:
$$f^*(p) \;\geq\; px - f(x).$$Rearranging gives $f(x) + f^*(p) \geq px$. Equality holds when the supremum is attained at $y = x$, that is, when $py - f(y)$ attains its maximum at $y = x$. If $f$ is convex, then $py - f(y)$ is concave, so the condition for the maximum is the stationarity condition $\dfrac{d}{dy}\bigl(py - f(y)\bigr)\big|_{y=x} = p - f'(x) = 0$, i.e., it is equivalent to $p = f'(x)$. Hence equality holds if and only if $p = f'(x)$. $\blacksquare$
Scaling Rules
- If $g(x) = \lambda f(x)$ ($\lambda > 0$), then $g^*(p) = \lambda\, f^*\!\left(\dfrac{p}{\lambda}\right)$
- If $g(x) = f(x) + c$, then $g^*(p) = f^*(p) - c$
- If $g(x) = f(x - a)$, then $g^*(p) = f^*(p) + ap$
Proof
In each case the result follows by substituting into the definition $g^*(p) = \sup_x\bigl(px - g(x)\bigr)$ and simply pulling constants or substitutions outside the supremum.
(1) $g(x) = \lambda f(x)$ ($\lambda > 0$): the positive constant $\lambda$ can be factored out of the supremum, so
$$g^*(p) = \sup_x\bigl(px - \lambda f(x)\bigr) = \lambda \sup_x\Bigl(\tfrac{p}{\lambda}\,x - f(x)\Bigr) = \lambda\, f^*\!\Bigl(\tfrac{p}{\lambda}\Bigr).$$(2) $g(x) = f(x) + c$: the constant $c$ does not depend on $x$, so it comes outside the supremum and
$$g^*(p) = \sup_x\bigl(px - f(x) - c\bigr) = \sup_x\bigl(px - f(x)\bigr) - c = f^*(p) - c.$$(3) $g(x) = f(x - a)$: substituting $y = x - a$ ($x = y + a$) gives
$$g^*(p) = \sup_x\bigl(px - f(x-a)\bigr) = \sup_y\bigl(p(y+a) - f(y)\bigr) = \sup_y\bigl(py - f(y)\bigr) + ap = f^*(p) + ap.$$$\blacksquare$
6. Examples
Example 1: $f(x) = x^2$
From $p = f'(x) = 2x$ we get $x = p/2$. Therefore
$$f^*(p) = p \cdot \dfrac{p}{2} - \left(\dfrac{p}{2}\right)^2 = \dfrac{p^2}{2} - \dfrac{p^2}{4} = \dfrac{p^2}{4}$$Check: $(f^*)'(p) = p/2 = x$, which confirms the duality of variables.
Verification of the involution: for $f^*(p) = p^2/4$ we have $f^{**}(x) = \sup_p(px - p^2/4)$. From $\dfrac{d}{dp}(px - p^2/4) = x - p/2 = 0$ we get $p = 2x$, so $f^{**}(x) = 2x \cdot x - (2x)^2/4 = x^2 = f(x)$.
Figure 3: Both $f$ and its conjugate $f^*$ are upward-convex parabolas; the steeper $f$ is (coefficient $1$), the flatter $f^*$ becomes (coefficient $1/4$).
Example 2: $f(x) = e^x$
From $p = f'(x) = e^x > 0$ we get $x = \ln p$ (for $p > 0$).
$$f^*(p) = p \ln p - p \qquad (p > 0)$$For $p \leq 0$ we have $px - e^x \to -\infty$ (as $x \to +\infty$, $e^x$ dominates), so the supremum is not defined and we set $f^*(p) = +\infty$ (or, equivalently, restrict the domain of $f^*$ to $p > 0$).
Figure 4: The conjugate of $f(x)=e^x$ is $f^*(p)=p\ln p - p$ (domain $p>0$, with minimum value $-1$ at $p=1$, and $f^*\to 0$ as $p\to 0^+$).
Example 3: $f(x) = |x|^p / p$ ($p > 1$)
With $q = p/(p-1)$ (the Hölder conjugate exponent),
$$f^*(s) = \dfrac{|s|^q}{q}$$This corresponds to the equality condition of Young's inequality $|xs| \leq |x|^p/p + |s|^q/q$.
Figure 5: The conjugate of a power function is again a power function, and the exponents $p$ and $q = \dfrac{p}{p-1}$ are in a dual relationship (here $p = 3,\ q = \tfrac{3}{2}$). The flatter the bottom of $f$, the sharper the bottom of the conjugate $f^*$.
7. Generalization to Several Variables
Multivariate Legendre Transform
For $f: \mathbb{R}^n \to \mathbb{R} \cup \{+\infty\}$,
$$f^*(\mathbf{p}) = \sup_{\mathbf{x} \in \mathbb{R}^n} \bigl( \mathbf{p} \cdot \mathbf{x} - f(\mathbf{x}) \bigr)$$where $\mathbf{p} \cdot \mathbf{x} = \displaystyle\sum_{i=1}^n p_i x_i$ is the inner product.
When $f$ is a differentiable strictly convex function, the condition for the supremum is given by the gradient condition
$$\mathbf{p} = \nabla f(\mathbf{x})$$This shows that the Legendre transform interchanges variables through "the inverse of the gradient map $\nabla f$."
As in the one-variable case, the involution property $f^{**} = f$, Young's inequality $f(\mathbf{x}) + f^*(\mathbf{p}) \geq \mathbf{p} \cdot \mathbf{x}$, and the preservation of convexity all hold.
8. Applications
8.1 Hamiltonian Mechanics (from the Lagrangian to the Hamiltonian)
In analytical mechanics, the generalized momentum is defined from the Lagrangian $L(q, \dot{q}, t)$ by
$$p = \dfrac{\partial L}{\partial \dot{q}}$$The Hamiltonian is obtained by the Legendre transform with respect to $\dot{q}$:
$$H(q, p, t) = p\dot{q} - L(q, \dot{q}, t)$$Here the $\dot{q}$ on the right-hand side is replaced by $\dot{q}(q, p, t)$, obtained by solving $p = \partial L / \partial \dot{q}$. The independent variables are switched from $(q, \dot{q})$ to $(q, p)$, and the Euler-Lagrange equation takes the form of the canonical equations
$$\dot{q} = \dfrac{\partial H}{\partial p}, \qquad \dot{p} = -\dfrac{\partial H}{\partial q}$$This makes the symplectic structure on phase space explicit.
8.2 Thermodynamics (transforms of thermodynamic potentials)
In thermodynamics, the internal energy $U(S, V)$ has the entropy $S$ and the volume $V$ as its natural variables. When one wishes to take the temperature $T = \partial U / \partial S$ as an independent variable, performing the Legendre transform with respect to $S$ yields the Helmholtz free energy:
$$F(T, V) = U - TS$$The other thermodynamic potentials are obtained in the same way:
| Potential | Natural variables | Legendre transform |
|---|---|---|
| Internal energy $U$ | $S, V$ | (base) |
| Helmholtz free energy $F$ | $T, V$ | $F = U - TS$ |
| Enthalpy $H$ | $S, P$ | $H = U + PV$ |
| Gibbs free energy $G$ | $T, P$ | $G = U - TS + PV$ |
The Maxwell relations (e.g., $(\partial T/\partial V)_S = -(\partial P/\partial S)_V$) follow naturally from the symmetry of the second partial derivatives of the Legendre transform.
8.3 Convex Optimization (conjugate duality)
The Fenchel dual problem in convex optimization is based on the Legendre transform. When the primal problem is
$$\min_x \bigl( f(x) + g(Ax) \bigr)$$the dual problem is
$$\max_p \bigl( -f^*(-A^T p) - g^*(p) \bigr)$$Weak duality $d^* \leq p^*$ (dual value $\leq$ primal value) always holds, and under convexity and a constraint qualification, strong duality $d^* = p^*$ holds. Within this framework, solving the dual problem yields the optimal value and the solution of the primal problem.
9. FAQ
Q1. What is the Legendre transform?
It is the transform defined for a convex function $f(x)$ by $f^*(p) = \sup_x(px - f(x))$. Intuitively, it is the operation of re-describing a function by "the slope and intercept of its tangent lines" instead of by "its pointwise values." In physics it is widely used as the transform from the Lagrangian to the Hamiltonian, and in thermodynamics as the transform from internal energy to a free energy.
Q2. Why is the Legendre transform an involution?
Applying the transform twice to a convex function $f$ gives $f^{**}(x) = \sup_p(px - f^*(p))$. Geometrically, this amounts to decomposing the function $f$ into its family of tangent lines ($f \to f^*$) and then recovering the original function as the envelope of that family ($f^* \to f^{**}$). By the Fenchel-Moreau theorem, $f^{**} = f$ is guaranteed whenever $f$ is a lower semicontinuous proper convex function.
Q3. How is the Legendre transform used in physics?
There are two principal applications. (1) Hamiltonian mechanics: taking the Legendre transform of the Lagrangian $L(q, \dot{q})$ with respect to the velocity $\dot{q}$ yields the Hamiltonian $H(q, p) = p\dot{q} - L$. The independent variable changes from velocity to momentum, leading to the symmetric form of the canonical equations. (2) Thermodynamics: taking the Legendre transform of the internal energy $U(S, V)$ with respect to the entropy $S$ yields the Helmholtz free energy $F(T, V) = U - TS$. The practical importance lies in being able to take the temperature $T$, which is easily controlled in experiments, as an independent variable.
Q4. Why does the Legendre transform require convexity?
The Legendre transform (convex conjugate) $f^*$ itself can be defined for any function. However, the involution property $f^{**} = f$ — recovering the original by transforming twice — holds only when $f$ is a lower semicontinuous proper convex function (the Fenchel–Moreau theorem). For a non-convex $f$, the biconjugate $f^{**}$ is the convex envelope of $f$ (the largest convex function below $f$) and does not equal the original $f$. Convexity also guarantees that the function is faithfully represented by its family of tangent (supporting) lines. For these reasons, convex functions are assumed as standard in both theory and applications.
10. References
- Rockafellar, R. T. (1970). Convex Analysis. Princeton University Press.
- Arnold, V. I. (1989). Mathematical Methods of Classical Mechanics, 2nd ed. Springer.
- Callen, H. B. (1985). Thermodynamics and an Introduction to Thermostatistics, 2nd ed. Wiley.
- Boyd, S., & Vandenberghe, L. (2004). Convex Optimization. Cambridge University Press. Online
- Wikipedia: Legendre transformation
- Wikipedia: Convex conjugate