Gaussian Elimination and Schur Complements
The most direct way to solve is Gaussian elimination. For Laplacians it has a graph meaning that is both pretty and algorithmically important: eliminating a vertex replaces it by a weighted clique on its neighbours, and the new matrix is again a Laplacian. Eliminating everything except a set of terminals produces the Schur complement, a smaller network that is electrically indistinguishable from the original as seen from the terminals. This lesson develops both, measures fill-in (the reason elimination can be slow), and ends with the idea behind the fastest practical Laplacian solvers: eliminate approximately, keeping the cliques sparse by random sampling.
Eliminating one vertex
Order the vertices so that comes first and write
One step of Gaussian elimination (or of Cholesky factorization) subtracts multiples of the first row to clear the first column, leaving the Schur complement
Claim. is the Laplacian of the graph obtained by deleting and adding, for every pair of neighbours of , an edge of weight .
Proof. is the Laplacian of plus the diagonal matrix (each neighbour lost an edge to but keeps it in its degree). Then has off-diagonal entries and diagonal entries , which is exactly the Laplacian of the clique with those weights.
This is the star-mesh transform of circuit theory. For degree 2 it is the series rule (two resistors become one of : conductance ), and for degree 3 it is the Y- transform.
import numpy as np
def laplacian(n, wedges):
L = np.zeros((n, n))
for u, v, w in wedges:
L[u, u] += w; L[v, v] += w; L[u, v] -= w; L[v, u] -= w
return L
# vertex 0 is a star centre with neighbours 1, 2, 3 (weights 1, 2, 3); edge 1-2 also present
wedges = [(0, 1, 1.0), (0, 2, 2.0), (0, 3, 3.0), (1, 2, 1.0), (3, 4, 1.0)]
L = laplacian(5, wedges)
a = -L[1:, 0]
schur = L[1:, 1:] - np.outer(a, a) / L[0, 0]
d0 = 6.0
mesh = [(1, 2, 1.0 + 1 * 2 / d0), (1, 3, 1 * 3 / d0), (2, 3, 2 * 3 / d0), (3, 4, 1.0)]
expected = laplacian(5, mesh)[1:, 1:]
print("Schur complement after eliminating vertex 0:\n", np.round(schur, 4) + 0.0)
print("equals the Laplacian of the star-mesh graph:", bool(np.allclose(schur, expected)))
print("row sums:", np.round(schur.sum(axis=1), 12) + 0.0)Schur complement after eliminating vertex 0:
[[ 1.8333 -1.3333 -0.5 0. ]
[-1.3333 2.3333 -1. 0. ]
[-0.5 -1. 2.5 -1. ]
[ 0. 0. -1. 1. ]]
equals the Laplacian of the star-mesh graph: True
row sums: [0. 0. 0. 0.]
Schur complements onto terminals
Eliminating every vertex outside a terminal set (in any order; the result does not depend on it) gives
again a Laplacian, on the vertex set . It is the network "seen from ":
- Energy. For any potentials on , , attained by the harmonic extension .
- Effective resistances between terminals are the same in as in .
- For the Schur complement is a single edge of conductance .
Schur complements are the backbone of multilevel solvers and of recent dynamic graph algorithms (maintaining approximate Schur complements onto a small terminal set lets one answer resistance and flow queries quickly; Durfee, Gao, Goranci and Peng, 2019).
import random
import numpy as np
rng = random.Random(42)
n = 10
edges = [(u, v) for u in range(n) for v in range(u + 1, n) if rng.random() < 0.4]
L = np.zeros((n, n))
for u, v in edges:
L[u, u] += 1; L[v, v] += 1; L[u, v] -= 1; L[v, u] -= 1
P = np.linalg.pinv(L)
reff = lambda M, s, t: M[s, s] + M[t, t] - 2 * M[s, t]
def schur(L, F):
C = [v for v in range(len(L)) if v not in F]
return L[np.ix_(F, F)] - L[np.ix_(F, C)] @ np.linalg.solve(L[np.ix_(C, C)], L[np.ix_(C, F)])
S2 = schur(L, [0, 9])
print(f"{len(edges)} edges; Schur complement onto {{0, 9}}:\n", np.round(S2, 4) + 0.0)
print(f"1 / R_eff(0, 9) = {1 / reff(P, 0, 9):.4f}")
F = [0, 3, 6, 9]
S4 = schur(L, F)
Ps = np.linalg.pinv(S4)
for i, j in [(0, 1), (0, 3), (2, 3)]:
print(f"R_eff({F[i]},{F[j]}): in G {reff(P, F[i], F[j]):.4f}, in the 4-vertex Schur complement {reff(Ps, i, j):.4f}")
y = np.array([1.0, -0.5, 0.25, 2.0]) # potentials on the terminals
C = [v for v in range(n) if v not in F]
z = -np.linalg.solve(L[np.ix_(C, C)], L[np.ix_(C, F)] @ y)
full = np.zeros(n); full[F] = y; full[C] = z
print(f"y^T SC y = {float(y @ S4 @ y):.4f}, energy of the harmonic extension = {float(full @ L @ full):.4f}")20 edges; Schur complement onto {0, 9}:
[[ 2.1988 -2.1988]
[-2.1988 2.1988]]
1 / R_eff(0, 9) = 2.1988
R_eff(0,3): in G 0.4607, in the 4-vertex Schur complement 0.4607
R_eff(0,9): in G 0.4548, in the 4-vertex Schur complement 0.4548
R_eff(6,9): in G 0.4659, in the 4-vertex Schur complement 0.4659
y^T SC y = 15.9957, energy of the harmonic extension = 15.9957
Fill-in and elimination orders
Eliminating a vertex of degree creates up to new edges (fill), which later steps must process. The order matters enormously:
- Trees can be eliminated leaf-first with no fill at all, so Laplacian systems on trees are solved in time. Degree-2 vertices also create no new edge beyond the one replacing the path; repeatedly removing degree-1 and degree-2 vertices is a standard preprocessing step in every fast solver.
- Planar graphs: with nested dissection (George, 1973; Lipton, Rose and Tarjan, 1979), eliminating the two halves before a small separator, the fill is and the time .
- Expanders: any order produces fill, because every separator is large. Exact elimination is then cubic.
The program counts the fill on a grid for three orders: row by row, the greedy minimum-degree heuristic (eliminate a vertex of currently smallest degree), and nested dissection by recursive middle cuts.
import random
def grid(r, c):
adj = {(i, j): set() for i in range(r) for j in range(c)}
for i in range(r):
for j in range(c):
for di, dj in ((0, 1), (1, 0)):
if i + di < r and j + dj < c:
adj[(i, j)].add((i + di, j + dj)); adj[(i + di, j + dj)].add((i, j))
return adj
def fill(adj, order):
adj = {v: set(nb) for v, nb in adj.items()}
added = 0
for v in order:
nbrs = list(adj.pop(v))
for u in nbrs:
adj[u].discard(v)
for i in range(len(nbrs)):
for j in range(i + 1, len(nbrs)):
a, b = nbrs[i], nbrs[j]
if b not in adj[a]:
adj[a].add(b); adj[b].add(a); added += 1
return added
def min_degree_order(adj):
adj = {v: set(nb) for v, nb in adj.items()}
order = []
while adj:
v = min(adj, key=lambda x: (len(adj[x]), x))
nbrs = adj.pop(v)
for u in nbrs:
adj[u].discard(v)
adj[u] |= nbrs - {u}
order.append(v)
return order
def nested_dissection(cells):
if len(cells) <= 2:
return list(cells)
rows = sorted({i for i, _ in cells}); cols = sorted({j for _, j in cells})
if len(cols) >= len(rows):
mid = cols[len(cols) // 2]
sep = [x for x in cells if x[1] == mid]
a = [x for x in cells if x[1] < mid]; b = [x for x in cells if x[1] > mid]
else:
mid = rows[len(rows) // 2]
sep = [x for x in cells if x[0] == mid]
a = [x for x in cells if x[0] < mid]; b = [x for x in cells if x[0] > mid]
return nested_dissection(a) + nested_dissection(b) + sep # separator last
k = 10
G = grid(k, k)
orders = {
"row by row": sorted(G),
"random": random.Random(3).sample(sorted(G), len(G)),
"minimum degree": min_degree_order(G),
"nested dissection": nested_dissection(sorted(G)),
}
print(f"{k} x {k} grid, {sum(len(v) for v in G.values()) // 2} edges")
for name, order in orders.items():
print(f" {name:18} fill = {fill(G, order)} new edges")10 x 10 grid, 180 edges
row by row fill = 729 new edges
random fill = 952 new edges
minimum degree fill = 376 new edges
nested dissection fill = 498 new edges
Row-by-row elimination keeps a "front" of about vertices that become a clique, so its fill grows like ; a random order is worse still. On a grid this small, minimum degree beats the simple nested dissection; the advantage of nested dissection is asymptotic ( fill, with a guarantee), and production codes (METIS, the approximate minimum degree ordering AMD) combine both ideas.
In C++
Elimination is also a way to compute an effective resistance without any linear algebra library: eliminate every vertex except and (minimum degree first), and the single remaining edge has conductance .
#include <cstdio>
#include <map>
#include <vector>
using Adj = std::vector<std::map<int, double>>; // neighbour -> conductance
// Eliminate vertex v: connect each pair of its neighbours with weight w_a w_b / d_v (star-mesh).
void eliminate(Adj& g, int v, long& fill) {
double d = 0;
for (auto& [u, w] : g[v]) d += w;
std::vector<std::pair<int, double>> nb(g[v].begin(), g[v].end());
for (auto& [u, w] : nb) g[u].erase(v);
for (std::size_t i = 0; i < nb.size(); ++i)
for (std::size_t j = i + 1; j < nb.size(); ++j) {
auto [a, wa] = nb[i];
auto [b, wb] = nb[j];
if (!g[a].count(b)) ++fill;
g[a][b] += wa * wb / d;
g[b][a] += wa * wb / d;
}
g[v].clear();
}
int main() {
const int k = 12, n = k * k;
Adj g(n);
auto add = [&](int a, int b) { g[a][b] += 1.0; g[b][a] += 1.0; };
for (int i = 0; i < k; ++i)
for (int j = 0; j < k; ++j) {
if (j + 1 < k) add(i * k + j, i * k + j + 1);
if (i + 1 < k) add(i * k + j, (i + 1) * k + j);
}
const int s = 0, t = n - 1; // opposite corners
std::vector<char> alive(n, 1);
long fill = 0;
for (int step = 0; step < n - 2; ++step) {
int best = -1;
for (int v = 0; v < n; ++v)
if (alive[v] && v != s && v != t && (best < 0 || g[v].size() < g[best].size())) best = v;
eliminate(g, best, fill);
alive[best] = 0;
}
double w = g[s].count(t) ? g[s][t] : 0.0;
std::printf("%d x %d grid: eliminated %d vertices, fill %ld edges\n", k, k, n - 2, fill);
std::printf("remaining edge s-t has conductance %.6f, so R_eff(s, t) = %.6f\n", w, 1.0 / w);
}12 x 12 grid: eliminated 142 vertices, fill 642 edges
remaining edge s-t has conductance 0.308354, so R_eff(s, t) = 3.243023
Approximate elimination
Fill is the enemy, and Kyng and Sachdeva (2016) defeated it with randomness: when a vertex is eliminated, do not add the whole clique on its neighbours; add a random sparse sample of it (about as many edges as the vertex had) whose expectation is the clique. Eliminating vertices in a random order and sampling each clique this way yields an approximate Cholesky factor with nonzeros, which as a preconditioner gives a solver running in time, simple enough to implement (the Laplacians.jl package does). The analysis uses matrix martingales, the same concentration tools as sparsification.
Test yourself
What does eliminating vertex from a Laplacian do to the graph?
- Deletes and its edges
- Deletes and joins each pair of its neighbours with weight
- Contracts into its heaviest neighbour
- Doubles the weights at
What is the Schur complement of onto ?
- The zero matrix
- A single edge of conductance
- The submatrix
- The identity
Why can Laplacian systems on trees be solved in linear time by elimination?
- Trees have no edges
- Eliminating leaves first creates no fill
- Trees are bipartite
- Their Laplacian is diagonal
What is the key idea of approximate Gaussian elimination (Kyng and Sachdeva, 2016)?
- Skip half the vertices
- Replace the clique created by each elimination with a sparse random sample that equals it in expectation
- Use floating point with fewer bits
- Eliminate only degree-1 vertices