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:

Generating prime numbers:

Generating relative prime numbers:

Make a sequence of random 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 )

This documentation was generated offline from a
`load-all`

image. If you want, you can also
browse the documentation from within the UI developer tools. See
the Factor website
for more information.

Factor 0.101 x86.64 (2284, heads/master-4a32b2801d, Nov 5 2024 16:06:40)