def rewriter(condition, rewrite):
 def _rewriter(integral):
  (integrand, symbol) = integral
  if condition(*integral):
   rewritten = rewrite(*integral)
   if (rewritten != integrand):
    substep = integral_steps(rewritten, symbol)
    if ((not isinstance(substep, DontKnowRule)) and substep):
     return RewriteRule(rewritten, substep, integrand, symbol)
 return _rewriter

def rewriter ( condition , rewrite ) : def _rewriter ( integral ) : ( integrand , symbol ) = integral if condition ( * integral ) : rewritten = rewrite ( * integral ) if ( rewritten != integrand ) : substep = integral_steps ( rewritten , symbol ) if ( ( not isinstance ( substep , DontKnowRule ) ) and substep ) : return RewriteRule ( rewritten , substep , integrand , symbol ) return _rewriter
create a template field function that rewrites the given field with the given rewriting rules .