I've been working on generating primes and prime products quickly to aid me in my research on prime numbers, their density, etc. The answer to my Large Number Limit Extravaganza question proved to be extremely useful in writing my programs. I have now expanded on this program to look at the difference in the amount of primes up to a certain point according to a lower bound, and the amount of "straight inhibitors" up to a certain point. A straight inhibitor is a figment of my imagination that I have used in my math and is extremely important for it.
import math
grandtotal = 1000
def prime_sieve(limit):
a = [True] * limit
a[0] = a[1] = False
for i, isprime in enumerate(a):
if isprime:
yield i
for n in xrange(i * i, limit, i):
a[n] = False
def getDotArrayLog():
e=55
data = []
while e<grandtotal:
e+=1
data.append((2 * e / (math.log(2.0 * e, 10) + 2)) - e / (math.log(e, 10) - 4))
return data
def getDotArrayProduct():
e=55
data = []
product = 1.0
while True:
if e==grandtotal: break
e+=1
for p in prime_sieve(e):
product *= (1.0 - 1.0 / p)
data.append(product)
product = 1.0
return data
if __name__ == "__main__":
logs = getDotArrayLog()
producta = getDotArrayProduct()
print "Tested all the way up to", grandtotal
counter = 0
for e in logs:
a = (1-producta[counter])*(counter+55)
print "Amount of primes:", e
print "Amount of inhibitors:", a
print e-a
counter+=1
I'm looking for some optimizations, condensations, and probably a great lecture on proper conventions.