Math::N...unction(3)

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

πŸ’– NAME πŸ’–

Math::NumSeq::MobiusFunction β€” bestie, it's the Mobius function sequence ✨ (a user-contributed Perl thing, filed under Math::N...unction(3), iykyk)


πŸ¦‹ SYNOPSIS πŸ¦‹

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

okay so literally three lines and you're in πŸ’…


🌸 DESCRIPTION 🌸

It's the sequence of the Mobius function, and here's the glow-up:

1, -1, -1, 0, -1, 1, ...
starting i=1

Each value is one of three things:

  • 1 β€” if i has an even number of distinct prime factors
  • -1 β€” if i has an odd number of distinct prime factors
  • 0 β€” if i has a repeated prime factor

The sequence starts from i=1 and, like, it's reckoned as having no prime factors β€” that's 0 factors β€” and 0 counts as even, so value 1. Then i=2 and i=3 are value -1 because they each have one prime factor (they're primes, periodt), and i=4 is value 0 because it's 2*2, aka a repeated prime 2 πŸ’€


✨ FUNCTIONS ✨

See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes β€” that's the shared lore 🫢

  • $seq = Math::NumSeq::MobiusFunction->new () β€” create and return a new sequence object. Fresh object, new era πŸ‘‘

πŸŽ€ Random Access πŸŽ€

  • $value = $seq->ith($i) β€” return the Mobius function of $i, being 1, 0 or -1 according to the prime factors of $i.
ngl this calculation requires factorizing $i, and in the current code small primes are checked then a hard limit of 2**32 is placed on $i β€” all in the interests of not going into a near-infinite loop 😭
  • $bool = $seq->pred($value) β€” return true if $value occurs in the sequence, which means simply 1, 0 or -1. That's it, that's the whole vibe check.

🌈 SEE ALSO 🌈

  • Math::NumSeq
  • Math::NumSeq::LiouvilleFunction
  • Math::NumSeq::PrimeFactorCount
  • "moebius" in Math::Prime::Util

🧚 HOME PAGE 🧚

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


πŸ‘‘ LICENSE πŸ‘‘

Copyright 2010, 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/>.


and that's the whole page bestie, no cap πŸ’… β€” brought to you by perl v5.42.0, dated 2025-07-25, living in the Math::N...unction(3) corner of the manual. slay 🌟

πŸ“¦ where this page comes from