NAME
Math::NumSeq::KlarnerRado -- Klarner-Rado sequences
SYNOPSIS
use Math::NumSeq::KlarnerRado;
my $seq = Math::NumSeq::KlarnerRado->new;
my ($i, $value) = $seq->next;
DESCRIPTION
Start with 1, then for any k in the sequence then 2*k, 3*k+2 and 6*k+3 are in the sequence too. Thus 1,2,4,5,8,9,etc.
FUNCTIONS
See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes.
$seq = Math::NumSeq::KlarnerRado->new ()
$seq = Math::NumSeq::KlarnerRado->new (start => $n)
-
Create and return a new sequence object.
The optional
start
parameter can start the sequence from a value other than 1, which changes the sequence and in general bigger values thin out the sequence. $bool = $seq->pred($value)
-
Return true if
$value
occurs in the sequence.
FORMULAS
Predicate
Taking value mod 6 can say whether it's a descendant of one of the 2*k, 3*k+2, 6*k+3 forms, and thus give one or two reduced values to then check for being in the sequence.
value mod 6 descendant of reduce to
0 2k value/2
1 none
2 2k or 3k+2 value/2 and (value-2)/3
3 6k+3 (value-3)/6
4 2k value/2
5 3k+2 (value-2)/3
The reduction dividing out 2, 3 or 6 makes the test logarithmic, except when 2mod6 gives two reduced values to check.
SEE ALSO
HOME PAGE
http://user42.tuxfamily.org/math-numseq/index.html
LICENSE
Copyright 2011, 2012, 2013, 2014, 2016, 2019 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/>.