Color refinement #
Color refinement, also called the 1-dimensional Weisfeiler–Leman algorithm or naive vertex
classification, refines a vertex coloring χ₀ of a graph G round by round: in each round, a
vertex is recolored by the pair of its old color and the multiset of the old colors of its
neighbors. Two vertices that have the same color so far get different colors in the next round
when, for some color c, they have different numbers of neighbors of color c.
The colors of round n live in a type RefinementColor α n that depends only on the type α of
initial colors and on n, not on the graph. Colors of different graphs are therefore directly
comparable, which is the canonical color naming behind the color refinement isomorphism test.
A coloring χ is equitable (SimpleGraph.IsEquitable) when vertices of the same color have the
same multiset of neighbor colors, that is, when one round of refinement does not split any color
class. For partitions, given as setoids, this is the classical notion of an equitable partition
(SimpleGraph.IsEquitablePartition): any two vertices of a block have the same number of neighbors
in every block. This is unrelated to Mathlib's Finpartition.IsEquipartition, which asks for blocks
of almost equal sizes.
A coloring is compared with others through its partition into color classes, Setoid.ker χ, and
Cslib.SetPartition.blocks counts the classes. The partitions of successive rounds refine each
other, and the number of classes increases strictly until the partition stops changing. So on a
finite graph whose initial coloring has k₀ classes, the partition is stable after |V| - k₀
rounds. The coloring after |V| rounds, SimpleGraph.stableColoring, is equitable, and its
partition is the coarsest equitable partition refining the initial one.
A graph isomorphism transports the colors of every round, so isomorphic graphs have the same color
histogram (multiset of vertex colors) in every round. This is the soundness of the color
refinement isomorphism test. The test is incomplete: two d-regular graphs with the same number of
vertices have the same histograms in every round. Running color refinement on the disjoint union
shows that agreement in round |V| + |W| implies agreement in every round.
The graphs are assumed LocallyFinite, which is what neighbor multisets need. Mathlib provides
this instance for a disjoint union G ⊕g H but no decidable adjacency instance.
Main definitions #
SimpleGraph.RefinementColor: the type of colors of roundn.SimpleGraph.refineColoring: one round of color refinement.SimpleGraph.refinementColoring: the coloring afternrounds.SimpleGraph.IsEquitable: equitable colorings.SimpleGraph.IsEquitablePartition: equitable partitions, given as setoids.SimpleGraph.stableColoring: the coloring after|V|rounds.SimpleGraph.colorHistogram: the multiset of the colors of roundn.
Main results #
SimpleGraph.blocks_ker_refinementColoring_lt_succ: the number of color classes increases strictly while the partition changes.SimpleGraph.ker_refinementColoring_eq: the partition is stable after|V| - k₀rounds.SimpleGraph.isEquitable_stableColoring: the stable coloring is equitable.SimpleGraph.isGreatest_ker_stableColoring: the partition of the stable coloring is the coarsest equitable partition refining the initial coloring.SimpleGraph.Iso.colorHistogram_eq: isomorphic colored graphs have the same color histograms.SimpleGraph.isEmpty_iso_of_colorHistogram_ne: soundness of the color refinement isomorphism test.SimpleGraph.forall_refinementColoring_eq_iff,SimpleGraph.forall_colorHistogram_eq_iff: vertex colors or histograms agree in every round when they agree in round|V| + |W|.SimpleGraph.IsRegularOfDegree.colorHistogram_eq: color refinement does not distinguish twod-regular graphs of the same order.
Implementation notes #
[GKMS14] describe color refinement on graphs in words at the start of
Section 1 (Introduction). In its paragraph "Colour Refinement on Matrices" they work with the
color refinement of a matrix A ∈ ℝ^{V×W}, a weighted bipartite graph whose two sides are the rows
V and the columns W, from the trivial partition. They state stabilization within |V| + |W|
rounds, the number of vertices of that one bipartite graph, and that the result is the coarsest
equitable partition. A 0-1 matrix gives the bipartite graph B_A; according to the source,
general weighted directed graphs correspond to square matrices, but the source presents only the
bipartite case. The present file treats simple graphs with an arbitrary initial coloring directly.
The bound of |V| - k₀ rounds is the standard counting argument. In
SimpleGraph.forall_colorHistogram_eq_iff, V and W are the vertex types of two graphs, so its
|V| + |W| is the order of their disjoint union and is unrelated to the source's bound. That
lemma and the regular-graph example are standard.
References #
- M. Grohe, K. Kersting, M. Mladenov, E. Selman, Dimension Reduction via Colour Refinement, Section 1 (Introduction), including the paragraph "Colour Refinement on Matrices".
The colors of round n of color refinement started from colors in α: a color of round
n + 1 is a color of round n together with a multiset of colors of round n.
Colors of every round have decidable equality when the initial colors do.
If g is constant on the fibers of f, then two multisets with the same image under f have
the same image under g.
One round of color refinement: the color of v together with the multiset of the colors of
its neighbors.
The coloring after n rounds of color refinement started from χ₀.
A coloring is equitable when vertices of the same color have the same multiset of neighbor colors.
A partition of the vertices, given as a setoid, is equitable when any two vertices of the
same block have the same number of neighbors in every block. The numbers are counted in ℕ∞, so
the definition also makes sense when neighborhoods are infinite.
The coloring after |V| rounds of color refinement started from χ₀. By
SimpleGraph.ker_refinementColoring_eq, its partition is the stable partition.
The color histogram of round n: the multiset of the colors of the vertices after n
rounds.
One round #
The multiset part of a refined color has as many elements as the vertex has neighbors.
A round of refinement refines the partition.
A round of refinement is monotone in the partition.
A coloring is equitable exactly when a round of refinement does not split its classes.
Being equitable depends only on the partition into color classes.
A constant coloring is equitable exactly when all vertices have the same degree.
A coloring is equitable exactly when vertices of the same color have the same number of neighbors of each color.
A partition is equitable exactly when its quotient map is an equitable coloring.
The partition into the color classes of χ is equitable exactly when χ is.
Refinement and stabilization #
Each round refines the partition of the previous round.
Every round refines the initial coloring.
The coloring of round n is equitable exactly when round n + 1 has the same partition.
Once a round does not change the partition, no later round does.
An equitable partition refining the initial coloring refines the coloring of every round.
The number of color classes does not decrease from one round to the next.
The number of color classes increases strictly as long as the partition changes.
Stabilization: if the initial coloring has k₀ classes, then the partition does not change
after round |V| - k₀.
From round |V| on, the partition is that of the stable coloring.
The stable coloring is equitable.
The stable coloring refines the initial coloring.
Every equitable coloring refining the initial coloring refines the stable coloring.
Coarsest equitable partition: the partition of the stable coloring is the coarsest equitable partition refining the initial coloring.
Isomorphism invariance and soundness #
An isomorphism maps the neighbors of v onto the neighbors of its image.
An embedding that maps the neighbors of every v onto the neighbors of its image transports
every round of color refinement.
An isomorphism of colored graphs preserves the colors of every round.
Isomorphic colored graphs have the same color histogram in every round.
Soundness of the color refinement test for colored graphs: if the color histograms differ in some round, then no isomorphism preserves the initial colors.
Soundness of the color refinement test: if the color histograms from the constant coloring differ in some round, then the graphs are not isomorphic.
Disjoint unions #
On the left summand, color refinement of a disjoint union is color refinement of G.
On the right summand, color refinement of a disjoint union is color refinement of H.
The histogram of a disjoint union is the sum of the histograms.
Earlier rounds and completeness of round |V| + |W| #
Forget the last k rounds of a color of round n + k.
The color of round n + k determines the color of round n.
Colors that agree in some round agree in every earlier round.
The histogram of round n + k determines the histogram of round n.
Histograms that agree in some round agree in every earlier round.
Color refinement distinguishes two vertices of two graphs in some round exactly when it
distinguishes them in round |V| + |W|, the order of the disjoint union.
Color refinement distinguishes two graphs in some round exactly when it distinguishes them in
round |V| + |W|. The proof runs color refinement on the disjoint union, whose partition is stable
from round |V| + |W| on.
Regular graphs #
Incompleteness of the color refinement test: two d-regular graphs with the same number of
vertices have the same color histograms in every round.