Stav dette: A theory of quantum subspace diagonalization