Weak and Strong Duality
Weak duality, , always holds. Strong duality, , is what makes duality useful: the dual then certifies optimality, its solution gives the KKT multipliers, and you may solve whichever problem is easier. This lesson says when strong duality holds and what the duality gap tells a solver.
Slater's condition
For a convex problem (, convex, affine), strong duality holds if Slater's condition holds: there is a strictly feasible point,
Affine inequalities need not be strict, so for LPs feasibility alone is enough. Without convexity there is no such guarantee (the partitioning example of the previous lesson had a gap), and without a constraint qualification even a convex problem can have one, though that is rare in practice.
A convex problem where the gap closes
Minimize subject to . The disk has interior points, so Slater holds. The dual has one multiplier; maximize it numerically and compare:
import numpy as np
# L(x, lam) = |x|^2 + lam (|x - c|^2 - 1); minimizer x = lam c / (1 + lam)
c = np.array([2.0, 1.0])
def g(lam):
x = lam * c / (1 + lam)
return x @ x + lam * ((x - c) @ (x - c) - 1)
lams = np.linspace(0, 10, 100001)
vals = np.array([g(l) for l in lams])
k = np.argmax(vals)
p_star = (np.linalg.norm(c) - 1)**2 # distance from origin to the disk, squared
print("d* =", round(float(vals[k]), 6), " at lambda =", round(float(lams[k]), 4))
print("p* =", round(float(p_star), 6))d* = 1.527864 at lambda = 1.2361
p* = 1.527864
Certificates and the duality gap
If is primal feasible and is dual feasible, then
The right-hand side, the duality gap of the pair, is computable without knowing . It is a rigorous stopping test: when the gap is below , the current point is within of optimal. Interior-point solvers drive this gap to zero.
import numpy as np
# Projected gradient on the disk problem, with a dual bound computed at each step.
c = np.array([2.0, 1.0])
x = np.array([2.0, 2.0]) # a feasible start on the circle
for k in range(1, 41):
x = x - 0.05 * 2 * x # gradient step on |x|^2
d = x - c
if np.linalg.norm(d) > 1: # project back onto the disk
x = c + d / np.linalg.norm(d)
lam = max(0.0, (x @ (c - x)) / ((x - c) @ (x - c))) # multiplier estimate from stationarity
xl = lam * c / (1 + lam)
gl = xl @ xl + lam * ((xl - c) @ (xl - c) - 1)
if k % 8 == 0:
print(f"iter {k:2d}: f = {x @ x:.6f}, dual bound = {gl:.6f}, gap = {x @ x - gl:.1e}")iter 8: f = 1.782812, dual bound = 1.520158, gap = 2.6e-01
iter 16: f = 1.535346, dual bound = 1.527858, gap = 7.5e-03
iter 24: f = 1.528079, dual bound = 1.527864, gap = 2.1e-04
iter 32: f = 1.527870, dual bound = 1.527864, gap = 6.2e-06
iter 40: f = 1.527864, dual bound = 1.527864, gap = 1.8e-07
Strong duality and KKT
If strong duality holds and , are primal and dual optimal, then
so both inequalities are equalities. The first says minimizes the Lagrangian (stationarity); the second says (complementary slackness). That is the KKT system, derived from duality.
Saddle-point view
Strong duality is equivalent to the min-max equality
The left side is the primal (the inner max is for infeasible ), the right side the dual. The optimal pair is a saddle point of the Lagrangian. Game theory (minimax strategies) and GAN training are other places where such saddle problems appear.
In software
- CVXPY returns
problem.valueand dual values for each constraint; solvers like MOSEK, Clarabel and ECOS report primal and dual objectives and stop on the relative gap. - Gurobi and HiGHS print the "gap" column during MIP solves: the relative distance between the best solution found and the best bound.
Exercises
Exercise 1: Does Slater hold?
(a) s.t. ; (b) s.t. .
Answer
(a) yes; (b) no.
Solution
(a) gives . (b) Only is feasible, and fails. In (b), , but , whose supremum 0 is not attained: strong duality holds only in the limit.
Exercise 2: Gap as a stopping rule
A feasible point has objective 10.03 and a dual-feasible point gives . How far from optimal can the point be?
Answer
At most 0.03.
Solution
, so .
Exercise 3: Solve the dual analytically (code)
For the disk example, the dual optimum satisfies on the circle. Solve for and compare with the grid search.
Answer
.
Solution
gives .
import numpy as np
print(round(float(np.sqrt(5) - 1), 4))1.2361
Test yourself
Slater's condition requires…
- a strictly feasible point for the (non-affine) inequality constraints
- an integer solution
- a non-convex objective
- no equality constraints
The duality gap of a feasible pair…
- is an upper bound on the suboptimality of
- is always zero
- can be negative
- requires knowing
Strong duality together with primal and dual optimality implies…
- the KKT conditions
- that the problem is an LP
- that all multipliers are zero
- a duality gap