++ed by:
Kevin Ryde
and 1 contributors

# NAME

Math::NumSeq::SternDiatomic -- Stern's diatomic sequence

# SYNOPSIS

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

# DESCRIPTION

This is Moritz Stern's diatomic sequence

``    0, 1, 1, 2, 1, 3, 2, 3, ...``

It's constructed by successive levels as D(2*i)=D(i) and D(2*i+1)=D(i)+D(i+1), so effectively the sequence is extended by interleaving the previous level with sums of adjacent terms,

``````   0,                i=0
1,                i=1
1,      2,        i=2,3
1,  3,  2,  3,    i=4,5,6,7
1,4,3,5,2,5,3,4,  i=8,9,...,15``````

For example the i=4 row is a copy of the preceding 1,2 with sums 1+2 and 2+1 interleaved. The new entry at the end of each row is the sum of the last of the previous row and the first of the current row (which is always 1).

# FUNCTIONS

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

`\$seq = Math::NumSeq::SternDiatomic->new ()`

Create and return a new sequence object.

## Random Access

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

Return the `\$i`'th value of the sequence.

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

Return true if `\$value` occurs in the sequence, which means simply integer `\$value>=0`.

Math::NumSeq