  We prove a generalization of the Hardy-Littlewood-P\'olya rearrangement
inequality to positive definite matrices. The inequality can be seen as a
commutation principle in the sense of Iusem and Seeger. An important instrument
in the proof is a first-order perturbation formula for a certain spectral
function, which could be of independent interests. The inequality is then
extended to rectangular matrices. Using our main results, we derive new
inequalities for several distance-like functions encountered in various signal
processing or machine learning applications.
