Phase transitions: The math behind the music