Polynomially scaling spin dynamics simulation algorithm based on adaptive state-space restriction.