Math::N...achCount(3)
π Math::NumSeq::GoldbachCount π
okay bestie, gather round, because today we're talking about Math::NumSeq::GoldbachCount β it's a lil Perl module from the User Contributed Perl Documentation crew, and it's literally just counting how many ways you can write a number as a sum of two primes. prime P plus prime Q, that's the whole vibe. π
β¨ NAME β¨
Math::NumSeq::GoldbachCount β the number of representations as a sum of primes, P+Q. π
π¦ SYNOPSIS π¦
use Math::NumSeq::GoldbachCount;
my $seq = Math::NumSeq::GoldbachCount->new;
my ($i, $value) = $seq->next;
like. that's it. that's the whole entry point bestie, go off. πΈ
π DESCRIPTION π
So the tea is: for every i, we count how many ways i can be represented as a sum of two primes, P+Q. We start from i=1 and just keep it moving:
0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 0, 1, 1, 2, 1, 2, 0, ...
starting i=1
Want examples? Say less. π
i=4can only be done as2+2, so that's just 1 way.i=10is3+7and also5+5, so that's 2 ways.
π Even Numbers π
If you pass the option "on_values => 'even'", you get the count on just the even numbers, starting at i=1 β which is the number of ways "2" can be expressed (spoiler: none, it can't π):
0, 1, 1, 1, 2, 1, 2, 2, 2, 2, 3, 3, 3, 2, 3, 2, 4, 4, ...
starting i=1
And this is where the iconic part comes in: Goldbach's famous conjecture says that for an even i >= 4 there's always at least one P+Q=i β which, in this count, would mean it's always >= 1. periodt. π
π§ Odd Numbers π§
ngl bestie, odd numbers i are not particularly interesting. An odd number can only ever be i=2+Prime, so the count is simply:
count(odd i) = 1 if i-2 prime
0 if not
that's it. that's the whole paragraph. moving on. π
π₯ FUNCTIONS π₯
go check out "FUNCTIONS" in Math::NumSeq for the behaviour that's common to all the sequence classes, because there's a whole shared situation going on there. β¨
$seq = Math::NumSeq::GoldbachCount->new ()$seq = Math::NumSeq::GoldbachCount->new (on_values => 'even')
Create and return a brand new sequence object. main character energy. π
β Random Access β
$value = $seq->ith($i)
Return the sequence value at $i β which is the number of ways $i can be represented as a sum of primes P+Q. Or, if you're using the "on_values=>'even'" option, it's the number of ways for "2*$i".
heads up bestie: this requires checking all primes up to$i(or"2*$i"), and the current code has a hard limit of2**24β in the interests of not going into a near-infinite loop. π so don't come for it.
$bool = $seq->pred($value)
Return true if $value occurs as a count. All counts 0 upwards occur, so this is simply integer "$value >= 0". lowkey the easiest function here. π«Ά
π SEE ALSO π
Math::NumSeqMath::NumSeq::PrimesMath::NumSeq::LemoineCountMath::NumSeq::PrimeFactorCount
πΈ HOME PAGE πΈ
<http://user42.tuxfamily.org/math-numseq/index.html>
π LICENSE π
Copyright 2012, 2013, 2014, 2016, 2019, 2020 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/>.
and that's the whole page bestie, no cap π«Ά this was perl v5.42.0, dated 2025-07-25, and it's the Math::NumSeq::GoldbachCount(3) manual page signing off. slay πβ¨
π¦ where this page comes from
- fedora 43: perl-Math-NumSeq 75-11.fc43 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms