Does a library for prime-related functions exist for Python? Does a library for prime-related functions exist for Python? python python

Does a library for prime-related functions exist for Python?


I just discovered isprime from the SymPy package:

import sympyprint sympy.isprime(10)

Output:

False

Not to confuse with prime, which returns the n-th prime number:

import sympyprint sympy.prime(10)

Output:

29


gmpy2 supports a variety of pseudoprime tests. The Miller-Rabin test is available as gmpy2.is_strong_prp().

gmpy2 does not have any factorization code yet.

Disclaimer: I'm the maintainer of gmpy2. The primality tests are based on code from http://sourceforge.net/projects/mpzprp/files/


I do not think that there exists such a module dedicated to prime functions in the standard library, but of course there are plenty of people who have written primality tests and such.

One library that is geared towards multiple-precision arithmetic, but which has several functions for primes (such as is_prime() and next_prime()) is GMPY2. The documentation is also available.