On the periodic writing of cubic irrationals and a generalization of Redei functions