code: def gosper_sum(f, k):
      r"""
      Gosper's hypergeometric summation algorithm.
  
      Explanation
      ===========
  
      Given a hypergeometric term ``f`` such that:
  
      .. math ::
          s_n = \sum_{k=0}^{n-1} f_k
  
      and `f(n)` does not depend on `n`, returns `g_{n} - g(0)` where
      `g_{n+1} - g_n = f_n`, or ``None`` if `s_n` cannot be expressed
      in closed form as a sum of hypergeometric terms.
  
      Examples
      ========
  
      >>> from sympy.concrete.gosper import gosper_sum
      >>> from sympy import factorial
      >>> from sympy.abc import n, k
  
      >>> f = (4*k + 1)*factorial(k)/factorial(2*k + 1)
      >>> gosper_sum(f, (k, 0, n))
      (-factorial(n) + 2*factorial(2*n + 1))/factorial(2*n + 1)
      >>> _.subs(n, 2) == sum(f.subs(k, i) for i in [0, 1, 2])
      True
      >>> gosper_sum(f, (k, 3, n))
      (-60*factorial(n) + factorial(2*n + 1))/(60*factorial(2*n + 1))
      >>> _.subs(n, 5) == sum(f.subs(k, i) for i in [3, 4, 5])
      True
  
      References
      ==========
  
      .. [1] Marko Petkovsek, Herbert S. Wilf, Doron Zeilberger, A = B,
             AK Peters, Ltd., Wellesley, MA, USA, 1997, pp. 73--100
  
      """
      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)
  
imports: from sympy.core import S, Dummy, symbols
  from sympy.polys import Poly, parallel_poly_from_expr, factor
  from sympy.utilities.iterables import is_sequence
label_desc: Use image node_id 3 for calling a global function with example usage: gosper_sum(f, k) and returns: factor, None