Math::N...nPrimes(3)
β¨ 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 optionalpairsparameter (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,17etc"second"β the second one of each pair,5,7,13,19etc"both"β both values,3,5,7,11,13,17,19etc"average"β the average of the pair,4,6,12,8etc
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$valueis a twin prime of whatever"pairs"type you picked. Example: with"second",pred()says true when$valueis the second of a pair, aka$value-2is also a prime. Math girlies, we're checking backwards π$i = $seq->value_to_i_estimate($value)β hands you an estimate of theithat 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::NumSeqMath::NumSeq::PrimesMath::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
- fedora 43: perl-Math-NumSeq 75-11.fc43 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms