TExcelTAD

The Lovász Local Lemma

The union bound proves that no bad event happens, with positive probability, when the bad probabilities add up to less than 1. At the other extreme, if the bad events are mutually independent, none of them happens with probability ∏i(1−Pr⁡[Ai])>0\prod_i (1 - \Pr[A_i]) > 0, however many there are. The Lovász Local Lemma (LLL) covers the large middle ground: many bad events, each one rare and each one dependent on only a few others. It was proved by Erdős and Lovász (1975) and is one of the most powerful existence tools in combinatorics. This lesson states the symmetric and general forms, proves them, and applies the lemma to kk-SAT. The next lesson turns it into an algorithm.

Dependency graphs

An event AA is mutually independent of a set of events {B1,…,Br}\{B_1, \ldots, B_r\} if Pr⁡[A∣C]=Pr⁡[A]\Pr[A \mid C] = \Pr[A] for every event CC formed from the BjB_j by intersections and complements (with Pr⁡[C]>0\Pr[C] > 0). This is stronger than being independent of each BjB_j separately.

A dependency graph for events A1,…,AmA_1, \ldots, A_m is a graph on {1,…,m}\{1, \ldots, m\} such that each AiA_i is mutually independent of the events that are not its neighbours. Write Γ(i)\Gamma(i) for the neighbours of ii. In the most common setting, the variable setting, every event is determined by a few independent random variables, and ii and jj are adjacent when AiA_i and AjA_j share a variable; that graph is always a valid dependency graph.

The symmetric lemma

Theorem (symmetric LLL). Let A1,…,AmA_1, \ldots, A_m be events with Pr⁡[Ai]≤p\Pr[A_i] \le p for all ii, with a dependency graph of maximum degree at most dd. If

e p (d+1)≤1,e\,p\,(d + 1) \le 1,

then Pr⁡[⋂iAi‾]>0\Pr\bigl[\bigcap_i \overline{A_i}\bigr] > 0: with positive probability, none of the events happens.

The original condition of Erdős and Lovász was 4pd≤14pd \le 1; the sharper form above is due to Lovász and first appeared in a paper of Spencer (1977). The constant ee cannot be improved in general (Shearer, 1985). Notice what is absent: the number of events. A billion bad events are fine as long as each one is rare and locally dependent.

The general lemma and its proof

Theorem (general LLL). If there are numbers x1,…,xm∈[0,1)x_1, \ldots, x_m \in [0, 1) with

Pr⁡[Ai]≤xi∏j∈Γ(i)(1−xj)for all i,\Pr[A_i] \le x_i \prod_{j \in \Gamma(i)} (1 - x_j) \quad \text{for all } i,

then Pr⁡[⋂iAi‾]≥∏i=1m(1−xi)>0\Pr\bigl[\bigcap_i \overline{A_i}\bigr] \ge \prod_{i=1}^m (1 - x_i) > 0.

The symmetric version follows with xi=1d+1x_i = \frac{1}{d + 1}: then xi∏j∈Γ(i)(1−xj)≥1d+1(1−1d+1)d≥1e(d+1)≥px_i \prod_{j \in \Gamma(i)}(1 - x_j) \ge \frac{1}{d + 1}\bigl(1 - \frac{1}{d + 1}\bigr)^d \ge \frac{1}{e(d + 1)} \ge p, using (1−1d+1)d≥1e\bigl(1 - \frac{1}{d + 1}\bigr)^d \ge \frac{1}{e}.

Proof of the general lemma

Claim. For every ii and every set S⊆{1,…,m}∖{i}S \subseteq \{1, \ldots, m\} \setminus \{i\} with Pr⁡[⋂j∈SAj‾]>0\Pr[\bigcap_{j \in S} \overline{A_j}] > 0,

Pr⁡[Ai∣⋂j∈SAj‾]≤xi.\Pr\Bigl[A_i \Bigm| \bigcap_{j \in S} \overline{A_j}\Bigr] \le x_i .

Induction on ∣S∣\lvert S \rvert. Split SS into S1=S∩Γ(i)S_1 = S \cap \Gamma(i) and S2=S∖S1S_2 = S \setminus S_1, and write BT=⋂j∈TAj‾B_T = \bigcap_{j \in T} \overline{A_j}. If S1=∅S_1 = \emptyset, then AiA_i is mutually independent of the events in SS, so the conditional probability is Pr⁡[Ai]≤xi\Pr[A_i] \le x_i. Otherwise

Pr⁡[Ai∣BS]=Pr⁡[Ai∩BS1∣BS2]Pr⁡[BS1∣BS2].\Pr[A_i \mid B_S] = \frac{\Pr[A_i \cap B_{S_1} \mid B_{S_2}]}{\Pr[B_{S_1} \mid B_{S_2}]} .

The numerator is at most Pr⁡[Ai∣BS2]=Pr⁡[Ai]≤xi∏j∈Γ(i)(1−xj)\Pr[A_i \mid B_{S_2}] = \Pr[A_i] \le x_i \prod_{j \in \Gamma(i)} (1 - x_j), by mutual independence from S2S_2. For the denominator, list S1={j1,…,jr}S_1 = \{j_1, \ldots, j_r\} and use the chain rule:

Pr⁡[BS1∣BS2]=∏t=1r(1−Pr⁡[Ajt∣BS2∩Aj1‾∩⋯∩Ajt−1‾])≥∏t=1r(1−xjt)≥∏j∈Γ(i)(1−xj),\Pr[B_{S_1} \mid B_{S_2}] = \prod_{t=1}^{r} \Bigl(1 - \Pr\bigl[A_{j_t} \bigm| B_{S_2} \cap \overline{A_{j_1}} \cap \cdots \cap \overline{A_{j_{t-1}}}\bigr]\Bigr) \ge \prod_{t=1}^r (1 - x_{j_t}) \ge \prod_{j \in \Gamma(i)} (1 - x_j),

where each conditional probability is at most xjtx_{j_t} by the induction hypothesis (the conditioning set is smaller than SS). Dividing gives the claim.

The lemma. By the chain rule and the claim,

Pr⁡[⋂i=1mAi‾]=∏i=1m(1−Pr⁡[Ai∣A1‾∩⋯∩Ai−1‾])≥∏i=1m(1−xi).□\Pr\Bigl[\bigcap_{i=1}^m \overline{A_i}\Bigr] = \prod_{i=1}^m \Bigl(1 - \Pr\bigl[A_i \bigm| \overline{A_1} \cap \cdots \cap \overline{A_{i-1}}\bigr]\Bigr) \ge \prod_{i=1}^m (1 - x_i). \qquad \square

Application: sparse kk-SAT is satisfiable

A kk-CNF formula has clauses of exactly kk literals on distinct variables. Choose every variable independently and uniformly. Clause CC is violated only if all kk of its literals are false, so Pr⁡[AC]=2−k\Pr[A_C] = 2^{-k}. The event ACA_C is determined by the variables of CC, so ACA_C and AC′A_{C'} need to be adjacent only when the clauses share a variable.

Corollary. If every clause shares variables with at most dd other clauses and e(d+1)≤2ke(d + 1) \le 2^k, the formula is satisfiable. In particular this holds when no variable occurs in more than 2kek\frac{2^k}{ek} clauses.

Proof. The first part is the symmetric LLL with p=2−kp = 2^{-k}. For the second, a clause has kk variables, each in at most T=2kekT = \frac{2^k}{ek} clauses including itself, so d≤k(T−1)d \le k(T - 1) and e(d+1)≤e kT=2ke(d + 1) \le e\,kT = 2^k. □\square

The number of clauses plays no role. The program builds a 5-CNF formula with 100 variables in which every variable occurs in exactly 2 clauses (255e≈2.35\frac{2^5}{5e} \approx 2.35, so the occurrence bound holds). There are 40 clauses, so the union bound fails (40⋅2−5>140 \cdot 2^{-5} > 1), yet the LLL guarantees a satisfying assignment.

python · try it yourself
import random
from math import e

rng = random.Random(21)
n, k = 100, 5
slots = [v for v in range(n) for _ in range(2)]          # every variable in exactly 2 clauses
while True:
    rng.shuffle(slots)
    clauses = [slots[i:i + k] for i in range(0, len(slots), k)]
    if all(len(set(c)) == k for c in clauses):           # distinct variables in each clause
        break
clauses = [[(v, rng.choice((True, False))) for v in c] for c in clauses]   # literal: (variable, wanted value)
m = len(clauses)
deg = [sum(1 for j, D in enumerate(clauses) if j != i and {v for v, _ in C} & {v for v, _ in D})
       for i, C in enumerate(clauses)]
d = max(deg)
p = 2 ** -k
print(f"{m} clauses of width {k} on {n} variables; max dependency degree d = {d}")
print(f"union bound: m p = {m * p:.3f}  (>= 1, no conclusion)")
print(f"symmetric LLL: e p (d + 1) = {e * p * (d + 1):.3f}  (<= 1, satisfiable)")
print(f"general LLL lower bound on Pr[random assignment satisfies]: (1 - 1/(d+1))^m = {(1 - 1 / (d + 1)) ** m:.2e}")

def satisfied(assign):
    return all(any(assign[v] == want for v, want in C) for C in clauses)
samples = 5000
good = sum(satisfied([rng.random() < 0.5 for _ in range(n)]) for _ in range(samples))
print(f"measured fraction of satisfying random assignments: {good / samples:.3f}; (1 - p)^m = {(1 - p) ** m:.3f}")
40 clauses of width 5 on 100 variables; max dependency degree d = 5
union bound: m p = 1.250  (>= 1, no conclusion)
symmetric LLL: e p (d + 1) = 0.510  (<= 1, satisfiable)
general LLL lower bound on Pr[random assignment satisfies]: (1 - 1/(d+1))^m = 6.80e-04
measured fraction of satisfying random assignments: 0.289; (1 - p)^m = 0.281

The LLL's lower bound ∏i(1−xi)\prod_i (1 - x_i) is tiny, below 10−310^{-3} here, but it is positive, and that is all an existence proof needs. Here the true probability is much larger, close to (1−2−5)40(1 - 2^{-5})^{40}, because the clauses overlap so little that they behave almost independently. In general, satisfying assignments guaranteed by the LLL can be exponentially rare, so sampling random assignments until one works is not an efficient algorithm. The program below shows the effect on 6-CNF formulas in which every variable occurs in 3 clauses (266e≈3.92\frac{2^6}{6e} \approx 3.92, so the LLL condition holds for every size).

python · try it yourself
import random
from math import e

def lll_instance(n, k, occ, rng):
    """Each round cuts a random permutation of the variables into clauses of k distinct variables."""
    clauses = []
    for _ in range(occ):
        perm = list(range(n))
        rng.shuffle(perm)
        clauses += [[(v, rng.random() < 0.5) for v in perm[i:i + k]] for i in range(0, n, k)]
    return clauses

rng = random.Random(22)
k, occ = 6, 3             # 2^6 / (6e) = 3.92, so 3 occurrences per variable are allowed
print("  n   clauses   e p (d+1)   (1 - p)^m   satisfying among 1000 random assignments")
for n in [48, 96, 192, 384]:
    cl = lll_instance(n, k, occ, rng)
    vs = [{v for v, _ in C} for C in cl]
    d = max(sum(1 for j in range(len(cl)) if j != i and vs[i] & vs[j]) for i in range(len(cl)))
    good = 0
    for _ in range(1000):
        a = [rng.random() < 0.5 for _ in range(n)]
        good += all(any(a[v] == w for v, w in C) for C in cl)
    print(f"{n:3}   {len(cl):7}   {e * 2 ** -k * (d + 1):9.3f}   {(1 - 2 ** -k) ** len(cl):9.4f}   {good}")
  n   clauses   e p (d+1)   (1 - p)^m   satisfying among 1000 random assignments
 48        24       0.552      0.6853   692
 96        48       0.552      0.4696   472
192        96       0.552      0.2205   223
384       192       0.552      0.0486   41

As nn grows, the fraction of satisfying assignments shrinks exponentially (roughly like (1−2−k)m(1 - 2^{-k})^m with mm proportional to nn), while the LLL still guarantees that one exists. Finding one efficiently needed a new idea, which arrived 35 years after the lemma: Moser-Tardos resampling.

Other applications, stated

  • Hypergraph 2-colouring. If every edge of a kk-uniform hypergraph meets at most dd other edges and e(d+1)≤2k−1e(d + 1) \le 2^{k-1}, the vertices can be 2-coloured with no monochromatic edge (each edge is monochromatic with probability 21−k2^{1-k}).
  • Ramsey lower bounds. The LLL improves the union-bound lower bound for the diagonal Ramsey numbers by a factor of 2: R(k,k)>(1+o(1))2ek 2k/2R(k, k) > (1 + o(1)) \frac{\sqrt 2}{e} k\, 2^{k/2} (Spencer, 1977).
  • Packet routing. Leighton, Maggs and Rao (1994) used the LLL to show that packets along given paths can be scheduled in O(C+D)O(C + D) steps, where CC is the congestion and DD the dilation.

Test yourself

What does the symmetric Lovász Local Lemma require?

  1. ∑iPr⁡[Ai]<1\sum_i \Pr[A_i] < 1
  2. Each Pr⁡[Ai]≤p\Pr[A_i] \le p, each event depends on at most dd others, and ep(d+1)≤1ep(d+1) \le 1
  3. The events are mutually independent
  4. At most dd events in total

In a 10-CNF formula, each clause shares variables with at most dd other clauses. What is the largest dd for which the LLL guarantees satisfiability?

  1. d=375d = 375
  2. d=1023d = 1023
  3. d=10d = 10
  4. d=100d = 100

Why does the LLL not directly give an efficient algorithm?

  1. Its proof uses the axiom of choice
  2. The probability it guarantees can be exponentially small, so random sampling may need exponentially many tries
  3. It only applies to infinite families of events
  4. Checking the dependency graph is NP-hard

In the variable setting, when must two events be adjacent in the dependency graph?

  1. Always
  2. When they depend on a common random variable
  3. When they have the same probability
  4. Never