TExcelTAD
Home › Optimization › Weak and Strong Duality

Weak and Strong Duality

Weak duality, d∗≤p∗d^* \le p^*, always holds. Strong duality, d∗=p∗d^* = p^*, 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 (f0f_0, fif_i convex, hjh_j affine), strong duality holds if Slater's condition holds: there is a strictly feasible point,

∃ x:fi(x)<0 for all i,Ax=b\exists\,\mathbf{x}: \quad f_i(\mathbf{x}) < 0 \ \text{for all } i, \qquad A\mathbf{x} = \mathbf{b}

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 x2+y2x^2 + y^2 subject to (x−2)2+(y−1)2≤1(x - 2)^2 + (y - 1)^2 \le 1. The disk has interior points, so Slater holds. The dual has one multiplier; maximize it numerically and compare:

python · try it yourself
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 x\mathbf{x} is primal feasible and (λ,ν)(\boldsymbol{\lambda}, \boldsymbol{\nu}) is dual feasible, then

f0(x)−p∗≤f0(x)−g(λ,ν)f_0(\mathbf{x}) - p^* \le f_0(\mathbf{x}) - g(\boldsymbol{\lambda}, \boldsymbol{\nu})

The right-hand side, the duality gap of the pair, is computable without knowing p∗p^*. It is a rigorous stopping test: when the gap is below 10−810^{-8}, the current point is within 10−810^{-8} of optimal. Interior-point solvers drive this gap to zero.

python · try it yourself
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 x∗\mathbf{x}^*, (λ∗,ν∗)(\boldsymbol{\lambda}^*, \boldsymbol{\nu}^*) are primal and dual optimal, then

f0(x∗)=g(λ∗,ν∗)≤L(x∗,λ∗,ν∗)≤f0(x∗)f_0(\mathbf{x}^*) = g(\boldsymbol{\lambda}^*, \boldsymbol{\nu}^*) \le \mathcal{L}(\mathbf{x}^*, \boldsymbol{\lambda}^*, \boldsymbol{\nu}^*) \le f_0(\mathbf{x}^*)

so both inequalities are equalities. The first says x∗\mathbf{x}^* minimizes the Lagrangian (stationarity); the second says ∑iλi∗fi(x∗)=0\sum_i\lambda_i^*f_i(\mathbf{x}^*) = 0 (complementary slackness). That is the KKT system, derived from duality.

Saddle-point view

Strong duality is equivalent to the min-max equality

min⁡xmax⁡λ≥0L(x,λ)=max⁡λ≥0min⁡xL(x,λ)\min_{\mathbf{x}}\max_{\boldsymbol{\lambda} \ge 0}\mathcal{L}(\mathbf{x}, \boldsymbol{\lambda}) = \max_{\boldsymbol{\lambda} \ge 0}\min_{\mathbf{x}}\mathcal{L}(\mathbf{x}, \boldsymbol{\lambda})

The left side is the primal (the inner max is +∞+\infty for infeasible x\mathbf{x}), 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.value and 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) min⁡x\min x s.t. x2≤1x^2 \le 1; (b) min⁡x\min x s.t. x2≤0x^2 \le 0.

Answer

(a) yes; (b) no.

Solution

(a) x=0x = 0 gives 0<10 < 1. (b) Only x=0x = 0 is feasible, and 0<00 < 0 fails. In (b), p∗=0p^* = 0, but g(λ)=inf⁡x(x+λx2)=−14λg(\lambda) = \inf_x(x + \lambda x^2) = -\frac{1}{4\lambda}, 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 g=10.00g = 10.00. How far from optimal can the point be?

Answer

At most 0.03.

Solution

10.00≤p∗≤10.0310.00 \le p^* \le 10.03, so f0(x)−p∗≤0.03f_0(\mathbf{x}) - p^* \le 0.03.

Exercise 3: Solve the dual analytically (code)

For the disk example, the dual optimum satisfies λ1+λc\frac{\lambda}{1 + \lambda}\mathbf{c} on the circle. Solve ∥c∥ (1−λ1+λ)=1\lVert \mathbf{c} \rVert\,(1 - \frac{\lambda}{1 + \lambda}) = 1 for λ\lambda and compare with the grid search.

Answer

λ=∥c∥−1=5−1≈1.2361\lambda = \lVert \mathbf{c} \rVert - 1 = \sqrt{5} - 1 \approx 1.2361.

Solution

∥c∥/(1+λ)=1\lVert \mathbf{c} \rVert/(1 + \lambda) = 1 gives λ=∥c∥−1\lambda = \lVert \mathbf{c} \rVert - 1.

python · try it yourself
import numpy as np
print(round(float(np.sqrt(5) - 1), 4))
1.2361

Test yourself

Slater's condition requires…

  1. a strictly feasible point for the (non-affine) inequality constraints
  2. an integer solution
  3. a non-convex objective
  4. no equality constraints

The duality gap f0(x)−g(λ,ν)f_0(\mathbf{x}) - g(\boldsymbol{\lambda}, \boldsymbol{\nu}) of a feasible pair…

  1. is an upper bound on the suboptimality of x\mathbf{x}
  2. is always zero
  3. can be negative
  4. requires knowing p∗p^*

Strong duality together with primal and dual optimality implies…

  1. the KKT conditions
  2. that the problem is an LP
  3. that all multipliers are zero
  4. a duality gap