Skip to main content
© 2026 ePowerAI — free, open courseware. No login required.
CoursesContact
ePOWERAI
CoursesContact
Week 2: Lagrangian Duality in Depth
Adv. Optimization

Duality & KKT

  1. 01Week 1: Optimality Conditions Revisited
  2. 02Week 2: Lagrangian Duality in Depth
  3. 03Week 3: KKT and Sensitivity

Cones & IPMs

  1. 04Week 4: LP, QP, and Conic Form
  2. 05Week 5: Semidefinite Programming
  3. 06Week 6: Interior-Point Methods
  4. 07Week 7: Proximal Methods and ADMM

Second-order & scale

  1. 08Week 8: Newton and Quasi-Newton
  2. 09Week 9: Variance Reduction
  3. 10Week 10: Large-Batch and Distributed Training

Geometry & training science

  1. 11Week 11: Automatic Differentiation
  2. 12Week 12: Sharpness and SAM
  3. 13Week 13: Landscapes and Implicit Bias

Capstone

  1. 14Week 14: Capstone — Structure Meets Scale
Week 02· Adv. Optimization· Duality & KKT10 min read

Week 2: Lagrangian Duality in Depth

Learning Outcomes
  • Form the Lagrangian for a constrained problem with equality and inequality constraints
  • Define the dual function g(λ,ν)=inf⁡xL(x,λ,ν)g(\lambda, \nu) = \inf_x \mathcal{L}(x, \lambda, \nu)g(λ,ν)=infx​L(x,λ,ν) as a pointwise infimum over the primal variable
  • State weak duality (g(λ,ν)≤f(x)g(\lambda, \nu) \leq f(x)g(λ,ν)≤f(x) for feasible pairs) and define the duality gap
  • State Slater's condition and when strong duality holds for convex problems
Prerequisites

Background: Week 1 (optimality conditions, constraint qualifications). Intermediate Optimization duality lite — you should recognise the idea of a lower bound from the dual but not its full theory. Familiarity with convex sets and convex functions from intermediate Optim is essential.

Later weeks: The dual function and strong duality are the foundation for KKTKarush–Kuhn–Tucker (optimality conditions) (Week 3), for interpreting cone-program duals (Weeks 4–5), and for SVM-style dual formulations (Week 12 context).

  • Also see: Probability & Statistics Week 12: Exponential Families (lite) — the conjugate-duality connection.

The Lagrangian#

Consider the primal problem in standard form:

min⁡xf(x)s.t.gi(x)=0,i=1,…,mhj(x)≤0,j=1,…,p\begin{aligned} \min_x &\quad f(x) \\ \text{s.t.} &\quad g_i(x) = 0, \quad i = 1, \ldots, m \\ &\quad h_j(x) \leq 0, \quad j = 1, \ldots, p \end{aligned}xmin​s.t.​f(x)gi​(x)=0,i=1,…,mhj​(x)≤0,j=1,…,p​

The Lagrangian L:Rd×Rm×R+p→R\mathcal{L}: \mathbb{R}^d \times \mathbb{R}^m \times \mathbb{R}_+^p \to \mathbb{R}L:Rd×Rm×R+p​→R folds the constraints into the objective via multipliers:

L(x,λ,ν)=f(x)+∑i=1mνigi(x)+∑j=1pλjhj(x)\mathcal{L}(x, \lambda, \nu) = f(x) + \sum_{i=1}^m \nu_i g_i(x) + \sum_{j=1}^p \lambda_j h_j(x)L(x,λ,ν)=f(x)+∑i=1m​νi​gi​(x)+∑j=1p​λj​hj​(x)

where νi∈R\nu_i \in \mathbb{R}νi​∈R (unrestricted — equality constraints) and λj≥0\lambda_j \geq 0λj​≥0 (inequality constraints). The sign convention matters: we write the primal with hj(x)≤0h_j(x) \leq 0hj​(x)≤0, and the Lagrangian adds λjhj(x)\lambda_j h_j(x)λj​hj​(x) with λj≥0\lambda_j \geq 0λj​≥0. If your primal uses hj(x)≥0h_j(x) \geq 0hj​(x)≥0, the term becomes −λjhj(x)-\lambda_j h_j(x)−λj​hj​(x).

Why this form? For a fixed xxx that is feasible:

  • Since gi(x)=0g_i(x) = 0gi​(x)=0, the νigi(x)\nu_i g_i(x)νi​gi​(x) terms vanish regardless of νi\nu_iνi​.
  • Since hj(x)≤0h_j(x) \leq 0hj​(x)≤0 and λj≥0\lambda_j \geq 0λj​≥0, we have λjhj(x)≤0\lambda_j h_j(x) \leq 0λj​hj​(x)≤0. Thus

L(x,λ,ν)≤f(x)\mathcal{L}(x, \lambda, \nu) \leq f(x)L(x,λ,ν)≤f(x)

for any λ≥0\lambda \geq 0λ≥0 and any ν\nuν. The Lagrangian is a lower bound on the objective at every feasible point. Maximising this lower bound over the multipliers gives the tightest possible bound — this is the dual problem.

Worked example — Simple QP with one inequality:

min⁡x  12x2s.t.x−1≥0\min_x \; \tfrac{1}{2}x^2 \quad \text{s.t.} \quad x - 1 \geq 0minx​21​x2s.t.x−1≥0

Rewrite as 1−x≤01 - x \leq 01−x≤0 to match the standard form h(x)≤0h(x) \leq 0h(x)≤0. The Lagrangian is

L(x,λ)=12x2+λ(1−x),λ≥0\mathcal{L}(x, \lambda) = \tfrac{1}{2}x^2 + \lambda(1 - x), \quad \lambda \geq 0L(x,λ)=21​x2+λ(1−x),λ≥0

For a fixed λ\lambdaλ, the Lagrangian is a quadratic in xxx: 12x2−λx+λ\tfrac{1}{2}x^2 - \lambda x + \lambda21​x2−λx+λ. Its unconstrained minimum over xxx is attained at x=λx = \lambdax=λ (set derivative x−λ=0x - \lambda = 0x−λ=0).

Dual function#

x* optimum dual lower bounds g(λ) the dual is the best linear lower bound; strong duality closes the gap Lagrangian duality: maximise a lower bound on the primal

For each multiplier λ\lambdaλ, g(λ)g(\lambda)g(λ) is a lower bound on the primal; maximising it gives the tightest bound available from linear underestimates. Strong duality is the statement that this bound is exact.

The dual function g:R+p×Rm→R∪{−∞}g: \mathbb{R}_+^p \times \mathbb{R}^m \to \mathbb{R} \cup \{-\infty\}g:R+p​×Rm→R∪{−∞} is defined as the pointwise infimum of the Lagrangian over the primal variable:

g(λ,ν)=inf⁡xL(x,λ,ν)=inf⁡x[f(x)+∑iνigi(x)+∑jλjhj(x)]g(\lambda, \nu) = \inf_{x} \mathcal{L}(x, \lambda, \nu) = \inf_x \left[ f(x) + \sum_i \nu_i g_i(x) + \sum_j \lambda_j h_j(x) \right]g(λ,ν)=infx​L(x,λ,ν)=infx​[f(x)+∑i​νi​gi​(x)+∑j​λj​hj​(x)]

The domain of ggg is {(λ,ν)∣λ≥0,  g(λ,ν)>−∞}\{ (\lambda, \nu) \mid \lambda \geq 0,\; g(\lambda, \nu) > -\infty \}{(λ,ν)∣λ≥0,g(λ,ν)>−∞}. Outside this set, g=−∞g = -\inftyg=−∞ and those dual variables are useless (they provide no lower bound).

Key property: ggg is always concave, regardless of whether the primal problem is convex. Why? ggg is a pointwise infimum of affine functions in (λ,ν)(\lambda, \nu)(λ,ν) — specifically, for each fixed xxx, L(x,⋅,⋅)\mathcal{L}(x, \cdot, \cdot)L(x,⋅,⋅) is affine in (λ,ν)(\lambda, \nu)(λ,ν). The infimum of a family of affine functions is concave. This means the dual problem — maximising ggg — is always a convex optimisation problem (maximise a concave function over a convex set). Even when the primal is nonconvex, the dual is well-behaved.

Continuing the QP example:

g(λ)=inf⁡x[12x2+λ(1−x)]=inf⁡x[12x2−λx+λ]g(\lambda) = \inf_x \left[ \tfrac{1}{2}x^2 + \lambda(1 - x) \right] = \inf_x \left[ \tfrac{1}{2}x^2 - \lambda x + \lambda \right]g(λ)=infx​[21​x2+λ(1−x)]=infx​[21​x2−λx+λ]

The minimiser is x∗(λ)=λx^*(\lambda) = \lambdax∗(λ)=λ. Plugging in:

g(λ)=12λ2−λ2+λ=−12λ2+λg(\lambda) = \tfrac{1}{2}\lambda^2 - \lambda^2 + \lambda = -\tfrac{1}{2}\lambda^2 + \lambdag(λ)=21​λ2−λ2+λ=−21​λ2+λ

The dual problem is max⁡λ≥0g(λ)\max_{\lambda \geq 0} g(\lambda)maxλ≥0​g(λ). Since ggg is a concave quadratic, maximising: g′(λ)=−λ+1=0⇒λ∗=1g'(\lambda) = -\lambda + 1 = 0 \Rightarrow \lambda^* = 1g′(λ)=−λ+1=0⇒λ∗=1, and g(1)=−12+1=12g(1) = -\tfrac{1}{2} + 1 = \tfrac{1}{2}g(1)=−21​+1=21​.

The primal optimum: the constraint x≥1x \geq 1x≥1 is active at the minimum, so x∗=1x^* = 1x∗=1 and f(1)=12f(1) = \tfrac{1}{2}f(1)=21​. Primal and dual optimal values agree: f(x∗)=g(λ∗)=12f(x^*) = g(\lambda^*) = \tfrac{1}{2}f(x∗)=g(λ∗)=21​.

Weak duality#

Theorem (Weak Duality). For any primal feasible xxx and any dual feasible (λ,ν)(\lambda, \nu)(λ,ν) with λ≥0\lambda \geq 0λ≥0,

g(λ,ν)≤f(x)g(\lambda, \nu) \leq f(x)g(λ,ν)≤f(x)

Proof. g(λ,ν)=inf⁡zL(z,λ,ν)≤L(x,λ,ν)=f(x)+∑iνigi(x)+∑jλjhj(x)g(\lambda, \nu) = \inf_z \mathcal{L}(z, \lambda, \nu) \leq \mathcal{L}(x, \lambda, \nu) = f(x) + \sum_i \nu_i g_i(x) + \sum_j \lambda_j h_j(x)g(λ,ν)=infz​L(z,λ,ν)≤L(x,λ,ν)=f(x)+∑i​νi​gi​(x)+∑j​λj​hj​(x)

Since gi(x)=0g_i(x) = 0gi​(x)=0 and λjhj(x)≤0\lambda_j h_j(x) \leq 0λj​hj​(x)≤0, the last two sums are ≤0\leq 0≤0, so L(x,λ,ν)≤f(x)\mathcal{L}(x, \lambda, \nu) \leq f(x)L(x,λ,ν)≤f(x). □\square□

Consequence: The optimal value of the dual, d∗=sup⁡λ≥0,νg(λ,ν)d^* = \sup_{\lambda \geq 0, \nu} g(\lambda, \nu)d∗=supλ≥0,ν​g(λ,ν), is always a lower bound on the optimal value of the primal, p∗=inf⁡x∈Ff(x)p^* = \inf_{x \in \mathcal{F}} f(x)p∗=infx∈F​f(x). That is,

d∗≤p∗d^* \leq p^*d∗≤p∗

The difference p∗−d∗≥0p^* - d^* \geq 0p∗−d∗≥0 is the duality gap. A zero gap means the dual provides a perfect certificate of optimality.

Weak duality always holds — no convexity, no constraint qualifications needed. This is why the dual is useful even for nonconvex problems: it gives a guaranteed lower bound (a "dual bound") that you can compute by solving a concave maximisation problem.

Strong duality and Slater#

Strong duality means d∗=p∗d^* = p^*d∗=p∗ — the duality gap is zero. This does not hold in general. For convex problems, Slater's condition provides a sufficient (and often easy-to-check) criterion.

Theorem (Slater's Condition). Consider a convex primal problem where fff and all hjh_jhj​ are convex, and all gig_igi​ are affine. If there exists a strictly feasible point — i.e., an xxx with

gi(x)=0,hj(x)<0    ∀jg_i(x) = 0,\quad h_j(x) < 0 \;\; \forall jgi​(x)=0,hj​(x)<0∀j

(affine inequalities may be non-strict) — then strong duality holds: d∗=p∗d^* = p^*d∗=p∗, and the dual optimum is attained if p∗>−∞p^* > -\inftyp∗>−∞.

Intuition. Slater says: if the feasible set has a non-empty interior relative to the affine equality constraints, then the dual captures the primal exactly. The strictly feasible point prevents the feasible set from "collapsing" to a lower-dimensional manifold where the dual could be weaker (recall the x2≤0x^2 \leq 0x2≤0 example from Week 1 where the constraint gradient vanished).

Refined Slater. If some hjh_jhj​ are affine, strict feasibility is required only for the non-affine inequalities. Affine inequalities only need hj(x)≤0h_j(x) \leq 0hj​(x)≤0.

When Slater fails but strong duality still holds. Slater is sufficient, not necessary. Many convex problems have zero duality gap without a strictly feasible point (e.g., semidefinite programs can have strong duality under subtler conditions). But Slater is the go-to check because it is simple and covers most practical convex programs.

Worked example — Quadratic with two inequalities:

min⁡x  x2s.t.x≥1,  x≤3\min_x \; x^2 \quad \text{s.t.} \quad x \geq 1,\; x \leq 3minx​x2s.t.x≥1,x≤3

In standard form: h1(x)=1−x≤0h_1(x) = 1 - x \leq 0h1​(x)=1−x≤0, h2(x)=x−3≤0h_2(x) = x - 3 \leq 0h2​(x)=x−3≤0. This is convex (quadratic objective, linear constraints). A strictly feasible point exists: x=2x = 2x=2 gives h1(2)=−1<0h_1(2) = -1 < 0h1​(2)=−1<0, h2(2)=−1<0h_2(2) = -1 < 0h2​(2)=−1<0. Slater holds, so strong duality applies. The primal optimum is x∗=1x^* = 1x∗=1 with p∗=1p^* = 1p∗=1.

Recovering primals#

When strong duality holds and both primal and dual optima are attained, the primal optimal x∗x^*x∗ is a minimiser of L(x,λ∗,ν∗)\mathcal{L}(x, \lambda^*, \nu^*)L(x,λ∗,ν∗):

x∗∈arg⁡min⁡xL(x,λ∗,ν∗)x^* \in \arg\min_x \mathcal{L}(x, \lambda^*, \nu^*)x∗∈argminx​L(x,λ∗,ν∗)

If the Lagrangian is strictly convex in xxx (e.g., a strictly convex fff plus affine constraints), this minimiser is unique and directly recoverable from the dual solution. This is the mechanism behind dual-based algorithms and kernel methods in ML (e.g., the SVM dual, where solving the dual in α\alphaα is cheaper than solving the primal in www).

In the QP example above: λ∗=1\lambda^* = 1λ∗=1, the Lagrangian 12x2+(1−x)\tfrac{1}{2}x^2 + (1 - x)21​x2+(1−x) is minimised at x=λ∗=1x = \lambda^* = 1x=λ∗=1, which recovers the primal optimum.

Knowledge Check#

Exercise · Multiple choice

Weak duality states that for any primal feasible x and dual feasible (λ, ν):

g(λ, ν) ≥ f(x)
g(λ, ν) ≤ f(x)
g(λ, ν) = f(x)
g(λ, ν) = 0
Question 1 of 3

The dual function is defined as g(λ, ν) = inf over x of ℒ(x, λ, ν). It is always a ____ function of (λ, ν).

Browser lab#

Consider the 1D problem min⁡x  x2\min_x \; x^2minx​x2 subject to x≥1x \geq 1x≥1. Form the dual function g(λ)=inf⁡x[x2+λ(1−x)]g(\lambda) = \inf_x [x^2 + \lambda(1 - x)]g(λ)=infx​[x2+λ(1−x)], compute it analytically as g(λ)=λ−λ2/4g(\lambda) = \lambda - \lambda^2/4g(λ)=λ−λ2/4, and verify that max⁡λ≥0g(λ)=1\max_{\lambda \geq 0} g(\lambda) = 1maxλ≥0​g(λ)=1 equals the primal optimal value.

python · runs in browser
import numpy as np
import matplotlib.pyplot as plt

def dual_func(lam):
    """g(lambda) = inf_x [x^2 + lambda*(1 - x)]
       Analytic: g(lambda) = lambda - lambda**2 / 4 for lambda >= 0"""
    return np.where(lam >= 0, lam - lam**2 / 4, -np.inf)

# Grid for dual variable
lams = np.linspace(0, 3, 200)
g_vals = dual_func(lams)

# Find the maximum analytically: g'(lambda) = 1 - lambda/2 = 0 => lambda* = 2
lam_star = 2.0
g_star = dual_func(lam_star)

fig, ax = plt.subplots(figsize=(7, 4.5))
ax.plot(lams, g_vals, "b-", linewidth=2, label=r"$g(\lambda) = \lambda - \lambda^2/4$")
ax.axvline(lam_star, color="gray", linestyle="--", alpha=0.6, label=f"$\\lambda^* = {lam_star}$")
ax.axhline(g_star, color="red", linestyle="--", alpha=0.6, label=f"$d^* = {g_star:.4f}$")
ax.plot(lam_star, g_star, "ro", markersize=8)

ax.set_xlabel(r"$\lambda$ (dual variable)")
ax.set_ylabel(r"$g(\lambda)$")
ax.set_title("Dual function for $\\min x^2$ s.t. $x \\geq 1$")
ax.legend()
ax.grid(True, alpha=0.3)
plt.show()

# Verify manually with explicit infimum computation
def lagrangian(x, lam):
    return x**2 + lam * (1 - x)

check_lams = [0.0, 0.5, 1.0, 1.5, 2.0, 2.5]
print("lambda | argmin_x | g(lambda) [analytic] | g(lambda) [numerical]")
for lam in check_lams:
    # Numerical infimum: the Lagrangian is convex in x, minimize via derivative x = lam/2
    x_opt = lam / 2
    g_num = lagrangian(x_opt, lam)
    g_an = dual_func(lam)
    print(f"  {lam:.1f}   |   {x_opt:.3f}   |   {g_an:.4f}   |   {g_num:.4f}")

print(f"\nPrimal optimum: x* = 1, p* = {1.0}")
print(f"Dual optimum:   lam* = {lam_star}, d* = {g_star}")
print(f"Strong duality holds: p* = d* = {1.0}")

print("Notice: the numerical infimum of the Lagrangian matches the analytic dual at every λ, and p* = d* = 1.0 confirms strong duality here.")

Key takeaways#

  • The Lagrangian folds constraints into the objective with multipliers: νi\nu_iνi​ free for equalities, λj≥0\lambda_j \geq 0λj​≥0 for inequalities. At any feasible point it lower-bounds the objective.
  • The dual function g(λ,ν)=inf⁡xL(x,λ,ν)g(\lambda, \nu) = \inf_x \mathcal{L}(x, \lambda, \nu)g(λ,ν)=infx​L(x,λ,ν) is always concave — a pointwise infimum of affine functions — so the dual problem is always convex, even when the primal is not.
  • Weak duality g(λ,ν)≤f(x)g(\lambda, \nu) \leq f(x)g(λ,ν)≤f(x) always holds, so the duality gap p∗−d∗p^* - d^*p∗−d∗ is never negative.
  • Strong duality (zero gap) holds for convex problems under Slater's condition: a strictly feasible point for the nonlinear inequalities.
  • When the Lagrangian is strictly convex in xxx, the primal optimum is recovered from the dual solution — the mechanism behind dual-based algorithms and kernel methods.
  • A zero gap is a certificate of optimality, and the dual variables carry the sensitivity information.

Further reading#

  • Stephen Boyd & Lieven Vandenberghe, Convex Optimization (Cambridge University Press, 2004) — Chapter 5 is the definitive treatment of the Lagrangian dual, weak/strong duality, and Slater's condition.
  • Dimitri P. Bertsekas, Nonlinear Programming (3rd ed., Athena Scientific, 2016) — duality theory with careful proofs.
  • Yurii Nesterov, Lectures on Convex Optimization (2nd ed., Springer, 2018) — duality alongside the analytic view of convex structure.

Reading is free. PDF and ePub unlock with the newsletter. Join once and every lesson opens in this browser.

← Previous
Week 1: Optimality Conditions Revisited
Next →
Week 3: KKT and Sensitivity
On this page
  • The Lagrangian
  • Dual function
  • Weak duality
  • Strong duality and Slater
  • Recovering primals
  • Knowledge Check
  • Browser lab
  • Key takeaways
  • Further reading