AnyLearn
All lessons
Mathadvanced

Lagrangian Duality: From Primal to Dual

Every constrained optimization problem has a twin. Learn how to build the Lagrangian, derive the dual problem, and use weak duality, strong duality, and the KKT conditions to certify optima — with worked examples from linear programming and SVMs.

Not signed in — your progress and quiz score won't be saved.
Lesson progress1 / 10

The primal problem

Start with a constrained minimization in standard form:

minxRn  f(x)s.t.  gi(x)0,i=1,,mhj(x)=0,j=1,,p\begin{aligned}\min_{x \in \mathbb{R}^n}\;& f(x) \\ \text{s.t.}\;& g_i(x) \le 0,\quad i = 1, \dots, m \\ & h_j(x) = 0,\quad j = 1, \dots, p\end{aligned}

We call this the primal. Write pp^\star for its optimal value (possibly ++\infty if infeasible). ff, gig_i, hjh_j can be anything for the definitions below — convexity is what we'll need later for strong duality, not for the construction itself.

The primal might be hard: non-smooth, non-convex, combinatorial. The dual problem we build next is always concave, regardless. That's its point.

Full lesson text

All 10 steps on one page — for reading, reference, and search.

Show

1. The primal problem

Start with a constrained minimization in standard form:

minxRn  f(x)s.t.  gi(x)0,i=1,,mhj(x)=0,j=1,,p\begin{aligned}\min_{x \in \mathbb{R}^n}\;& f(x) \\ \text{s.t.}\;& g_i(x) \le 0,\quad i = 1, \dots, m \\ & h_j(x) = 0,\quad j = 1, \dots, p\end{aligned}

We call this the primal. Write pp^\star for its optimal value (possibly ++\infty if infeasible). ff, gig_i, hjh_j can be anything for the definitions below — convexity is what we'll need later for strong duality, not for the construction itself.

The primal might be hard: non-smooth, non-convex, combinatorial. The dual problem we build next is always concave, regardless. That's its point.

2. The Lagrangian

Pack every constraint into the objective with a per-constraint multiplier:

L(x,λ,ν)  =  f(x)  +  i=1mλigi(x)  +  j=1pνjhj(x)L(x, \lambda, \nu) \;=\; f(x) \;+\; \sum_{i=1}^{m} \lambda_i\, g_i(x) \;+\; \sum_{j=1}^{p} \nu_j\, h_j(x)

The rules on the multipliers are not symmetric:

  • λi0\lambda_i \ge 0 for inequalities (because we want the term to penalize infeasibility, gi>0g_i > 0).
  • νj\nu_j free for equalities (sign doesn't matter — only hj=0h_j = 0 does).

For a feasible xx, every λigi(x)0\lambda_i g_i(x) \le 0 and every νjhj(x)=0\nu_j h_j(x) = 0, so L(x,λ,ν)f(x)L(x, \lambda, \nu) \le f(x). Hold that thought — it's the seed of weak duality.

3. The dual function

Minimize the Lagrangian over xx unconstrained, treating the multipliers as parameters:

g(λ,ν)  =  infxRnL(x,λ,ν)g(\lambda, \nu) \;=\; \inf_{x \in \mathbb{R}^n} L(x, \lambda, \nu)

Two properties hold for free, no matter what the primal looks like:

  1. gg is concave in (λ,ν)(\lambda, \nu). It's a pointwise infimum of affine functions of (λ,ν)(\lambda, \nu) — and the pointwise infimum of affine functions is concave.
  2. gg can be -\infty. If LL is unbounded below in xx for some (λ,ν)(\lambda, \nu), we drop those multipliers from consideration.

The domain of gg — the set where g>g > -\infty — is where the action is.

4. The dual problem

The dual problem is to make gg as large as possible while respecting the sign constraint on λ\lambda:

maxλ,ν  g(λ,ν)s.t.  λ0\begin{aligned}\max_{\lambda, \nu}\;& g(\lambda, \nu) \\ \text{s.t.}\;& \lambda \ge 0\end{aligned}

Write dd^\star for the optimal dual value. Because gg is concave and the constraint λ0\lambda \ge 0 is convex, the dual is always a convex problem — even when the primal is wildly non-convex.

That's already a striking payoff: you can hand any optimization problem a convex relaxation by passing through the Lagrangian. The question is how tight the relaxation is.

5. Weak duality (always holds)

Theorem (weak duality). For any primal-feasible xx and any dual-feasible (λ,ν)(\lambda, \nu),

g(λ,ν)    f(x).g(\lambda, \nu) \;\le\; f(x).

In particular, dpd^\star \le p^\star. The proof fits on a postcard:

g(λ,ν)=infxL(x,λ,ν)    L(x,λ,ν)=f(x)+λigi(x)0+νjhj(x)=0    f(x).g(\lambda, \nu) = \inf_{x'} L(x', \lambda, \nu) \;\le\; L(x, \lambda, \nu) = f(x) + \underbrace{\sum \lambda_i g_i(x)}_{\le\, 0} + \underbrace{\sum \nu_j h_j(x)}_{=\, 0} \;\le\; f(x).

Every dual-feasible point gives a certified lower bound on the primal optimum. This is already useful: branch-and-bound, cutting-plane methods, and the simplex method's stopping certificate all live here.

6. Strong duality and Slater's condition

Sometimes d=pd^\star = p^\star exactly — no duality gap. We call this strong duality. Without it, the dual is a relaxation; with it, the dual is the primal in disguise.

Strong duality is not automatic, even for convex problems. The most useful sufficient condition is:

Slater's condition. If the primal is convex and there exists a strictly feasible xx — meaning gi(x)<0g_i(x) < 0 for all non-affine gig_i and hj(x)=0h_j(x) = 0 — then strong duality holds.

For LPs (everything affine), Slater reduces to plain feasibility: strong duality holds whenever both primal and dual are feasible. Outside convexity, strong duality can fail in subtle ways (the duality gap is then pd>0p^\star - d^\star > 0).

7. The KKT conditions

When strong duality holds, the optimal xx^\star and (λ,ν)(\lambda^\star, \nu^\star) jointly satisfy the Karush–Kuhn–Tucker conditions:

  1. Stationarity: f(x)+λigi(x)+νjhj(x)=0\nabla f(x^\star) + \sum \lambda_i^\star \nabla g_i(x^\star) + \sum \nu_j^\star \nabla h_j(x^\star) = 0
  2. Primal feasibility: gi(x)0g_i(x^\star) \le 0, hj(x)=0h_j(x^\star) = 0
  3. Dual feasibility: λi0\lambda_i^\star \ge 0
  4. Complementary slackness: λigi(x)=0\lambda_i^\star\, g_i(x^\star) = 0 for every ii

For convex problems with strong duality, KKT is necessary and sufficient. Complementary slackness is the punchline: at the optimum, either a constraint is active (gi=0g_i = 0) or its multiplier is zero (λi=0\lambda_i = 0). The multipliers tell you which constraints actually matter.

8. Primal and dual at a glance

How the four objects connect:

flowchart LR
  P["Primal: min f(x) s.t. g(x) <= 0, h(x) = 0"]
  L["Lagrangian: L(x, lambda, nu)"]
  G["Dual function: g(lambda, nu) = inf_x L"]
  D["Dual: max g(lambda, nu) s.t. lambda >= 0"]
  W["Weak duality: d* <= p* (always)"]
  S["Strong duality: d* = p* (under Slater, etc.)"]
  K["KKT conditions hold at the optimum"]
  P --> L
  L --> G
  G --> D
  D --> W
  W --> S
  S --> K

9. Worked example: LP duality

Take the canonical LP

minx0  cxs.t.  Axb.\min_{x \ge 0}\; c^\top x \quad \text{s.t.}\; Ax \ge b.

The Lagrangian (with y0y \ge 0 for bAx0b - Ax \le 0, no equality constraints) is

L(x,y)=cx+y(bAx)=by+(cAy)x.L(x, y) = c^\top x + y^\top(b - Ax) = b^\top y + (c - A^\top y)^\top x.

Minimizing over x0x \ge 0: if any component of cAyc - A^\top y is negative, the infimum is -\infty; otherwise the optimal x=0x = 0 and g(y)=byg(y) = b^\top y. So

  maxy0  bys.t.  Ayc.  \boxed{\;\max_{y \ge 0}\; b^\top y \quad \text{s.t.}\; A^\top y \le c.\;}

That's the dual LP. Slater holds whenever both are feasible, so d=pd^\star = p^\starexactly. The simplex method exploits this: it walks both primal and dual at once and stops when complementary slackness holds.

10. Why duality matters in practice

Four places duality shows up that aren't obviously about optimization:

  • Support Vector Machines. The SVM dual is the famous one — its number of variables equals the number of training points, not the feature dimension. Sparsity falls out: only support vectors have λi>0\lambda_i > 0.
  • Max-flow / min-cut. Min-cut is the LP dual of max-flow. Strong duality gives you the celebrated equality max flow=min cut\text{max flow} = \text{min cut}.
  • Sensitivity analysis. The optimal multiplier λi\lambda_i^\star is the shadow price of constraint ii: how much pp^\star improves per unit relaxation of bib_i. Economists, traders, and scheduling engineers live in this column.
  • Interior-point methods. Modern solvers (Mosek, Gurobi, CVXPY backends) solve the KKT system itself — they march primal and dual variables together, terminating when the duality gap drops below a tolerance.

Duality is the optimization world's most overpowered theorem because it turns one problem into two views of the same problem — and you can pick whichever is easier to solve.

Check your understanding

The lesson ends with a 5-question quiz. Take it in the player above to see your score.

  1. Which statement about weak duality is correct?
    • $d^\star \le p^\star$ holds whenever the primal is convex.
    • $d^\star \le p^\star$ holds for every optimization problem, convex or not.
    • $d^\star \le p^\star$ holds only when Slater's condition is satisfied.
    • $d^\star = p^\star$ always, by definition of the dual.
  2. Why is the dual function $g(\lambda, \nu)$ always concave?
    • Because the primal objective $f$ is assumed convex.
    • Because the pointwise infimum of affine functions of $(\lambda, \nu)$ is concave.
    • Because the multipliers $\lambda$ are constrained to be non-negative.
    • Because the Lagrangian is convex in $x$.
  3. Complementary slackness at a KKT point says:
    • $\lambda_i^\star + g_i(x^\star) = 0$ for every $i$.
    • $\lambda_i^\star \cdot g_i(x^\star) = 0$ for every $i$.
    • $g_i(x^\star) = 0$ for every $i$.
    • $\lambda_i^\star = 0$ for every $i$.
  4. Take the LP $\min c^\top x$ s.t. $Ax \ge b$, $x \ge 0$. What is its dual?
    • $\max b^\top y$ s.t. $A^\top y \le c$, $y \ge 0$.
    • $\min b^\top y$ s.t. $A^\top y = c$, $y$ free.
    • $\max c^\top y$ s.t. $A y \le b$, $y \ge 0$.
    • $\min c^\top y$ s.t. $A^\top y \ge b$, $y \ge 0$.
  5. Slater's condition guarantees strong duality. What does it actually require?
    • The primal is convex and there exists a feasible point with $g_i(x) \le 0$.
    • The primal is convex and there exists a strictly feasible point with $g_i(x) < 0$ for every non-affine $g_i$.
    • The primal is linear and the dual is feasible.
    • The Lagrangian is differentiable at the optimum.

Related lessons