Almost every function needs an enormous circuit, yet nobody can name one that does. Count gates, find the smallest circuit for every small function, and watch parity defeat shallow circuits
Forget Turing machines. A circuit is AND, OR and NOT gates wired together, and “how many gates does this function need?” is a question of pure combinatorics. Prove that some problem in NP needs more than polynomially many, and P ≠ NP follows. It looked like the easy road. It was not.
Slide n and watch where the circuits run out. Then draw random functions, or tap the truth table to design your own, and see how many gates each one needs.
Both curves are on a log scale: the height is the number of binary digits in the count. Rose is the number of functions, 2 to the power 2n. Sky is the exact number of ways to write down a circuit with s gates when each gate may be any of the 16 two-input operations applied to two earlier wires; that is an upper bound on how many functions s gates can compute, with reuse of gates allowed. The amber mark is 2n/n.
The census counts formulas, not circuits: every gate’s output is used once, the gates are two-input AND and OR, and NOT is free. It is exact, because every pair of smaller formulas is combined. Circuits may reuse a gate’s output, so they can be smaller (see Circuit Golf below). Rows of the truth table are labelled by the inputs x₁x₂…; the amber frame and arrow mark your function’s bar. Majority of 4 means at least 3 of 4. The search stops at 4 inputs because 5 inputs have about 4 billion functions.
A function of n bits is a truth table with 2n rows, so there are 2 to the power 2n of them. A circuit with s gates is a short description: each gate names an operation and two earlier wires, about 2 log s bits apiece. There are simply not enough short descriptions to go round. Claude Shannon made this precise in 1949: almost every function of n variables needs a circuit of size about 2n/n. In 1958 Oleg Lupanov showed the count is tight: every function has a circuit of about that size.
The argument is non-constructive. It proves that hard functions exist, and even that nearly all functions are hard, without exhibiting a single one. The census in the demo finds the hard ones by exhaustion, which works for 4 inputs and is hopeless soon after. The difficulty in this lesson is the gap between “almost every function is hard” and “this particular function is hard”.
The link to P versus NP is the class P/poly: the problems that can be solved, for each input length n, by a circuit whose size is polynomial in n. A polynomial-time algorithm can be unrolled into such a family of circuits, so P ⊆ P/poly. To prove P ≠ NP it would therefore be enough to show that one problem in NP, satisfiability say, has no polynomial-size circuits. Nobody expects it to have them: Richard Karp and Richard Lipton proved in 1980 that if NP ⊆ P/poly then the polynomial hierarchy collapses to its second level, which most researchers consider unlikely. But that is a conditional theorem, not a lower bound.
Two measures appear on this page and they are not the same. In a formula each gate’s output is used once, so a shared subcomputation has to be built again each time it is needed. In a circuit an output may fan out to many gates. Circuits are never larger than formulas and can be much smaller. The counting chart counts circuits over all 16 two-input operations; the census counts formulas over AND and OR with free NOT.
Place gates and tap wires to build each target in as few gates as you can. Then slide n under the chart below to see how far proof has reached.
| a | b | a ⊕ b | yours |
|---|---|---|---|
| 0 | 0 | 0 | · |
| 1 | 0 | 1 | · |
| 0 | 1 | 1 | · |
| 1 | 1 | 0 | · |
Only two-input gates count; NOT is free, drawn as an amber bubble on the input it negates. A gate reads the inputs and gates placed before it, and one gate’s output may feed many others: that reuse is what separates a circuit from a formula. The truth table compares each target with the complete gate that comes closest to it. Par comes from an exhaustive search of every circuit with fewer gates over the chosen gate set (it skips only circuits that repeat a wire, waste a gate, or list the same gates in another order). Up to 10 gates.
| Year | Proved lower bound | Proved by |
|---|---|---|
| 1974 | 2n | Schnorr |
| 1977 | 2.5n | Paul; Stockmeyer |
| 1984 | 3n | Blum |
| 2016 | (3 + 1/86)n | Find, Golovnev, Hirsch and Kulikov |
| 2022 | 3.1n | Li and Yang |
Emerald: the best proved lower bound on the number of gates for some explicit function of n inputs, for circuits whose gates may be any two-input operation, ignoring lower-order terms. Dashed: polynomials, for scale. The vertical axis is logarithmic, which is why the steps from 2n to 3.1n are almost invisible. The rose arrow points to where the counting argument puts almost every function, far above the chart.
For a function of three inputs, a lower bound can be proved by brute force. There are finitely many circuits with five gates; try them all, and if none computes parity then parity needs six. That is how every par in the demo was obtained, and it is a genuine proof. The pars are for circuits, with reuse allowed, over the gate set chosen: AND and OR with free NOT, or the same with XOR added.
The method dies quickly. The number of circuits with s gates grows roughly like s to the power 2s, and the number of functions to keep track of is doubly exponential in n. Exhaustive search has settled the exact circuit size of functions of a handful of inputs and will never reach n = 100.
For general n, proof has to replace search, and here the record is humbling. For circuits over all two-input gates, the best lower bound proved for any explicit function rose from 2n (Claus Schnorr, 1974) to 2.5n (Wolfgang Paul, 1977; Larry Stockmeyer, 1977), to 3n (Norbert Blum, 1984), and then stood still for three decades until Magnus Find, Alexander Golovnev, Edward Hirsch and Alexander Kulikov reached (3 + 1/86)n in 2016. Jiatu Li and Tianqi Yang improved it to 3.1n in 2022. Each of these is a linear bound. Counting says almost every function needs exponentially many gates, and yet for functions anyone can write down, including every problem in NP, nothing better than a small multiple of n is known.
This is why attention moved, in the 1980s, to restricted circuits: limit the depth or forbid negation, and real lower bounds can be proved. The third demo is about the most famous of them.
Slide n to see parity’s depth-2 circuit double each time. Then press Play to fix variables at random, and compare what is left of a narrow DNF with what is left of parity.
A DNF is a circuit of depth 2: one OR gate fed by AND gates, each AND reading as many inputs as it likes. The counts are exact, found by listing every prime implicant and searching for the smallest set of them that covers the function. Parity’s terms cannot merge: flip any one input and the answer changes, so each term has to name all n variables and covers a single row of the truth table.
| Depth at least t | t = 1 | t = 2 | t = 3 | t = 4 | t = 5 |
|---|---|---|---|---|---|
| DNF, measured | 0% | 0% | 0% | 0% | 0% |
| Lemma’s bound, (5pk)t | — | — | — | — | — |
| Parity, measured | 0% | 0% | 0% | 0% | 0% |
Sky is the DNF, rose is parity, indigo marks free variables. Decision-tree depth is the number of variables an adaptive questioner must read in the worst case to learn the function’s value; it is computed exactly here, by dynamic programming over every subcube. This is a simulation on 16 variables illustrating what the switching lemma says. It is not a proof, and the real argument needs n large and one round of restriction for each layer of the circuit.
AC⁰ is the class of problems solved by circuits of constant depth and polynomial size, built from NOT gates and AND and OR gates with any number of inputs. Such circuits can add two numbers. They cannot compute parity: Merrick Furst, James Saxe and Michael Sipser proved it in 1981 and Miklós Ajtai independently in 1983, and in 1986 Johan Håstad gave bounds that are essentially optimal.
Håstad’s tool is the switching lemma. Take a DNF whose terms each have at most k literals, and apply a random restriction that leaves each variable free with probability p. Then the probability that what remains needs a decision tree of depth t or more is at most (5pk)t, no matter how many terms the DNF has. A function with a shallow decision tree can be rewritten as a CNF with short clauses, so an OR of ANDs has been switched into an AND of ORs. In a layered circuit that lets two adjacent layers merge, and the depth drops by one.
Repeat for each layer. After d − 2 rounds a small circuit of depth d has become a circuit of depth 2 with narrow gates, on the variables still free. But parity restricted is still parity, and the first panel shows what parity demands at depth 2. Working through the numbers, a depth-d circuit for parity of n bits must have size exp(Ω(n1/(d−1))). The second panel is a simulation with 12 to 16 variables that illustrates the lemma’s statement; it is not a proof of anything.
The hope in the 1980s was to climb from AC⁰ one class at a time until the bounds reached P/poly. The ladder in the demo records how far that went. Progress slowed sharply around 1990, and the leading explanation is itself a theorem: the natural proofs barrier. See also: The Barriers.
Spot a mistake or have an idea?