(s)
return 1.0 + 2.0**(-s) + 3.0**(-s) + 4.0**(-s)*z
Riemann zeta function, real argument
Riemann zeta function, real argument
Riemann zeta function real argument
def zeta(s):
    """
    Riemann zeta function, real argument
    """
    if not isinstance(s, (float, int)):
        try:
            s = float(s)
        except (ValueError, TypeError):
            try:
                s = complex(s)
                if not s.imag:
                    return complex(zeta(s.real))
            except (ValueError, TypeError):
                pass
            raise NotImplementedError
    if s == 1:
        raise ValueError("zeta(1) pole")
    if s >= 27:
        return 1.0 + 2.0**(-s) + 3.0**(-s)
    n = int(s)
    if n == s:
        if n >= 0:
            return _zeta_int[n]
        if not (n % 2):
            return 0.0
    if s <= 0.0:
        return 2.**s*pi**(s-1)*_sinpi_real(0.5*s)*_gamma_real(1-s)*zeta(1-s)
    if s <= 2.0:
        if s <= 1.0:
            return _polyval(_zeta_0,s)/(s-1)
        return _polyval(_zeta_1,s)/(s-1)
    z = _polyval(_zeta_P,s) / _polyval(_zeta_Q,s)
    return 1.0 + 2.0**(-s) + 3.0**(-s) + 4.0**(-s)*z
def zeta ( s ) : if not isinstance ( s , ( float , int ) ) : try : s = float ( s ) except ( ValueError , TypeError ) : try : s = complex ( s ) if not s . imag : return complex ( zeta ( s . real ) ) except ( ValueError , TypeError ) : pass raise NotImplementedError if s == 1 : raise ValueError ( "zeta(1) pole" ) if s >= 27 : return 1.0 + 2.0 ** ( - s ) + 3.0 ** ( - s ) n = int ( s ) if n == s : if n >= 0 : return _zeta_int [ n ] if not ( n % 2 ) : return 0.0 if s <= 0.0 : return 2. ** s * pi ** ( s - 1 ) * _sinpi_real ( 0.5 * s ) * _gamma_real ( 1 - s ) * zeta ( 1 - s ) if s <= 2.0 : if s <= 1.0 : return _polyval ( _zeta_0 , s ) / ( s - 1 ) return _polyval ( _zeta_1 , s ) / ( s - 1 ) z = _polyval ( _zeta_P , s ) / _polyval ( _zeta_Q , s ) return 1.0 + 2.0 ** ( - s ) + 3.0 ** ( - s ) + 4.0 ** ( - s ) * z