Skip to content
AI360XpertBeta

Lagrangian Duality

Hard constraints become prices. The Lagrangian adds each violation times its price, and the best prices certify how good any solution can be.

Pricing the bound constraint turns the primal minimum 4 into a dual maximum 4, so the best price 4 certifies optimality with zero gap.
Pricing the bound constraint turns the primal minimum 4 into a dual maximum 4, so the best price 4 certifies optimality with zero gap.

Why Does This Exist?

Constrained problems are hard to certify. Claiming 4 is optimal needs proof that no feasible 3.9 exists, and enumerating feasibility is hopeless at scale. Duality manufactures certificates cheaply: any dual-feasible price vector yields a lower bound with no enumeration.

This page is the pricing view with gaps and certificates. The equality-only tangency mechanism lives in Lagrange multipliers. The full constrained-to-dual story with the SVM dual and the kernel trick lives in constrained optimisation and duality. The four-condition inequality test lives in KKT conditions and is checked step by step in optimality conditions. Convexity background lives in convex optimization, and the splitting algorithm that climbs the dual lives in ADMM.

The prerequisite is one idea: pricing a violation means charging λi≥0\lambda_i \ge 0 per unit of fi(x)>0f_i(x) > 0, where fif_i is the ii-th inequality function and λi\lambda_i its price. Feasible points pay nothing extra and infeasible ones pay up, so the dual searches prices that make even the cheapest xx expensive.

Think of It Like This

Parking fines instead of gates

A lot owner can gate every spot or set fines so parking elsewhere beats violating. Gating is the primal route: enforce each constraint directly. Fines are the dual route: price each violation and let drivers sort themselves out.

Any fine schedule yields a revenue lower bound without checking each car, which is weak duality. Well-set fines empty violations exactly, which is strong duality with zero gap. Weak fines leave tolerated cheating, which is a positive gap.

Where it stops: fines need collection power. An ungoverned lot ignores prices, and in optimisation that missing power is a failed constraint qualification, where no price schedule certifies the optimum.

How It Actually Works

For minimise f0(x)f_0(x) subject to fi(x)≤0f_i(x) \le 0 and hj(x)=0h_j(x) = 0, where f0f_0 is the objective, each fif_i is one inequality, and each hjh_j is one equality, form the Lagrangian with prices λ≥0\lambda \ge 0 and ν\nu free:

L(x,λ,ν)=f0(x)+∑iλifi(x)+∑jνjhj(x)L(x, \lambda, \nu) = f_0(x) + \sum_i \lambda_i f_i(x) + \sum_j \nu_j h_j(x)

The dual function is the cheapest Lagrangian over xx, written g(λ,ν)=inf⁡xLg(\lambda, \nu) = \inf_x L, and the dual problem maximises gg over λ≥0\lambda \ge 0. Every dual-feasible pair lower-bounds the primal minimum p⋆p^{\star}, so the dual optimum d⋆d^{\star} satisfies d⋆≤p⋆d^{\star} \le p^{\star}, which is weak duality and always holds. The saddle view reads sup⁡λ≥0,νinf⁡xL≤inf⁡xsup⁡λ≥0,νL\sup_{\lambda \ge 0, \nu} \inf_x L \le \inf_x \sup_{\lambda \ge 0, \nu} L: pricing before choosing beats choosing before pricing.

When the gap closes

Strong duality d⋆=p⋆d^{\star} = p^{\star} needs convexity plus a regularity condition. Slater's condition is the common one: a strictly feasible convex point with fi(x)<0f_i(x) < 0 for non-affine inequalities. Then the KKT conditions hold and complementary slackness prices exactly the active walls. Dual ascent, augmented Lagrangians, and decomposition climb gg when the primal splits across blocks, which is the mechanism behind ADMM.

Worked example

Minimise x2x^2 subject to x≥2x \ge 2, written as 2−x≤02 - x \le 0. The primal optimum is p⋆=4p^{\star} = 4 at x=2x = 2.

The Lagrangian with price λ≥0\lambda \ge 0 is L=x2+λ(2−x)L = x^2 + \lambda(2 - x). Minimising over xx sets 2x−λ=02x - \lambda = 0, so x=λ/2x = \lambda/2, and the dual function is:

g(λ)=2λ−λ2/4g(\lambda) = 2\lambda - \lambda^2/4

Maximise: g′=2−λ/2=0g' = 2 - \lambda/2 = 0 gives λ⋆=4\lambda^{\star} = 4 and d⋆=8−4=4d^{\star} = 8 - 4 = 4. Gap zero, matching the diagram bars at 4 and 4. The price reads as sensitivity: loosening to x≥1.9x \ge 1.9 drops the optimum to 1.92=3.611.9^2 = 3.61, a fall of 0.390.39 against the first-order prediction 4×0.1=0.44 \times 0.1 = 0.4.

Code

The snippet scans the dual curve with only the standard library and confirms the hand calculation.

def g(lam: float) -> float:    return 2 * lam - lam ** 2 / 4

grid = [i * 0.5 for i in range(17)]  # 0.0 to 8.0best = max(grid, key=g)print(round(g(best), 2))  # -> 4.0print(round(best, 1))  # -> 4.0print(round(1.9 ** 2, 2))  # -> 3.61print(round(2.0 ** 2, 2))  # -> 4.0

Dual peak 4.0 at price 4.0 matches primal 4.0, and the relaxed bound 3.61 confirms the sensitivity reading.

Watch Out For

Assuming zero gap without convexity

On non-convex problems the dual can sit far below the primal, and integer programs routinely show large gaps. Rounding the dual up as optimal ships points certified by nothing.

The symptom is a dual value quoted as the answer with no gap reported. Quote d⋆d^{\star} as a bound only, measure p⋆−d⋆p^{\star} - d^{\star}, and switch to branch-and-bound or tracked convex relaxations when the gap will not close.

Dualising into a harder algorithm

Moving coupling constraints into prices can destroy separability a solver exploited, or create a nonsmooth dual needing bundle or augmented methods. Naive dual ascent then crawls or oscillates on step sizes.

The symptom is dual values that bounce instead of climbing. Match the method to dual smoothness with subgradient or augmented Lagrangian steps such as ADMM, and treat the step size as the first suspect when values oscillate.

The Quick Version

  • The Lagrangian prices violations and the dual maximum always lower-bounds the primal minimum.
  • The scalar example minimising x2x^2 above 2 gives primal 4 and dual 4 at price 4 with zero gap.
  • Convexity plus Slater closes the gap, and then KKT holds with priced active walls.
  • Each price is a sensitivity: λi\lambda_i values relaxing one unit of its wall.
  • Non-convex gaps stay open, so report dual values as bounds with measured gaps.
  • Climb nonsmooth duals with stabilised methods such as ADMM, not raw ascent.