This is one step in diagonalizing by completing the square over and over. As long as $a_{11} \neq 0,$ the revised form
$$ f(x) - \frac{1}{4 a_{11} \left( \frac{\partial f}{\partial x_1} \right)^2} $$
is still a quadratic form, but no longer has any terms involving $x_1.$ Therefore the step can be repeated. As long as the revised diagonal entries never become zero, this works. If, at some intermediate step, the revised $a_{kk} = 0,$ other things need to be done.
Works: $f = x^2 + 5 xy - 17 y^2.$ Then the derivative $f_1 = 2x+5y,$ then $f_1^2 = 4x^2 + 20 xy + 25 y^2,$ and $(1/4) f_1^2 = x^2 + 5 xy + (25/4)y^2,$ so
$$f(x) - \frac{1}{4 a_{11} \left( \frac{\partial f}{\partial x_1} \right)^2} = - \frac{93}{4} y^2 $$
Does not work: $g = 2xy$
For an algorithmic method that works even when the eigenvalues of the symmetric matrix are very bad, see reference for linear algebra books that teach reverse Hermite method for symmetric matrices