An inertia theorem for symmetric matrices and its application to nonlinear programming