Math::N...inPrimes(3)

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

πŸ’– NAME πŸ’–

Math::NumSeq::SophieGermainPrimes β€” bestie, it's Sophie Germain primes: primes p where 2*p+1 is also prime. That's the whole vibe. It's a Perl module in the user-contributed Perl documentation, section 3 of the manual, and honestly? iconic.


✨ SYNOPSIS ✨

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

Like, that's it. Three lines and you're pulling prime numbers out of the void. slay. πŸ’…


🌸 DESCRIPTION 🌸

So the deal is: we're talking about the primes P where 2*P+1 is also prime. Double the prime, add one, and boom β€” still prime. That's the whole personality of this sequence.

2, 3, 5, 11, 23, 29, 41, 53, 83, 89, 113, 131, 173, 179, ...
starting i=1

Notice how 2 is up in there at index i=1 β€” yeah because 2*2+1 = 5 and 5 is prime, no cap. Every single one of those numbers passes the check. Obsessed, honestly. πŸ¦‹


πŸŽ€ FUNCTIONS πŸŽ€

Okay so first thing: go read "FUNCTIONS" in Math::NumSeq because that's where all the behaviour common to every sequence class lives. This module is just one lil guy in a bigger family.

  • $seq = Math::NumSeq::SophieGermainPrimes->new () β€” makes you a brand new sequence object and hands it over. That's your starting point, your main character, your little guy. ✨
  • $bool = $seq->pred($value) β€” returns true when $value is a Sophie Germain prime, which literally means both $value and 2*$value+1 are prime. Both. Not one. Both. It's giving "yes and also yes". πŸ‘‘
  • $i = $seq->value_to_i_estimate($value) β€” gives you an estimate of the i that goes with $value. Not exact, bestie, it's a whole estimate situation.

Right now this is literally the same as the TwinPrimes estimate. Is it a conjecture by Hardy and Littlewood that the two are asymptotically the same? That's what the docs are asking, and honestly, that's the question on the table. In any case, the result comes out roughly a factor 0.9 too small for the small to medium size integers this module might calculate. So like, close but spicy. 🌢️

(Go peek at Math::NumSeq::TwinPrimes if you want the deets.)


πŸ’« FORMULAS πŸ’«

πŸ”₯ Next πŸ”₯

next() is implemented by a Math::NumSeq::Primes sequence that gets filtered down to the primes where 2P+1 is a prime too.

And here's the tea: Dana Jacobsen noticed this is faster than running a second Primes iterator just to find the primes 2P+1. Why? Because for a prime P, 2P+1 often has a small factor β€” like 3, 5 or 11. And check this: a factor 3 occurs for any P=6k+1, since in that case 2P+1 is a multiple of 3. Cute little shortcut, we love her. πŸ’…

And then the docs hit us with the open question: what else can be said about the density or chance of a small factor? Like, genuinely, that's still being asked. 🧚


🌈 SEE ALSO 🌈

Go check out these besties too:

  • Math::NumSeq
  • Math::NumSeq::Primes
  • Math::NumSeq::TwinPrimes

🏠 HOME PAGE 🏠

The whole thing lives at <http://user42.tuxfamily.org/math-numseq/index.html> if you wanna go hang out there. 🫢


πŸ“œ LICENSE πŸ“œ

Copyright 2010, 2011, 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/>.


Little sign-off moment: this page came from perl v5.42.0 and it's dated 2025-07-25, filed under Math::N...inPrimes(3) in the user-contributed Perl docs. bye bestie, go count some primes πŸ’–πŸŒΈβœ¨
πŸ“¦ where this page comes from