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.
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 per unit of , where is the -th inequality function and its price. Feasible points pay nothing extra and infeasible ones pay up, so the dual searches prices that make even the cheapest 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 subject to and , where is the objective, each is one inequality, and each is one equality, form the Lagrangian with prices and free:
The dual function is the cheapest Lagrangian over , written , and the dual problem maximises over . Every dual-feasible pair lower-bounds the primal minimum , so the dual optimum satisfies , which is weak duality and always holds. The saddle view reads : pricing before choosing beats choosing before pricing.
When the gap closes
Strong duality needs convexity plus a regularity condition. Slater's condition is the common one: a strictly feasible convex point with for non-affine inequalities. Then the KKT conditions hold and complementary slackness prices exactly the active walls. Dual ascent, augmented Lagrangians, and decomposition climb when the primal splits across blocks, which is the mechanism behind ADMM.
Worked example
Minimise subject to , written as . The primal optimum is at .
The Lagrangian with price is . Minimising over sets , so , and the dual function is:
Maximise: gives and . Gap zero, matching the diagram bars at 4 and 4. The price reads as sensitivity: loosening to drops the optimum to , a fall of against the first-order prediction .
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.0Dual 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 as a bound only, measure , 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 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: 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.