(ctx, s, n)
return d
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.
r"""
    Given a sequence `(s_k)` containing at least `n+1` items, returns the
    `n`-th forward difference,
r Given a sequence ( s_k ) containing at least n + 1 items returns the n - th forward difference
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
def difference ( ctx , s , n ) : 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