Math::N...:Primes(3)

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

πŸ’– Math::N...:Primes β€” prime numbers πŸ’–

okay bestie, so this is a page from the User Contributed Perl Documentation (yes it really says Math::N...:Primes(3) at the top, that's not a typo, that's just how the header truncates it, slay) and it's literally about the most iconic sequence in all of math. primes. periodt.


✨ NAME ✨

Math::NumSeq::Primes β€” prime numbers πŸ‘‘


🌸 SYNOPSIS 🌸

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

that's it. that's the whole vibe. create the sequence, ask for the next thing, get numbers. no cap. πŸ¦‹


πŸ’… DESCRIPTION πŸ’…

okay so. the prime numbers. they're the numbers that aren't divisible by anything except themselves and 1. like they refuse to be broken down. main character energy fr fr. ✨

2, 3, 5, 7, 11, 13, 17, 19, ...         (A000040)
starting i=1

(yes the OEIS number is A000040, iykyk πŸ“–)

right now, this is implemented with Math::Prime::XS, which generates blocks of primes using a sieve of Eratosthenes. the result is reasonably progressive, so it's not just sitting there doing nothing while you wait. 🫢

⚠️ on a 32-bit system there's a hard limit at 2^31 β€” though honestly, even approaching that number takes a really long time to calculate. like, go get a snack. maybe two. 😭

πŸŽ€ FUNCTIONS πŸŽ€

peep "FUNCTIONS" in Math::NumSeq for the behaviour that's common to all the sequence classes, because those are shared bestie behaviour. πŸ’œ

  • $seq = Math::NumSeq::Primes->new () β€” creates and returns a brand new sequence object. your own personal prime generator. obsessed. ✨
  • $bool = $seq->pred($value) β€” returns true if $value is a prime. πŸ’―
in the current code there's a hard limit of 2**32 on the $value you're checking, and that's specifically in the interests of not going into a near-infinite loop. so don't test your luck past that, bestie. πŸ’€
  • $i = $seq->value_to_i_estimate($value) β€” returns an estimate of the i that corresponds to $value. $value can be any size here, it's not limited like it is in pred(). check out "Value to i Estimate" down below for the deets. πŸ”

🌈 FORMULAS 🌈

⭐ Value to i Estimate ⭐

in the current code, the number of count of primes up to value is estimated by the well-known asymptotic:

i ~= value/log(value)

that's the formula, that's the whole thing, she's simple and she works. 🧚


πŸ¦‹ SEE ALSO πŸ¦‹

  • Math::NumSeq
  • Math::NumSeq::TwinPrimes
  • Math::NumSeq::SophieGermainPrimes
  • Math::NumSeq::Emirps
  • Math::Prime::XS
  • Math::Prime::TiedArray
  • Math::Prime::FastSieve
  • Math::Prime::Util

go read them, they're all part of the same little universe. 🌸


🏠 HOME PAGE 🏠

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


πŸ“œ LICENSE πŸ“œ

copyright 2010, 2011, 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, peep <http://www.gnu.org/licenses/>. πŸ‘‘


okay that's the whole page bestie, no skips, no skims, every single detail accounted for. πŸ’–

this was perl v5.42.0, dated 2025-07-25 β€” love that for us. stay iconic, stay prime. πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from