Skip to content
DeepForgeby svx
All problems
MediumCalculusca-217

Fenchel Duality Gap

Problem

The Fenchel-Young inequality states f(x) + f*(y) >= x*y for all x, y, with equality when y is a subgradient of f at x.

For f(x) = 0.5*x^2 with f*(y) = 0.5*y^2, the gap is f(x) + f*(y) - x*y = 0.5*(x - y)^2. Given x and y, return this gap.

Hint

The gap is zero exactly when y = f'(x) = x.

Test cases

case 1
in: [1,1]
expected: 0
case 2
in: [1,0]
expected: 0.5
case 3
in: [-2,3]
expected: 12.5
case 4
in: [0,0]
expected: 0
Starter codePython
def fenchel_duality_gap(x, y):
    # Your code here
    pass

4 test cases · run your code against them in the editor