Arithmetic Functions and the Mobius Inversion Formula
Meet the divisor, totient and Mobius functions, learn how divisor sums combine them, and undo those sums with one formula.
Key takeaways
- An arithmetic function takes positive integers as inputs, and many important ones are multiplicative.
- A multiplicative function is determined entirely by its values on prime powers.
- The Möbius function μ(n) is 0 when a square of a prime divides n, and otherwise +1 or −1 according to the parity of the number of primes.
- If g(n) is the sum of f(d) over the divisors d of n, then f(n) is the sum of μ(d) g(n/d).
- Dirichlet convolution turns these facts into an algebra in which inversion is simply division.
An arithmetic function is a function whose input is a positive whole number, usually chosen to record something about its factors. The number of divisors, the sum of divisors and Euler's totient are standard examples.
Many identities say that adding one such function over all divisors of n gives another. The Möbius inversion formula runs that process backwards: if you know the divisor sums, it recovers the original function. It is a short formula with a long reach.
Four functions to know
| Function | Meaning | Value at n = 12 |
|---|---|---|
| d(n) | Number of positive divisors | 6 |
| σ(n) | Sum of positive divisors | 28 |
| φ(n) | Count of integers from 1 to n sharing no factor with n | 4 |
| μ(n) | Möbius function | 0 |
The divisors of 12 are 1, 2, 3, 4, 6 and 12, which gives the first two values. The totient counts 1, 5, 7 and 11. The last value is explained below.
Multiplicative functions
A function f is multiplicative if f(mn) = f(m) f(n) whenever m and n share no common factor, and f(1) = 1. All four functions above are multiplicative.
This means you only need values at prime powers. For a prime p and exponent k ≥ 1:
d(p^k) = k + 1
σ(p^k) = 1 + p + ... + p^k = (p^(k+1) − 1)/(p − 1)
φ(p^k) = p^k − p^(k−1) So for 360 = 2³ × 3² × 5, the number of divisors is 4 × 3 × 2 = 24, the sum is 15 × 13 × 6 = 1170, and the totient is 4 × 6 × 4 = 96. This relies on unique factorization into primes. The counting argument for d(n) is spelled out in counting divisors.
Beware the condition: d(4) is 3, while d(2) × d(2) is 4. The two factors must be coprime.
The Möbius function
August Ferdinand Möbius studied this function in 1832. Its definition looks odd at first:
- μ(1) = 1.
- μ(n) = 0 if some prime square divides n.
- μ(n) = (−1)^r if n is a product of r different primes.
The first twelve values are 1, −1, −1, 0, −1, 1, −1, 0, 0, 1, −1, 0.
The reason for the definition is a single identity: the sum of μ(d) over all divisors d of n equals 1 when n = 1 and 0 otherwise.
To prove it, suppose n > 1 has r distinct primes. Only squarefree divisors contribute, and each corresponds to a subset of those r primes. The sum counts even-sized subsets minus odd-sized ones, which is (1 − 1)^r = 0. For n = 12 the contributing divisors are 1, 2, 3 and 6, with values 1, −1, −1 and 1.
The inversion formula
Suppose that for every n,
g(n) = sum of f(d) over all divisors d of n Then, for every n,
f(n) = sum of μ(d) × g(n/d) over all divisors d of n The proof substitutes the first equation into the second and swaps the order of addition:
sum over d | n of μ(d) g(n/d)
= sum over d | n of μ(d) × (sum over e | (n/d) of f(e))
= sum over e | n of f(e) × (sum over d | (n/e) of μ(d))
= f(n) (the inner sum is 0 unless n/e = 1) The notation d | n means "d divides n". The converse holds as well, so the two equations are equivalent. Neither requires f to be multiplicative.
Worked example with the totient
A classic identity says that the totients of the divisors of n add up to n. To see why, write the fractions 1/12, 2/12, ..., 12/12 in lowest terms. For each divisor d of 12, exactly φ(d) of them end up with denominator d.
φ(1)+φ(2)+φ(3)+φ(4)+φ(6)+φ(12) = 1+1+2+2+2+4 = 12 Here f = φ and g(n) = n. Inverting gives a formula for the totient:
φ(12) = μ(1)·12 + μ(2)·6 + μ(3)·4 + μ(4)·3 + μ(6)·2 + μ(12)·1
= 12 − 6 − 4 + 0 + 2 + 0
= 4 You can read the signs as inclusion and exclusion: start with all 12 numbers, remove multiples of 2 and of 3, then restore multiples of 6, which were removed twice. The totient's main application appears in Euler's theorem.
Counting patterns that do not repeat
How many strings of six 0s and 1s are not a shorter block repeated? For instance, 010101 repeats "01", while 000101 repeats nothing.
Let f(n) count the non-repeating strings of length n. Every string of length n is a unique shortest block, of length d dividing n, repeated. So the sum of f(d) over divisors equals 2ⁿ. Inverting,
f(6) = μ(1)·2⁶ + μ(2)·2³ + μ(3)·2² + μ(6)·2¹
= 64 − 8 − 4 + 2
= 54 If strings that are rotations of one another count once, as for beads on a necklace, divide by 6 to get 9. The same computation with a prime q in place of 2 counts irreducible polynomials of degree n over the field with q elements: divide f(n) by n.
Counting coprime pairs
How many pairs (a, b), with both numbers from 1 to N, have no common factor greater than 1? Möbius inversion turns the condition into a sum. Because the sum of μ(d) over common divisors is 1 for coprime pairs and 0 otherwise, you can add it over all pairs and swap the order.
The number of pairs where d divides both entries is the square of the number of multiples of d up to N, written floor(N/d)². So
coprime pairs = sum over d from 1 to N of μ(d) × floor(N/d)²
N = 4: μ(1)·16 + μ(2)·4 + μ(3)·1 + μ(4)·1
= 16 − 4 − 1 + 0
= 11 Checking directly, the pairs that share a factor are (2, 2), (2, 4), (4, 2), (4, 4) and (3, 3). That is 5 of the 16, leaving 11.
For large N, floor(N/d)² is close to N²/d². The proportion of coprime pairs therefore tends to the sum of μ(d)/d², which equals 6/π², about 0.608. A question about shared factors has produced the circle constant.
Why divisor sums keep multiplicativity
Suppose f is multiplicative and g(n) adds f(d) over the divisors of n. Take m and n with no common factor. Every divisor of mn splits in exactly one way as a divisor a of m times a divisor b of n, and a and b are again coprime.
g(mn) = sum over a | m, b | n of f(ab)
= sum over a | m, b | n of f(a) f(b)
= (sum over a | m of f(a)) × (sum over b | n of f(b))
= g(m) g(n) Choosing f = 1 shows d(n) is multiplicative, and choosing f(n) = n shows σ(n) is. Inversion gives the reverse direction too: if g is multiplicative, so is f.
This yields a practical technique. To prove an identity between multiplicative functions, check it on prime powers only. For the totient identity, the sum over the divisors of p^k is 1 + (p − 1) + (p² − p) + ... + (p^k − p^(k−1)), which collapses to p^k.
The divisor sum also frames an old question. A number n is perfect exactly when σ(n) = 2n, as with σ(28) = 56.
Dirichlet convolution
Define the convolution of f and g by
(f * g)(n) = sum over d | n of f(d) g(n/d) This operation is commutative and associative. Its identity element is the function that equals 1 at n = 1 and 0 elsewhere. If u denotes the constant function 1, the key identity says μ * u is the identity, so μ and u are inverses.
Inversion then takes one line: if g = f * u, then g * μ = f * u * μ = f. The convolution of two multiplicative functions is again multiplicative, which gives quick proofs that d and σ are multiplicative, since d = u * u.
In terms of series, convolution matches multiplication of sums of the form f(n)/nˢ. The series for μ is the reciprocal of the zeta function, a link developed in the Euler product.
Squarefree numbers and cancellation
A number is squarefree if no square larger than 1 divides it, in other words if μ(n) ≠ 0. The proportion of squarefree numbers up to x tends to 6/π², about 61%.
The sum M(x) = μ(1) + μ(2) + ... + μ(x) measures how well the plus and minus signs cancel. The statement that M(x)/x tends to 0 is equivalent to the prime number theorem. A much stronger bound on M(x) would be equivalent to the Riemann hypothesis.
Franz Mertens conjectured that |M(x)| is always less than √x for x > 1. It holds in every range that is easy to test, yet Andrew Odlyzko and Herman te Riele disproved it in 1985, without exhibiting a specific counterexample.
Exercises
- Verify that the sum of d(k) over divisors k of 6 equals 1 + 2 + 2 + 4 = 9, and invert to recover d(6) = 4.
- Show that σ(n) summed against μ gives back n.
- Count non-repeating binary strings of length 4. You should find 16 − 4 = 12.
For longer practice, tabulate μ up to 50 with a sieve: start every entry at 1, flip the sign for each prime factor, and zero out multiples of each prime square.