I've just implemented the Miller-Rabin-Test and a simple function for factorizing numbers. Both could be done better and at least the Miller-Rabin-Test is well-known.
So could you please tell me if a Python-Library, that implements such common prime functions exists or why no such library exists?
primePy is that library of Python which is used to compute operations related to prime numbers. It will perform all the functions in less time with the help of the functions of this primePy module.
We could have used the range, range(2,num//2) or range(2,math.floor(math.sqrt(num)+1)) . The latter range is based on the fact that a composite number must have a factor less than or equal to the square root of that number. Otherwise, the number is prime.
SymPy is a python module which contains some really cool prime number related library functions.
I just discovered isprime
from the SymPy package:
import sympy print sympy.isprime(10)
Output:
False
Not to confuse with prime
, which returns the n-th prime number:
import sympy print 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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With