\sum_{n}|n\rangle\langle n||\psi\rangle=\sum_{n}a_n|n\rangle=|\psi\rangle