Documentation

CslibFrontier.Foundations.Combinatorics.SimpleGraph.WeisfeilerLeman

The k-dimensional Weisfeiler–Leman algorithm #

The (folklore) k-dimensional Weisfeiler–Leman algorithm (k-WL) colors k-tuples u : Fin k → V of a finite simple graph G round by round ([CFI92], Section 5):

Recording the atomic isomorphism type of Fin.snoc u v in the step profile matches W^r in [CFI92], Section 5. For k ≥ 2, every coordinate of u already survives in some Function.update u i v, whereas for k = 1, Function.update u 0 v overwrites the sole coordinate u 0; including G.tupleAtom (Fin.snoc u v) keeps v = u 0 and G.Adj (u 0) v so that k = 1 agrees with vertex color refinement (SimpleGraph.refinementColoring) and the correspondence with the (k + 1)-pebble bijective game holds uniformly for every k : ℕ.

The colors of round n live in SimpleGraph.WLColor k n : Type, independent of the vertex type and its universe, so tuple colors and histograms (SimpleGraph.wlHistogram) of different graphs are directly comparable without decidable-equality or decidable-adjacency hypotheses.

Partitioning Fin k → V by Setoid.ker (G.wlColoring n) refines the partition each round until it stabilizes within |V| ^ k - k₀ rounds (SimpleGraph.ker_wlColoring_eq), where k₀ is the number of atomic k-tuple classes. Applying the same counting argument to the combined coloring Sum.elim (G.wlColoring n) (H.wlColoring n) on (Fin k → V) ⊕ (Fin k → W) shows that k-WL distinguishes two tuples or two graphs in some round if and only if it distinguishes them in round |V| ^ k + |W| ^ k (SimpleGraph.forall_wlColoring_eq_iff, SimpleGraph.forall_wlHistogram_eq_iff).

Main definitions #

Main results #

References #

Atomic isomorphism types of tuples #

@[reducible, inline]

The ordered atomic isomorphism type of an m-tuple in a simple graph: the equality relation and the adjacency relation among its coordinates.

def SimpleGraph.tupleAtom {V : Type u_1} (G : SimpleGraph V) {m : ℕ} (t : Fin m → V) :

The ordered atomic isomorphism type of t : Fin m → V in G.

@[simp]
theorem SimpleGraph.tupleAtom_fst {V : Type u_1} (G : SimpleGraph V) {m : ℕ} (t : Fin m → V) (i j : Fin m) :
(G.tupleAtom t).1 i j ↔ t i = t j
@[simp]
theorem SimpleGraph.tupleAtom_snd {V : Type u_1} (G : SimpleGraph V) {m : ℕ} (t : Fin m → V) (i j : Fin m) :
(G.tupleAtom t).2 i j ↔ G.Adj (t i) (t j)
theorem SimpleGraph.tupleAtom_eq_iff {V : Type u_1} {W : Type u_2} {G : SimpleGraph V} {H : SimpleGraph W} {m : ℕ} {t₁ : Fin m → V} {t₂ : Fin m → W} :
G.tupleAtom t₁ = H.tupleAtom t₂ ↔ ∀ (i j : Fin m), (t₁ i = t₁ j ↔ t₂ i = t₂ j) ∧ (G.Adj (t₁ i) (t₁ j) ↔ H.Adj (t₂ i) (t₂ j))

Two tuples have the same atomic isomorphism type exactly when equality and adjacency agree on all coordinate pairs.

theorem SimpleGraph.tupleAtom_comp_eq {V : Type u_1} {W : Type u_2} {G : SimpleGraph V} {H : SimpleGraph W} {m r : ℕ} {t₁ : Fin m → V} {t₂ : Fin m → W} (h : G.tupleAtom t₁ = H.tupleAtom t₂) (g : Fin r → Fin m) :
G.tupleAtom (t₁ ∘ g) = H.tupleAtom (t₂ ∘ g)

Reindexing coordinates preserves equality of atomic isomorphism types.

theorem SimpleGraph.Iso.tupleAtom_comp {V : Type u_1} {W : Type u_2} {G : SimpleGraph V} {H : SimpleGraph W} (e : G ≃g H) {m : ℕ} (t : Fin m → V) :
H.tupleAtom (⇑e ∘ t) = G.tupleAtom t

Graph isomorphisms preserve the atomic isomorphism type of every tuple.

Colors, step profiles and k-WL refinement #

The colors of round n of k-dimensional Weisfeiler–Leman: round 0 records the atomic isomorphism type of a k-tuple, and round n + 1 pairs the round-n color with a multiset of step profiles.

def SimpleGraph.wlStepProfile {V : Type u_1} {β : Type u_3} (G : SimpleGraph V) {k : ℕ} (χ : (Fin k → V) → β) (u : Fin k → V) (v : V) :
TupleAtom (k + 1) × (Fin k → β)

The step profile of extending u : Fin k → V by v : V under a tuple coloring χ: the atomic isomorphism type of Fin.snoc u v together with the colors of the k tuples obtained by replacing each coordinate of u with v.

def SimpleGraph.wlRefine {V : Type u_1} {β : Type u_3} [Fintype V] (G : SimpleGraph V) {k : ℕ} (χ : (Fin k → V) → β) (u : Fin k → V) :
β × Multiset (TupleAtom (k + 1) × (Fin k → β))

One round of k-dimensional Weisfeiler–Leman refinement on u : Fin k → V.

def SimpleGraph.wlColoring {V : Type u_1} [Fintype V] (G : SimpleGraph V) {k : ℕ} (n : ℕ) :
(Fin k → V) → WLColor k n

The k-dimensional Weisfeiler–Leman coloring of G after n rounds.

def SimpleGraph.stableWLColoring {V : Type u_1} [Fintype V] (G : SimpleGraph V) (k : ℕ) :
(Fin k → V) → WLColor k (Fintype.card V ^ k)

The k-WL coloring after |V| ^ k rounds, whose partition is stable by SimpleGraph.ker_stableWLColoring.

def SimpleGraph.wlHistogram {V : Type u_1} [Fintype V] (G : SimpleGraph V) (k n : ℕ) :

The k-WL color histogram of round n: the multiset of colors of all k-tuples in G.

theorem SimpleGraph.wlStepProfile_apply {V : Type u_1} {β : Type u_3} {G : SimpleGraph V} {k : ℕ} (χ : (Fin k → V) → β) (u : Fin k → V) (v : V) :
G.wlStepProfile χ u v = (G.tupleAtom (Fin.snoc u v), fun (i : Fin k) => χ (Function.update u i v))
theorem SimpleGraph.wlStepProfile_eq_iff {V : Type u_1} {W : Type u_2} {β : Type u_3} {G : SimpleGraph V} {H : SimpleGraph W} {k : ℕ} {χ : (Fin k → V) → β} {ψ : (Fin k → W) → β} {u : Fin k → V} {w : Fin k → W} {v : V} {z : W} :
G.wlStepProfile χ u v = H.wlStepProfile ψ w z ↔ G.tupleAtom (Fin.snoc u v) = H.tupleAtom (Fin.snoc w z) ∧ ∀ (i : Fin k), χ (Function.update u i v) = ψ (Function.update w i z)
theorem SimpleGraph.wlRefine_apply {V : Type u_1} {β : Type u_3} {G : SimpleGraph V} {k : ℕ} [Fintype V] (χ : (Fin k → V) → β) (u : Fin k → V) :
theorem SimpleGraph.wlColoring_succ {V : Type u_1} {G : SimpleGraph V} {k : ℕ} [Fintype V] (n : ℕ) :
G.wlColoring (n + 1) = G.wlRefine (G.wlColoring n)
theorem SimpleGraph.card_wlRefine_snd {V : Type u_1} {β : Type u_3} {G : SimpleGraph V} {k : ℕ} [Fintype V] (χ : (Fin k → V) → β) (u : Fin k → V) :
theorem SimpleGraph.card_wlHistogram {V : Type u_1} {G : SimpleGraph V} [Fintype V] (k n : ℕ) :
theorem SimpleGraph.mem_wlHistogram {V : Type u_1} {G : SimpleGraph V} {k : ℕ} [Fintype V] {n : ℕ} {c : WLColor k n} :
c ∈ G.wlHistogram k n ↔ ∃ (u : Fin k → V), G.wlColoring n u = c
theorem SimpleGraph.wlRefine_eq_wlRefine_iff {V : Type u_1} {W : Type u_2} {β : Type u_3} {G : SimpleGraph V} {H : SimpleGraph W} {k : ℕ} [Fintype V] [Fintype W] {χ : (Fin k → V) → β} {ψ : (Fin k → W) → β} {u : Fin k → V} {w : Fin k → W} :
theorem SimpleGraph.wlColoring_zero_eq_iff {V : Type u_1} {W : Type u_2} {G : SimpleGraph V} {H : SimpleGraph W} {k : ℕ} [Fintype V] [Fintype W] {u : Fin k → V} {w : Fin k → W} :
G.wlColoring 0 u = H.wlColoring 0 w ↔ ∀ (i j : Fin k), (u i = u j ↔ w i = w j) ∧ (G.Adj (u i) (u j) ↔ H.Adj (w i) (w j))
theorem SimpleGraph.wlColoring_succ_eq_iff {V : Type u_1} {W : Type u_2} {G : SimpleGraph V} {H : SimpleGraph W} {k : ℕ} [Fintype V] [Fintype W] {n : ℕ} {u : Fin k → V} {w : Fin k → W} :
theorem SimpleGraph.wlRefine_eq_of_imp {V : Type u_1} {W : Type u_2} {β : Type u_3} {γ : Type u_4} {G : SimpleGraph V} {H : SimpleGraph W} {k : ℕ} [Fintype V] [Fintype W] {χ₁ : (Fin k → V) → β} {ψ₁ : (Fin k → W) → β} {χ₂ : (Fin k → V) → γ} {ψ₂ : (Fin k → W) → γ} (himp : ∀ (u' : Fin k → V) (w' : Fin k → W), χ₁ u' = ψ₁ w' → χ₂ u' = ψ₂ w') {u : Fin k → V} {w : Fin k → W} (h : G.wlRefine χ₁ u = H.wlRefine ψ₁ w) :
G.wlRefine χ₂ u = H.wlRefine ψ₂ w

If χ₁ u = ψ₁ w implies χ₂ u = ψ₂ w for all k-tuples, then the same implication holds after one round of k-WL refinement.

theorem SimpleGraph.ker_wlRefine_le {V : Type u_1} {β : Type u_3} {G : SimpleGraph V} {k : ℕ} [Fintype V] (χ : (Fin k → V) → β) :

A round of k-WL refinement refines the tuple partition.

theorem SimpleGraph.ker_wlRefine_mono {V : Type u_1} {β : Type u_3} {γ : Type u_4} {G : SimpleGraph V} {k : ℕ} [Fintype V] {χ : (Fin k → V) → β} {ψ : (Fin k → V) → γ} (h : Setoid.ker χ ≤ Setoid.ker ψ) :

A round of k-WL refinement is monotone in the tuple partition.

Refinement and stabilization #

Each round of k-WL refines the tuple partition of the previous round.

Every round of k-WL refines the atomic tuple partition of round 0.

theorem SimpleGraph.ker_wlColoring_eq_of_succ_eq {V : Type u_1} [Fintype V] {G : SimpleGraph V} {k n : ℕ} (h : Setoid.ker (G.wlColoring (n + 1)) = Setoid.ker (G.wlColoring n)) {m : ℕ} (hm : n ≤ m) :

Once a round of k-WL does not change the tuple partition, no later round does.

The number of k-WL color classes does not decrease from one round to the next.

The number of k-WL color classes increases strictly as long as the partition changes.

Stabilization of k-WL: if round 0 has k₀ atomic tuple classes, then the tuple partition does not change after round |V| ^ k - k₀.

From round |V| ^ k on, the tuple partition is that of stableWLColoring.

Isomorphism invariance and soundness #

theorem SimpleGraph.Iso.wlColoring_comp {V : Type u_1} {W : Type u_2} [Fintype V] [Fintype W] {G : SimpleGraph V} {H : SimpleGraph W} {k : ℕ} (e : G ≃g H) (n : ℕ) (u : Fin k → V) :
H.wlColoring n (⇑e ∘ u) = G.wlColoring n u

A graph isomorphism preserves the k-WL color of every tuple in every round.

theorem SimpleGraph.Iso.wlHistogram_eq {V : Type u_1} {W : Type u_2} [Fintype V] [Fintype W] {G : SimpleGraph V} {H : SimpleGraph W} (e : G ≃g H) (k n : ℕ) :

Isomorphic finite graphs have the same k-WL histogram in every round.

theorem SimpleGraph.isEmpty_iso_of_wlHistogram_ne {V : Type u_1} {W : Type u_2} [Fintype V] [Fintype W] {G : SimpleGraph V} {H : SimpleGraph W} {k n : ℕ} (h : G.wlHistogram k n ≠ H.wlHistogram k n) :

Soundness of the k-WL isomorphism test: if the k-WL histograms differ in some round, then the graphs are not isomorphic.

Earlier rounds and completeness of round |V| ^ k + |W| ^ k #

def SimpleGraph.WLColor.truncate {k : ℕ} (n r : ℕ) :
WLColor k (n + r) → WLColor k n

Forget the last r rounds of a k-WL color of round n + r.

theorem SimpleGraph.truncate_wlColoring {V : Type u_1} [Fintype V] {G : SimpleGraph V} {k : ℕ} (n r : ℕ) (u : Fin k → V) :
WLColor.truncate n r (G.wlColoring (n + r) u) = G.wlColoring n u

The k-WL color of round n + r determines the color of round n.

theorem SimpleGraph.wlColoring_eq_of_le {V : Type u_1} {W : Type u_2} [Fintype V] [Fintype W] {G : SimpleGraph V} {H : SimpleGraph W} {k m n : ℕ} (hnm : n ≤ m) {u : Fin k → V} {w : Fin k → W} (h : G.wlColoring m u = H.wlColoring m w) :
G.wlColoring n u = H.wlColoring n w

k-WL colors that agree in some round agree in every earlier round.

The k-WL histogram of round n + r determines the histogram of round n.

theorem SimpleGraph.wlHistogram_eq_of_le {V : Type u_1} {W : Type u_2} [Fintype V] [Fintype W] {G : SimpleGraph V} {H : SimpleGraph W} {k m n : ℕ} (hnm : n ≤ m) (h : G.wlHistogram k m = H.wlHistogram k m) :

k-WL histograms that agree in some round agree in every earlier round.

theorem SimpleGraph.forall_wlColoring_eq_iff {V : Type u_1} {W : Type u_2} [Fintype V] [Fintype W] {G : SimpleGraph V} {H : SimpleGraph W} {k : ℕ} {u : Fin k → V} {w : Fin k → W} :
(∀ (n : ℕ), G.wlColoring n u = H.wlColoring n w) ↔ G.wlColoring (Fintype.card V ^ k + Fintype.card W ^ k) u = H.wlColoring (Fintype.card V ^ k + Fintype.card W ^ k) w

k-WL distinguishes two k-tuples of G and H in some round if and only if it distinguishes them in round |V| ^ k + |W| ^ k.

theorem SimpleGraph.forall_wlHistogram_eq_iff {V : Type u_1} {W : Type u_2} [Fintype V] [Fintype W] {G : SimpleGraph V} {H : SimpleGraph W} {k : ℕ} :

k-WL distinguishes two graphs G and H in some round if and only if it distinguishes them in round |V| ^ k + |W| ^ k.