Math::N...dgeClass(3)

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

πŸ’– Math::NumSeq::ErdosSelfridgeClass πŸ’–

okay bestie, this is a page from the User Contributed Perl Documentation and it's literally about Math::NumSeq::ErdosSelfridgeClass β€” the Erdos-Selfridge classification of primes. yes it's a whole mouthful, we'll get through it together 🫢


✨ SYNOPSIS ✨

like, the absolute bare minimum to get going:

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

🌸 DESCRIPTION 🌸

so the tea is this: it's a class number for primes, worked out by Erdos and Selfridge, and for composites it just hands you a big fat 0. and the default flavor of the whole thing is "class+".

the sequence it spits out looks like:

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

okay so how does a prime get classified? you take your prime p, you factorize p+1 into primes, then for each of those primes q you factorize q+1, and you just keep going like that, over and over, until literally everything left is 2s and 3s. cute, right?

and lowkey iconic detail: p=2 or p=3 interchange on factorizing p+1 β€” because 2+1=3 and 3+1=2*2. they're just passing the vibe back and forth πŸ’«

a prime p where p+1 factorizes into nothing but 2s and 3s is class 1. for example i=11 has 11+1=12=2*2*3 which is all 2s and 3s, so that's class 1, periodt. and 2 and 3 themselves are class 1 too, because their p+1 factorizing gives you 2s and 3s. slay.

now, primes further out get classified by how many iterations of that p+1 factorizing you need before you finally reach 2s and 3s. take prime p=3847 β€” it goes like this:

3847+1 = 2*13*37

then 13+1 = 2*7
     37+1 = 2*19

then 7+1 = 2*2*2
     19+1 = 2*2*5

then 5+1 = 2*3

so 3847 is class 4 because it took 4 whole steps to reach all 2s and 3s. ngl, some of those factors do become 2s and 3s earlier than others, but no β€” the steps keep going until all the factors are reduced to 2s and 3s. no shortcuts, bestie 😌

πŸŽ€ Class - πŸŽ€

option "p_or_m => '-'" runs the exact same procedure but on the prime factors of p-1 instead, and gives you a "class-" number.

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

sometimes class+ happens to be the same as class-, but generally speaking the two are unrelated. different queens, different kingdoms πŸ‘‘

πŸ¦‹ Primes Only πŸ¦‹

option "on_values => 'primes'" gives you the classes of just the primes and nothing else:

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

⭐ FUNCTIONS ⭐

for the behaviour that's common to all sequence classes, go peek at "FUNCTIONS" in Math::NumSeq. but here's what this one brings to the group chat:

  • $seq = Math::NumSeq::ErdosSelfridgeClass->new ()
  • $seq = Math::NumSeq::ErdosSelfridgeClass->new (p_or_m => $str, on_values => $str)

creates and returns a brand new sequence object for you πŸ’–

"p_or_m" (a string) can be:

"+"    factors of p+1 (the default)
"-"    factors of p-1

"on_values" (a string) can be:

"all"      classify all integers
"primes"   classify just the primes

🌈 Random Access 🌈

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

returns the class number of $value, or 0 if $value is not a prime.

heads up bestie: this method is only available for the default "on_values=>'all'". if you wanna know whether ith() is even usable, "$seq->can('ith')" tells you (and hands you a coderef). πŸ™ˆ
  • $bool = $seq->pred($value)

returns true if $value occurs as a classification, which basically means any integer "$value >= 0".


πŸ‘€ SEE ALSO πŸ‘€

Math::NumSeq, Math::NumSeq::Primes


🧚 HOME PAGE 🧚

<http://user42.tuxfamily.org/math-numseq/index.html>


πŸ’œ LICENSE πŸ’œ

Copyright 2012, 2013, 2014, 2016, 2017, 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 thing, bestie, no cap πŸ’…βœ¨ this page came to you from perl v5.42.0, dated 2025-07-25, and the manual section was Math::N...dgeClass(3) β€” go forth and classify some primes, you've got this 🫢🌸

πŸ“¦ where this page comes from