The Mathematics of Rhythm and Polyrhythms