#%matplotlib inline
The autoreload extension is already loaded. To reload it, use:
%reload_ext autoreload
README file and the index of documentation.
pip install nbdev_sieve
For now, only the sieve(N: int) generator can be called
## Helper functions
def primes(N: int = 10):
"get list of primes"
return [p for p in sieve(N)]
print (primes(17))
[2, 3, 5, 7, 11, 13, 17]
n | π(n) |
---|---|
0 | |
4 | |
25 | |
168 | |
1,229 | |
9,592 | |
78,498 | |
664,579 | |
5,761,455 | |
50,847,534 | |
455,052,511 |
def prime_count(om: int = 8):
"#primes < 10^om"
return {n: len(primes(n)) for o in range(om) if(n:=10**o)}
π = prime_count()
π
{1: 0,
10: 4,
100: 25,
1000: 168,
10000: 1229,
100000: 9592,
1000000: 78498,
10000000: 664579}
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.scatter([math.log10(n) for n in π], [c/n for n, c in π.items()])
plt.xlabel("Order of Magnitude (10^n)")
plt.ylabel("Fraction of primes")
plt.show()