Walks on Expanders: Error Reduction and Pseudorandomness
Independent random samples are expensive in random bits: samples from a set of size cost bits. A random walk on a constant-degree expander whose vertices are those points costs only bits for points, yet the points it visits behave, for many purposes, almost like independent samples. This lesson proves the key "hitting" property, applies it to reduce the error of randomized algorithms with few extra random bits (Ajtai, Komlós and Szemerédi, 1987; Cohen and Wigderson, 1989; Impagliazzo and Zuckerman, 1989), and states the Chernoff bound for expander walks.
Normalized expansion
Let be a -regular graph on vertices with walk matrix . Its eigenvalues are , and the normalized two-sided expansion is . A random walk starts at a uniform vertex and moves to a uniform neighbour at each step. Each alone is uniform, because the uniform distribution is stationary; the question is how correlated they are.
The hitting property
Theorem (Ajtai, Komlós and Szemerédi, 1987; in the form of Vadhan, Pseudorandomness, 2012, Theorem 4.17). Let have density . Then
For independent samples the probability would be . With and , the walk gives : still exponentially small in .
Proof sketch
Let be the diagonal 0/1 matrix projecting onto and the uniform distribution. The probability that all visited vertices lie in is . Bound the operator norm of : for any supported on , decompose with . Then with , while projecting onto keeps only a fraction of its squared norm. Since lives on , Cauchy-Schwarz gives . Combining the two parts carefully gives . Finally, the vector is supported on , which has vertices, so by Cauchy-Schwarz its entry sum is at most times its Euclidean norm. With this gives .
The program computes the exact probability on the 8-regular Margulis-Gabber-Galil graph on vertices from Constructing Expanders, for a random half of the vertices and for a structured half, the vertices with . (The second eigenvalue of this graph has multiplicity 4, so "the" second eigenvector, the usual source of a worst-case set, is not well defined; the structured half is nearly as sticky.)
import numpy as np
def mgg(m):
n = m * m
A = np.zeros((n, n))
idx = lambda x, y: (x % m) * m + (y % m)
for x in range(m):
for y in range(m):
v = idx(x, y)
for u in (idx(x + 2 * y, y), idx(x - 2 * y, y), idx(x + 2 * y + 1, y), idx(x - 2 * y - 1, y),
idx(x, y + 2 * x), idx(x, y - 2 * x), idx(x, y + 2 * x + 1), idx(x, y - 2 * x - 1)):
A[v, u] += 1
return A
m = 16
n = m * m
W = mgg(m) / 8
w = np.linalg.eigvalsh(W)
lam = float(max(abs(w[-2]), abs(w[0])))
print(f"n = {n}, normalized lambda = {lam:.4f}")
sets = {
"random half": np.random.default_rng(7).permutation(n)[: n // 2],
"structured half x < m/2": np.flatnonzero(np.arange(n) // m < m // 2), # vertex (x, y) has index x*m + y
}
for name, B in sets.items():
mu = len(B) / n
P = np.zeros((n, n)); P[B, B] = 1
x = P @ np.full(n, 1 / n) # P u
print(f"{name}: mu = {mu}")
for t in range(1, 11):
if t > 1:
x = P @ (W.T @ x) # one more step that must stay inside B
if t in (1, 2, 5, 10):
print(f" t = {t:2}: exact {float(x.sum()):.3e} independent mu^t {mu ** t:.3e} "
f"bound (mu + lambda (1 - mu))^t {(mu + lam * (1 - mu)) ** t:.3e}")n = 256, normalized lambda = 0.7568
random half: mu = 0.5
t = 1: exact 5.000e-01 independent mu^t 5.000e-01 bound (mu + lambda (1 - mu))^t 8.784e-01
t = 2: exact 2.666e-01 independent mu^t 2.500e-01 bound (mu + lambda (1 - mu))^t 7.716e-01
t = 5: exact 5.542e-02 independent mu^t 3.125e-02 bound (mu + lambda (1 - mu))^t 5.229e-01
t = 10: exact 4.683e-03 independent mu^t 9.766e-04 bound (mu + lambda (1 - mu))^t 2.735e-01
structured half x < m/2: mu = 0.5
t = 1: exact 5.000e-01 independent mu^t 5.000e-01 bound (mu + lambda (1 - mu))^t 8.784e-01
t = 2: exact 3.750e-01 independent mu^t 2.500e-01 bound (mu + lambda (1 - mu))^t 7.716e-01
t = 5: exact 1.877e-01 independent mu^t 3.125e-02 bound (mu + lambda (1 - mu))^t 5.229e-01
t = 10: exact 6.549e-02 independent mu^t 9.766e-04 bound (mu + lambda (1 - mu))^t 2.735e-01
The graph is only a moderate expander (), so the walk is visibly more "sticky" than independent sampling: after 10 steps it has stayed inside the random half about 5 times as often as , and inside the structured half about 67 times as often. But both probabilities decay exponentially, at rates the theorem's bound guarantees; a better expander (smaller ) brings the walk closer to independent sampling.
Error reduction with few random bits
Let an RP algorithm use random bits and accept a "yes" instance with probability at least (and never accept a "no" instance). The bad seeds on a yes instance have density . Three ways to get error :
| Method | Random bits | Error after runs |
|---|---|---|
| independent runs | ||
| pairwise independent seeds (Chor and Goldreich, 1989) | , by Chebyshev | |
| walk on an explicit -regular expander on |
With an explicit expander of constant degree and , error needs steps and only random bits instead of . For BPP algorithms (two-sided error), take the majority vote over the walk; the expander Chernoff bound below guarantees that the majority is correct except with probability .
The expander Chernoff bound
Theorem (Gillman, 1998; stated). For a -regular graph with normalized expansion , a set of density , and the walk started uniformly, the fraction of visits deviates from by more than with probability at most for an absolute constant .
So expander walks are samplers: they estimate the density of any set as well as independent samples do, up to the factor in the exponent. Sharper constants are known (Lezaud, 1998; Healy, 2008), and the bound extends to functions with values in .
In C++
An explicit expander needs no adjacency list: the neighbours of in the Margulis-Gabber-Galil graph are computed by arithmetic, so the graph can have vertices. The program estimates the density of a set (density about ) on with , using 4000 walk steps that each consume 3 random bits, and compares with 4000 independent samples that each consume 40 bits.
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <random>
using u64 = std::uint64_t;
const u64 m = u64(1) << 20;
// neighbour i (0..7) of (x, y) in the Margulis-Gabber-Galil graph on Z_m x Z_m
void step(u64& x, u64& y, int i) {
switch (i) {
case 0: x = (x + 2 * y) % m; break;
case 1: x = (x + m - (2 * y) % m) % m; break;
case 2: x = (x + 2 * y + 1) % m; break;
case 3: x = (x + 2 * m - (2 * y + 1) % m) % m; break;
case 4: y = (y + 2 * x) % m; break;
case 5: y = (y + m - (2 * x) % m) % m; break;
case 6: y = (y + 2 * x + 1) % m; break;
default: y = (y + 2 * m - (2 * x + 1) % m) % m; break;
}
}
bool in_A(u64 x, u64 y) { return (x + y) % 7 < 3; }
int main() {
std::mt19937_64 rng(2024);
const double density = 3.0 / 7.0; // m is not a multiple of 7, but this is accurate to 1e-6
std::printf("target density %.4f\n", density);
for (int t : {500, 4000}) {
double worst_walk = 0, worst_ind = 0;
for (int rep = 0; rep < 20; ++rep) {
u64 x = rng() % m, y = rng() % m; // 40 random bits to start the walk
int hits = 0;
for (int s = 0; s < t; ++s) {
hits += in_A(x, y);
step(x, y, int(rng() % 8)); // 3 random bits per step
}
worst_walk = std::fmax(worst_walk, std::fabs(double(hits) / t - density));
hits = 0;
for (int s = 0; s < t; ++s) { // 40 bits per sample
u64 a = rng() % m;
u64 b = rng() % m;
hits += in_A(a, b);
}
worst_ind = std::fmax(worst_ind, std::fabs(double(hits) / t - density));
}
std::printf("t = %4d: worst error over 20 runs walk %.4f (%d bits) independent %.4f (%d bits)\n",
t, worst_walk, 40 + 3 * (t - 1), worst_ind, 40 * t);
}
}target density 0.4286
t = 500: worst error over 20 runs walk 0.0546 (1537 bits) independent 0.0414 (20000 bits)
t = 4000: worst error over 20 runs walk 0.0172 (12037 bits) independent 0.0177 (160000 bits)
Both estimators have errors of the order , but the walk uses about 13 times fewer random bits.
Further uses
- Expander codes (Sipser and Spielman, 1996): a bipartite expander's check constraints define a code that can be decoded in linear time by flipping bits, because expansion guarantees that most corrupted bits have many unsatisfied checks.
- Pseudorandom generators for space-bounded computation (Nisan, 1992; Impagliazzo, Nisan and Wigderson, 1994): recursively combining expander-style mixing fools log-space algorithms with seed bits.
- Undirected connectivity in log space (Reingold, 2008): the zig-zag product turns each component into an expander of logarithmic diameter, which a log-space walk can explore exhaustively.
Test yourself
How many random bits does a walk ( vertices, steps) on a -regular expander with vertices use?
- only
What does the hitting property bound for a set of density ?
- The expected number of visits to
- The mixing time
An RP algorithm has error with random bits. With an explicit constant-degree expander, how many random bits give error ?
What does the expander Chernoff bound (Gillman) say about the fraction of time a walk spends in a set of density ?
- It is exactly
- It deviates from by more than with probability
- It converges only for bipartite graphs
- It is at most