Trace identities for commutators, with applications to the distribution of eigenvalues