Draw a hexagon: six nodes in a ring. Next to it, draw two separate triangles: also six nodes, also six edges. In both pictures every node has exactly two neighbours. Now feed both graphs to a graph neural network of the most common kind, one that passes messages along edges and adds up the result. Give it no node features beyond the structure itself. Train it however you like, and make it as deep as you like. It will give the two graphs exactly the same output.

The notebook tries 200 random three-layer networks. For every one, the outputs for the hexagon and for the two triangles are exactly equal, to the last bit. Yet the graphs are plainly different: one is in one piece and the other in two, and one has two triangles while the other has none. A single matrix, the graph Laplacian, sees the difference at once. Its eigenvalue 0 appears once for the hexagon and twice for the triangles (Fig. 1).

Left: a hexagon and two separate triangles, every node coloured the same blue. Right: their Laplacian eigenvalues on a line; the hexagon has 0, 1 twice, 3 twice and 4; the two triangles have 0 twice and 3 four times.
Fig. 1. Two graphs that message passing cannot separate. Left: colour refinement (the Weisfeiler–Lehman test) gives every node of both graphs the same colour, forever. Right: the Laplacian's eigenvalues differ, starting with how often 0 appears.

This is no accident of the example. Message passing can only ever see what a simple colouring procedure sees, and that procedure is blind to some differences that linear algebra spots immediately. By the end of this post both halves of that sentence will be theorems, and the second will come from tools built in earlier parts.

This is Part 8 of Math for GDL, and the last. The series has worked through a review paper by Sáez de Ocáriz Borde & Bronstein (2025), called the review below, one section at a time. This part covers §7, graphs, and it is where earlier parts meet:

Earlier ideaWhat it becomes on a graph
Symmetry and equivariance (Part 2)relabelling nodes; message passing commutes with it
The Laplacian and Dirichlet energy (Part 4)\( L = D - A \), and \( x^\top L x \) sums squared differences along edges
Counting pieces with \( b_0 \) (Part 5)the number of zero eigenvalues of \( L \)
The spectral theorem and Fourier (Part 7)Laplacian eigenvectors as the graph's Fourier basis
Table of contents
  1. Notation
  2. Graphs as matrices
  3. Kinds of graphs
  4. Relabelling nodes
  5. Isomorphism and the Weisfeiler–Lehman test
  6. The graph Laplacian
  7. Graph Fourier analysis
  8. Message passing
  9. The series in one table
  10. Quick summary
  11. Open questions
  12. Code
  13. Citation
  14. References

Notation

SymbolMeaning
\( G = (V, E) \), \( N \)A graph: nodes \( V \), edges \( E \); \( N = |V| \) nodes
\( A \)Adjacency matrix: \( A_{ij} \) is the weight of edge \( \{i, j\} \), or 0 if there is none
\( D \)Degree matrix: diagonal, \( D_{ii} = \sum_j A_{ij} \)
\( L = D - A \)The graph Laplacian
\( \mathcal{N}(i) \)The neighbours of node \( i \)
\( X \in \mathbb{R}^{N \times d} \)Node features, one row per node
\( P \)A permutation matrix: a relabelling of the nodes
\( C_N \), \( K_N \)The cycle and the complete graph on \( N \) nodes

Graphs as matrices

If adjacency matrices and shortest paths are familiar, skip to kinds of graphs.

Definition 1 (Graph). A graph \( G = (V, E) \) is a set of nodes \( V \) and a set of edges \( E \), each edge joining two nodes. Edges are undirected unless stated otherwise. Its adjacency matrix \( A \) has \( A_{ij} = 1 \) (or the edge's weight) when \( i \) and \( j \) are joined, and 0 otherwise; for undirected graphs it is symmetric. The degree of a node is its row sum: for an unweighted graph, the number of its neighbours.

A path is a sequence of consecutive edges, and the distance between two nodes is the smallest total weight of a path joining them. With positive weights on a connected graph, this distance is a metric on the nodes (Part 3). It is symmetric, zero only from a node to itself, and it obeys the triangle inequality. The review's example has weights \( w(1,2) = 2 \), \( w(1,3) = 4 \), \( w(2,3) = 1 \) and \( w(3,4) = 3 \). Dijkstra's algorithm gives \( d(1,3) = 3 \), through node 2 rather than along the direct edge, and the largest distance, the diameter, is 6.

One convention in that example needs care. The review sets the weight of every missing pair to 0. In an adjacency matrix a 0 does mean no edge, but read as the length of an edge it means free. Treat the missing pairs as edges of weight 0 and the distance from node 1 to node 4 drops from 6 to 0. Missing edges must count as absent, or as infinitely long. The review's own calculation does treat them that way, which is why its distances come out right.

Kinds of graphs

A few shapes recur. A path graph \( P_N \) is a chain and a cycle \( C_N \) closes it into a ring. A tree is connected with no cycles, and always has \( N - 1 \) edges. In the complete graph \( K_N \) every pair of nodes is joined; an unmasked self-attention layer passes messages over this graph, with self-loops added. A bipartite graph splits its nodes into two sides with edges only between them, like users and the products they buy. A graph is \( k \)-regular if every node has degree \( k \); the hexagon and the two triangles are both 2-regular.

Geometric graphs start from points in space. Join every pair closer than a threshold, or join each point to its \( k \) nearest neighbours. The review says the second rule connects every node to exactly \( k \) others, making the graph \( k \)-regular. That does not hold: once the edges are made undirected, a point that is many others' nearest neighbour collects extra edges. The review adds that the rule can prevent disconnected pieces. It does rule out isolated nodes, its real advantage over a threshold, but not separate pieces: two far-apart clusters never link up. In the notebook, the 4-nearest-neighbour graph of two clusters of 40 points has degrees from 4 to 8 and two connected pieces.

Homophily measures how often an edge joins two nodes with the same label: the fraction of such edges. In the two-cluster graph, labelled by cluster, it is 1.00. Classic graph networks work best when it is high, because averaging over neighbours then averages over nodes of the same kind.

Relabelling nodes

Numbering the nodes is an arbitrary choice, and changing it should change nothing that matters. Renumbering is a permutation, written as a permutation matrix \( P \), with a single 1 in each row and column. Swapping nodes 1 and 2, for example, swaps the first two rows of \( X \). It acts on the adjacency matrix and the features by $$ A \mapsto P A P^\top, \qquad X \mapsto P X. $$ This is Part 2's symmetric group acting on graphs. The eigenvalues of \( A \) do not change, and neither do those of the Laplacian below, since \( L \mapsto P L P^\top \) too. The degrees are shuffled but keep their values.

Proposition 1 (Invariance and equivariance). A message-passing layer \( F(A, X) = \sigma\big(X W_1 + A X W_2\big) \) is permutation equivariant: \( F(PAP^\top, PX) = P\, F(A, X) \). A readout that sums, averages or takes the maximum over nodes is permutation invariant.

Proof

Since \( P^\top P = I \), $$ \begin{aligned} F(PAP^\top, PX) &= \sigma\big(P X W_1 + P A P^\top P X W_2\big) && \text{; substitute} \\ &= \sigma\big(P (X W_1 + A X W_2)\big) && \text{; } P^\top P = I \\ &= P\, \sigma\big(X W_1 + A X W_2\big) && \text{; } \sigma \text{ acts entry by entry} \end{aligned} $$ A sum, mean or maximum over the rows of \( PX \) runs over the same rows in another order. ∎

The notebook checks both on random graphs and relabellings. The review's worked example with \( X = \begin{pmatrix} 1 & 2 \\ 3 & 4 \\ 5 & 6 \end{pmatrix} \) gets the readouts right, but ends with \( \sum_i (PX)_i = \sum_i P x_i = P \sum_i x_i \). That line does not typecheck: \( P \) is \( 3 \times 3 \) and acts on the node index, while each \( x_i \) has 2 entries. The readout is invariant, \( \sum_i (PX)_i = \sum_i x_i \), not equivariant.

Isomorphism and the Weisfeiler–Lehman test

Definition 2 (Homomorphism, isomorphism). A graph homomorphism \( f : G \to H \) maps nodes to nodes so that every edge \( \{i, j\} \) of \( G \) lands on an edge \( \{f(i), f(j)\} \) of \( H \). An isomorphism is a bijection on nodes with \( \{i, j\} \in E_G \iff \{f(i), f(j)\} \in E_H \): the same graph with different labels.

Homomorphisms can merge nodes. The hexagon maps onto a triangle by sending nodes \( 0, \ldots, 5 \) to \( 0, 1, 2, 0, 1, 2 \), and onto a single edge by alternating \( 0, 1, 0, 1, \ldots \). A graph with at least one edge has a homomorphism to a single edge exactly when it is bipartite, so a triangle cannot: the notebook tries all 8 maps.

No fast algorithm is known that decides, for every pair of graphs, whether they are isomorphic. A cheap first test is colour refinement, the Weisfeiler–Lehman (WL) test. Give every node the same colour. Then, round after round, give each node a new colour determined by its current colour together with the multiset of its neighbours' colours: a set that keeps repeats, so two blue neighbours count twice. On a path of four nodes, the first round already splits the two ends, with one neighbour each, from the two middle nodes, with two. If at some round the two graphs have different numbers of nodes of some colour, they are not isomorphic.

The review describes WL as "a method used to determine whether two graphs are isomorphic". It works in one direction only. Different colour counts prove the graphs differ; equal counts prove nothing. On the hexagon and the two triangles every node has two neighbours of the starting colour, so every node gets the same new colour, and the counts never change. The same happens for the cube against the Möbius ladder, two 3-regular graphs on 8 nodes, and for two molecules, decalin (two fused six-rings) against bicyclopentyl (two five-rings joined by a bond). None of these pairs is isomorphic: their Laplacian spectra differ, as the notebook checks, and isomorphic graphs always share a spectrum. WL does separate the path from the star, at the first round, because their degrees differ.

Theorem 1 (Message passing is at most WL). Start WL from the nodes' initial features as colours (all equal, if there are no features). If WL then cannot tell two graphs apart, no message-passing network with a permutation-invariant readout can either. With injective aggregation, update and readout, and enough layers, a message-passing network is exactly as powerful as WL (Xu et al. 2019; Morris et al. 2019).

The reason is that a message-passing layer computes each node's new feature from the node's old feature and the multiset of its neighbours' features, which is exactly the information WL uses. If WL gives two nodes the same colour, the network gives them the same feature. This resolves the first half of the opening puzzle. It also explains why all three failing pairs have equal degrees: on two \( d \)-regular graphs of the same size, with no features, every node sees \( d \) neighbours of the starting colour, so WL can never separate them.

The graph Laplacian

Definition 3 (Graph Laplacian). The graph Laplacian is \( L = D - A \). Applied to a signal \( x \) on the nodes, \( (Lx)_i = \sum_{j \in \mathcal{N}(i)} A_{ij} (x_i - x_j) \): how much node \( i \) differs from its neighbours.

Proposition 2 (Energy and pieces). For an undirected graph with positive edge weights, $$ x^\top L x = \sum_{\{i, j\} \in E} A_{ij} (x_i - x_j)^2 \;\ge\; 0, $$ so \( L \) is positive semidefinite. The eigenvalue 0 occurs exactly as many times as the graph has connected pieces.

Proof

Expanding, \( x^\top L x = \sum_i D_{ii} x_i^2 - \sum_{i, j} A_{ij} x_i x_j \), and each edge \( \{i, j\} \) contributes \( A_{ij}(x_i^2 + x_j^2 - 2 x_i x_j) = A_{ij}(x_i - x_j)^2 \). For a positive semidefinite matrix, \( Lx = 0 \) exactly when \( x^\top L x = 0 \), which by the formula means \( x_i = x_j \) along every edge: \( x \) is constant on each connected piece. Such signals form a space whose dimension is the number of pieces. ∎

This is the second half of the puzzle. The hexagon is one piece and the triangles are two, so 0 appears once in one spectrum and twice in the other. It is also Part 5's \( b_0 \), the number of pieces, read off a matrix. The full spectra are \( 0, 1, 1, 3, 3, 4 \) and \( 0, 0, 3, 3, 3, 3 \), and in the notebook the spectrum separates all four pairs. Counting triangles works too: \( \operatorname{tr}(A^3)/6 \) is 0 for the hexagon and 2 for the triangles. Neither count is something WL computes.

\( x^\top L x \) is the graph version of Part 4's Dirichlet energy, and the sign is worth getting right. On a fine cycle graph with spacing \( h \), the notebook confirms that \( L/h^2 \) acts on \( \sin(3x) \) as approximately \( 9 \sin(3x) \): the graph Laplacian approximates \( -\Delta \), not \( \Delta \). That is why its energy is \( +\|\nabla x\|^2 \). The review's margin note writes the continuous identity as \( \langle f, \Delta f \rangle = \langle \nabla f, \nabla f \rangle \), the same missing minus sign flagged in Part 4.

On the cycle graph, the discrete Fourier waves of Part 7 are eigenvectors of \( L \), with eigenvalues \( 2 - 2\cos(2\pi k/N) \). The cycle is shift-symmetric, so the discrete analogue of Part 7's Proposition 3 applies. (Frequencies \( k \) and \( N - k \) share an eigenvalue, so their cosine and sine mixtures are eigenvectors too.) The normalised Laplacian \( I - D^{-1/2} A D^{-1/2} \) divides each edge's weight by the square roots of the two degrees, so that busy nodes do not dominate. For a graph with no isolated nodes, its eigenvalues lie in \( [0, 2] \), and 2 appears exactly when a piece of the graph is bipartite (Chung 1997). In the notebook it does for the hexagon and the cube, and not for the triangles or the Möbius ladder, which contain odd cycles.

Graph Fourier analysis

A graph has no shifts, so it has no waves in the usual sense. It does have a Laplacian, and Part 7's spectral theorem gives it an orthonormal basis of eigenvectors, \( L = U \Lambda U^\top \). These eigenvectors are the graph's Fourier basis. Small eigenvalues belong to smooth patterns, which change little along edges: for a unit eigenvector \( u \), its energy \( u^\top L u \) is exactly its eigenvalue \( \lambda \). Large eigenvalues belong to patterns that flip sign from node to node (Fig. 2).

Five panels on a 10 by 10 grid graph. Three Laplacian eigenvectors with eigenvalues 0.10, 1.76 and 7.80, going from a smooth gradient to a checkerboard-like pattern. Then a noisy signal, 49 percent off, and the same signal keeping only the 10 lowest graph frequencies, 15 percent off and smooth.
Fig. 2. Graph Fourier analysis on a \( 10 \times 10 \) grid. Left: Laplacian eigenvectors from low to high frequency. Right: a smooth signal plus noise, and the same signal keeping only its 10 lowest graph frequencies.

The graph Fourier transform of a signal is \( \hat x = U^\top x \), and filtering means rescaling its coefficients. On the grid of Fig. 2, a noisy signal is 49% off the smooth original; keeping its 10 lowest graph frequencies brings that to 15%. Heat flow on the graph, \( e^{-tL} \), is another low-pass filter.

Graph neural networks use it too. The averaging step of a graph convolutional network is \( x \mapsto \tilde D^{-1/2} \tilde A \tilde D^{-1/2} x \), with self-loops added (Kipf & Welling 2017). It is one explicit heat-flow step, of size 1, on the normalised Laplacian of the graph with self-loops. Repeat it 200 times on a connected graph and, in the notebook, every signal ends up proportional to the square root of the degrees, whatever it started as: Part 4's oversmoothing.

Why ML cares. Laplacian eigenvectors also serve as positional encodings: each node gets the coordinates \( (u_2(i), \ldots, u_{k+1}(i)) \), which tell the network where the node sits in the graph. The review calls these encodings isomorphism-invariant. They are not, quite. If \( u \) is an eigenvector, so is \( -u \), and an eigenvalue that repeats, like the first nonzero one on the square grid, leaves any rotation or reflection of the eigenvectors free; the notebook checks both ambiguities. Relabel the nodes and a solver may return flipped or rotated vectors. Dwivedi et al. (2023) flip signs at random during training so the network learns to ignore them; Lim et al. (2023) build networks that are invariant to sign flips and basis changes by design.

Message passing

The general layer of Gilmer et al. (2017), as the review writes it, updates every node from its own feature and an aggregate of messages from its neighbours: $$ x_i^{(l+1)} = \phi\Big(x_i^{(l)},\; \bigoplus_{j \in \mathcal{N}(i)} \psi\big(x_i^{(l)}, x_j^{(l)}\big)\Big), $$ where \( \bigoplus \) is a permutation-invariant aggregator such as a sum. Proposition 1 makes each layer equivariant, and Theorem 1 caps what a stack of them can distinguish.

Why ML cares. The cap matters in chemistry, where decalin and bicyclopentyl are different molecules with different properties, and in any task that depends on cycles. The first step is to reach the ceiling: sum aggregation with injective updates, as in the Graph Isomorphism Network of Xu et al. (2019), is exactly as powerful as WL, but no more. There are two standard ways past it. Give the network information WL lacks, such as Laplacian positional encodings or counts of triangles and other small patterns. Or pass messages between pairs or larger groups of nodes instead of single nodes, as in the higher-order networks of Morris et al. (2019), at a higher cost.

The series in one table

Eight parts, one review paper. Here is where each part's idea ended up.

PartMathematicsWhat it does in geometric deep learning
1sets, maps, function spacesa network is a map; a hypothesis class is a set of maps
2groups, actions, equivariancebuild symmetry in: convolution, permutation equivariance
3norms, metrics, inner productsmeasure distance and similarity between inputs
4gradients, divergence, the Laplaciantraining by gradient descent; smoothing and its limits
5topology, the manifold hypothesisthe shape a latent space must have
6manifolds, geodesics, gaugesnetworks on curved domains
7Hilbert spaces, the spectral theorem, Fourierconvolution as multiplication; spectral filters; what filtering cannot undo
8graphs, the graph Laplacian, WLmessage passing and its limits

Quick summary

Each idea from this post, with its example.

IdeaIn one lineExample in this postIn ML
Shortest-path distancea metric on the nodesreview's example: diameter 6graph distances as features
k-nearest-neighbour graphnot regular, maybe disconnecteddegrees 4 to 8, two piecesbuilding graphs from point clouds
Permutation equivariancerelabelling commutes with layers\( F(PAP^\top, PX) = P F(A, X) \)every GNN layer
WL testcolour refinement; one-sidedhexagon vs two triangles: same coloursthe ceiling on message passing
Graph Laplacian\( x^\top L x \) = squared edge differenceszero eigenvalue once vs twicesmoothness, clustering, oversmoothing
Graph Fouriereigenvectors of \( L \)10 lowest frequencies: 49% → 15%spectral filters, positional encodings

Open questions

Questions I'm carrying beyond this series:

  • How much expressive power is enough? Higher-order networks pass WL's ceiling at a steep cost. Which tasks need it, and which are fine with plain message passing?
  • Where does the graph come from? Here the graphs were given. For point clouds and latent structure the graph is a modelling choice, and the k-nearest-neighbour example shows how much it can change.
  • How do the pieces combine? Real models mix symmetry, geometry and spectra: an equivariant network on a mesh with spectral positional encodings uses Parts 2, 6, 7 and 8 at once. The architectures themselves are a story for another series.

Code

All checks in this post, and Figs. 1 and 2, are in math-gdl-08-graphs.ipynb (NumPy and Matplotlib; runs in a few seconds). Each demo ends with a short exercise, such as finding a graph feature that separates the cube from the Möbius ladder.

To skip the setup, open the interactive playground. It runs the same checks in your browser and adds controls for the exercises. The first load can take up to half a minute while Python starts up. Its source is math-gdl-08-graphs-playground.py, a marimo notebook.

Corrections are welcome at .

Previous: Part 7, The Blur You Cannot Undo. First: Part 1. Series overview: Eight Puzzles That Helped Me Understand Geometric Deep Learning.

Citation

Cited as:

Pham, Anh-Duy. (Nov 2026). Graphs a GNN cannot tell apart. Math for GDL, Part 8. https://www.adpham.de/blog/math-gdl-08-graphs.html

Or

@article{pham2026mathgdl08,
  title   = "Graphs a GNN Cannot Tell Apart",
  author  = "Pham, Anh-Duy",
  journal = "www.adpham.de",
  year    = "2026",
  month   = "Nov",
  url     = "https://www.adpham.de/blog/math-gdl-08-graphs.html"
}

References

  1. Sáez de Ocáriz Borde, H. & Bronstein, M. M. “Mathematical Foundations of Geometric Deep Learning.” arXiv:2508.02723 (2025).
  2. Xu, K., Hu, W., Leskovec, J. & Jegelka, S. “How powerful are graph neural networks?” International Conference on Learning Representations (2019).
  3. Morris, C., Ritzert, M., Fey, M., Hamilton, W. L., Lenssen, J. E., Rattan, G. & Grohe, M. “Weisfeiler and Leman go neural: higher-order graph neural networks.” Proceedings of the AAAI Conference on Artificial Intelligence 33, 4602–4609 (2019).
  4. Gilmer, J., Schoenholz, S. S., Riley, P. F., Vinyals, O. & Dahl, G. E. “Neural message passing for quantum chemistry.” Proceedings of the 34th International Conference on Machine Learning, PMLR 70, 1263–1272 (2017).
  5. Lim, D., Robinson, J., Zhao, L., Smidt, T., Sra, S., Maron, H. & Jegelka, S. “Sign and basis invariant networks for spectral graph representation learning.” International Conference on Learning Representations (2023).
  6. Dwivedi, V. P., Joshi, C. K., Luu, A. T., Laurent, T., Bengio, Y. & Bresson, X. “Benchmarking graph neural networks.” Journal of Machine Learning Research 24(43), 1–48 (2023).
  7. Chung, F. R. K. Spectral Graph Theory. CBMS Regional Conference Series in Mathematics 92, American Mathematical Society (1997).
  8. Kipf, T. N. & Welling, M. “Semi-supervised classification with graph convolutional networks.” International Conference on Learning Representations (2017).