Proofs: Björklund's chromatic number algorithm
These are the human proofs of Björklund's chromatic number algorithm, at full length.
Björklund's algorithm returns the chromatic number full
This proof shows: correctness, termination.
Let be a finite simple undirected graph with , and identify subsets of with bit masks. A set is independent if no edge has both ends in ; the empty set is independent. For let
If , line L1 returns . Assume from now on.
Lemma 1 (lines L2 and L3). After line L3 has run for every nonempty mask, if is independent and otherwise, for every .
Proof. Induction on the mask value. and is independent. For , let be its smallest vertex. The mask of is smaller, so is already correct when is processed. is independent if and only if is independent and has no neighbor in ; since , the second condition is .
Lemma 2 (lines L4 and L5). After line L5 has run for every vertex, for every .
Proof. Let be the vertices in the order of line L4, and . We claim that after the first rounds,
For the only such is , and . In round , line L5 changes only the entries with , and it reads , which round does not change because . So, for , the new is the sum of the old and the old . By the claim for , the first sums over the with , which are those with ; the second sums over the with , which are those with . Together they are the with . For , no differs from at , and the entry is already right. After round , , so by Lemma 1.
Lemma 3 (covers). For every , the value of line L7 equals the number of -tuples of independent sets with .
Proof. By Lemma 2, is the number of -tuples of independent sets that all lie in , that is, whose union satisfies . So
where the outer sum on the right runs over all -tuples of independent sets and is the union of the tuple. Writing with , and , the inner sum is , which is 1 if and 0 if . So each tuple with union counts once and every other tuple counts zero.
Lemma 4. For , if and only if .
Proof. If is a proper coloring, the color classes are independent, possibly empty, and their union is , so . Conversely, given a cover by independent sets, color each vertex with the least such that . Every vertex gets a color, since the union is . If is an edge and both get color , then , which contradicts independence. So this is a proper coloring with at most colors.
Theorem. BJORKLUND-CHROMATIC terminates and returns .
Proof. The case is line L1. For , lines L2 to L5 are loops over finite ranges. The loop of line L6 tries in order. By Lemmas 3 and 4, at round line L8 returns exactly when . Since , because the singletons form a proper coloring, the loop returns at round and not before. In the implementation, line L7 builds as the product of the stored and , which equals the value in the pseudocode.