def Is(self, x): if x < 0: return -x - math.log(2) * mpmath.li(2 - x) + math.log(2) * mpmath.li(2) else: return x - math.log(2) * mpmath.li(2 + x) + math.log(2) * mpmath.li(2)
def solve_fx(initial, p): x = initial # initial value while True: fx = f(x, p) fpx = fp(x, 1, p) xnew = x - (mpmath.li(x) - p) * (math.log(x)) / (1 + (mpmath.li(x) - p) / (2 * x)) if abs(xnew - x) <= eps: return xnew x = xnew
def pi(n): if n < 2657: app = int(n/math.log(n)) for i, x in enumerate(list(sieve(2658))[app:]): if x > n: return i + app else: app = int(mpmath.li(n)) limit = math.ceil(math.sqrt(n)*math.log(n)/(8*math.pi)) print(app, limit, list(itertools.islice(sieve(10**6), app-limit, app+limit)))
# Jun/12/2016 # Yurani Melisa Palacios Palacios # Integration, being as important as it is, has several highly efficient implementations available for us. # Among them are the ones found in scipy # "Integracion, siendo tan importante como lo es, tiene varias implementaciones altamente eficientes disponibles para nosotros. # Entre ellos se encuentran los que se encuentran en scipy" import numpy as np import mpmath import scipy.integrate as integrate def function (x): return 1 / np.log(x) result = integrate.quad( function, 2, 10) print result print mpmath.li (10, ofsset=True)
# Jun/10/2016 # Yurani Melisa Palacios Palacios import numpy as np import mpmath import scipy.integrate as integrate def f(x): return 1 / np.log(x) a = 2.0 b = 10.0 N = 1000 d = (b - a) / N A = 0 for k in range(N): a1 = a + k * d b1 = a1 + d A += (b1 - a1) * (f(a1) + f(b1)) / 2. print 'we calculated = ', A print 'mpmath calculated = ', mpmath.li(b, offset = True) print 'scipy calculated = ', integrate.quad(f, 2, 10)
def getLI( n ): return li( n )
def Li(x): return mpmath.li(x, offset=True) last_printed = -threshold
def getLIOperator(n): return li(n)
from mpmath import li from sympy import sieve import matplotlib.pyplot as plt li_offset = lambda x: li(x, offset=True) N = 1000000 step = 1000 xx = [step * (i + 1) for i in range(N // step)] primes = list(sieve.primerange(1, N)) estimate = list(map(li_offset, xx)) actual = [] for x in xx: actual.append(len([prime for prime in primes if prime < x])) yy = [a / e for a, e in zip(actual, estimate)] plt.plot(xx, yy) plt.title('|{primes<x}|/li(x)') plt.show()
def f(x, p): return mpmath.li(x) - p