Ab initio chemical potentials of solid and liquid solutions and the chemistry of the Earth's core