NAME

Math::NumSeq::FibbinaryBitCount -- number of bits in each fibbinary number

SYNOPSIS

use Math::NumSeq::FibbinaryBitCount;
my $seq = Math::NumSeq::FibbinaryBitCount->new;
my ($i, $value) = $seq->next;

DESCRIPTION

The number of 1 bits in the i'th fibbinary number.

0, 1, 1, 1, 2, 1, 2, 2, 1, 2, 2, 2, 3, 1, 2, 2, 2, 3, 2, ...
starting i=0

For example i=9 is Fibbinary "1001" so value=2 for 2 1-bits.

The count is 1 for the Fibonacci numbers, as they're "100..00" with a single 1-bit in fibbinary.

Digit 0

Option digit => "0" counts instead the 0-bits

# digit=>"0"   starting i=0
0, 0, 1, 2, 1, 3, 2, 2, 4, 3, 3, 3, 2, 5, 4, 4, 4, 3, 4, ...

i=0 is considered to be an empty set of digits, so it has value=0. This is the same as the DigitCount sequence treats i=0.

Digit 00

Option digit => "00" counts the 0-bits which don't follow a 1-bit, which is equivalent to "00" pairs (including overlapping pairs).

# digit=>"00"   starting i=0
0, 0, 0, 1, 0, 2, 1, 0, 3, 2, 1, 1, 0, 4, 3, 2, 2, 1, 2, ...

For example i=42 is fibbinary "10010000" (42=34+8). It has value=4 for 4 0-bits not counting the two which immediately follow the two 1-bits. Or equivalently 4 "00" pairs

         v  vvv    four 0s which don't follow a 1
i=42   10010000
        ^^ ^^      four "00" pairs, overlaps allowed
            ^^
             ^^

Fibbinary numbers by definition never have consecutive 1-bits, so there's always a 0 following a 1. Excluding those leaves a count of genuinely skipped positions.

When passing the "00" option don't forget to quote it as a string, since a literal number 00 is an octal 0.

$seq = Math::NumSeq::FibbinaryBitCount->new (digit => "00");  # good
$seq = Math::NumSeq::FibbinaryBitCount->new (digit => 00);    # bad

FUNCTIONS

See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes.

$seq = Math::NumSeq::FibbinaryBitCount->new ()
$seq = Math::NumSeq::FibbinaryBitCount->new (digit => $str)

Create and return a new sequence object.

Random Access

$value = $seq->ith($i)

Return the bit count of the $i'th fibbinary number.

$bool = $seq->pred($value)

Return true if $value occurs as a bit count, which simply means $value >= 0.

SEE ALSO

Math::NumSeq, Math::NumSeq::Fibbinary, Math::NumSeq::DigitCount, Math::NumSeq::Fibonacci

HOME PAGE

http://user42.tuxfamily.org/math-numseq/index.html

LICENSE

Copyright 2011, 2012, 2013, 2014, 2016 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/>.