All problems
Legendre Transform Value
Problem
The Legendre transform of f(x) = a*x^2 / 2 with a > 0 is f*(p) = sup over x of (p*x - f(x)).
Maximizing gives x = p/a and f*(p) = p^2 / (2*a). Given a and p, return f*(p).
Hint
Set f'(x) = p and substitute back into p*x - f(x).
Test cases
case 1
in: [1,2]
expected: 2
case 2
in: [2,3]
expected: 2.25
case 3
in: [4,0]
expected: 0
case 4
in: [0.5,1]
expected: 1
case 5
in: [1,-3]
expected: 4.5
Starter codePython
def legendre_transform(a, p):
# Your code here
pass5 test cases · run your code against them in the editor