- SEE ALSO
- HOME PAGE
Math::NumSeq::GoldbachCount -- number of representations as sum of primes P+Q
use Math::NumSeq::GoldbachCount; my $seq = Math::NumSeq::GoldbachCount->new; my ($i, $value) = $seq->next;
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, ... starting i=1
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.
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, ... starting i=1
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 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
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.
$value = $seq->ith($i)
Return the sequence value at
$i, being the number of ways
$ican be represented as a sum of primes P+Q, or with the
on_values=>'even'option the number of ways for
This requires checking all primes up to
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
$valueoccurs as a count. All counts 0 upwards occur so this is simply integer
$value >= 0.
Copyright 2012, 2013, 2014, 2016, 2019 Kevin Ryde
Math-NumSeq is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Math-NumSeq is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Math-NumSeq. If not, see <http://www.gnu.org/licenses/>.