The math.primes vocabulary implements words related to prime numbers. Several useful vocabularies exist for testing primality. The Sieve of Eratosthenes in math.primes.erato is useful for testing primality below five million. For larger integers, math.primes.miller-rabin is a fast probabilistic primality test. The math.primes.lucas-lehmer vocabulary implements an algorithm for finding huge Mersenne prime numbers.

Testing if a number is prime:
prime? ( n -- ? )


Generating prime numbers:
next-prime ( n -- p )

primes-upto ( n -- seq )

primes-between ( low high -- seq )

random-prime ( numbits -- p )


Generating relative prime numbers:
find-relative-prime ( n -- p )

find-relative-prime* ( n guess -- p )


Make a sequence of random prime numbers:
unique-primes ( n numbits -- seq )