---
title: 3D Weisfeiler-Leman Algorithm
url: https://www.emergentmind.com/topics/3-dimensional-weisfeiler-leman-algorithm
type: topic
---

# 3D Weisfeiler-Leman Algorithm

The 3-dimensional Weisfeiler-Leman algorithm (3-WL) is a canonical combinatorial refinement procedure that operates on ordered triples of vertices in a graph or, more generally, within a finite relational structure. As a central tool in graph isomorphism testing, algebraic combinatorics, and finite model theory, 3-WL generalizes the color refinement algorithm (often termed 1-WL), providing substantially greater discriminative power by considering colored structures and homomorphism counts of treewidth at most 2. Recent work has deepened the understanding of its complexity, lower and upper bounds on iteration counts, its logical characterization, extensions to graphons, and connections to coherent algebras.

## 1. Formal Definition and Iterative Procedure

The 3-WL algorithm associates a coloring $\chi^r : V^3 \to \mathrm{Colors}$ to the set of ordered vertex triples of a given relational structure $G = (V, ...)$, iteratively refining this coloring to encode increasingly fine-grained structural information.

- **Initialization ($r=0$):**
  $$
  \chi^0(v_1, v_2, v_3) := \mathrm{atp}_G(v_1, v_2, v_3)
  $$
  where $\mathrm{atp}_G$ is the isomorphism type of the induced substructure on $\{v_1, v_2, v_3\}$ (including equality patterns and edge-relations).
- **Refinement (one round):**
  $$
  \chi^{r+1}(v_1, v_2, v_3) := \left( \chi^r(v_1, v_2, v_3), \, M^r(v_1, v_2, v_3) \right)
  $$
  where $M^r$ is a multiset over all $w \in V$ of the triples:
  $$
  \left\{ (\chi^r(w, v_2, v_3),\, \chi^r(v_1, w, v_3),\, \chi^r(v_1, v_2, w)) \mid w \in V \right\}
  $$
- **Termination and Stability:**  
  The process stabilizes after a finite number of rounds $r_\infty$ when the coloring ceases to change ($\chi^{r_\infty} \equiv \chi^{r_\infty+1}$). The stabilized coloring is denoted $\chi^3 := \chi^{r_\infty}$.
- **Distinguishing Power:**  
  Two structures $G$ and $H$ are distinguished by 3-WL if the multiset of stabilized 3-colors differs between $G$ and $H$ [2301.13317, 1002.1921, 2308.11970].

## 2. Algorithmic Implementation and Complexity

Algorithmic instantiations center on iteratively updating the coloring of triples via hashing, multisets, and efficient encoding schemes:

- **Pseudocode highlights:**
  - For each triple $t = (v_1,v_2,v_3)$, build multiset $M_t$ of all triples formed by replacing one coordinate with $w \in V$.
  - New color is given by an injective encoding of previous color and sorted multiset [1708.07354, 1002.1921].
  ```python
  for t in V^3:
      M_t = { (χ(w,v2,v3), χ(v1,w,v3), χ(v1,v2,w)) for w in V }
      newχ[t] = encode(χ[t], sort_multiset(M_t))
  ```
- **Complexity:**  
  - Number of triples: $O(n^3)$ for graph of $n$ vertices.
  - Per round: $O(n^4 \log n)$ in careful implementations.
  - Number of rounds: Upper bound $O(3 n^2 \log n)$ [2301.13317], with naive theoretical bound $O(n^3)$ [1708.07354].
  - Total runtime: Typically $O(n^7 \log n)$ in naive form, but $O(n^4 \log n)$ is attainable through careful splitting and data structures [1002.1921].

## 3. Upper and Lower Bounds on Iteration Number

Recent work provides the first nontrivial bounds on the required number of refinement rounds for stabilization:

**Upper Bound (3-WL):**
$$
r_\infty \leq O(3 n^2 \log n)
$$
This result uses algebraic embedding techniques, associating partitions of $V^3$ to semisimple matrix algebras, and leverages the chain length bound for increasing chains of semisimple subalgebras [2301.13317].

**Lower Bound (Worst-case):**
$$
r_\infty \geq \Omega(n^{3/2}) \quad \text{on graphs} \qquad [2308.11970]
$$
Another construction gives larger lower bounds on relational structures:
$$
r_\infty \geq n^{\Omega(3)}
$$
The lower bounds are realized through Cay–Fürer–Immerman (CFI) constructions and compressed XOR gadgets that force the color refinement process to survive super-linear (and even polynomial) numbers of rounds.

**Summary Table (Specialized to $k=3$):**

| Bound Type      | Structure Type      | Lower Bound                | Upper Bound              |
|-----------------|--------------------|----------------------------|--------------------------|
| Worst-case Graph| Simple graphs      | $\Omega(n^{3/2})$          | $O(3 n^2 \log n)$        |
| Relational      | 3-ary structures   | $n^{\Omega(3)}$            | $O(3 n^2 \log n)$        |

## 4. Logical Characterizations and Connections to First-order Counting

The iteration number required by the 3-WL procedure to distinguish $G$ and $H$ corresponds precisely to the quantifier rank of sentences in the 4-variable fragment $C_4$ of first-order logic with counting quantifiers. Formally:

- 3-WL splits $G,H$ after $r$ rounds iff there exists a $C_4$-sentence of quantifier rank at most $r$ distinguishing them [2301.13317].
- Therefore, upper and lower bounds on $r_\infty$ translate into bounds on the quantifier rank necessary in $C_4$. Specifically:
  $$
  \text{Separation in $C_4$} \implies \text{Quantifier rank } O(n^2 \log n)
  $$
- Dually, lower bounds show the existence of graph pairs requiring quantifier rank $n^{\Omega(1)}$ in $C_4$.

## 5. Extensions: Graphons, Homomorphism Densities, and Linear Equation Systems

The 3-WL algorithm generalizes naturally to graphons (measurable symmetric functions $W:[0,1]^2\to[0,1]$ as limit objects for dense graphs):

- **Color refinement for graphons:**  
  Colors points $(x_1,x_2,x_3) \in X^3$ by distributions of edge values $W(x_i, x_j)$ and recursively refines using probability measures over multisets derived from $W$ [2112.09001].
- **Homomorphism-density characterization:**  
  3-WL indistinguishability of graphons $U, W$ is equivalent to equality of homomorphism densities $t(F,U) = t(F,W)$ for every multigraph $F$ of treewidth $\leq 2$.
- **Parallel edges:**  
  In the graphon setting, parallel edges affect homomorphism densities; thus, the multigraph version of $k$-WL is strictly stronger than its simple graph variant. For ordinary graphs, the distinction vanishes due to integrality [2112.09001].
- **Linear/fractional isomorphism system:**  
  Non-distinguishability by 3-WL is equivalent to the solvability of a system of linear equations on partial isomorphisms between graphs (and their infinite-dimensional analogue for graphons).

## 6. Algebraic Combinatorics and Cellular Algebras

The output of stabilized 3-WL colorings corresponds to the cellular algebra $W(G)$ generated by the adjacency matrix $A(G)$, encapsulating automorphism orbits and providing a powerful algebraic invariant:

- For most molecular and combinatorial graphs, $W(G)$ coincides with the centralizer algebra of the automorphism group $\mathrm{Aut}(G)$.
- The stable partition returned by 3-WL (or its equivalent depth-one stabilization) matches the orbit partition of $\mathrm{Aut}(G)$ in generic cases [1002.1921, 2311.09940].
- Efficient implementations allow handling graphs of several thousand vertices in practice.

## 7. Applications, Special Classes, and Limitations

**Planar Graphs:**  
The WL-dimension of all finite planar graphs is at most 3, meaning 3-WL suffices to characterize them up to isomorphism. This improves previously best-known bounds from dimension 14 to 3 and ensures definability in first-order logic with counting using at most 4 variables. Exceptional 3-connected planar graphs with fixing number 3 require individualization of certain vertices, but 3-WL still resolves their orbits correctly [1708.07354].

**Coherent Configurations and Depth-1 Stabilization:**  
A simplified depth-1 version of Weisfeiler’s deep stabilization ("W₁⁄₂", *Editor's term*) matches the distinguishing power of non-recursive 3-WL projected to pairs, both in terms of coherent configurations and computational complexity [2311.09940].

**Limitations:**  
Some structures, such as incidence graphs of projective planes of order $q$ with at least two non-isomorphic planes, require WL-dimension at least 4 for identification.

## References

- "The Iteration Number of the Weisfeiler-Leman Algorithm" [2301.13317]
- "Compressing CFI Graphs and Lower Bounds for the Weisfeiler-Leman Refinements" [2308.11970]
- "The Weisfeiler-Leman Dimension of Planar Graphs is at most 3" [1708.07354]
- "Algebraic Combinatorics in Mathematical Chemistry. Methods and Algorithms. II. Program Implementation of the Weisfeiler-Leman Algorithm" [1002.1921]
- "On the Weisfeiler algorithm of depth-$1$ stabilization" [2311.09940]
- "Weisfeiler-Leman Indistinguishability of Graphons" [2112.09001]

Source: https://www.emergentmind.com/topics/3-dimensional-weisfeiler-leman-algorithm