Math::NumSeq::Pell(3)
π Math::NumSeq::Pell β bestie it's literally the Pell numbers π
okay so this is Math::NumSeq::Pell, a lil Perl module from the User Contributed Perl Documentation collection, and it's giving β¨sequence energyβ¨. Come sit with me, we're gonna go through it together, no cap.
πΈ NAME πΈ
Math::NumSeq::Pell β Pell numbers π
β¨ SYNOPSIS β¨
the whole vibe in four lines, bestie:
use Math::NumSeq::Pell;
my $seq = Math::NumSeq::Pell->new;
my ($i, $value) = $seq->next;
that's it. that's the entry point. iconic honestly π«Ά
π¦ DESCRIPTION π¦
so the Pell numbers are these:
0, 1, 2, 5, 12, 29, 70, 169, 408, 985, 2378, 5741, 13860, ...
starting i=0
and the glow-up rule that makes them is:
P[k] = 2*P[k-1] + P[k-2] starting P[0]=0 and P[1]=1
like, each one is twice the one before it plus the one before that. it's Fibonacci's cooler cousin, fr fr. π₯
π FUNCTIONS π
heads up: check out "FUNCTIONS" in Math::NumSeq for all the behaviour that's shared across every sequence class, because this one inherits the whole squad's manners.
$seq = Math::NumSeq::Pell->new ()β makes you a brand new sequence object and hands it back to you. fresh start, main character energy. π($i, $value) = $seq->next()β gives you the next index and the next value in the sequence. simple as.
and when$valuegrows past the range of a Perl unsigned integer, what comes back is aMath::BigIntso the precision stays intact. no silent rounding betrayal here bestie π
$seq->seek_to_i($i)β jumps the current sequence position over to$i. the next time you callnext()it'll hand you$iand the matching value. it's giving teleport. π§
π Random Access π
$value = $seq->ith($i)β returns the$i'th Pell number, exactly the one you asked for.
and for negative $i the sequence gets extended backwards using P[i]=P[i+2]-2*P[i+1]. the numbers are the same, but they come out negative at negative even i:
i P[i]
--- ----
0 0
-1 1
-2 -2 <----+ negative at even i
-3 5 |
-4 -12 <----+
same caveat as before: when$valueexceeds the range of a Perl unsigned integer, you get aMath::BigIntback to preserve precision. π
$bool = $seq->pred($value)β returns true if$valueshows up in the sequence, so basically "is this a positive Pell number?" vibe check. β$i = $seq->value_to_i_estimate($value)β returns an estimate of theithat corresponds to$value. more on that down below in "Value to i Estimate". π
β FORMULAS β
π« Value to i Estimate π«
the Pell numbers are a Lucas sequence, which means they're also a power:
(1+sqrt(2))^i - (1-sqrt(2))^i
P[i] = ----------------------------- # exactly
2*sqrt(2)
and since abs(1-sqrt(2)) < 1, that whole second term just fades away toward zero (it's giving "not me disappearing mid-sentence"). so if you take logs, what's left gives you i approximately:
log(value) + log(2*sqrt(2))
i ~= ---------------------------
log(1+sqrt(2))
math but make it slay. π
π₯ SEE ALSO π₯
- Math::NumSeq
- Math::NumSeq::Fibonacci
- Math::NumSeq::LucasNumbers
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/>.
lowkey important: that warranty bit is not a joke, it's literally no warranty, bestie. read the license fr fr. π
okay that's the whole page!! this came from perl v5.42.0 dated 2025-07-25, and yeah the manual is literally called Math::NumSeq::Pell(3). go forth and Pell, periodt. π β¨πΈ
π¦ 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