# NAME

Math::NumSeq::MephistoWaltz -- Mephisto waltz sequence

# SYNOPSIS

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

# DESCRIPTION

This sequence is the Mephisto waltz, being the count mod 2 of ternary digit 2s in i.

``````    0,0,1, 0,0,1, 1,1,0, ...            (A064990)
starting i=0``````

i=0 has no 2s so value=0, and likewise i=1 value=0. Then i=2 has one 2 so value=1.

The sequence can also be expressed as a morphism starting from single term 0 and repeatedly expanding

``````    0 -> 0,0,1
1 -> 1,1,0``````

So

``````    0
0,0,1
0,0,1, 0,0,1, 1,1,0,
0,0,1, 0,0,1, 1,1,0, 0,0,1, 0,0,1, 1,1,0, 1,1,0, 1,1,0, 0,0,1

|   original      |  |     copy        |  |  0<->1 flipped  |
+-----------------+  +-----------------+  +-----------------+``````

The effect of the expansion is keep the first third the same, append a copy of it, and append an 0<->1 flipped copy of it .

# FUNCTIONS

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

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

Create and return a new sequence object.

## Random Access

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

Return the `\$i`'th MephistoWaltz value, being the count mod 2 of the ternary digit 2s in `\$i`.

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

Return true if `\$value` occurs in the sequence, which simply means 0 or 1.

# FORMULAS

The calculation can also be made in a power-of-3 base like 9, 27, 81, etc instead of just 3. For example in base 9 digits 2, 5, 6, 7 have a one (mod 2) ternary 2. These base 9 digits correspond to the 1s in the initial sequence 0,0,1, 0,0,1, 1,1,0 shown above.