Exemplo n.º 1
0
    def __init__(self, npts):
        # Legendre poly
        lp = lambda x: mp.legendre(npts - 1, x)

        # Coefficients of lp
        cf = mp.taylor(lp, 0, npts - 1)

        # Coefficients of dlp/dx
        dcf = [i*c for i, c in enumerate(cf[1:], start=1)]

        self.points = [mp.mpf(-1)] + mp.polyroots(dcf[::-1]) + [mp.mpf(1)]
        self.weights = [2/(npts*(npts - 1)*lp(p)**2) for p in self.points]
# NOTE: This file implements an slightly different version of li_criter.
#       It finds the taylor expansion coefficients of log(xi(z/(z-1)), instead if its derivative,
#       which is in the original li_criterion
#
# the following code is from
# http://fredrikj.net/blog/2013/03/testing-lis-criterion/
# It uses mpmath to calculate taylor expansion of xi function
#
# It will produce the 1st 21 coefficients for Li-criter
# [-0.69315, 0.023096, 0.046173, 0.069213, 0.092198, 0.11511, 0.13793, 0.16064, 0.18322, 0.20566,
#  0.22793, 0.25003,  0.27194,  0.29363,  0.31511,  0.33634, 0.35732, 0.37803, 0.39847, 0.41862, 0.43846]
#
# More information about mpmath can be found at: mpmath.org
# http://mpmath.org/

from mpmath import mp

mp.dps = 5
mp.pretty = True
xi = lambda s: (s - 1) * mp.pi ** (-0.5 * s) * mp.gamma(1 + 0.5 * s) * mp.zeta(s)

# calculate 1st 21 coefficients of taylor expansion of log(xi(z/(z-1))
tmp = mp.taylor(lambda z: mp.log(xi(z / (z - 1))), 0, 20)
print tmp
Exemplo n.º 3
0
    def __init__(self, npts):
        # Legendre poly
        lp = lambda x: mp.legendre(npts, x)

        self.points = mp.polyroots(mp.taylor(lp, 0, npts)[::-1])
        self.weights = [2/((1 - p*p)*mp.diff(lp, p)**2) for p in self.points]