- SEE ALSO
- HOME PAGE
Math::NumSeq::Tetrahedral -- tetrahedral numbers i*(i+1)*(i+2)/6
use Math::NumSeq::Tetrahedral; my $seq = Math::NumSeq::Tetrahedral->new; my ($i, $value) = $seq->next;
The tetrahedral numbers, i*(i+1)*(i+2)/6.
0, 1, 4, 10, 20, 35, 56, 84, 120, ...
See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes.
$value = $seq->ith($i)
$bool = $seq->pred($value)
Return true if
$valuehas the form i*(i+1)*(i+2)/6 for some positive integer i.
$i = $seq->value_to_i_floor($value)
Return the index i of
$valueor of the next tetrahedral number below
$i = $seq->value_to_i_estimate($value)
Return an estimate of the i corresponding to
In the current code this
$igives the tetrahedral above or below
$value, so is out by no more than 1.
i*(i+1)*(i+2) always fall in between cubes, so
T(i) = i*(i+1)*(i+2)/6 = (i^3 + 3*i^2 + 2*i)/6 i^3 < 6*T(i) < (i+1)^3
value_to_i_estimate() it's enough to apply a cube root,
i_estimate = floor(cbrt(6*value))
value_to_i_floor() the cube root can be 1 too big when the given value is in between successive T() tetrahedrals. For example if value=57 floor(cbrt(6*57))=6 is correct, but value=58 floor(cbrt(6*58))=7 is 1 too big.
i = floor(cbrt(6*value)) if i*(i+1)*(i+2) <= 6*value then i_floor = i else i_floor = i-1 # cbrt was 1 too big
Copyright 2010, 2011, 2012, 2013, 2014 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/>.