++ed by:
Kevin Ryde
and 1 contributors

# NAME

Math::NumSeq::GoldbachCount -- number of representations as sum of primes P+Q

# SYNOPSIS

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

# DESCRIPTION

The number of ways each i can be represented as a sum of two primes P+Q, starting from i=1,

0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 0, 1, 1, 2, 1, 2, 0, ...

For example i=4 can be represented only as 2+2 so just 1 way. Or i=10 is 3+7 and 5+5 so 2 ways.

## Even Numbers

Option on_values => 'even' gives the count on just the even numbers, starting i=1 for number of ways "2" can be expressed (none),

0, 1, 1, 1, 2, 1, 2, 2, 2, 2, 3, 3, 3, 2, 3, 2, 4, 4, ...

Goldbach's famous conjecture is that for an even i >= 4 there's always at least one P+Q=i, which would be a count here always >= 1.

## Odd Numbers

Odd numbers i are not particularly interesting. An odd number can only be i=2+Prime, so the count is simply

count(odd i) = 1  if i-2 prime
0  if not

# FUNCTIONS

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

\$seq = Math::NumSeq::GoldbachCount->new ()
\$seq = Math::NumSeq::GoldbachCount->new (on_values => 'even')

Create and return a new sequence object.

## Random Access

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

Return the sequence value at \$i, being the number of ways \$i can be represented as a sum of primes P+Q, or with the on_values=>'even' option the number of ways for 2*\$i.

This requires checking all primes up to \$i (or 2*\$i) and the current code has a hard limit of 2**24 in the interests of not going into a near-infinite loop.

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

Return true if \$value occurs as a count. All counts 0 upwards occur so this is simply integer \$value >= 0.