NAME
Math::NumSeq::ReRound -- sequence from repeated rounding up
SYNOPSIS
use Math::NumSeq::ReRound;
my $seq = Math::NumSeq::ReRound->new;
my ($i, $value) = $seq->next;
DESCRIPTION
This is the sequence of values formed by repeatedly rounding up to a multiple of i-1,i-2,...,2,1.
1, 2, 4, 6, 10, 12,
For example i=5 is rounded up to a multiple of 4 to give 8, then rounded up to a multiple of 3 to give 9, then rounded up to a multiple of 2 for value 10 at i=5.
When rounding up if a value is already a suitable multiple then it's unchanged. For example i=4 round up to a multiple of 3 to give 6, then 6 round up to a multiple of 2 is 6 unchanged since it's already a multiple of 2.
For i>2 the last step rounds up to a multiple of 2 so the values are all even. They're also always increasing and end up approximately
value ~= i^2 / pi
though there's values both bigger and smaller than this approximation.
Extra Multiples
The extra_multiples
option can round up at each step to an extra multiple. For example extra_multiples >= 2
changes i=5 to round up to a multiple of 4 and then step by 2 further multiples of 4, similarly for round up to 3 and 2 further multiples, etc.
FUNCTIONS
$seq = Math::NumSeq::ReRound->new ()
$seq = Math::NumSeq::ReRound->new (extra_multiples => $integer)
-
Create and return a new sequence object.
$value = $seq->ith($i)
-
Return
$i
rounded up to multiples of i-1,...,2. $bool = $seq->pred($value)
-
Return true if
$value
is a ReRound value.
FORMULAS
Predicate
The rounding procedure can be reversed to test for a ReRound value.
for i=2,3,4,etc
remainder = value mod i
if remainder==i-1 then not a ReRound
otherwise
value -= remainder # round down to multiple of i
stop when value <= i
is a ReRound if value==i (and i is its index)
For example to test 28, it's a multiple of 2, so ok for the final rounding. It's predecessor in the rounding steps was a multiple of 3, so round down to a multiple of 3 which is 27. The predecessor of 27 was a multiple of 4 so round down to 24. But at that point there's a contradiction because if 24 was the value then it's already a multiple of 3 and so wouldn't have gone up to 27. This case where a round-down gives a multiple of both i and i-1 is identified by the remainder value % i == i-1, since the value is already a multiple of i-1 and subtracting an i-1 would leave it still so.
SEE ALSO
HOME PAGE
http://user42.tuxfamily.org/math-numseq/index.html
LICENSE
Copyright 2011, 2012 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/>.