Text this: A theory of quantum subspace diagonalization