++ed by:
Kevin Ryde
and 1 contributors

# NAME

Math::NumSeq::LiouvilleFunction -- Liouville function sequence

# SYNOPSIS

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

# DESCRIPTION

The Liouville function, 1, -1, -1, 0, -1, 1, etc, being

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

The sequence starts from i=1 which is taken to be no prime factors, ie. zero, which is even, hence Liouville function 1. Then i=2 and i=3 are -1 since they have one prime factor (they're primes), and i=4 is value 1 because it's 2*2 which is an even number of prime factors (two 2s).

# FUNCTIONS

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

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

Create and return a new sequence object.

## Random Access

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

Return the Liouville function of `\$i`, being 1 or -1 according to the number of prime factors in `\$i`.

This calculation requires factorizing `\$i` and in the current code a hard limit of 2**32 is placed on `\$i`, in the interests of not going into a near-infinite loop.

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

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