AI Wiki中文/EN

Optimization duality

优化对偶性

Derive lower bounds and distinguish an iterate gap from the optimal duality gap.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

A good candidate is more convincing when you know a lower bound

A feasible solution to a minimization problem tells you a cost you can achieve. It does not tell you how much better another solution might be. A lower bound supplies the other side: no feasible solution can beat that value. When the two meet, you have an optimality certificate.

Lagrangian duality constructs such lower bounds from constraint multipliers. It turns the search for a good bound into another optimization problem. The dual variables need not resemble the original decision variables, and a useful bound can exist even when solving the original problem is difficult.

Begin with Lagrange multipliers and KKT conditions. We keep the same minimization convention: inequalities are cᵢ(x)≤0, their multipliers are nonnegative, and equality multipliers are unrestricted.

Minimize the Lagrangian to obtain a bound

Let D be the common domain of the objective and constraint functions, before imposing the listed constraints. Define:

L(x,λ,ν)=f(x)+∑iλici(x)+∑jνjhj(x),g(λ,ν)=inf⁡x∈DL(x,λ,ν).\mathcal L(x,\lambda,\nu)=f(x)+\sum_i\lambda_i c_i(x)+\sum_j\nu_j h_j(x),\qquad g(\lambda,\nu)=\inf_{x\in D}\mathcal L(x,\lambda,\nu).

The infimum is over D, not just the primal feasible points. It may be −∞; it need not be attained by an x. For a primal feasible point z and nonnegative λ, equality terms vanish and inequality terms are nonpositive. Therefore:

g(λ,ν)≤L(z,λ,ν)≤f(z),d∗=sup⁡λ≥0,νg(λ,ν)≤p∗.g(\lambda,\nu)\le\mathcal L(z,\lambda,\nu)\le f(z),\qquad d^*=\sup_{\lambda\ge0,\nu}g(\lambda,\nu)\le p^*.

Here p* is the infimum of the primal objective over feasible points. This is weak duality, and its argument does not require convexity. The dual function is concave because it is the pointwise infimum of functions affine in the multipliers. Convex Optimization §5.1–5.2 derives both facts. Concavity does not mean g is finite or differentiable everywhere.

The dual problem maximizes g subject to its multiplier restrictions. Strong duality means d*=p*. It does not, by definition alone, assert that either optimum is attained. Standard constraint qualifications such as Slater’s condition give stronger existence and equality guarantees for suitable convex problems; see the duality lecture slides. A nonconvex primal problem may have a positive optimal duality gap.

Derive a scalar dual rather than guessing its formula

Consider minimizing f(x)=(x−a)²/2 subject to x≥b, with x real. Write the constraint as b−x≤0. Complete the square in x:

L(x,λ)=12(x−a)2+λ(b−x)=12(x−a−λ)2+λ(b−a)−12λ2,g(λ)=λ(b−a)−12λ2.\mathcal L(x,\lambda)=\frac12(x-a)^2+\lambda(b-x) =\frac12(x-a-\lambda)^2+\lambda(b-a)-\frac12\lambda^2,\qquad g(\lambda)=\lambda(b-a)-\frac12\lambda^2.

For a fixed λ, the infimum occurs at x=a+λ. That point is allowed when evaluating g even if it violates x≥b. The dual maximizer is λ*=max(b−a,0), and the primal minimizer is x*=max(a,b). Both optimal values equal half the square of max(b−a,0).

For a=1 and b=3, the solution is x*=3 with cost 2. Multiplier λ=1 gives lower bound 3/2: useful but not sharp. Multiplier λ=2 gives lower bound 2 and certifies the optimum. If a=3 and b=1, the unconstrained target is already feasible and λ*=0.

Distinguish a current certificate gap from an optimal duality gap

For any feasible x and λ≥0 in this example, subtraction gives:

f(x)−g(λ)=12(x−a−λ)2+λ(x−b)≥0.f(x)-g(\lambda)=\frac12(x-a-\lambda)^2+\lambda(x-b)\ge0.

The first term measures failure to minimize the Lagrangian at that multiplier. The second is a nonnegative slack contribution. Their sum is the gap for the current pair, not necessarily the optimal duality gap p*−d*. At x=3, λ=1, the current gap is 1/2 even though this problem has zero optimal duality gap.

If both values are valid bounds, a gap at most ε certifies that the feasible candidate’s objective is at most ε above the primal optimum. Feasibility is part of that statement. A low objective at an infeasible point is not a primal upper bound.

Return both bounds and their exact gap

Run the following complete Python 3.12 standard-library program. It accepts integer or Fraction parameters and rejects floats and booleans. certificate refuses an infeasible primal point or a negative inequality multiplier, then checks the completed-square gap identity exactly. The solver uses this problem’s closed form rather than an iterative optimization package.

from fractions import Fraction as F


def rational(value):
    if type(value) not in (int,F):
        raise ValueError('integer or Fraction required')
    return F(value)


def certificate(a,b,x,multiplier):
    a,b,x,multiplier=map(rational,(a,b,x,multiplier))
    if x < b:
        raise ValueError('x must be primal feasible')
    if multiplier < 0:
        raise ValueError('inequality multiplier must be nonnegative')
    upper=(x-a)**2/2
    lower=multiplier*(b-a)-multiplier**2/2
    gap=upper-lower
    identity=(x-a-multiplier)**2/2+multiplier*(x-b)
    assert gap==identity and gap >= 0
    return lower,upper,gap


def optimum(a,b):
    a,b=map(rational,(a,b))
    return max(a,b),max(b-a,F(0))


if __name__ == '__main__':
    for x,multiplier in [(3,1),(3,2),(4,2)]:
        lower,upper,gap=certificate(1,3,x,multiplier)
        print('x='+str(x),'lambda='+str(multiplier),'lower='+str(lower),
              'upper='+str(upper),'gap='+str(gap))
    x,multiplier=optimum(3,1)
    assert certificate(3,1,x,multiplier)==(F(0),F(0),F(0))
    print('inactive constraint: x='+str(x),'lambda='+str(multiplier),'gap=0')

Output:

x=3 lambda=1 lower=3/2 upper=2 gap=1/2
x=3 lambda=2 lower=2 upper=2 gap=0
x=4 lambda=2 lower=2 upper=9/2 gap=5/2
inactive constraint: x=3 lambda=0 gap=0

The first pair proves that the optimum lies between 3/2 and 2. The second closes the interval to the single value 2. The third has an optimal dual bound but a worse primal candidate, so its positive gap diagnoses the candidate, not a failure of strong duality.

Solving and evaluating this scalar certificate require a constant number of arithmetic operations; Fraction bit cost depends on numerator and denominator size. In a large problem, computing the infimum that defines g may itself require substantial work. Plugging a merely approximate inner minimizer into the Lagrangian gives a value above g, which is not automatically a valid lower bound. Certified inner bounds or controlled errors are needed.

A multiplier sign error can destroy the guarantee

For a=3, b=1, the primal optimum is zero. Illegally using λ=−2 in the algebraic expression gives g=2, above the optimum. The expression can still be evaluated, but it is no longer a valid dual certificate under the chosen inequality convention. That is why the program rejects the sign instead of reporting an attractive bound.

A dual optimum is not necessarily easy to find, and a dual solution may not uniquely recover a primal solution. Nondifferentiable dual functions often require methods beyond ordinary smooth gradient ascent. Domain restrictions must also remain in the inner infimum; silently minimizing over a larger or smaller domain changes the dual construction.

Strong duality is a mathematical property under stated assumptions. A solver’s stopping status is an observation about an algorithm and tolerances. With floating-point arithmetic, check bound validity, feasibility residuals and the relevant scale before treating a small reported gap as a certificate.

Say what each number bounds

  1. For a=1, b=3, x=3 and λ=1, what interval contains the primal optimum?

Answer 1: [3/2,2]. The dual value supplies the lower endpoint and the feasible point’s objective supplies the upper endpoint.

  1. Why can x=a+λ be used to compute the dual value even when it violates the primal constraint?

Answer 2: The dual definition minimizes the Lagrangian over the common domain D, which is all real x here. The listed primal constraint is represented in the multiplier term rather than enforced inside that infimum.

  1. At x=4, λ=2 in the same problem, a gap of 5/2 remains. Does that prove a positive optimal duality gap?

Answer 3: No. The optimal pair x=3, λ=2 has gap zero. The larger gap comes from the suboptimal feasible candidate x=4.

  1. Why reject λ=−2 for a=3, b=1 even though the formula returns a finite value?

Answer 4: The sign violates dual feasibility. Its value 2 exceeds the primal optimum zero, so it cannot serve as the claimed lower bound.

Use bounds to judge progress, not just objective decreases

The textbook and lecture slides provide the general Lagrangian construction and weak/strong-duality distinction. The scalar derivation makes every part of the bound inspectable, including the inner minimization and multiplier sign.

For an extension, maximize this example’s concave quadratic dual with projected gradient ascent and track the certified gap of a separately feasible primal point. Its derivative is b−a−λ; relate a positive derivative to the constraint violation of the Lagrangian minimizer a+λ. Do not confuse that inner point with a feasible reported solution. Larger constrained optimization methods build on this distinction.

Make a prediction, then check

A positive gap at the current feasible primal-dual pair proves what?

Choose one answer

Learning objectives

  • Derive and verify a valid primal-dual bound pair.
  • Separate current gaps, optimal gaps and feasibility.

Prerequisites & connections

Explore related knowledge →

References

  1. Convex Optimization
    Stephen Boyd; Lieven Vandenberghe · 2004
  2. Convex Optimization — Duality lecture slides
    Stephen Boyd; Lieven Vandenberghe; Parth Nobel

Version1 · Editorial status: Recorded technical checks completed

View technical check record (AI)

Codex · 2026-09-06 · Codex single-agent authored technical review: primary-source locations, explicit assumptions, derivations, literal or exact computational checks, and bilingual review; not independent human or second-agent peer review.

  • Single-agent authored technical review: source locations, stated domains and assumptions, derivations, literal or exact reference cases and matching bilingual programs/exercises. Not independent human or second-agent peer review.
  • Four focused tests passed on CPython 3.12.4. Exact Fraction examples are used except for the explicitly floating-point damped Newton experiment. Strict bilingual MDX/KaTeX rendering gives four equations, six anchors and four answers per language; repository publication checks are recorded separately.
  • Promoted the full prose, equations, code and exercises. Tests read formal MDX only; removed temporary fallbacks/draft skips and updated review assertion to checked. Algorithm and independent references are unchanged; final record binds both locale hashes.
  • Publication navigation points published topics to complete articles and removes corresponding pending wording, retaining directory entries for unwritten targets. Principles, equations, programs and exercises are unchanged; final article SHA values rebound.

Source locations checked:

  • Convex Optimization · §5.1.2–5.1.3: infimum over common domain, concavity and lower bound for nonnegative multipliers; §5.2 weak/strong duality.
  • Convex Optimization — Duality lecture slides · Slides 5.2–5.3: Lagrangian, extended-valued dual function and lower-bound proof; convex Slater discussion and KKT continuation.

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.