Kevin Ryde > Math-NumSeq-64 > Math::NumSeq::FibbinaryBitCount

Math-NumSeq-64.tar.gz

Dependencies

Annotate this POD

Website

# CPAN RT

 Open 0
View/Report Bugs
Module Version: 64   Source   Latest Release: Math-NumSeq-69

# 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`.

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