def normal_order(expr, recursive_limit=10, _recursive_depth=0):
 if (_recursive_depth > recursive_limit):
  warnings.warn('Too many recursions, aborting')
  return expr
 if isinstance(expr, Add):
  return _normal_order_terms(expr, recursive_limit=recursive_limit, _recursive_depth=_recursive_depth)
 elif isinstance(expr, Mul):
  return _normal_order_factor(expr, recursive_limit=recursive_limit, _recursive_depth=_recursive_depth)
 else:
  return expr

def normal_order ( expr , recursive_limit = 10 , _recursive_depth = 0 ) : if ( _recursive_depth > recursive_limit ) : warnings . warn ( 'Too many recursions, aborting' ) return expr if isinstance ( expr , Add ) : return _normal_order_terms ( expr , recursive_limit = recursive_limit , _recursive_depth = _recursive_depth ) elif isinstance ( expr , Mul ) : return _normal_order_factor ( expr , recursive_limit = recursive_limit , _recursive_depth = _recursive_depth ) else : return expr
normal order an expression with bosonic or fermionic operators .