recursively sorting an infinite tree of representations