Solution (source code)

= Solution

At a constrained <critical point>, the directional <derivative> of $f$ vanishes along every admissible tangent velocity:
$$
Df_a(v)=0\qquad(v\in T_aM).
$$
For a regular zero locus, $T_aM=\ker Dg_a$. A <linear functional> vanishing on this kernel lies in the <row space> of $Dg_a$. Equivalently there are <Lagrange multipliers> $\lambda_1,\ldots,\lambda_k$ such that
$$
\boxed{\nabla f(a)=Dg_a^T\lambda
=\sum_{j=1}^k\lambda_j\nabla g_j(a),\qquad g(a)=0.}
$$
Geometrically, $\nabla f$ is orthogonal to the <tangent space>, so it lies in its <orthogonal complement>, spanned by the independent constraint <gradients>. Thus the level set of $f$ has no first-order change in a tangent direction. The equations provide candidates for constrained extrema; they must still be classified and compared, and boundary or singular cases must be treated separately. The condition is necessary for a regular constrained extremum, not a guarantee of a maximum.