def _eapply(func, e, cond=None):
 if (not isinstance(e, Expr)):
  return e
 if (_is_Expr(e) or (not e.args)):
  return func(e)
 return e.func(*[(_eapply(func, ei) if ((cond is None) or cond(ei)) else ei) for ei in e.args])

def _eapply ( func , e , cond = None ) : if ( not isinstance ( e , Expr ) ) : return e if ( _is_Expr ( e ) or ( not e . args ) ) : return func ( e ) return e . func ( * [ ( _eapply ( func , ei ) if ( ( cond is None ) or cond ( ei ) ) else ei ) for ei in e . args ] )
apply func to e if all args are exprs else only apply it to those args that *are* exprs .