Randomized Complexity: BPP, RP, ZPP, and the Schwartz-Zippel Lemma
Anchor (Master): Arora & Barak 2009 Computational Complexity: A Modern Approach (Cambridge) §7.1-7.6 (BPP ⊆ P/poly, Sipser-Gacs-Lautemann theorem BPP ⊆ Σ₂ᵖ ∩ Π₂ᵖ, derandomisation conjectures)
Intuition Beginner
Sometimes flipping a coin helps. Imagine you are at a fork in a maze and do not know which way to go. If you choose randomly, you will eventually find the exit, even though any single guess might be wrong. Randomised algorithms work the same way: they make random choices during execution and have a small probability of giving the wrong answer, but by repeating the computation a few times, the error probability drops to nearly zero.
The class BPP (Bounded-error Probabilistic Polynomial time) contains every problem that can be solved by a randomised algorithm in polynomial time with error probability at most one third. Why one third? Because the exact constant does not matter: by running the algorithm a few dozen times and taking a majority vote, you can drive the error probability down to less than one in a billion.
Some problems have an even stronger guarantee. RP (Randomised Polynomial time) is the class of problems where the algorithm never says "yes" when the answer is "no" (no false positives), but it might say "no" when the answer is "yes" (a false negative) with probability at most one half. If the algorithm says "yes," you know the answer is correct. If it says "no," run it again.
The Schwartz-Zippel lemma is the workhorse of randomised algebra. It says: if you have two different multivariate polynomials, the chance that they agree at a random point is small. This lets you test whether two polynomials are identical by plugging in random values — a simple, fast, and highly effective strategy.
Visual Beginner
The relationships between randomised complexity classes:
P ⊆ ZPP ⊆ RP ⊆ BPP
⊆ coRP ⊆ BPP
ZPP = RP ∩ coRP (zero-error, expected polynomial time)
RP: one-sided error (no false positives)
coRP: one-sided error (no false negatives)
BPP: two-sided error (bounded in both directions)| Class | Error type | Guarantee | Example |
|---|---|---|---|
| ZPP | Zero error | Always correct, expected poly-time | Las Vegas algorithms |
| RP | One-sided | If yes, always correct; if no, may be wrong | Polynomial identity testing |
| BPP | Two-sided | Correct with probability | Majority vote after repetition |
| P | No error | Always correct, worst-case poly-time | Deterministic algorithms |
Worked example Beginner
You have two polynomials over the integers: and . Are they the same polynomial?
Expanding gives , which matches . But what if and had thousands of terms and expanding was impractical?
The Schwartz-Zippel lemma gives a shortcut. Pick random values for and , say and . Compute and . They agree. But this could happen by coincidence even if .
The lemma says: if , then the probability that and agree at a random point chosen from a set is at most , where is the degree. Here . If we pick from , the error probability is at most .
Repeat with new random values. After independent tests, the error drops to at most . After 5 tests, the error is less than one in two million. This is polynomial identity testing — a fast, practical randomised algorithm for a fundamental algebraic question.
Check your understanding Beginner
Formal definition Intermediate+
A probabilistic Turing machine (PTM) is a Turing machine with access to a coin-flip tape: at each step, the machine can read the next bit from a tape initialised with independent uniform random bits. The output of a PTM on input is a random variable.
Definition (BPP). A language if there exists a polynomial-time PTM such that for all :
where if and otherwise. The probability is over the random bits of .
Definition (RP). A language if there exists a polynomial-time PTM such that for all :
- If : .
- If : .
Definition (coRP). iff .
Definition (ZPP). . Equivalently, iff there exists an expected-polynomial-time PTM that never errs: either outputs the correct answer or outputs a special "don't know" symbol , and the probability of is at most .
Lemma (Schwartz-Zippel). Let be a nonzero polynomial of total degree over a field . Let be a finite subset. Then:
Each is chosen independently and uniformly from [Arora & Barak §7.3].
Counterexamples to common slips
"BPP means the algorithm is correct with probability at least 2/3, which is too weak for practice." Error reduction by repetition drives the error probability to with repetitions. Any desired confidence level is achievable with modest overhead.
"RP algorithms have 50 percent error rate." The error is one-sided and only on "yes" instances. On "no" instances the algorithm is always correct. By repetition, the false-negative rate drops to .
"Schwartz-Zippel requires the field to be finite." The lemma works over any field. The random evaluation points must come from a finite subset , but the polynomial itself can live over , , or any field.
Key theorem with proof Intermediate+
Theorem (Schwartz-Zippel lemma). Let be nonzero of total degree . Then for chosen independently and uniformly from : .
Proof. By induction on . Base case : a nonzero univariate polynomial of degree has at most roots, so .
Inductive step: write where and . Then:
By the inductive hypothesis, . Conditioned on , the polynomial is a nonzero polynomial in of degree , so . Adding: .
Bridge. The Schwartz-Zippel lemma is the foundational reason polynomial identity testing (PIT) is in coRP: two distinct polynomials can agree at a random point only with low probability, so disagreement at a random point is a reliable certificate of difference. This builds toward the derandomisation programme in 47.05.01, where universal hash families use a similar probabilistic argument for load balancing, and it appears again in 47.05.03 where Miller-Rabin primality testing applies the same error-reduction-by-repetition strategy. The central insight is that random evaluation converts an algebraic identity question into a numeric computation, and putting these together with Chernoff-bound amplification gives a practical, highly reliable randomised algorithm.
Exercises Intermediate+
Lean formalization Intermediate+
Mathlib has basic probability infrastructure (Probability.ProbabilityMassFunction) but no probabilistic Turing machine model or complexity class definitions for BPP, RP, or ZPP. The Chernoff bound for error amplification and the Schwartz-Zippel lemma for polynomial identity testing are absent. A Codex.Complexity.BPP module defining BPP via polynomial-bounded PTM computations with error reduction would be the foundational step; this unit ships without it.
Advanced results Master
Three structural results sharpen the relationship between randomised and deterministic computation.
Theorem 1 (BPP P/poly). Every language in BPP has polynomial-size circuits [Arora & Barak §7.5]. The proof uses the probabilistic method: a BPP machine uses random bits, and there are possible random strings. By averaging, for every input of length , at most random strings cause to err. A counting argument shows there exists a fixed set of random strings (an "advice" string) that works for all inputs of length ; this advice string defines a polynomial-size circuit.
Theorem 2 (Sipser-Gacs-Lautemann: BPP ). BPP is contained in the second level of the polynomial hierarchy [Arora & Barak §7.6]. The proof uses the pairwise independence hashing technique: the acceptance condition of a BPP machine can be expressed as a predicate ("there exist shifts such that for all inputs, the majority of shifted random strings give the correct answer"). This places BPP inside the polynomial hierarchy and suggests that randomisation does not add much power beyond determinism, assuming the polynomial hierarchy does not collapse.
Theorem 3 (derandomisation conjectures). Several hardness-vs-randomness tradeoffs relate derandomisation to circuit lower bounds. The Impagliazzo-Wigderson theorem (1997) shows that if there exists a language in E = DTIME() that requires exponential-size circuits, then BPP = P. The proof constructs a pseudorandom generator from the hard language, whose output is indistinguishable from truly random bits by any polynomial-time algorithm. This is the strongest evidence that BPP = P: it reduces the question to a (plausible) circuit lower bound [Arora & Barak §7.5].
Synthesis. The randomised complexity classes BPP, RP, and ZPP are the foundational reason randomised algorithms are practical: error reduction via repetition drives the failure probability to negligible levels, and the Schwartz-Zippel lemma provides a general-purpose randomised test for algebraic identities. The central insight is that randomness is a resource that, like time and space, can be quantified and controlled, and putting these together with the Sipser-Gacs-Lautemann theorem places BPP inside the polynomial hierarchy of 47.02.04, suggesting randomisation does not add fundamental power. This builds toward the derandomisation programme of 47.05.01, where universal hash families replace true randomness with structured pseudorandom objects, and appears again in 47.05.03 where Miller-Rabin primality testing demonstrates a natural problem in BPP (and now in P, after AKS 2002).
Full proof set Master
Proposition 1 (error reduction for BPP). If , then for every constant there is a BPP machine for with error at most .
Proof. Let have error . Run independently times and take the majority. Let be the indicator of correct output on run . Each has and the are independent. The majority errs iff , a deviation of below the mean . By the Chernoff bound: . For , the error is at most .
Proposition 2 (Schwartz-Zippel, full proof by induction). Let have total degree . Then .
Proof. Induction on . For , a univariate polynomial of degree has at most roots, so . For , write with , . Then:
where by induction and by the univariate case applied to as a polynomial in with coefficients evaluated at .
Connections Master
37.01.01— Probability spaces and discrete distributions provide the mathematical foundation for defining the error probabilities of BPP, RP, and ZPP machines; independence of random bits is a key assumption.47.02.01— P and NP are the deterministic analogues against which the randomised classes are measured; the containment and the conjecture frame the role of randomisation.47.02.04— The polynomial hierarchy contains BPP by the Sipser-Gacs-Lautemann theorem, placing randomised computation within the structural framework of alternation.47.05.01— Universal hashing and perfect hashing use the probabilistic method to construct deterministic data structures; the underlying argument is the same "most random choices are good" principle.47.05.03— Miller-Rabin primality testing is a landmark RP/coRP algorithm; its error analysis relies on the same amplification techniques developed here.
Historical & philosophical context Master
Randomised algorithms entered computational complexity through the work of Michael Rabin (1976) and Robert Solovay and Volker Strassen (1977), who independently discovered randomised primality tests. Rabin's paper "Probabilistic Algorithm for Testing Primality" introduced the concept of a probabilistic algorithm with bounded one-sided error (the class RP), and the Solovay-Strassen test provided an alternative with similar guarantees [Arora & Barak §7.1].
The class BPP was formally defined by John Gill (1977) in his paper "Computational Complexity of Probabilistic Turing Machines." The Schwartz-Zippel lemma was discovered independently by Jack Schwartz (1980) and Richard Zippel (1979). Schwartz's paper "Fast Probabilistic Algorithms for Verification of Polynomial Identities" established the lemma for multivariate polynomials over arbitrary fields and used it for polynomial identity testing.
The Sipser-Gacs-Lautemann theorem (1983) showed that BPP resides in the polynomial hierarchy, providing the first evidence that randomisation does not dramatically increase computational power. The Impagliazzo-Wigderson theorem (1997) strengthened this by showing that BPP = P under plausible hardness assumptions, essentially reducing derandomisation to circuit lower bounds.
Bibliography Master
@book{arora-barak2009,
author = {Arora, Sanjeev and Barak, Boaz},
title = {Computational Complexity: A Modern Approach},
publisher = {Cambridge University Press},
year = {2009},
}
@article{rabin1976probabilistic,
author = {Rabin, Michael O.},
title = {Probabilistic Algorithm for Testing Primality},
journal = {Journal of Number Theory},
volume = {12},
number = {1},
pages = {128--138},
year = {1980},
note = {First presented at the 1976 Carnegie Mellon conference},
}
@article{schwartz1980fast,
author = {Schwartz, Jacob T.},
title = {Fast Probabilistic Algorithms for Verification of Polynomial Identities},
journal = {Journal of the ACM},
volume = {27},
number = {4},
pages = {701--717},
year = {1980},
}
@article{zippel1979probabilistic,
author = {Zippel, Richard},
title = {Probabilistic Algorithms for Sparse Polynomials},
journal = {Proceedings of the International Symposium on Symbolic and Algebraic Computation},
pages = {216--226},
year = {1979},
}
@article{gill1977computational,
author = {Gill, John},
title = {Computational Complexity of Probabilistic Turing Machines},
journal = {SIAM Journal on Computing},
volume = {6},
number = {4},
pages = {675--695},
year = {1977},
}