Math::N...stoWaltz(3)

πŸ“¦
version 75 Β· 2 versions
, in fedora 43

🌸 NAME 🌸

Math::NumSeq::MephistoWaltz β€” the Mephisto waltz sequence, bestie πŸ’ƒ (it's a Perl manual page, section 3, and yes the module name is doing the most but we love her)


✨ SYNOPSIS ✨

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

that's it. that's the whole vibe. three lines and you're in 🫢


πŸ’… DESCRIPTION πŸ’…

okay so this sequence is literally the Mephisto waltz, and what it actually is: the count mod 2 of ternary digit 2s in i. no cap, that's the whole thing.

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

i=0 has no 2s so value=0, and same energy for i=1, value=0. then i=2 has one 2 so value=1. iconic behavior honestly.

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  |
+-----------------+  +-----------------+  +-----------------+

so what's the expansion actually doing? the way that it keeps the first third exactly the same, then appends a copy of it, then appends a 0<->1 flipped copy of it. three parts, no notes. πŸ’…


πŸŽ€ FUNCTIONS πŸŽ€

peep "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes, because this module is a team player.

  • $seq = Math::NumSeq::MephistoWaltz->new () β€” create and return a brand new sequence object. main character energy, freshly spawned ✨

πŸ¦‹ Random Access πŸ¦‹

  • $value = $seq->ith($i) β€” return the $i'th MephistoWaltz value, which is the count mod 2 of the ternary digit 2s in $i. jump straight to the tea, no waiting in line β˜•
  • $bool = $seq->pred($value) β€” return true if $value occurs in the sequence, which literally just means 0 or 1. that's the whole test, bestie, it's not deep 😭

🌈 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. so yeah, base 9 is lowkey just the same girl wearing a different outfit πŸ’œ


πŸ‘‘ SEE ALSO πŸ‘‘

  • Math::NumSeq
  • Math::NumSeq::DigitSumModulo

go read those too, they're the extended universe 🫢


πŸ’– HOME PAGE πŸ’–

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


πŸ“ LICENSE πŸ“

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

fr fr read the license, bestie, it's giving "legally binding but make it cute" πŸ’€

and that's the whole page, mwah πŸ’‹ β€” this was perl v5.42.0, dated 2025-07-25, and it lives at Math::N...stoWaltz(3) in the manual, iykyk. slay, go compute some waltzes πŸŽ€βœ¨

πŸ“¦ where this page comes from