Julia functions for computing prime numbers.
At the moment, this repository just contains the following functions which have been duplicated from Base Julia:
factor(n) -> Dict
Compute the prime factorization of an integer
n
. Returns a dictionary. The keys of the dictionary correspond to the factors, and hence are of the same type asn
. The value associated with each key indicates the number of times the factor appears in the factorization.
julia> factor(100) # == 225*5 Dict{Int64,Int64} with 2 entries: 2 => 2 5 => 2
isprime(x::Integer) -> Bool
Returns
true
ifx
is prime, andfalse
otherwise.
julia> isprime(3) true
isprime(x::BigInt, [reps = 25]) -> Bool
Probabilistic primality test. Returns
true
ifx
is prime with high probability (pseudoprime); andfalse
ifx
is composite (not prime). The false positive rate is about0.25^reps
.reps = 25
is considered safe for cryptographic applications (Knuth, Seminumerical Algorithms).
julia> isprime(big(3)) true
primes([lo,] hi)
Returns a collection of the prime numbers (from
lo
, if specified) up tohi
.
primesmask([lo,] hi)
Returns a prime sieve, as a
BitArray
, of the positive integers (fromlo
, if specified) up tohi
. Useful when working with either primes or composite numbers.
To avoid naming conflicts with Base, these are not exported for Julia version 0.4. In this case you will need to explicitly import the symbols:
using Primes
import Primes: isprime, primes, primesmask, factor