The Legendre transform is a cornerstone of convex analysis and plays a critical role in classical mechanics, optimization, and thermodynamics. Given a real-valued convex function , the Legendre transform produces a new function defined by
Intuitively, we look for the point where the line with slope is tangent to . The Legendre transform then records the intercept of that tangent line on the axis. This construction converts a function of position or configuration into a function of slope or momentum. In physics, this operation translates the Lagrangian into the Hamiltonian, reorienting our view from coordinates to momenta. In optimization, the Legendre transform forms the basis of duality theory, allowing us to solve problems by examining their dual formulations.
For a differentiable convex function, the maximizing in the definition is characterized by the condition . This means that finding requires solving for . Once is known, the transform value is . The resulting function is itself convex. If is strictly convex, then the derivative is invertible, guaranteeing a unique solution for .
In classical mechanics, the Legendre transform converts the Lagrangian into the Hamiltonian by setting and evaluating . This shift reveals conservation laws via Hamilton's equations and is central to the formulation of modern physics. In thermodynamics, Legendre transforms convert between different energy potentials, such as internal energy and enthalpy, depending on which variables (entropy, volume, pressure, etc.) are held fixed.
Our calculator handles general analytic expressions using the math.js
library. After you provide and the slope , it performs the following steps:
The initial guess parameter is important because Newton's method converges only when started close enough to the solution. For strictly convex functions, any reasonable guess will converge, but complicated functions might need experimentation. If the second derivative is zero anywhere, we could run into division by zero or slow convergence. The script caps the iteration count at twenty steps and stops early if the update becomes tiny.
Consider . Differentiation gives . Setting yields . Our calculator reproduces this simple result and demonstrates the algorithm on a function where the exact answer is known.
The Legendre transform extends far beyond basic quadratic examples. In large-deviation theory, it converts cumulant generating functions into rate functions, connecting probability distributions to thermodynamic entropy. In convex optimization, it underlies Fenchel duality and appears whenever Lagrange multipliers enforce constraints. By flipping a function's viewpoint from positions to slopes, we often gain deeper insight into stability and sensitivity.
Mathematically, the Legendre transform is an involution when applied to strictly convex, lower semicontinuous functions. That means ; applying the transform twice brings you back to the original function. This self-duality is elegant and hints at deeper geometric structures. One can think of the transform as reflecting a curve across the line that swaps and , though in a generalized sense.
In physics, Hamilton's principle uses the Legendre transform implicitly when moving from the Lagrangian description (position and velocity) to the Hamiltonian description (position and momentum). The conjugate momentum arises from the derivative of the Lagrangian with respect to velocity, and the Legendre transform yields the energy-like Hamiltonian. This shift permits symplectic geometry and canonical transformations, which elegantly describe the conservation of phase space volume and the architecture of classical trajectories.
Thermodynamics also relies on Legendre transforms to switch between energy potentials depending on which variables are controlled experimentally. The internal energy as a function of entropy and volume can be transformed into the enthalpy by introducing pressure. Similarly, the Helmholtz and Gibbs free energies incorporate temperature and pressure via Legendre transforms. Understanding these conversions is key to analyzing chemical reactions and phase transitions.
The Legendre transform also appears in optimization algorithms, such as mirror descent, which generalizes gradient descent by measuring steps in a dual norm defined by a strongly convex function. The connection between Bregman divergences and Legendre transforms clarifies the geometry of these algorithms, particularly in high-dimensional settings like machine learning.
Our calculator focuses on a single variable for clarity, but the Legendre transform generalizes to multivariate functions by replacing derivatives with gradients and using the dot product in place of multiplication. The resulting computation uses matrix inverses in the second derivative (the Hessian) to solve for the gradient equation. Extending the code to handle multivariate cases would be a fascinating next step, though more numerically involved.
Experiment with different convex functions to appreciate how the transform behaves. Try exponential forms such as or trigonometric versions on restricted domains. Observe how the tangency condition picks out unique points and how the resulting grows or decays. Because convexity guarantees a single tangent at each slope, the Legendre transform elegantly packages global information about into a dual perspective.
Although powerful, the Legendre transform requires convexity to ensure uniqueness. Non-convex functions lead to multiple solutions or none at all. Even with convex functions, if the derivative does not cover the desired slope range, the transform may be undefined. In such cases, we extend the definition using generalized derivatives or consider convex envelopes.
This calculator aims to provide intuition rather than industrial-grade accuracy. Newton's method may fail for complicated functions or poor initial guesses. Nevertheless, it gives a hands-on feel for how Legendre transforms arise from tangency conditions and serve as bridges between dual viewpoints in mathematics and physics.
Perform basic quaternion arithmetic including multiplication, conjugation, and magnitude.
Approximate the zero-order Hankel transform of a radial function using numerical integration.
Compute the discrete Hartley transform of a sequence and explore its relationship to the Fourier transform.