The Lagrangian#
Consider the primal problem in standard form:
The Lagrangian folds the constraints into the objective via multipliers:
where (unrestricted — equality constraints) and (inequality constraints). The sign convention matters: we write the primal with , and the Lagrangian adds with . If your primal uses , the term becomes .
Why this form? For a fixed that is feasible:
- Since , the terms vanish regardless of .
- Since and , we have . Thus
for any and any . 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:
Rewrite as to match the standard form . The Lagrangian is
For a fixed , the Lagrangian is a quadratic in : . Its unconstrained minimum over is attained at (set derivative ).
Dual function#
For each multiplier , 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 is defined as the pointwise infimum of the Lagrangian over the primal variable:
The domain of is . Outside this set, and those dual variables are useless (they provide no lower bound).
Key property: is always concave, regardless of whether the primal problem is convex. Why? is a pointwise infimum of affine functions in — specifically, for each fixed , is affine in . The infimum of a family of affine functions is concave. This means the dual problem — maximising — 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:
The minimiser is . Plugging in:
The dual problem is . Since is a concave quadratic, maximising: , and .
The primal optimum: the constraint is active at the minimum, so and . Primal and dual optimal values agree: .
Weak duality#
Theorem (Weak Duality). For any primal feasible and any dual feasible with ,
Proof.
Since and , the last two sums are , so .
Consequence: The optimal value of the dual, , is always a lower bound on the optimal value of the primal, . That is,
The difference 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 — 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 and all are convex, and all are affine. If there exists a strictly feasible point — i.e., an with
(affine inequalities may be non-strict) — then strong duality holds: , and the dual optimum is attained if .
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 example from Week 1 where the constraint gradient vanished).
Refined Slater. If some are affine, strict feasibility is required only for the non-affine inequalities. Affine inequalities only need .
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:
In standard form: , . This is convex (quadratic objective, linear constraints). A strictly feasible point exists: gives , . Slater holds, so strong duality applies. The primal optimum is with .
Recovering primals#
When strong duality holds and both primal and dual optima are attained, the primal optimal is a minimiser of :
If the Lagrangian is strictly convex in (e.g., a strictly convex 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 is cheaper than solving the primal in ).
In the QP example above: , the Lagrangian is minimised at , which recovers the primal optimum.
Knowledge Check#
Weak duality states that for any primal feasible x and dual feasible (λ, ν):
The dual function is defined as g(λ, ν) = inf over x of ℒ(x, λ, ν). It is always a ____ function of (λ, ν).
Browser lab#
Consider the 1D problem subject to . Form the dual function , compute it analytically as , and verify that equals the primal optimal value.
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: free for equalities, for inequalities. At any feasible point it lower-bounds the objective.
- The dual function is always concave — a pointwise infimum of affine functions — so the dual problem is always convex, even when the primal is not.
- Weak duality always holds, so the duality gap 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 , 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.