mpmath 1.4.1 /home/sage/sage/local/var/lib/sage/venv-python3.12/lib/python3.12/site-packages/mpmath/functions/zeta.py
default diff 1.562159984098654997128120946226456e-11 0.02251040122905366072265119305629258148849
direct derivative 0.0 0.02251040121343206088166464308501137202623
step -2.4891779699413390477185955219072022e-111 0.02251040121343206088166464308501137202623
zeta0 0.25
exact derivative 0.02251040121343206088166464308501137202623
@defun
def zeta(ctx, s, a=1, derivative=0, method=None, **kwargs):
    d = int(derivative)
    if a == 1 and not (d or method):
        try:
            return ctx._zeta(s, **kwargs)
        except NotImplementedError:
            pass
    s = ctx.convert(s)
    prec = ctx.prec
    verbose = kwargs.get('verbose')
    if (not s) and (not derivative):
        return ctx.mpf(0.5) - ctx._convert_param(a)[0]
    if a == 1 and method != 'euler-maclaurin':
        im = abs(ctx._im(s))
        re = abs(ctx._re(s))
        #if (im < prec or method == 'borwein') and not derivative:
        #    try:
        #        if verbose:
        #            print "zeta: Attempting to use the Borwein algorithm"
        #        return ctx._zeta(s, **kwargs)
        #    except NotImplementedError:
        #        if verbose:
        #            print "zeta: Could not use the Borwein algorithm"
        #        pass
        if abs(im) > 500*prec and 10*re < prec and derivative <= 4 or \
            method == 'riemann-siegel':
            try:
                if verbose:
                    print("zeta: Attempting to use the Riemann-Siegel algorithm")
                return ctx.rs_zeta(s, derivative, **kwargs)
            except NotImplementedError:
                if verbose:
                    print("zeta: Could not use the Riemann-Siegel algorithm")
            finally:
                ctx.prec = prec
    if s == 1:
        return ctx.inf
    abss = abs(s)
    if abss == ctx.inf:
        if ctx.re(s) == ctx.inf:
            if d == 0:
                return ctx.one
            return ctx.zero
        return s*0
    elif ctx.isnan(abss):
        return 1/s
    if ctx.re(s) > 2*ctx.prec and a == 1 and not derivative:
        return ctx.one + ctx.power(2, -s)
    return +ctx._hurwitz(s, a, d, **kwargs)

