The dual approach to recursive optimization: theory and examples