KKT Conditions

lean4-proofoptimizationvisualization
f(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 0

Statement

At a local minimum xx^* of ff subject to inequality constraints gi(x)0g_i(x) \le 0, the Karush–Kuhn–Tucker (KKT) conditions must hold (under suitable regularity):

f(x)=iλigi(x),λi0,λigi(x)=0.\nabla f(x^*) = \sum_i \lambda_i \nabla g_i(x^*), \qquad \lambda_i \ge 0, \qquad \lambda_i g_i(x^*) = 0.

The third condition is complementary slackness: either λi=0\lambda_i = 0 (constraint is inactive) or gi(x)=0g_i(x^*) = 0 (constraint is active).

Equality-constrained example. Minimize f(x,y)=x2+y2f(x,y) = x^2 + y^2 subject to x+y=1x + y = 1.

The Lagrangian is:

L(x,y,λ)=x2+y2λ(x+y1).\mathcal{L}(x, y, \lambda) = x^2 + y^2 - \lambda(x + y - 1).

Setting x,yL=0\nabla_{x,y}\mathcal{L} = 0: 2x=λ2x = \lambda and 2y=λ2y = \lambda, so x=yx = y. Combined with x+y=1x + y = 1: the optimum is x=y=1/2x^* = y^* = 1/2 with multiplier λ=1\lambda = 1.

Visualization

Contours of f(x,y)=x2+y2f(x,y) = x^2 + y^2 (concentric circles) and the constraint line x+y=1x + y = 1:

  y
  1 |  *
    | / constraint: x + y = 1
0.5 |*  optimum (1/2, 1/2)
    |  \
  0 +----*----  x
    0  0.5  1

The optimum is the point on the line closest to the origin — the circle x2+y2=r2x^2 + y^2 = r^2 is tangent to the line exactly at (1/2,1/2)(1/2, 1/2).

(x,y)(x, y)x2+y2x^2 + y^2x+yx + yfeasible?
(0,1)(0, 1)1.001yes
(1/2,1/2)(1/2, 1/2)0.501yes (opt)
(1,0)(1, 0)1.001yes
(0,0)(0, 0)0.000no

Complementary slackness: the equality constraint is active (λ=1>0\lambda = 1 > 0).

Proof Sketch

  1. Form the Lagrangian L(x,λ)=f(x)λg(x)\mathcal{L}(x,\lambda) = f(x) - \lambda^\top g(x).
  2. First-order stationarity: xL=0\nabla_x \mathcal{L} = 0 gives f=λg\nabla f = \lambda^\top \nabla g.
  3. Primal feasibility: gi(x)0g_i(x^*) \le 0 for all ii.
  4. Dual feasibility: λi0\lambda_i \ge 0 for all ii.
  5. Complementary slackness: λigi(x)=0\lambda_i g_i(x^*) = 0 — active constraints have positive multipliers; inactive constraints have zero multiplier.

For minx2+y2\min x^2 + y^2 s.t. x+y=1x + y = 1: the symmetry x=yx = y follows from 2x=λ=2y2x = \lambda = 2y, and feasibility pins down x=y=1/2x = y = 1/2.

Connections

  • Lagrange MultipliersLagrange Multipliersf(x)=λg(x)\nabla f(x^*) = \lambda\, \nabla g(x^*)At a constrained extremum, the gradient of the objective is proportional to the gradient of the constraintRead more → — KKT generalises Lagrange multipliers from equalities to mixed equality/inequality constraints
  • Convex FunctionConvex Functionf(λx+(1λ)y)λf(x)+(1λ)f(y)f(\lambda x + (1-\lambda)y) \le \lambda f(x) + (1-\lambda)f(y)A function is convex when the chord between any two points lies above the graphRead more → — for convex ff and convex feasible sets, KKT conditions are also sufficient
  • AM–GM InequalityAM–GM Inequalitya1++anna1ann\frac{a_1+\cdots+a_n}{n} \geq \sqrt[n]{a_1 \cdots a_n}The arithmetic mean is always at least as large as the geometric meanRead more → — AM–GM is itself an instance of a constrained optimality result recoverable via KKT
  • 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 → — Cauchy–Schwarz can be derived by KKT applied to a unit-sphere constraint

Lean4 Proof

import Mathlib.Analysis.InnerProductSpace.Basic

/-- At the KKT optimum of min x²+y² s.t. x+y=1, the minimiser is (1/2, 1/2)
    and the objective value is 1/2. Verified by nlinarith. -/
theorem kkt_min_sum_sq :
     x y : , x + y = 1  (1 : ) / 2  x ^ 2 + y ^ 2 := by
  intro x y hxy
  nlinarith [sq_nonneg (x - y), sq_nonneg (x + y)]