Solution (source code)

= Solution

The <contingent tangent cone> consists of feasible first-order velocities:
$$
\boxed{T_\Omega(x)=\{d:\exists t_n\downarrow0,\ x_n\in\Omega,\ (x_n-x)/t_n\to d\}.}
$$
If $x_*$ is a local minimizer, then $\boxed{\nabla f(x_*)^Td\geq0\text{ for every }d\in T_\Omega(x_*)}$. Indeed, $x_n\to x_*$ along the defining sequence, so eventually $f(x_n)-f(x_*)\geq0$. Differentiability gives
$$
\frac{f(x_n)-f(x_*)}{t_n}=\nabla f(x_*)^T\frac{x_n-x_*}{t_n}+o(1)\longrightarrow\nabla f(x_*)^Td.
$$
This proves the inequality. Using feasible limiting velocities avoids assuming that every tangent direction is realized by a straight segment staying in the feasible set.