moebius: Moebius Function

View source: R/functions.R

moebiusR Documentation

Moebius Function

Description

The classical Moebius and Mertens functions in number theory.

Usage

moebius(n)
mertens(n)

Arguments

n

Positive integer.

Details

moebius(n) is +1 if n is a square-free positive integer with an even number of prime factors, or +1 if there are an odd of prime factors. It is 0 if n is not square-free.

mertens(n) is the aggregating summary function, that sums up all values of moebius from 1 to n.

Value

For moebius, 0, 1 or -1, depending on the prime decomposition of n.

For mertens the values will very slowly grow.

Note

Works well up to 10^9, but will become very slow for the Mertens function.

See Also

primeFactors, eulersPhi

Examples

sapply(1:16, moebius)
sapply(1:16, mertens)

## Not run: 
x <- 1:50; y <- sapply(x, moebius)
plot(c(1, 50), c(-3, 3), type="n")
grid()
points(1:50, y, pch=18, col="blue")

x <- 1:100; y <- sapply(x, mertens)
plot(c(1, 100), c(-5, 3), type="n")
grid()
lines(1:100, y, col="red", type="s")
## End(Not run)

numbers documentation built on Nov. 23, 2022, 9:06 a.m.