def gosper_sum(f, k):
 indefinite = False
 if is_sequence(k):
  (k, a, b) = k
 else:
  indefinite = True
 g = gosper_term(f, k)
 if (g is None):
  return None
 if indefinite:
  result = (f * g)
 else:
  result = ((f * (g + 1)).subs(k, b) - (f * g).subs(k, a))
  if (result is S.NaN):
   try:
    result = ((f * (g + 1)).limit(k, b) - (f * g).limit(k, a))
   except NotImplementedError:
    result = None
 return factor(result)

def gosper_sum ( f , k ) : indefinite = False if is_sequence ( k ) : ( k , a , b ) = k else : indefinite = True g = gosper_term ( f , k ) if ( g is None ) : return None if indefinite : result = ( f * g ) else : result = ( ( f * ( g + 1 ) ) . subs ( k , b ) - ( f * g ) . subs ( k , a ) ) if ( result is S . NaN ) : try : result = ( ( f * ( g + 1 ) ) . limit ( k , b ) - ( f * g ) . limit ( k , a ) ) except NotImplementedError : result = None return factor ( result )
gospers hypergeometric summation algorithm .