Precompute the changes in energy.