A Representation Theory for Ranking Functions