Linear Programming Duality

lean4-proofoptimizationvisualization
mincTx  s.t.  Axb,x0maxbTy  s.t.  ATyc,y0\min c^T x\;\text{s.t.}\;Ax\ge b,x\ge 0 \quad\Longleftrightarrow\quad \max b^T y\;\text{s.t.}\;A^T y\le c,y\ge 0

Statement

Given a primal linear program:

(P)min  cxs.t.Axb,  x0,\text{(P)}\quad \min\; c^\top x \quad \text{s.t.}\quad Ax \ge b,\; x \ge 0,

its dual is:

(D)max  bys.t.Ayc,  y0.\text{(D)}\quad \max\; b^\top y \quad \text{s.t.}\quad A^\top y \le c,\; y \ge 0.

Weak duality holds always: for any primal-feasible xx and dual-feasible yy, bycxb^\top y \le c^\top x.

Strong duality (LP duality theorem): if both programs are feasible and bounded, their optimal values coincide, by=cxb^\top y^* = c^\top x^*.

Visualization

2x2 example. Primal: min  x1+2x2\min\; x_1 + 2x_2 s.t. x11x_1 \ge 1, x21x_2 \ge 1, x1,x20x_1, x_2 \ge 0.

Dual: max  y1+y2\max\; y_1 + y_2 s.t. y11y_1 \le 1, y22y_2 \le 2, y1,y20y_1, y_2 \ge 0.

Primal optimal: x1=1,x2=1x_1^* = 1, x_2^* = 1, objective =1+2=3= 1 + 2 = 3.

Dual optimal: y1=1,y2=2y_1^* = 1, y_2^* = 2, objective =1+2=3= 1 + 2 = 3. Duality gap =0= 0

Solution typex1x_1x2x_2primal obj x1+2x2x_1 + 2x_2
Primal feas.125
Primal opt.113
Solution typey1y_1y2y_2dual obj y1+y2y_1 + y_2
Dual feas.011
Dual opt.123

Weak duality lower-bounds primal: y1+y2x1+2x2y_1 + y_2 \le x_1 + 2x_2 for all feasible pairs. At optimality, both sides equal 3.

Proof Sketch

  1. Weak duality: for primal-feasible xx and dual-feasible yy:
by(Ax)y=x(Ay)xc=cx.b^\top y \le (Ax)^\top y = x^\top (A^\top y) \le x^\top c = c^\top x.
  1. Strong duality: if the primal is bounded below and feasible, KKT conditions produce a dual certificate yy^* with by=cxb^\top y^* = c^\top x^*.
  2. Complementary slackness: at optimality, (cAy)x=0(c - A^\top y^*)^\top x^* = 0 and (Axb)y=0(Ax^* - b)^\top y^* = 0.
  3. Mathlib contains LP theory via Mathlib.LinearProgramming.* (work in progress); the weak duality bound is a direct arithmetic consequence.

Connections

  • KKT ConditionsKKT Conditionsf(x)=iλigi(x),λigi(x)=0,λi0\nabla f(x^*) = \sum_i \lambda_i \nabla g_i(x^*),\quad \lambda_i g_i(x^*) = 0,\quad \lambda_i \ge 0Necessary optimality conditions for constrained optimization via Lagrangian gradient and complementary slacknessRead more → — LP duality is a special case of KKT conditions; the dual variables are the Lagrange multipliers of the primal constraints
  • Minimax Theorem — LP duality is equivalent to the minimax theorem for bilinear zero-sum games
  • Cauchy–Schwarz InequalityCauchy–Schwarz Inequalityu,vuv|\langle u, v \rangle| \leq \|u\| \, \|v\|The inner product of two vectors is bounded by the product of their normsRead more → — both are instances of the broader Hahn–Banach duality theory
  • Rank–Nullity TheoremRank–Nullity Theoremrank(f)+nullity(f)=dimV\operatorname{rank}(f) + \operatorname{nullity}(f) = \dim VThe dimensions of image and kernel of a linear map sum to the domain dimensionRead more → — the primal/dual feasibility conditions are linear systems; rank-nullity governs when they have solutions

Lean4 Proof

import Mathlib.Algebra.Order.Field.Basic

/-- Weak LP duality for the 2x2 example:
    y₁ + y₂ ≤ x₁ + 2 * x₂ for any primal-feasible (x₁,x₂) and dual-feasible (y₁,y₂). -/
theorem lp_weak_duality_2x2
    (x1 x2 y1 y2 : )
    (hx1 : 1  x1) (hx2 : 1  x2)
    (hy1 : y1  1) (hy2 : y2  2)
    (hy1n : 0  y1) (hy2n : 0  y2) :
    y1 + y2  x1 + 2 * x2 := by
  linarith