def _normal_order_terms(expr, recursive_limit=10, _recursive_depth=0):
 new_terms = []
 for term in expr.args:
  if isinstance(term, Mul):
   new_term = _normal_order_factor(term, recursive_limit=recursive_limit, _recursive_depth=_recursive_depth)
   new_terms.append(new_term)
  else:
   new_terms.append(term)
 return Add(*new_terms)

def _normal_order_terms ( expr , recursive_limit = 10 , _recursive_depth = 0 ) : new_terms = [ ] for term in expr . args : if isinstance ( term , Mul ) : new_term = _normal_order_factor ( term , recursive_limit = recursive_limit , _recursive_depth = _recursive_depth ) new_terms . append ( new_term ) else : new_terms . append ( term ) return Add ( * new_terms )
helper function for normal_order: look through each term in an addition expression and call _normal_order_factor to perform the normal ordering on the factors .