Math::N...nPrimes(3)

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

✨ NAME ✨

Math::NumSeq::TwinPrimes β€” it's giving twin primes, bestie πŸ’– (and yes it lives in section 3 of the manual, <pink>Math::N...nPrimes(3)</pink>, iconic naming, don't question it)


🌸 SYNOPSIS 🌸

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

okay so literally three lines and you're already generating primes, we love a low-effort slay πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

So the twin primes are 3, 5, 11, 19, 29, etc β€” and the whole vibe is that both P and P+2 are primes. Two primes, two apart, holding hands forever 🫢 that's the entire concept, no cap.


πŸ’… FUNCTIONS πŸ’…

Head over to "FUNCTIONS" in Math::NumSeq for the behaviour that's common to all the sequence classes, because we're not rewriting that whole thing here, bestie.

  • $seq = Math::NumSeq::TwinPrimes->new ()
  • $seq = Math::NumSeq::TwinPrimes->new (pairs => 'second') β€” makes you a brand new sequence object and hands it over πŸŽ€. That optional pairs parameter (it's a string, okay) decides which one of each twin-prime pair gets returned:
    • "first" β€” the first one of each pair, 3,5,11,17 etc
    • "second" β€” the second one of each pair, 5,7,13,19 etc
    • "both" β€” both values, 3,5,7,11,13,17,19 etc
    • "average" β€” the average of the pair, 4,6,12,8 etc

And the tea on "both" β˜•: it comes without repetition. So like, 5 belongs to the pair 3,5 and also to the pair 5,7, but it shows up in the sequence just the one time. No duplicates, we're not doing that here πŸ™ˆ

  • $bool = $seq->pred($value) β€” returns true if $value is a twin prime of whatever "pairs" type you picked. Example: with "second", pred() says true when $value is the second of a pair, aka $value-2 is also a prime. Math girlies, we're checking backwards πŸ’€
  • $i = $seq->value_to_i_estimate($value) β€” hands you an estimate of the i that goes with $value. Currently this is the asymptotic by Brun:
      value
i ~= 2 * C * --------------
           (log(value))^2

with Hardy and Littlewood's conjectured twin-prime constant C=0.66016. And honestly? In practice it's quite close β€” it comes out too small by a factor between 0.75 and 0.85 in the small to medium size integers this module might calculate. Not perfect but she's trying her best and she's doing great 🌈


πŸ‘‘ SEE ALSO πŸ‘‘

  • Math::NumSeq
  • Math::NumSeq::Primes
  • Math::NumSeq::SophieGermainPrimes

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


πŸŽ€ 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, see <http://www.gnu.org/licenses/>.

fr fr read the license, it's the whole point of the free software moment, don't skip it πŸ’–

okay that's the whole page bestie, mwah 🫢 this was shipped as perl v5.42.0, dated 2025-07-25, filed under Math::N...nPrimes(3) β€” go forth and count your twins πŸ’…βœ¨

πŸ“¦ where this page comes from