Math::N...neCount(3)

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

πŸŽ€ Math::N...neCount(3) πŸŽ€

okay so bestie, this page lives in the User Contributed Perl Documentation section, and its full name is Math::N...neCount(3) (yes the name is truncated in the header, that's just how it's filed, don't come for me). The real star here is Math::NumSeq::LemoineCount. Buckle up. πŸ’…


✨ NAME ✨

Math::NumSeq::LemoineCount β€” the number of ways something can be written as P+2*Q for primes P,Q. that's it, that's the whole vibe πŸ¦‹


✨ SYNOPSIS ✨

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

three lines, no drama, iconic behavior πŸ’–


✨ DESCRIPTION ✨

So the whole thing is a count of how many ways i can be represented as P+2*Q for primes P,Q, and it starts from i=1. Periodt.

0, 0, 0, 0, 0, 1, 1, 1, 2, 0, 2, 1, 2, 0, 2, 1, 4, 0, ...
starting i=1

like, let's actually walk through it, because the numbers go crazy:

  • i=6 can only be written 2+2*2, so it's just 1 way. lowkey minimal.
  • but i=9 is 3+2*3=9 and 5+2*2=9, so that's 2 ways. she's flexible, she contains multitudes ✨

🌸 Odd Numbers 🌸

Option "on_values => 'odd'" gives you the count on just the odd numbers, and here it starts at i=0 for the number of ways "1" can be expressed β€” which is none. πŸ™ˆ

0, 0, 0, 1, 2, 2, 2, 2, 4, 2, 3, 3, 3, 4, 4, 2, 5, 3, 4, ...
starting i=0

Lemoine conjectured circa 1894 β€” yes, 1894, the man was ahead of his time, main character energy fr β€” that all odd i >= 7 can be represented as P+2*Q, which would mean the count here is always >=1. not proven, just conjectured. we stan a hopeful king πŸ‘‘

🌸 Even Numbers 🌸

Even numbers i are not particularly interesting. ngl they're giving background character. An even number must have P even, ie. P=2, so i=2+2*Q, for a count of:

count(even i) = 1 if i/2-1 is prime
              = 0 if not

that's the whole even plotline. short arc. πŸ’€


✨ FUNCTIONS ✨

peep "FUNCTIONS" in Math::NumSeq for the behaviour that's common to all sequence classes, bestie, that's the shared lore.

  • $seq = Math::NumSeq::LemoineCount->new ()
  • $seq = Math::NumSeq::LemoineCount->new (on_values => 'odd')

Create and return a new sequence object. fresh out the box, no cap 🫢

🌈 Random Access 🌈

  • $value = $seq->ith($i) β€” Return the sequence value at $i, being the number of ways $i can be represented as P+2*Q for primes P,Q. Or, with the "on_values=>'odd'" option, the number of ways for "2*$i+1".
okay heads up bestie, this one requires checking all primes up to $i or "2*$i+1", 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 go past it, she will simply not. πŸ›‘

✨ SEE ALSO ✨

  • Math::NumSeq
  • Math::NumSeq::Primes
  • Math::NumSeq::GoldbachCount

the whole friend group, go say hi πŸ’œ


✨ 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/>.

no warranty bestie, it's giving "use at your own risk" but make it legally binding πŸ’…

and that's the page!! πŸŽ€βœ¨ this was perl v5.42.0, dated 2025-07-25, filed under Math::N...neCount(3) β€” love her, read her, represent your primes as P+2*Q, mwah πŸ’–

πŸ“¦ where this page comes from