def factor_sum(self, limits=None, radical=False, clear=False, fraction=False, sign=True):
 from sympy.core.exprtools import factor_terms
 from sympy.concrete.summations import Sum
 result = (self.function if (limits is None) else self)
 limits = (self.limits if (limits is None) else limits)
 if (result == 0):
  return S.Zero
 sum_vars = set([limit.args[0] for limit in limits])
 retv = factor_terms(result, radical=radical, clear=clear, fraction=fraction, sign=sign)
 if (not result.is_commutative):
  return Sum(result, *limits)
 (i, d) = retv.as_independent(*sum_vars)
 if isinstance(retv, Add):
  return ((i * Sum(1, *limits)) + Sum(d, *limits))
 else:
  return (i * Sum(d, *limits))

def factor_sum ( self , limits = None , radical = False , clear = False , fraction = False , sign = True ) : from sympy . core . exprtools import factor_terms from sympy . concrete . summations import Sum result = ( self . function if ( limits is None ) else self ) limits = ( self . limits if ( limits is None ) else limits ) if ( result == 0 ) : return S . Zero sum_vars = set ( [ limit . args [ 0 ] for limit in limits ] ) retv = factor_terms ( result , radical = radical , clear = clear , fraction = fraction , sign = sign ) if ( not result . is_commutative ) : return Sum ( result , * limits ) ( i , d ) = retv . as_independent ( * sum_vars ) if isinstance ( retv , Add ) : return ( ( i * Sum ( 1 , * limits ) ) + Sum ( d , * limits ) ) else : return ( i * Sum ( d , * limits ) )
helper function for sum simplification if limits is specified .