1Math::NumSeq::Pell(3) User Contributed Perl DocumentationMath::NumSeq::Pell(3)
2
3
4

NAME

6       Math::NumSeq::Pell -- Pell numbers
7

SYNOPSIS

9        use Math::NumSeq::Pell;
10        my $seq = Math::NumSeq::Pell->new;
11        my ($i, $value) = $seq->next;
12

DESCRIPTION

14       The Pell numbers
15
16           0, 1, 2, 5, 12, 29, 70, 169, 408, 985, 2378, 5741, 13860, ...
17           starting i=0
18
19       where
20
21           P[k] = 2*P[k-1] + P[k-2] starting P[0]=0 and P[1]=1
22

FUNCTIONS

24       See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence
25       classes.
26
27       "$seq = Math::NumSeq::Pell->new ()"
28           Create and return a new sequence object.
29
30       "($i, $value) = $seq->next()"
31           Return the next index and value in the sequence.
32
33           When $value exceeds the range of a Perl unsigned integer the return
34           is a "Math::BigInt" to preserve precision.
35
36       "$seq->seek_to_i($i)"
37           Move the current sequence position to $i.  The next call to
38           "next()" will return $i and corresponding value.
39
40   Random Access
41       "$value = $seq->ith($i)"
42           Return the $i'th Pell number.
43
44           For negative <$i> the sequence is extended backwards as
45           P[i]=P[i+2]-2*P[i+1].  The effect is the same numbers but negative
46           at negative even i.
47
48                i     P[i]
49               ---    ----
50                0       0
51               -1       1
52               -2      -2       <----+ negative at even i
53               -3       5            |
54               -4     -12       <----+
55
56           When $value exceeds the range of a Perl unsigned integer the return
57           is a "Math::BigInt" to preserve precision.
58
59       "$bool = $seq->pred($value)"
60           Return true if $value occurs in the sequence, so is a positive Pell
61           number.
62
63       "$i = $seq->value_to_i_estimate($value)"
64           Return an estimate of the i corresponding to $value.  See "Value to
65           i Estimate" below.
66

FORMULAS

68   Value to i Estimate
69       The Pell numbers are a Lucas sequence and hence a power
70
71                  (1+sqrt(2))^i - (1-sqrt(2))^i
72           P[i] = -----------------------------     # exactly
73                          2*sqrt(2)
74
75       Since abs(1-sqrt(2)) < 1 that term approaches zero, so taking logs the
76       rest gives i approximately
77
78                log(value) + log(2*sqrt(2))
79           i ~= ---------------------------
80                     log(1+sqrt(2))
81

SEE ALSO

83       Math::NumSeq, Math::NumSeq::Fibonacci, Math::NumSeq::LucasNumbers
84

HOME PAGE

86       <http://user42.tuxfamily.org/math-numseq/index.html>
87

LICENSE

89       Copyright 2010, 2011, 2012, 2013, 2014 Kevin Ryde
90
91       Math-NumSeq is free software; you can redistribute it and/or modify it
92       under the terms of the GNU General Public License as published by the
93       Free Software Foundation; either version 3, or (at your option) any
94       later version.
95
96       Math-NumSeq is distributed in the hope that it will be useful, but
97       WITHOUT ANY WARRANTY; without even the implied warranty of
98       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
99       General Public License for more details.
100
101       You should have received a copy of the GNU General Public License along
102       with Math-NumSeq.  If not, see <http://www.gnu.org/licenses/>.
103
104
105
106perl v5.28.0                      2014-06-29             Math::NumSeq::Pell(3)
Impressum