Legendre Transform Calculator

Stephanie Ben-Joseph headshot Stephanie Ben-Joseph

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 p, and supply an initial x 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 f(x), the Legendre transform f^*(p) is defined as:

f^*(p) = supx px - f(x)

This means the calculator is searching for the value of x that makes the expression px - f(x) as large as possible. Geometrically, that is the same as sliding a line with slope p until it just touches the curve of f. 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 x satisfies the condition:

f'(x) = p

Once this x is found, the Legendre transform value is computed as:

f^*(p) = px - f(x)

The calculator follows exactly that logic: it differentiates your expression, solves f'(x) = p 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 f^*(p) 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 x makes the derivative condition f'(x) = p true.

Worked Example: Quadratic Legendre Transform for x^2/2

Consider the quadratic function:

f(x) = x22

Its derivative is:

f'(x) = x

Setting f'(x) = p gives x = p. Substituting back, the Legendre transform is:

f^*(p) = pā‹…p - p22 = p22

This is a useful sanity check because the transform of x^2/2 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 x = 1 and a dual value near 1/2. 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

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 f'(x) = p. 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 f'(x) = p 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 f'(x) = p 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 x and f^*(p) 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.

Enter function and slope.

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.

Score: 0 Timer: 30s Best: 0

Start the game, then use your pointer or arrow keys to catch useful inputs and avoid bad assumptions.