The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

# NAME

Math::NumSeq::Primes -- prime numbers

# SYNOPSIS

use Math::NumSeq::Primes;
my \$seq = Math::NumSeq::Primes->new;
my (\$i, \$value) = \$seq->next;

# DESCRIPTION

The prime numbers, not divisible by anything except themselves and 1.

2, 3, 5, 7, 11, 13, 17, 19, ...         (A000040)
starting i=1

Currently this is implemented with Math::Prime::XS generating blocks of primes with a sieve of Eratosthenes. The result is reasonably progressive. On a 32-bit system there's a hard limit at 2^31 (though even approaching that takes a long time to calculate).

# FUNCTIONS

See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes.

\$seq = Math::NumSeq::Primes->new ()

Create and return a new sequence object.

\$bool = \$seq->pred(\$value)

Return true if \$value is a prime.

In the current code a hard limit of 2**32 is placed on the \$value to be checked, in the interests of not going into a near-infinite loop.

\$i = \$seq->value_to_i_estimate(\$value)

Return an estimate of the i corresponding to \$value. \$value can be any size, it's not limited as in pred(). See "Value to i Estimate" below.

# FORMULAS

## Value to i Estimate

In the current code the number of count of primes up to value is estimated by the well-known asymptotic

i ~= value/log(value)