This Optimization concept is the current idea: keep the same invariant visible across Intuition, Math, Code, Interactive Demo.
Optimization
Duality and KKT Conditions
KKT conditions turn constrained convex optimality into a checkable certificate: feasibility, nonnegative multipliers, complementary slackness, stationarity, and zero duality gap.
Concept Structure
Duality and KKT Conditions
Start with the picture, metaphor, or geometric mechanism.
Make the objects explicit and connect them with notation.
Mirror the equations with runnable implementation details.
Manipulate the mechanism and watch the idea respond.
Learner Contract
What this page should let you do.
2 prerequisites listed; refresh them before leaning on the math or code.
Explain the mechanism, trace the main notation, and test one prediction in the live demo.
Read the intuition before the notation; the math should name a mechanism you already felt.
Follow this edge after making one prediction here; the next page should reuse the result, not restart the route.
Claim/source review status
Substantive review recorded
1/1 claims have bounded review metadata; still check caveats and source scope.Metadata-derived; review may be AI-assisted. Not a human certification.01
Intuition
Build the mental picture first so the rest of the page has something to attach to.
KKT conditions are often presented like a checklist. That is technically useful, but pedagogically backwards.
The real idea is a certificate. A constrained optimum should come with evidence that no feasible move can do better. In convex optimization, duality gives that evidence as a lower bound on the best possible primal value. If the lower bound meets the value of a feasible point, the point is optimal.
The KKT conditions are the local shape of that certificate:
- primal feasibility says the proposed point obeys the original constraints;
- dual feasibility says inequality multipliers are nonnegative prices;
- complementary slackness says a constraint gets a positive price only when it is tight;
- stationarity says the objective gradient is balanced by priced constraint normals.
Think of a ball rolling downhill until it hits a wall. If the wall is not touched, its contact force is zero. If the wall is touched, the contact force can be positive. KKT writes that story in symbols.
The lab uses one problem all the way through: move a target point to the closest point inside a half-plane. When the target is already feasible, the constraint is quiet and . When the target lies outside, the boundary becomes active, the multiplier is positive, and the primal value equals the best dual lower bound.
02
Math
Translate the story into symbols, assumptions, and a derivation you can inspect.
Start with a differentiable constrained problem in standard form:
The Lagrangian is
The dual function minimizes the Lagrangian over the primal variable:
For every dual feasible , weak duality gives
where is the primal optimum. So is a lower-bound certificate. The duality gap for a feasible is
When the problem is convex and the usual strong-duality conditions hold, a zero gap certificate is possible. For differentiable convex problems, the KKT conditions are sufficient for optimality:
Now specialize to the demo. Let be a target point and solve
where and . The feasible set is the half-plane below the line .
The Lagrangian is
Stationarity gives
Substitute this minimizer into the Lagrangian. If and , the dual function is
Maximizing this concave parabola over gives
If the target is feasible, , then and . If the target violates the constraint, , lands exactly on the boundary, and complementary slackness holds because .
03
Code
Keep the implementation aligned with the notation so the algorithm is legible.
import numpy as np
a = np.array([1.0, 1.0])
b = 1.0
def kkt_certificate(c):
c = np.array(c, dtype=float)
violation = a @ c - b
lambda_star = max(0.0, violation / (a @ a))
x_star = c - lambda_star * a
slack = a @ x_star - b
grad_f = x_star - c
stationarity = grad_f + lambda_star * a
primal = 0.5 * np.linalg.norm(x_star - c) ** 2
dual = lambda_star * violation - 0.5 * lambda_star**2 * (a @ a)
gap = primal - dual
return x_star, lambda_star, slack, stationarity, gap
for c in ([1.25, 1.10], [0.25, 0.35]):
x, lam, slack, residual, gap = kkt_certificate(c)
print("target:", c)
print("x*:", np.round(x, 3), "lambda:", round(lam, 3))
print("slack:", round(slack, 6))
print("stationarity residual:", round(np.linalg.norm(residual), 6))
print("duality gap:", round(gap, 6), "\n")
The code mirrors the math. The multiplier is positive only when the target violates the half-plane. The stationarity residual and duality gap are zero for the KKT certificate.
04
Interactive Demo
Use direct manipulation to connect the explanation to a moving system.
The lab asks you to predict the certificate before the numbers are revealed. Decide whether the active-constraint, inactive-constraint, or invalid-negative-multiplier story matches the current target.
Live Concept Demo
Explore Duality and KKT Conditions
The stage is code-native and interactive. Use it to test the explanation against the mechanism.
Manipulate one control and predict the visible change.
Commit to what Duality and KKT Conditions should make visible before reading the result.
After The First Pass
Turn the concept into an inspected object.
Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.
Mechanism Storyboard
See the idea move before the page explains it
KKT conditions turn constrained convex optimality into a checkable certificate: feasibility, nonnegative multipliers, complementary slackness, stationarity, and zero duality gap.
Start with the picture, metaphor, or geometric mechanism.
Before reading further, choose the kind of change Duality and KKT Conditions should make visible.
Visual Inquiry
Make the image answer a mathematical question
KKT conditions turn constrained convex optimality into a checkable certificate: feasibility, nonnegative multipliers, complementary slackness, stationarity, and zero duality gap.
Which visible object should carry the first intuition?
Pick the cue that should make Duality and KKT Conditions easier to reason about before the page gives the answer.
Source Grounding
Canonical references for the mechanism on this page.
Supports Lagrange dual functions, weak and strong duality, Slater's condition, duality gaps, complementary slackness, and KKT optimality conditions.
Open sourceSupports constrained optimization, primal/dual language, strong duality in convex optimization, and the SVM duality bridge.
Open sourceSupports Lagrangian dual variables, weak/strong duality, Slater-style constraint qualifications, complementary slackness, active constraints, KKT conditions, and SVM motivation.
Open sourceClaim Review
KKT conditions turn constrained convex optimality into a checkable certificate: feasibility, nonnegative multipliers, complementary slackness, stationarity, and zero duality gap.
Claims without a substantive review badge still need exact source-support review.
boyd-2004-convex-optimization-duality-kkt, deisenroth-2020-mml-duality-kkt, cs229-cvxopt2-kkt
Use equations, runnable code, and demos to check whether the source support is operational.
The sources support the Lagrangian, dual function as a lower-bound certificate, zero duality gap under convex strong-duality assumptions, complementary slackness, and the KKT feasibility/stationarity conditions.
Sources: Convex Optimization, Mathematics for Machine Learning, CS229 Section Notes: Convex Optimization OverviewThis page teaches a smooth convex toy with one affine inequality. It does not prove every constraint qualification, cover nonsmooth/subgradient KKT, solve nonconvex KKT sufficiency, or derive the SVM dual.A bounded review summary is present; still check caveats and exact reference scope.Checked Boyd/Vandenberghe chapter 5 for Lagrange dual functions, weak/strong duality, Slater's condition, duality gaps, complementary slackness, and KKT necessity/sufficiency for differentiable convex problems; MML chapter 7 for ML-oriented constrained optimization and strong-duality framing; and Stanford CS229 convex optimization notes for KKT conditions, active constraints, and the SVM support-vector motivation. GPT Pro publication critique remains pending because 127.0.0.1:51672 refused connection.
Reviewer: codex-local-source-review; reviewed 2026-07-02Source support candidates
book 2004Convex OptimizationSupports Lagrange dual functions, weak and strong duality, Slater's condition, duality gaps, complementary slackness, and KKT optimality conditions.
book 2020Mathematics for Machine LearningSupports constrained optimization, primal/dual language, strong duality in convex optimization, and the SVM duality bridge.
course-notes 2009CS229 Section Notes: Convex Optimization OverviewSupports Lagrangian dual variables, weak/strong duality, Slater-style constraint qualifications, complementary slackness, active constraints, KKT conditions, and SVM motivation.
Practice Loop
Try the idea before it explains itself
KKT conditions turn constrained convex optimality into a checkable certificate: feasibility, nonnegative multipliers, complementary slackness, stationarity, and zero duality gap.
Before touching the demo, predict one visible change that should happen in Duality and KKT Conditions.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
A concrete answer is on the canvas.
The answer names why the claim should hold.
It touches the page context or a neighboring idea.
Research Room
Attach the question to a claim, equation, code, or demo
Pick the concept, equation, source, runnable code, claim, misconception, or demo state before asking for help. The handoff keeps that page item in context.Open the draft below to save one note and next action in this browser.
Duality and KKT Conditions
What is the smallest example that makes Duality and KKT Conditions click without losing the math?
Local action draftNo local draft saved yetExpand only when ready to capture one local next action
This draft stays in this browser, attached to the selected learning item.
- References to inspect: attached references on this page.
- Definition, prerequisite, and contrast concept links
- The equation or runnable code that makes the concept operational
- One demo state that shows the invariant instead of a slogan
- The learner can state the mechanism in their own words
- The learner can name the prerequisite that would repair confusion
- The learner can predict how the mechanism changes under one perturbation
I am working in Continuous Function's research reading room. Object: concept - Duality and KKT Conditions Selected item key: recorded for copy. Context: Optimization Page anchor: recorded for copy. Open question: What is the smallest example that makes Duality and KKT Conditions click without losing the math? Evidence to inspect: - References to inspect: attached references on this page. - Definition, prerequisite, and contrast concept links - The equation or runnable code that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.
concept/concept-notebook/optimization/duality-kkt-conditions
concept:optimization/duality-kkt-conditions