

@defun
def sumap(ctx, f, interval, integral=None, error=False):
    '\n    Evaluates an infinite series of an analytic summand *f* using the\n    Abel-Plana formula\n\n    .. math ::\n\n        \\sum_{k=0}^{\\infty} f(k) = \\int_0^{\\infty} f(t) dt + \\frac{1}{2} f(0) +\n            i \\int_0^{\\infty} \\frac{f(it)-f(-it)}{e^{2\\pi t}-1} dt.\n\n    Unlike the Euler-Maclaurin formula (see :func:`~mpmath.sumem`),\n    the Abel-Plana formula does not require derivatives. However,\n    it only works when `|f(it)-f(-it)|` does not\n    increase too rapidly with `t`.\n\n    **Examples**\n\n    The Abel-Plana formula is particularly useful when the summand\n    decreases like a power of `k`; for example when the sum is a pure\n    zeta function::\n\n        >>> from mpmath import *\n        >>> mp.dps = 25; mp.pretty = True\n        >>> sumap(lambda k: 1/k**2.5, [1,inf])\n        1.34148725725091717975677\n        >>> zeta(2.5)\n        1.34148725725091717975677\n        >>> sumap(lambda k: 1/(k+1j)**(2.5+2.5j), [1,inf])\n        (-3.385361068546473342286084 - 0.7432082105196321803869551j)\n        >>> zeta(2.5+2.5j, 1+1j)\n        (-3.385361068546473342286084 - 0.7432082105196321803869551j)\n\n    If the series is alternating, numerical quadrature along the real\n    line is likely to give poor results, so it is better to evaluate\n    the first term symbolically whenever possible:\n\n        >>> n=3; z=-0.75\n        >>> I = expint(n,-log(z))\n        >>> chop(sumap(lambda k: z**k / k**n, [1,inf], integral=I))\n        -0.6917036036904594510141448\n        >>> polylog(n,z)\n        -0.6917036036904594510141448\n\n    '
    prec = ctx.prec
    try:
        ctx.prec += 10
        (a, b) = interval
        if (b != ctx.inf):
            raise ValueError('b should be equal to ctx.inf')
        g = (lambda x: f((x + a)))
        if (integral is None):
            (i1, err1) = ctx.quad(g, [0, ctx.inf], error=True)
        else:
            (i1, err1) = (integral, 0)
        j = ctx.j
        p = (ctx.pi * 2)
        if ctx._is_real_type(i1):
            h = (lambda t: (((- 2) * ctx.im(g((j * t)))) / ctx.expm1((p * t))))
        else:
            h = (lambda t: ((j * (g((j * t)) - g(((- j) * t)))) / ctx.expm1((p * t))))
        (i2, err2) = ctx.quad(h, [0, ctx.inf], error=True)
        err = (err1 + err2)
        v = ((i1 + i2) + (0.5 * g(ctx.mpf(0))))
    finally:
        ctx.prec = prec
    if error:
        return ((+ v), err)
    return (+ v)

dataset/ETHPy150Open fredrik-johansson/mpmath/mpmath/calculus/extrapolation.py sumap/original