Giter Club home page Giter Club logo

nbdev_sieve's Introduction

nbdev_sieve

#%matplotlib inline
The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload

README file and the index of documentation.

Install

pip install nbdev_sieve

How to use

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]

Count primes at higher order of magnitude

see prime counting function

n π(n)
$10^0$ 0
$10^1$ 4
$10^2$ 25
$10^3$ 168
$10^4$ 1,229
$10^5$ 9,592
$10^6$ 78,498
$10^7$ 664,579
$10^8$ 5,761,455
$10^9$ 50,847,534
$10^{10}$ 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()

nbdev_sieve's People

Contributors

nitinverma78 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.