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.99 x86.64 (2203, heads/master-424edf64aa, Mar 8 2023 13:48:50)