def postprocess_for_cse(expr, optimizations):
 for (pre, post) in reversed(optimizations):
  if (post is not None):
   expr = post(expr)
 return expr

def postprocess_for_cse ( expr , optimizations ) : for ( pre , post ) in reversed ( optimizations ) : if ( post is not None ) : expr = post ( expr ) return expr
postprocess an expression after common subexpression elimination to return the expression to canonical sympy form .