Git Product home page Git Product logo

python-primes's Introduction

Prime Functions for Python

Some functions to play with prime numbers for python.

Some of them are similar (or equal) to functions from SymPy library.

Implemented functions:

  • inefficient_isprime(n): Inefficient (and simpliest) way to verify if a number is prime or not. Returns True if integer n is prime.
  • isprime(n): More efficient way to verify if a number is prime or not. Returns True if integer n is prime.
  • allprevprime(n): Efficient way of making a list of primes <= n.
  • arecoprime(a,b): It verifies if two numbers doesn't have factors in common. Checkout the definition of CoPrimes for more info. Returns True if a and b are coprimes.
  • nextprime(n): Returns the next prime > n.
  • prevprime(n): Returns the previous prime < n.
  • primerange(a, b): Returns a list of prime numbers in the range [a, b[.
  • primepi(n): Returns the number of prime numbers <= n.
  • sheldonprime(n): Returns True if number n is a sheldon prime. Checkout the definition of sheldon prime to more info.
  • prime(nth): Returns nth prime number. In case nth < 1, returns None.

Also is featured the primality test (in this case, Solovay-Strassen primality test). It is a randomised probabilistic test, so it can verify if a number is prime. it is very efficient and it is implemented in the primality_test file.

Other functions:

  • notfactors(list): Returns True if no number in list is factor of n.
  • factorsproduct(list): Returns the product of all elements of a list in a recursive way. Returns a float.
  • notfactors_forprime(list): Variation of notfactors function for more efficiency. Useful to determine if n is prime if the numbers of list are sorted and are primes < n.

python-primes's People

Contributors

alfremk avatar

Stargazers

 avatar  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.