Constrained Optimality and Dual Certificates
An optimum on a constraint boundary can have a nonzero gradient. One way to prove optimality is to find a lower bound that applies to every feasible point, then show that a candidate attains it. The Lagrange multipliers producing that bound form a dual certificate. The underlying lower-bound argument and optimality conditions are developed in Boyd and Vandenberghe, Chapter 5.
The convex optimization overview introduces convexity and KKT; gradient and multidimensional optimization explains gradients and Hessians. For background on choosing variables, an objective, and a feasible set, see optimization modeling. Here those ideas meet in one calculation.
Objective and feasible set
For real variables , consider the primal problem:
The feasible set is a closed triangle. The objective is half the squared distance to . Since is nonempty and compact and the objective is continuous, a minimum exists. The Hessian is the identity matrix, so the objective is strictly convex and its minimizer is unique.
This fits the form used in CVXPY's quadratic-program example: , with and positive-semidefinite . Here , , , and
The constant does not change the minimizer. Keep it to recover the values of and defined here; subtracting it from both leaves the primal–dual gap unchanged.
Find a candidate
The unconstrained minimizer violates . Try the boundary by substituting :
The minimum along this edge is therefore
Both coordinates are positive, so the candidate lies on the edge. Minimizing on one edge alone does not rule out better points elsewhere in the triangle. The dual bound below will complete the global proof.
A constraint is active at a point when it holds with equality. Here , whereas and : only the constraint on the sum is active. The objective gradient is . Moving along the negative gradient would increase and leave the feasible set.
Lagrangian and dual bound
Using the convention , assign nonnegative multipliers to the three constraints. Following Boyd and Vandenberghe, §§5.1.1–5.1.3, form
For fixed multipliers, the dual function is the infimum of over the variable domain:
Take this infimum over all of . The three inequalities are already incorporated into ; restricting this calculation to the triangle would change the dual function.
The Hessian of with respect to is still . Setting its partial derivatives to zero thus finds its unique global minimizer:
giving and . Completing the square yields
The dual problem maximizes subject to . Here is finite for all finite multipliers. For any feasible and nonnegative multipliers,
The second inequality holds because each added term is a nonnegative multiplier times a nonpositive constraint value. Write for the primal optimal value and for the dual optimal value. Then , known as weak duality. This argument does not require convexity.
Calculate the multipliers and check all four KKT conditions
Complementary slackness requires each multiplier times its constraint value to vanish. Since , we get . Substitution into the stationarity equations gives
The four KKT conditions from §5.5.3 of the textbook now have explicit checks:
A finite dual lower bound additionally requires . This is automatic for this quadratic program, but does not follow from the multiplier signs alone in a general problem.
A positive multiplier requires its constraint to be active; an inactive constraint requires a zero multiplier. An active constraint can still have a zero multiplier. For example, change the bound in this problem to : the unconstrained minimizer lies on , with every multiplier zero.
For a differentiable convex problem, with convex objective and inequality functions and affine equalities, satisfying KKT certifies global optimality. Here the certificate also gives a numerical equality:
Every feasible point has objective at least , and the candidate attains it. Hence . The squared terms give the same conclusion directly:
Equality holds only at . This proves optimality and uniqueness without searching through every feasible point.
Measure a candidate's error with the gap
For a primal feasible point and dual feasible multipliers, the primal–dual gap is . It bounds the candidate's suboptimality:
Each row below is a feasible primal–dual pair, but the first two use multipliers that are not dual optimal.
The second row gives and a suboptimality bound of . The candidate's actual suboptimality is . A positive gap for a candidate pair does not establish a positive gap between the optimal values: here the optimal duality gap is zero.
What regularity and convexity each guarantee
A convex optimum can lack KKT multipliers
Slater's condition, §5.2.3, requires a convex problem to have a point in the relative interior of its common domain satisfying the equalities and all inequalities strictly. It guarantees strong duality and, for a finite optimal value, attainment of the dual optimum by finite multipliers. With differentiability, KKT becomes necessary and sufficient for optimality. The textbook's refined version allows affine inequalities to hold without strict inequality.
The point satisfies all three inequalities strictly in our quadratic program, so Slater holds. It guarantees that an optimal certificate exists. Sufficiency of an already established KKT certificate in a convex problem does not itself require Slater.
Now consider a different convex problem:
Its only feasible point is , with . No point satisfies , so Slater fails. The stationarity equation for is . No finite multiplier can satisfy it at .
For , the minimizer of is , giving ; at , . Thus , but no finite multiplier attains the supremum. Multiplier existence and KKT necessity fail in this example; strong duality still holds.
A nonconvex KKT point can be a maximum
Consider
The feasible set is , and the objective is not convex. At with both multipliers zero, primal feasibility, nonnegative multipliers, stationarity, and complementary slackness all hold. Yet and : this KKT point is the strict maximum over the feasible set.
The stationary point of is not its global minimizer; . In fact, any finite multipliers only add affine terms, leaving a downward-opening quadratic, so in this problem. Weak duality survives but gives no finite lower bound. Although satisfies both constraints strictly, Slater's theorem for convex problems cannot be applied to this nonconvex objective.
Recompute with Python
This trace uses only rational arithmetic from Python's standard library. It checks the derived point and multipliers and recomputes the gaps and counterexamples. The global infimum needed for the certificate follows from the completed-square derivation above.
from fractions import Fraction as F
def objective(x, y):
return F(1, 2) * ((x - 2)**2 + (y - 1)**2)
def dual(lam, mu, nu):
return lam - 2*mu - nu - F(1, 2)*((lam-mu)**2 + (lam-nu)**2)
def vector(values):
return '(' + ', '.join(map(str, values)) + ')'
x, y = F(3, 2), F(1, 2)
lam, mu, nu = F(1, 2), F(0), F(0)
constraints = (x+y-2, -x, -y)
multipliers = (lam, mu, nu)
stationarity = (x-2+lam-mu, y-1+lam-nu)
kkt = (
all(c <= 0 for c in constraints),
all(m >= 0 for m in multipliers),
all(s == 0 for s in stationarity),
all(m*c == 0 for m, c in zip(multipliers, constraints)),
)
assert all(kkt)
print('x=' + vector((x, y)) + ', multipliers=' + vector(multipliers))
print('constraints=' + vector(constraints))
print('stationarity=' + vector(stationarity))
print('KKT=' + vector(kkt))
for label, a, b, l in [('candidate', F(1), F(1), F(1, 4)),
('optimum', x, y, lam)]:
p, d = objective(a, b), dual(l, F(0), F(0))
print(f'{label}: f={p}, g={d}, gap={p-d}')
for l in (F(1), F(10), F(100)):
z = -1/(2*l)
g = z + l*z*z
assert g == -1/(4*l)
print(f'degenerate: lambda={l}, x_min_L={z}, g={g}')
z = F(0)
nonconvex_constraints = (z-1, -z-1)
nonconvex_multipliers = (F(0), F(0))
nonconvex_kkt = (
all(c <= 0 for c in nonconvex_constraints),
all(m >= 0 for m in nonconvex_multipliers),
-2*z + nonconvex_multipliers[0] - nonconvex_multipliers[1] == 0,
all(m*c == 0 for m, c in zip(nonconvex_multipliers, nonconvex_constraints)),
)
print('nonconvex: KKT=' + vector(nonconvex_kkt)
+ f', f(0)={-z*z}, f(-1)=f(1)={-F(1)**2}')
Actual output:
x=(3/2, 1/2), multipliers=(1/2, 0, 0)
constraints=(0, -3/2, -1/2)
stationarity=(0, 0)
KKT=(True, True, True, True)
candidate: f=1/2, g=3/16, gap=5/16
optimum: f=1/4, g=1/4, gap=0
degenerate: lambda=1, x_min_L=-1/2, g=-1/4
degenerate: lambda=10, x_min_L=-1/20, g=-1/40
degenerate: lambda=100, x_min_L=-1/200, g=-1/400
nonconvex: KKT=(True, True, True, True), f(0)=0, f(-1)=f(1)=-1
For larger quadratic programs, the CVXPY example retrieves multipliers through a constraint object's dual_value. Keep the constraint order and sign convention consistent, then check feasibility, stationarity residuals, complementary products, and the lower bound from the actual dual function. A small stationarity residual alone would not exclude the nonconvex maximum above.