code: def difference(ctx, s, n):
      r"""
      Given a sequence `(s_k)` containing at least `n+1` items, returns the
      `n`-th forward difference,
  
      .. math ::
  
          \Delta^n = \sum_{k=0}^{\infty} (-1)^{k+n} {n \choose k} s_k.
      """
      n = int(n)
      d = ctx.zero
      b = (-1) ** (n & 1)
      for k in xrange(n + 1):
          d += b * s[k]
          b = (b * (k - n)) // (k + 1)
      return d
  
file_path: catboost/contrib/python/mpmath/py3/mpmath/calculus/differentiation.py
imports: from ..libmp.backend import xrange
  from .calculus import defun
label_desc: Use image node_id 1 for calling a global function with example usage: difference(ctx, s, n) and returns: d