1Math::NumSeq::TetrahedrUasle(r3)Contributed Perl DocumenMtaatthi:o:nNumSeq::Tetrahedral(3)
2
3
4

NAME

6       Math::NumSeq::Tetrahedral -- tetrahedral numbers i*(i+1)*(i+2)/6
7

SYNOPSIS

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

DESCRIPTION

14       The tetrahedral numbers, i*(i+1)*(i+2)/6.
15
16           0, 1, 4, 10, 20, 35, 56, 84, 120, ...
17

FUNCTIONS

19       See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence
20       classes.
21
22       "$seq = Math::NumSeq::Tetrahedral->new ()"
23           Create and return a new sequence object.
24
25   Random Access
26       "$value = $seq->ith($i)"
27           Return "$i*($i+1)*($i+2)/6".
28
29       "$bool = $seq->pred($value)"
30           Return true if $value has the form i*(i+1)*(i+2)/6 for some
31           positive integer i.
32
33       "$i = $seq->value_to_i_floor($value)"
34           Return the index i of $value or of the next tetrahedral number
35           below $value.
36
37       "$i = $seq->value_to_i_estimate($value)"
38           Return an estimate of the i corresponding to $value.
39
40           In the current code this $i gives the tetrahedral above or below
41           $value, so is out by no more than 1.
42

FORMULAS

44   Value to i Estimate
45       i*(i+1)*(i+2) always fall in between cubes,  so
46
47           T(i) = i*(i+1)*(i+2)/6
48                = (i^3 + 3*i^2 + 2*i)/6
49
50           i^3 < 6*T(i) < (i+1)^3
51
52       For "value_to_i_estimate()" it's enough to apply a cube root,
53
54           i_estimate = floor(cbrt(6*value))
55
56   Value to i Floor
57       For "value_to_i_floor()" the cube root can be 1 too big when the given
58       value is in between successive T() tetrahedrals.  For example if
59       value=57 floor(cbrt(6*57))=6 is correct, but value=58
60       floor(cbrt(6*58))=7 is 1 too big.
61
62           i = floor(cbrt(6*value))
63           if i*(i+1)*(i+2) <= 6*value
64           then i_floor = i
65           else i_floor = i-1    # cbrt was 1 too big
66

SEE ALSO

68       Math::NumSeq, Math::NumSeq::Cubes
69

HOME PAGE

71       <http://user42.tuxfamily.org/math-numseq/index.html>
72

LICENSE

74       Copyright 2010, 2011, 2012, 2013, 2014, 2016, 2019 Kevin Ryde
75
76       Math-NumSeq is free software; you can redistribute it and/or modify it
77       under the terms of the GNU General Public License as published by the
78       Free Software Foundation; either version 3, or (at your option) any
79       later version.
80
81       Math-NumSeq is distributed in the hope that it will be useful, but
82       WITHOUT ANY WARRANTY; without even the implied warranty of
83       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
84       General Public License for more details.
85
86       You should have received a copy of the GNU General Public License along
87       with Math-NumSeq.  If not, see <http://www.gnu.org/licenses/>.
88
89
90
91perl v5.32.0                      2020-07-28      Math::NumSeq::Tetrahedral(3)
Impressum