−∇f(z*) = zt − z* (the cost pulls downhill, toward the target)
−λ∇g(z*) (the fence pushes back, normal to the boundary, into the feasible side)
level sets of f
Numbers
The four KKT conditions, checked live
Closed forms used here (no solver): round fence z* = zt if ‖zt‖ ≤ 1, else zt/‖zt‖ with λ = ‖zt‖ − 1;
straight fence z* = zt − max(0, g(zt)) n with λ = max(0, g(zt)); rail z* = zt − h(zt) n with κ = h(zt) of either sign.
Companion notes: modules/kkt-explorer/notes.md; lecture: Deck 05, session 4.1.