μ on the divisors
30 = 2·3·5 is squarefree with three primes, so μ = −1. 12 is divisible by 4, so μ = 0.
The incidence algebra of a finite poset P has a basis indexed by its intervals — the pairs x≤y — and a product that is composition:
e[x,y]⋅e[u,z]={e[x,z]0y=uotherwiseComposable intervals compose; non-composable ones annihilate. That makes this the first family here whose product is usually zero — an honest annihilation, not a refusal to answer.
The zeta function ζ(x,y)=1 on every interval is an element of this algebra, and because a poset can be listed in a linear extension, ζ is upper-triangular with ones on the diagonal — so it is invertible over the integers. Its inverse is the Möbius function μ, defined by the recursion that inverting forces:
μ(x,x)=1,μ(x,y)=−x≤z<y∑μ(x,z).That single fact — ζ∗μ=δ — is Möbius inversion, and it is the test the whole package rests on, checked as a matrix identity on every poset here.
What makes it worth building is that specialising the poset recovers classical theorems.
Order the divisors of n by divisibility, and the poset Möbius function of [a,b] is exactly the classical μ(b/a) — zero when a square divides it, (−1)k otherwise. Number theory's Möbius function is not an analogy here; it is this one, on this poset.
30 = 2·3·5 is squarefree with three primes, so μ = −1. 12 is divisible by 4, so μ = 0.
The tests check this against an independently written classical μ for every interval of D(12), D(30), D(36), D(60) and D(210).
Order subsets of {1,…,n} by inclusion and μ([S,T])=(−1)∣T∖S∣. Möbius inversion over this poset is the inclusion–exclusion principle — the alternating signs everyone writes by hand are the Möbius function of the Boolean lattice.
Three elements added, so (−1)³. Adding two gives +1.
PosetSumDown computes g(y)=∑x≤yf(x); MoebiusInvert undoes it. The two are inverse on every poset here, which is the theorem in executable form.
Sum down the chain, then invert: the original comes back. On a chain the inversion is just first differences.
A chain on n has C(n+1,2) intervals; the Boolean lattice on n has 3ⁿ — for each element, it is in S, in T\S, or in neither.
The linear extension is load-bearing, and it is easy to get wrong. Elements are stored so that i≤j whenever element i≤ element j; that is what makes ζ triangular and therefore invertible over ℤ. Sorting with "is a≤b?" as a comparator does not produce one — on a genuine partial order that comparator is not transitive, and DivisorLattice(60) came out with 12 before 3. Sorting by how many elements lie below each one does work, because x<y forces a strictly larger down-set.
Posets available: Chain(n), BooleanLattice(n) (elements are subsets), DivisorLattice(n) (elements are divisors). The element type differs per poset, and each one reads and prints its own.
Not built yet. The partition lattice — whose Möbius function is (−1)k−1(k−1)!, and which would connect this page to the diagram algebras and set partitions. Also the characteristic polynomial, and general element arithmetic: only the interval basis and the two named functions ζ and μ are here, not arbitrary elements of the algebra.