Math::NumSeq::Pell(3)

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

πŸ’– 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 $value grows past the range of a Perl unsigned integer, what comes back is a Math::BigInt so 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 call next() it'll hand you $i and 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 $value exceeds the range of a Perl unsigned integer, you get a Math::BigInt back to preserve precision. πŸ’œ
  • $bool = $seq->pred($value) β€” returns true if $value shows 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 the i that 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