Calculus & Analysis

Legendre Transform

Calculates the Legendre transform of a strictly convex quadratic function.

By Riano · Published · Updated · Report a correction

Legendre Transform

Concept Overview

The Legendre transform is an operation that transforms a strictly convex function into another function, called its convex conjugate or dual function. Instead of representing the original function by its values at specific points, the dual function represents it by its supporting tangent lines.

Worked Example

Let's calculate the Legendre transform for a specific quadratic function. Consider f(x) = 0.5 * x2. Here, the quadratic coefficient a = 1, and the linear coefficient b = 0. We want to find its dual function f*(p) at a slope p = 2.

  1. Identify the parameters: a = 1, b = 0. So, f(x) = x2 / 2.
  2. Form the expression to maximize: We want to maximize px - f(x) over all x. For p = 2, the expression is 2x - 0.5x2.
  3. Find the critical point (maximizer x*): Take the derivative with respect to x and set it to 0: p - f'(x) = 0, which means p = ax + b. Substituting our values: 2 = 1 * x + 0. Therefore, x* = 2.
  4. Calculate f*(p): Substitute x* back into the expression: f*(2) = 2 * (2) - 0.5 * (2)2 = 4 - 2 = 2.
  5. Calculate the probe gap: Let's test an independent probe position, z = 0. The Fenchel gap is defined as f(z) + f*(p) - pz. Here, f(0) = 0, f*(2) = 2, and pz = 2 * 0 = 0. The gap is 0 + 2 - 0 = 2.

Experiment

You can interact with the Legendre Transform module to see these calculations in action.

  1. Set Quadratic coefficient a to 1.
  2. Set Linear coefficient b to 0.
  3. Set Dual slope p to 2.
  4. Set Probe position z to 0.
  5. Observe the results: The Maximizer x* is 2, f*(p) is 2, and the Probe gap is 2, matching our manual calculation. The original graph shows f(x) and its supporting tangent at x=2, and the dual graph shows f*(p).
  6. Set Quadratic coefficient a to 2, Linear coefficient b to 1, Dual slope p to 3 and Probe position z to 1. The contact is x* = 1, dual value 1 and gap 0.
  7. Set Quadratic coefficient a to 0.5, Linear coefficient b to -1, Dual slope p to 0 and Probe position z to 0. The contact is x* = 2, dual value 1 and gap 1.
  8. Keep a = 0.5, set b = -2, p = 4 and z = 0 using the same labelled controls. The maximizer is 12 and the dual value is 36. The original view includes that contact outside the probe's [-4,4] input range.
  9. Set Quadratic coefficient a to 0. The visible strict-convexity error replaces results. Restore a = 1, set b = 1, p = 1 and z = 0: the maximizer, dual value and gap are all 0. Pan, then choose Reset view; values remain unchanged.

Limitations

This model demonstrates the Legendre transform specifically for strictly convex quadratic functions of a single real variable, f(x) = (a/2)x2 + bx. It assumes the domain is all real numbers. If the function is not strictly convex (e.g., a = 0), the transform is not well-defined in this simple unconstrained setting for all p, and the UI will show an error. The model does not implement symbolic differentiation or transformation of arbitrary non-quadratic or non-convex functions. The identity f(z) + f*(p) - pz = a(z - x*)2/2 shows that the gap is nonnegative and vanishes at the contact. The plots auto-fit independently and pixel angles are not measurements. Calculations are performed using standard double-precision floating-point arithmetic, which may introduce minor rounding errors for very large or small inputs.

References

The following reference discusses the mechanics and interpretations of Legendre transforms.

Experience it interactively

Adjust parameters, observe in real time, and build deep intuition with Riano’s interactive Legendre Transform module.

Try Legendre Transform on Riano →

More in Calculus & Analysis