Skip to content
AI360XpertBeta

KKT Conditions

Four checkable equations that certify a constrained optimum with inequalities: the forces balance, the point obeys the walls, the prices are nonnegative, and idle walls price zero.

Minimizing x minus 2 squared left of the wall x equals 1 stops at x equals 1, where the objective pull of 2 balances the wall price of 2
Minimizing x minus 2 squared left of the wall x equals 1 stops at x equals 1, where the objective pull of 2 balances the wall price of 2

Why Does This Exist?

Unconstrained optimization ends when the gradient vanishes. Constrained problems usually end somewhere the gradient does not vanish: on the boundary, where the objective still pulls outward and only the wall holds the point in place. Declaring "nonzero gradient, so keep going" at such a point walks straight through the wall.

Lagrange multipliers solve the equality case with tangency: parallel gradients, one multiplier per constraint. Real constraints are usually inequalities: budgets that may go unspent, weights that must stay nonnegative, margins with slack. Forcing every inequality to bind invents optima that are not there, and ignoring them walks through walls. The Karush Kuhn Tucker conditions add the missing switch: every inequality gets a multiplier, and complementary slackness turns the idle constraints off.

This page is the inequality upgrade of the Lagrange picture: the four-condition test plus the support-vector payoff. The equality-only machinery lives in Lagrange multipliers. The pricing view with primal dual gaps lives in Lagrangian duality. The full duality story with the SVM dual and the kernel trick lives in constrained optimisation and duality. The certificate-checker view with its own fixture lives in optimality conditions. Convexity background lives in convex optimization, and the linear-constraint special case in linear programming.

The one idea you need first

A constraint g(x)≤0g(x) \le 0 is active at a candidate x⋆x^{\star} when g(x⋆)=0g(x^{\star}) = 0 (the point sits on the wall) and inactive when g(x⋆)<0g(x^{\star}) < 0 (strictly inside). Only active walls push, and each push is priced by a multiplier λ≥0\lambda \ge 0. Inactive walls push nothing and price zero. Combined with the Lagrange tangency idea, gradients parallel at the optimum, that is the whole page in one paragraph.

Think of It Like This

A ball rolling inside a fenced yard

A ball rolls downhill inside a fenced yard and comes to rest against the fence. At rest, the downhill pull plus the fence push balance to zero, which is stationarity. The fence pushes only while the ball touches it, which is complementary slackness. It never pulls the ball outward, which is dual feasibility with λ≥0\lambda \ge 0. And the ball stays inside the yard, which is primal feasibility.

A fence on the far side of the yard prices zero: removing it changes nothing, because the ball never touched it. That is the switch the whole page is about.

The analogy stops at one smooth fence. Real problems stack many walls with corners and kinks, where multipliers can misbehave unless a constraint qualification holds. And a ball can rest in a dip that is not the deepest point, so these conditions certify global optimality only with convexity behind them.

How It Actually Works

For minimizing f0(x)f_0(x) subject to fi(x)≤0f_i(x) \le 0 and hj(x)=0h_j(x) = 0, with all functions differentiable, the KKT conditions on (x⋆,λ⋆,ν⋆)(x^{\star}, \lambda^{\star}, \nu^{\star}) are four checks. In plain words: f0f_0 is the objective, each fif_i is an inequality wall, each hjh_j is an equality wall, each λi\lambda_i prices one inequality wall, each νj\nu_j prices one equality wall.

  1. Stationarity — ∇f0+∑iλi∇fi+∑jνj∇hj=0\nabla f_0 + \sum_i \lambda_i \nabla f_i + \sum_j \nu_j \nabla h_j = 0. The objective pull plus all wall pushes balance to zero.
  2. Primal feasibility — fi(x⋆)≤0f_i(x^{\star}) \le 0 and hj(x⋆)=0h_j(x^{\star}) = 0. The point obeys every wall.
  3. Dual feasibility — λi≥0\lambda_i \ge 0 for every inequality. Walls push back only, never pull.
  4. Complementary slackness — λifi(x⋆)=0\lambda_i f_i(x^{\star}) = 0 for every ii. For each wall, either the price is zero or the wall is tight.

The fourth condition does the work. It says an idle constraint has no influence, so its price is zero, and a binding constraint carries a positive price. In an SVM the margin constraints of comfortably classified examples are inactive, so their multipliers are zero and those examples drop out of the solution entirely. Only the examples on the margin keep nonzero multipliers, and those are exactly the support vectors. Sparsity was forced by the mathematics, not chosen by the designer.

Worked example

Minimize (x−2)2(x - 2)^2 subject to x≤1x \le 1, written g(x)=x−1≤0g(x) = x - 1 \le 0. The Lagrangian is L=(x−2)2+λ(x−1)L = (x - 2)^2 + \lambda(x - 1), and stationarity reads 2(x−2)+λ=02(x - 2) + \lambda = 0.

Guess the wall is active, so x⋆=1x^{\star} = 1. Then 2(1−2)+λ=02(1 - 2) + \lambda = 0 gives λ⋆=2\lambda^{\star} = 2, which satisfies λ≥0\lambda \ge 0. Primal feasibility holds with equality (1−1=01 - 1 = 0), and slackness holds as 2×0=02 \times 0 = 0. The certified constrained optimum has value (1−2)2=1(1 - 2)^2 = 1 with wall price 2. The diagram above draws exactly this: the pull of 2 against the price of 2.

The inactive guess correctly fails: λ=0\lambda = 0 would give x=2x = 2, which violates x≤1x \le 1 and is rejected. And the multiplier prices the wall: loosen it to x≤1.1x \le 1.1 and the new optimum is x=1.1x = 1.1 with value (1.1−2)2=0.81(1.1 - 2)^2 = 0.81, a drop of 0.190.19 for 0.10.1 of slack, about λ×0.1\lambda \times 0.1. Note the sign under this convention: for minimization with ≤\le walls, df⋆/db=−λdf^{\star}/db = -\lambda where bb is the wall position, so loosening cuts the optimum. The equality page states the maximization mirror image.

Code

The point is the check: four numbers that certify the point, plus the shadow-price confirmation.

def objective(x: float) -> float:    return (x - 2.0) ** 2

x, lam = 1.0, 2.0stat = 2 * (x - 2.0) + lam  # pull -2 against wall price +2print(round(stat, 6))  # -> 0.0print(x <= 1, lam >= 0, round(lam * (x - 1), 6))  # -> True True 0.0print(round(objective(1.0), 2), round(objective(1.1), 2))  # -> 1.0 0.81

Stationarity residual zero, feasibility, sign, and slackness all passing, and relaxing the wall to 1.11.1 drops the value from 1.01.0 to 0.810.81, about λ×0.1\lambda \times 0.1 as priced.

Watch Out For

Treating KKT as sufficient on non-convex problems

Stationarity plus feasibility plus slackness finds candidates, and on non-convex problems those candidates include local minima along the wall, constrained maxima, and saddles. The equations do not label which is which. A solver reporting "KKT satisfied" on a neural network loss or an integer program has produced a candidate, not a certificate.

The symptom is a "verified optimum" that a restart or a neighboring feasible point beats. The fix is to state convexity before claiming sufficiency: under convexity plus a constraint qualification, any KKT point is globally optimal. Without it, verify with multi-start comparison, check second-order conditions on the wall, or switch to global methods with gap tracking. Never report a KKT point as the answer on a non-convex problem without that extra evidence.

Flipping the sign convention on the multipliers

The pairing λ≥0\lambda \ge 0 belongs to minimization with ≤\le constraints (or maximization with ≥\ge). Mix the pairing, for example enforcing λ≥0\lambda \ge 0 against a ≥\ge wall in a minimizer, and the stationarity equation certifies points on the wrong side of the wall. Nothing crashes; the check passes on a point the wall never pushed.

The symptom is a negative multiplier that gets "fixed" by taking an absolute value, or a price whose shadow prediction points the wrong way when the wall is relaxed. The fix is mechanical: write the Lagrangian as L=f+∑λigiL = f + \sum \lambda_i g_i with gi≤0g_i \le 0 and λi≥0\lambda_i \ge 0, then test the whole pipeline on the worked fixture above, where the answer must come out x⋆=1x^{\star} = 1 with λ⋆=2\lambda^{\star} = 2. If your code produces −2-2, the convention is flipped, not the problem.

The Quick Version

  • KKT certifies inequality-constrained optima with four checks: stationarity, primal feasibility, dual feasibility, complementary slackness.
  • Complementary slackness is the switch: each wall either binds with a positive price or sits idle with price zero.
  • Minimizing (x−2)2(x - 2)^2 left of x=1x = 1 certifies x⋆=1x^{\star} = 1 with λ⋆=2\lambda^{\star} = 2 and value 11.
  • Loosening the wall to 1.11.1 drops the optimum to 0.810.81, about λ×0.1\lambda \times 0.1, with sign df⋆/db=−λdf^{\star}/db = -\lambda.
  • SVM support vectors are exactly the active set: margin constraints with positive multipliers.
  • KKT is necessary in general and sufficient only under convexity plus a constraint qualification.
  • Pair λ≥0\lambda \ge 0 with minimization and ≤\le walls; test any implementation on the fixture above.