def optimize(expr, optimizations):
    " Apply optimizations to an expression.\n\n    Parameters\n    ==========\n\n    expr : expression\n    optimizations : iterable of ``Optimization`` instances\n        The optimizations will be sorted with respect to ``priority`` (highest first).\n\n    Examples\n    ========\n\n    >>> from sympy import log, Symbol\n    >>> from sympy.codegen.rewriting import optims_c99, optimize\n    >>> x = Symbol('x')\n    >>> optimize(log(x+3)/log(2) + log(x**2 + 1), optims_c99)\n    log1p(x**2) + log2(x + 3)\n\n    "
    for optim in sorted(optimizations, key=(lambda opt: opt.priority), reverse=True):
        new_expr = optim(expr)
        if (optim.cost_function is None):
            expr = new_expr
        else:
            (before, after) = map((lambda x: optim.cost_function(x)), (expr, new_expr))
            if (before > after):
                expr = new_expr
    return expr
Apply optimizations to an expression.

Parameters
==========

expr : expression
optimizations : iterable of ``Optimization`` instances
    The optimizations will be sorted with respect to ``priority`` (highest first).

Examples
========

>>> from sympy import log, Symbol
>>> from sympy.codegen.rewriting import optims_c99, optimize
>>> x = Symbol('x')
>>> optimize(log(x+3)/log(2) + log(x**2 + 1), optims_c99)
log1p(x**2) + log2(x + 3)
def optimize(expr, optimizations):
    " Apply optimizations to an expression.\n\n    Parameters\n    ==========\n\n    expr : expression\n    optimizations : iterable of ``Optimization`` instances\n        The optimizations will be sorted with respect to ``priority`` (highest first).\n\n    Examples\n    ========\n\n    >>> from sympy import log, Symbol\n    >>> from sympy.codegen.rewriting import optims_c99, optimize\n    >>> x = Symbol('x')\n    >>> optimize(log(x+3)/log(2) + log(x**2 + 1), optims_c99)\n    log1p(x**2) + log2(x + 3)\n\n    "
    for optim in sorted(optimizations, key=(lambda opt: opt.priority), reverse=True):
        new_expr = optim(expr)
        if (optim.cost_function is None):
            expr = new_expr
        else:
            (before, after) = map((lambda x: optim.cost_function(x)), (expr, new_expr))
            if (before > after):
                expr = new_expr
    return expr