Legendre Transform Calculator
Introduction to the Legendre Transform Calculator for Convex Functions
The Legendre transform takes a convex function and recasts it in terms of slope instead of position, which is why it shows up in convex analysis, mechanics, thermodynamics, and optimization. This calculator evaluates that dual value for a single-variable function at a chosen slope, so you can see both the tangent-line interpretation and the numeric result without working through the algebra by hand. Enter a function that can be differentiated, choose a slope , and supply an initial guess that is close enough for Newton's method to settle on the stationary point.
In practical terms, the tool is looking for the point on your curve where the derivative matches the slope you entered, then it computes the gap between the tangent line and the function value at that point. That makes the calculator useful when you want to check a derivation, compare dual functions, or confirm that a convex function produces the transform you expect. Because the page works with a single expression, it is best suited to textbook-style examples and smooth formulas that math.js can parse and differentiate.
Understanding the Legendre Transform Definition
Given a real-valued convex function , the Legendre transform is defined as:
This means the calculator is searching for the value of that makes the expression as large as possible. Geometrically, that is the same as sliding a line with slope until it just touches the curve of . The Legendre transform then stores the intercept information of that supporting line, which is why the output is often described as the dual of the original function rather than a simple rearrangement of its graph.
Formula: Tangency Condition for the Legendre Transform Calculator
For differentiable convex functions, the maximizing satisfies the condition:
Once this is found, the Legendre transform value is computed as:
The calculator follows exactly that logic: it differentiates your expression, solves numerically, and then evaluates the dual value at the same point. When the function is smooth and the starting guess is sensible, the result is usually stable and easy to interpret. When the derivative is steep, flat, or difficult to invert, the initial guess becomes more important because Newton's method can jump toward a different stationary point or fail to settle at all.
How to Interpret the Legendre Transform Calculator Results
The output is the Legendre transform evaluated at the slope you entered, so it should be read as a slope-domain description of the same convex shape. A larger value means the supporting line with that slope sits farther above the graph after the contact point is chosen, while a smaller value means the curve and tangent are closer together at the maximizing point. In many convex problems, the transform highlights which slopes are compatible with which locations on the original curve, and that correspondence is often the real quantity of interest.
In physics, this slope-based result is what lets a Lagrangian be rewritten as a Hamiltonian, replacing velocity-like variables with momentum-like ones. In optimization, the same dual viewpoint helps compare primal and dual problems, interpret sensitivity to constraints, and reason about how changes in slope move the best-fitting point along the curve. If you are checking a derivation, the most useful thing to compare is not just the final number but also whether the reported makes the derivative condition true.
Worked Example: Quadratic Legendre Transform for x^2/2
Consider the quadratic function:
Its derivative is:
Setting gives . Substituting back, the Legendre transform is:
This is a useful sanity check because the transform of is the same quadratic form in the dual variable. If you enter f(x) = x^2/2 and choose p = 1, the calculator should return the tangency point near and a dual value near . That makes this example a good way to confirm that the derivative condition, the Newton iteration, and the final dual evaluation all line up.
Quadratic examples are especially friendly because the derivative is linear and the supporting line touches the parabola in a very predictable way. If you are learning the transform, they are often the easiest starting point before moving on to exponentials, logs, or piecewise smooth convex functions. The calculator remains most reliable when the starting guess is placed near the expected solution, so a simple example like this is a good first test whenever you are unsure whether your expression is being parsed correctly.
Comparison Table: Legendre Transform vs. Related Dual Transforms
| Transform | Domain | Purpose | Key Property |
|---|---|---|---|
| Legendre Transform | Convex functions | Convert function to slope/momentum domain | Involution for strictly convex, lower semicontinuous functions |
| Fourier Transform | Integrable functions | Convert time/space domain to frequency domain | Linear and invertible |
| Laplace Transform | Functions of exponential order | Analyze system dynamics and differential equations | Transforms convolution into multiplication |
| Fenchel Conjugate | Convex functions | Generalization of Legendre transform in convex analysis | Supports duality in optimization |
Limitations and Assumptions for This Legendre Transform Calculator
- Convexity Required: The Legendre transform is meant for convex functions, where the supporting-line picture makes sense and the dual value behaves predictably. If the curve bends the wrong way in the region you care about, the calculator may still produce a number, but that number may not correspond to the standard convex-analysis transform you expect.
- Differentiability Matters: This calculator assumes the expression can be differentiated so it can solve with Newton's method. Sharp corners, cusps, or other non-differentiable points can make the derivative undefined and leave the iteration without a valid target.
- Initial Guess Sensitivity: The initial value is not just a convenience field; it steers the Newton iteration toward one of the candidate solutions. A poor guess can slow convergence, overshoot the right point, or move the calculation toward a different stationary point than the one you had in mind.
- Single Variable Only: The page is built for one expression in one variable, so it follows the one-dimensional tangent-slope version of the transform. Multivariate versions use gradients, Hessians, and vector slopes, which are outside the scope of this calculator.
- Numerical Approximation: The result is computed iteratively and depends on symbolic differentiation from math.js, so it is still subject to rounding, convergence, and parsing limits. If the expression is highly nonlinear, nearly flat, or poorly conditioned around the solution, it is wise to verify the answer with an alternative derivation or a different starting guess.
Frequently Asked Questions About the Legendre Transform Calculator
What does the initial x guess do in the Legendre transform calculator?
It gives Newton's method a starting point for solving . When the guess is close to the tangency point, the iteration usually settles faster and with less risk of wandering away from the desired root.
Can this Legendre transform calculator handle non-convex functions?
It is designed for convex functions, where the tangent-line interpretation and the dual value behave as expected. If the function is non-convex, the equation may have several stationary points or none, so the result may not represent a true Legendre transform.
Why does the calculator use Newton's method?
The calculator uses Newton's method because the script solves numerically from your entered expression. That approach is fast for smooth functions, but it depends on a usable first derivative, a second derivative, and a starting guess that does not send the iteration into a bad region.
Is the Legendre transform reversible?
For functions that are strictly convex and lower semicontinuous, taking the transform twice gives back the original function. In practice, that means the dual captures the same shape information from the slope side, not just a one-way summary.
Can I save or export the Legendre transform result?
The page includes a Copy Result button so you can copy the displayed and values into notes or another document. That keeps the tangency point and dual value together without retyping them.
How does the Legendre transform connect to physics?
In classical mechanics, the Legendre transform rewrites a system from a velocity-based Lagrangian to a momentum-based Hamiltonian. That change of variables is one reason the same mathematical idea appears in mechanics, thermodynamics, and optimization.
Arcade Mini-Game: Legendre Transform Calculator Calibration Run
Use this quick arcade run to practice separating useful scenario inputs from common planning mistakes before you rely on the calculator output.
Start the game, then use your pointer or arrow keys to catch useful inputs and avoid bad assumptions.
