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


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


The Mephisto waltz sequence 0,0,1, 0,0,1, 1,1,0, etc, being the mod 2 count of ternary digit 2s in i. i=0 has no 2s so 0 and similarly i=1. Then i=2 has one 2 so 1.

The sequence can also be expressed as starting with 0 and repeatedly expanding

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


    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

    |                 |  |     copy        |  |     inverse     |
    +-----------------+  +-----------------+  +-----------------+

The effect of the expansion is keep the initial third the same, append a copy of it, and an inverse of it 0 changed to 1 and 1 changed to 0.


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

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

Create and return a new sequence object.

$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 Mephisto waltz sequence, which means simply being 0 or 1.


The calculation can 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.


Math::NumSeq, Math::NumSeq::DigitSumModulo



Copyright 2011 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 <>.