Solution (source code)

= Solution

At a regular constrained <stationary point>, the change in $f$ along every allowed tangent direction must vanish. Thus its <gradient> is normal to the <constraint> curve, giving the <Lagrange multiplier> equations
$$
\boxed{\nabla f=\lambda\nabla g,\qquad g=c},
$$
provided $\nabla g\ne0$. Solve these equations for $x,y,\lambda$, then classify the candidates using the <constraint> or a constrained second-derivative test. Points where the <constraint> <gradient> vanishes require separate analysis.

For $n$ variables and $r$ regular independent constraints $g_j=c_j$, use one multiplier per <constraint>:
$$
\boxed{\nabla f=\sum_{j=1}^r\lambda_j\nabla g_j,\qquad g_j=c_j}.
$$
There are $n+r$ scalar equations in the $n+r$ unknowns. Independence of the <constraint> gradients is the regularity condition; boundary points must be treated separately when present.