A helper function for gorenstein() computations.