Foundations to Frontier
Tests
A. Mathematical Foundations › A6 Optimization › Convex optimization

The KKT Conditions

The Karush–Kuhn–Tucker conditions are the master optimality test for constrained optimization: stationarity of the Lagrangian, primal and dual feasibility, and complementary slackness. For convex problems they are necessary and sufficient; for general smooth problems they are necessary under a constraint qualification. You will derive and interpret them as a force balance, solve small QPs by enumerating active sets, use multipliers as shadow prices, and build a control-barrier-function safety filter whose closed form comes straight from KKT.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

A tug of war that balances

At the best allowed point, two kinds of forces balance. The objective pulls toward lower cost. Each wall you’re pressing against pushes back, straight out from the wall. A wall you aren’t touching doesn’t push at all. And walls can only push, never pull.

Those four common-sense facts are the KKT conditions: forces balance, you’re inside the walls, walls only push, and only walls you touch push.

KKT: the pull of the objective balanced by the push of active constraints
x* = (1.300, 0.700) · λ = (1.800, 0.000, 0.000) · active: g1 · ‖−∇f − Σλᵢ∇gᵢ‖ = 0.0e+0
Orange arrow: −∇f(x*), the direction the objective wants to go. Coloured arrows: λᵢ∇gᵢ for each active constraint (outward normals scaled by their multipliers). KKT stationarity says they add up exactly. Primal feasibility: x* is in the polygon. Dual feasibility: λ ≥ 0. Complementary slackness: inactive constraints get λ = 0. Move c inside the polygon and every λ drops to zero. Move it beyond a corner and two constraints share the load.
Why engineers care

Every QP and NLP solver in robotics and aerospace (OSQP for MPC, IPOPT for trajectory optimization, SNOPT for mission design) is built to satisfy the KKT conditions. The multipliers they return say which constraints bind and how much each costs. That’s exactly what an engineer needs to decide which limit to relax.

📝 Quick check (Level 0)
0/3 answered
  1. 1. A constraint you aren't touching pushes…
  2. 2. Walls (inequality constraints) can only…
  3. 3. At the optimum, the objective's pull is…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

The four conditions

For min⁡f(x)\min f(x) s.t. gi(x)≤0g_i(x)\le0, hj(x)=0h_j(x) = 0, a point x⋆x^\star with multipliers λ⋆,ν⋆\lambda^\star, \nu^\star satisfies KKT if:

  1. Stationarity: ∇f(x⋆)+∑iλi⋆∇gi(x⋆)+∑jνj⋆∇hj(x⋆)=0\nabla f(x^\star) + \sum_i\lambda_i^\star\nabla g_i(x^\star) + \sum_j\nu_j^\star\nabla h_j(x^\star) = 0.
  2. Primal feasibility: gi(x⋆)≤0g_i(x^\star)\le0 and hj(x⋆)=0h_j(x^\star) = 0.
  3. Dual feasibility: λ⋆≥0\lambda^\star\ge0.
  4. Complementary slackness: λi⋆gi(x⋆)=0\lambda_i^\star g_i(x^\star) = 0 for each ii.

1-D example

min⁡(x−3)2\min(x - 3)^2 s.t. x≤2x\le2:

  • Stationarity: 2(x−3)+λ=02(x - 3) + \lambda = 0.
  • If λ=0\lambda = 0, then x=3x = 3, which is infeasible.
  • So the constraint is active: x=2x = 2 and λ=2≥0\lambda = 2\ge0. ✓
📝 Quick check (Level 1)
0/3 answered
  1. 1. Complementary slackness says…
  2. 2. min (x − 3)² s.t. x ≤ 2: λ* =
  3. 3. Multipliers of equality constraints must be…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 45 minUndergraduate students and practising engineers.

When are KKT conditions necessary or sufficient?

  • Convex problems: KKT is sufficient. If Slater holds, it’s also necessary, and the KKT multipliers are exactly the dual optimal solution (A6.2-4).
  • General smooth problems: at a local minimum, KKT multipliers exist if a constraint qualification holds, for example LICQ (the active constraint gradients are linearly independent). Without one, they may not exist. Second-order conditions on the Lagrangian Hessian then classify the point.

Solving with KKT

  • Small problems: guess which constraints are active, solve the resulting equations, and check λ≥0\lambda\ge0 and feasibility. Active-set methods do this systematically.
  • Interior-point methods relax complementary slackness to λigi=−μ\lambda_ig_i = -\mu and drive μ→0\mu\to0 with Newton steps.
  • Closed forms: for one linear constraint, min⁡∥u−ud∥2\min\|u - u_d\|^2 s.t. a⊤u≤ba^\top u\le b gives u=ud−max⁡(0,a⊤ud−b)∥a∥2au = u_d - \frac{\max(0, a^\top u_d - b)}{\|a\|^2}a. That’s the control-barrier-function filter.

Multipliers as shadow prices

At the optimum, ∂f⋆/∂bi=−λi⋆\partial f^\star/\partial b_i = -\lambda_i^\star for constraint gi≤big_i\le b_i. A large multiplier means that constraint is expensive. An engineer might buy more battery, actuator authority or margin there.

🐍 Exercise 1: solving a QP by its KKT conditions
Implement KKT residuals and an active-set enumeration solver for a small inequality-constrained QP. Check all four conditions, compare with brute force, and verify that the multiplier equals the sensitivity of the optimal value.
📝 Quick check (Level 2)
0/3 answered
  1. 1. For a convex problem, a KKT point is…
  2. 2. LICQ requires the active constraint gradients to be…
  3. 3. Interior-point methods replace λᵢgᵢ = 0 by…

Level 3: Advanced

★★★★☆ Advanced⏱ 45 minGraduate level, with full derivations and proofs.

Proof: KKT is sufficient for convex problems

With λ⋆≥0\lambda^\star\ge0, the Lagrangian L(x,λ⋆,ν⋆)L(x, \lambda^\star, \nu^\star) is convex in xx (the hjh_j are affine), and stationarity says x⋆x^\star minimizes it. For any feasible xx:

f(x)≥L(x,λ⋆,ν⋆)≥L(x⋆,λ⋆,ν⋆)=f(x⋆)+∑λi⋆gi(x⋆)=f(x⋆)f(x)\ge L(x, \lambda^\star, \nu^\star)\ge L(x^\star, \lambda^\star, \nu^\star) = f(x^\star) + \sum\lambda_i^\star g_i(x^\star) = f(x^\star)

The first inequality holds because λ⋆gi(x)≤0\lambda^\star g_i(x)\le0 and hj(x)=0h_j(x) = 0. The last equality is complementary slackness. ∎

Why must λ be non-negative?

At x⋆x^\star, stationarity is −∇f=∑λi∇gi-\nabla f = \sum\lambda_i\nabla g_i. If some active λi<0\lambda_i < 0, moving slightly into the interior along −∇gi-\nabla g_i would stay feasible and decrease ff, contradicting optimality. Geometrically, −∇f-\nabla f must lie in the cone of outward normals (A6.2-3).

The CBF filter from KKT

L=∥u−ud∥2+λ(a⊤u−b)L = \|u - u_d\|^2 + \lambda(a^\top u - b). Stationarity gives u=ud−λ2au = u_d - \frac\lambda2a. If the constraint is inactive, λ=0\lambda = 0. If active, a⊤u=ba^\top u = b gives λ=2(a⊤ud−b)/∥a∥2>0\lambda = 2(a^\top u_d - b)/\|a\|^2 > 0. Combining: λ=2max⁡(0,a⊤ud−b)/∥a∥2\lambda = 2\max(0, a^\top u_d - b)/\|a\|^2. ∎

Exercise 3.1: min x² + y² s.t. x + y ≥ 2

Write it as 2−x−y≤02 - x - y\le0. Stationarity: 2x−λ=02x - \lambda = 0 and 2y−λ=02y - \lambda = 0, so x=y=λ/2x = y = \lambda/2. Active: λ=2\lambda = 2, x=y=1x = y = 1, f⋆=2f^\star = 2.

📝 Quick check (Level 3)
0/3 answered
  1. 1. The sufficiency proof uses that x* minimizes…
  2. 2. A negative multiplier on an active constraint would mean…
  3. 3. min x² + y² s.t. x + y ≥ 2 gives λ* =

Level 4: Expert

★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.

A safety filter that is pure KKT

A mobile robot follows a nominal controller straight toward its goal, through an obstacle. A control barrier function h(x)=∥x−o∥2−r2h(x) = \|x - o\|^2 - r^2 defines the safe set h≥0h\ge0. Requiring h˙≥−αh\dot h\ge-\alpha h gives a linear constraint on the control at each instant. The safety filter solves min⁡∥u−unom∥2\min\|u - u_{\text{nom}}\|^2 subject to that constraint. KKT gives it in closed form. The robot slides around the obstacle, the constraint is active only nearby, and complementary slackness holds at every step.

🐍 Exercise 2 (research): a CBF-QP safety filter
Implement the closed-form CBF filter from KKT and simulate a robot with and without it. Check safety (h ≥ 0), goal reaching, and the KKT conditions at every time step.

KKT in AI, robotics and aerospace

  • Control barrier functions for collision avoidance on drones, legged robots and cars (Ames et al., 2017, 2019).
  • MPC and trajectory optimization solvers are built around the KKT system: OSQP (ADMM on the KKT system), IPOPT and SNOPT.
  • SVM support vectors are exactly the data points with positive KKT multipliers (complementary slackness).
  • Contact mechanics in robotics simulation: non-penetration and Coulomb friction are complementarity conditions (LCPs; Stewart and Trinkle, 1996).

References

  1. W. Karush (1939). “Minima of functions of several variables with inequalities as side conditions.” MSc thesis, University of Chicago.
  2. H. Kuhn, A. Tucker (1951). “Nonlinear programming.” Proc. 2nd Berkeley Symposium.
  3. S. Boyd, L. Vandenberghe (2004). Convex Optimization. Cambridge University Press. §5.5.
  4. J. Nocedal, S. Wright (2006). Numerical Optimization, 2nd ed. Springer. Ch. 12, 16, 19.
  5. A. Ames, X. Xu, J. Grizzle, P. Tabuada (2017). “Control barrier function based quadratic programs for safety critical systems.” IEEE Transactions on Automatic Control, 62(8).
  6. A. Ames et al. (2019). “Control barrier functions: theory and applications.” European Control Conference.
  7. B. Stellato et al. (2020). “OSQP: an operator splitting solver for quadratic programs.” Mathematical Programming Computation, 12.
  8. D. Stewart, J. Trinkle (1996). “An implicit time-stepping scheme for rigid body dynamics with inelastic collisions and Coulomb friction.” International Journal for Numerical Methods in Engineering, 39.
  9. C. Cortes, V. Vapnik (1995). “Support-vector networks.” Machine Learning, 20.
  10. A. Wächter, L. Biegler (2006). “On the implementation of an interior-point filter line-search algorithm for large-scale nonlinear programming.” Mathematical Programming, 106.