Math::N...Function(3)

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

πŸ’– Math::NumSeq::LiouvilleFunction β€” the manual page, bestie edition πŸ’–

okay so this is the user-contributed Perl documentation for Math::NumSeq::LiouvilleFunction(3), and honestly? it's giving math girlie energy and i'm obsessed. sit down, grab a snack, we're doing number theory πŸ“


✨ NAME ✨

Math::NumSeq::LiouvilleFunction β€” the Liouville function sequence. that's it, that's the name, iconic πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

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

literally three lines and you're in. we love a low-effort entry point 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

so the Liouville function is the parity of the prime factors of i, and it goes like this:

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

and the meaning of each value is:

1   if i has an even number of prime factors
-1  if i has an odd number of prime factors

the sequence starts at i=1, which we just decide has no prime factors, aka zero prime factors, and zero is even, so boom: value 1. then i=2 and i=3 are both -1 because each has exactly one prime factor (they're primes, bestie, they're literally primes). and i=4 is value 1 because it's 2*2, which is an even number of prime factors (two 2s, no cap) ✨

this parity is similar to "MobiusFunction", but here's the tea: with this one, repeated prime factors are included, whereas in "MobiusFunction" repeated factors give a value 0. different function, different vibe, don't mix them up πŸ™ˆ

πŸ’œ Values Type πŸ’œ

the "values_type" parameter can change the two values that get returned for even or odd prime factors. "0,1" gives 0 for even and 1 for odd, which is the same thing as the count mod 2:

values_type => '0,1'
0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, ...

or "1,0" flips it the other way around, 1 for even and 0 for odd:

values_type => '1,0'
1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, ...

🌈 FUNCTIONS 🌈

see "FUNCTIONS" in Math::NumSeq for the behaviour that's common to all sequence classes, because sharing is caring πŸ’–

  • $seq = Math::NumSeq::LiouvilleFunction->new ()
  • $seq = Math::NumSeq::LiouvilleFunction->new (values_type => $str)

create and return a new sequence object, slay. the optional "values_type" (a string, bestie, it's a string) can be:

"1,-1"     1=even, -1=odd  (the default)
"0,1"      0=even, 1=odd
"1,0"      1=even, 0=odd

🧚 Random Access 🧚

  • $value = $seq->ith($i) β€” return the Liouville function of $i, being 1 or -1 (or whatever other "values_type" you picked) according to how many prime factors $i has.
heads up: this calculation requires factorizing $i, and in the current code, after small factors, a hard limit of 2**32 is enforced. the reason? so it doesn't wander off into a near-infinite loop. we're not doing that today, no thank you πŸ’€
  • $bool = $seq->pred($value) β€” return true if $value occurs in the sequence, which simply means 1 or -1, or the two "values_type" values. easy peasy ⭐

πŸ‘‘ SEE ALSO πŸ‘‘

  • Math::NumSeq
  • Math::NumSeq::MobiusFunction
  • Math::NumSeq::PrimeFactorCount

🌸 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/>.


and that's the whole page, bestie!! this absolute queen of a manpage is served up by perl v5.42.0 and it's dated 2025-07-25 β€” go forth and compute parities, you've got this πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from