Math::N...achCount(3)

πŸ“¦
version 75 Β· 2 versions
, in fedora 43

πŸ’– 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=4 can only be done as 2+2, so that's just 1 way.
  • i=10 is 3+7 and also 5+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 of 2**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::NumSeq
  • Math::NumSeq::Primes
  • Math::NumSeq::LemoineCount
  • Math::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