sarvesh.
Blogs

Why thirteen gates aren’t enough

Three people apply for three jobs. You know which jobs each person can do. What is the smallest circuit that can tell, every time, whether everyone can get a different job?

A circuit with 14 gates was already known. What I wanted to understand was why the fourteenth gate was necessary. Checking a working design took 512 yes-or-no tests. Ruling out every smaller design took a different idea.

Start with a matching you can break

Suppose Ben can only do Job 1. Ada can do Jobs 1 and 2. Giving Ada Job 1 would strand Ben, even though Ada was qualified for it. Give her Job 2 and all three people can work. Try removing that qualification below. Everyone still has an option, and every job still has a candidate. See if you can find a way to fill all three jobs.

Can everyone take a different job?

Change who qualifies for each job. Try switching off Job 2 for Ada.

AdaBenCyJob 1Job 2Job 3
AssignedAlso qualified
PersonJob 1Job 2Job 3
Ada
Ben
Cy
A perfect matching exists.Ada takes Job 2, Ben takes Job 1, and Cy takes Job 3.

The nine qualifications are the circuit’s nine inputs. Each can be on or off, giving 29 = 512 possible boards. The circuit must give the correct answer on all of them. An AND gate answers yes when both inputs are yes. An OR gate answers yes when either input is yes. Each gate takes two inputs, and its output can feed as many later gates as needed. Adding a qualification can only help a matching, which makes this a natural problem to study with these monotone gates.

This is a small question inside circuit complexity. P versus NP asks whether every decision problem whose yes answers can be checked efficiently can also be solved efficiently as inputs grow. Bipartite matching already has efficient algorithms. Here the question is the exact cost of a particular nine-input function under particular rules. The general P versus NP question remains open.

Counting the gates that disappear

First, build the known circuit. Suppose Ada takes Job 1. Ben and Cy must take Jobs 2 and 3 in one order or the other. Two AND gates check those two orders. An OR combines them, and one more AND checks that Ada can actually do Job 1. That costs four gates. Repeat for Ada taking Job 2 or Job 3, then combine the three answers with two OR gates. The total is 3 × 4 + 2 = 14.

A successful test of those 14 gates says nothing about what an ingenious 13-gate design might do. To get a lower bound, I asked what happens to any correct circuit if one qualification is fixed to yes. With eight inputs still free, our finite calculation found that the remaining matching problem needs at least 12 gates. By relabeling people and jobs, that bound holds whichever qualification is fixed.

12still needed+2removed=14at least
Fix one input that feeds two gates. Count what remains, then put back what the restriction removed.

Why can we find an input that feeds two gates? Look at the first gate. If its two qualifications were never read anywhere else, the circuit would have to give the same answer when their values were swapped. An AND or OR cannot tell which input supplied which value. But any two different qualifications can be distinguished. Start with exactly three edges forming a matching that uses the first qualification and omits the second. Exchange those two edges. Someone loses their only assignment or two people now need the same job. The answer changes.

So at least one input must be read twice by distinct gates. Fix it to yes. An AND with yes reduces to its other input. An OR with yes reduces to yes. Both gates disappear. If a 13-gate circuit had existed, that would leave at most 11 gates to do a job requiring 12. This rules out 13 and every smaller size. The known construction gives the matching upper bound.

Where the number 12 comes from

The verifier represents the eight-input problem by its truth table. It explores possible beginnings of a smallest circuit. For each beginning it tries fixing additional inputs, uses bounds already established for the resulting smaller functions, and counts which gates simplify away. It only raises a bound when all the possible beginnings are covered.

The first implementation combined equivalent cases into 56 classes. A separately written checker examined 1,665 labeled restrictions without that symmetry reduction. Both obtained 12 with one edge fixed present. As a control, we compared the method against exhaustive gate counts for all 168 monotone functions on four inputs. Read the algorithm and the control.

What a reused wire is worth

In the matching problem, a wire can carry a result to several gates for free. I wanted an example where you could point to the reused result and put a price on losing it.

I studied a six-by-six pattern of cells. The starting sets are whole rows and whole columns. Taking the union of sets is free. Taking their intersection costs one. A circuit can save a set and use it again. In a formula, writing the same expression twice incurs the cost twice. For this particular pattern, the cheapest circuit costs three intersections and the cheapest formula costs four.

Where the fourth gate comes from

Six rectangles, A through F, are the inputs. Follow the diagram down to find the graph’s empty cells. Each union (∪) costs one gate. Intersections (∩) are free here.

Choose a representation
3 paid unions
Shared resultH = A ∪ B
Left branch · LC ∪ (D ∩ H)
Right branch · RE ∪ (F ∩ H)
Empty cellsL ∩ R

Each miniature grid shades the cells produced at that step.

One result feeds two branches.

The circuit pays once for A ∪ B. Both branches read that wire, then each performs one more union.

The original graph is the complement of these empty cells. By De Morgan’s laws, each paid union here becomes one paid intersection there.

The drawing uses the empty cells to show the computation. Taking complements exchanges union and intersection. In this view a paid operation is a union, and the shared result is the union of rectangles A and B. Both branches need it. Expanding those two uses into a formula makes the second copy visible. To prove that four is the minimum, the checker ruled out every cheaper formula shape that could produce the same cells. Inspect the graph and its exact-cost proof.

What started as a single graph became a family. For every integer k from three upward, we gave an explicit graph whose circuit needs exactly k paid intersections and whose formula needs exactly k + 1. The combined theorem was checked in Lean. This extends a one-intersection saving to every one of those budgets. We went on to ask how large that saving can grow on trees and finite projective planes. Read the family construction and theorem.

What a failed design can tell you

In a point-and-line experiment, a 61-gate candidate passed 755 of 756 boundary tests. I found the failing input more informative than the pass count. It led to a Lean proof that ruled out a whole wiring pattern. Any successful 61-gate design would need to combine line-dependent wires in a way this candidate did not. Read the one-input failure.

For a separate six-row grid, the starting design used 29 gates. We could rearrange several rows at once and let them share intermediate wires. The question was whether any design that kept two standard rows connected to the output could reach 28. We checked all 15 choices for the two rows. Across those choices, 494 candidate input sets survived the early reductions. Two exhaustive searches eliminated every one.

That result changes the next search. A 28-gate solution, if one exists, must redesign or disconnect at least five of the six standard rows. Keeping two intact is enough to force 29. Inspect the assumptions and the grid proof.

How to check the matching result

I set the research direction and the verification requirements and used Codex to develop the argument and implement the checks. The published package contains the written proof, the known construction, two Python verifiers and the Lean files. Each artifact answers a different question.

Does 14 work?
The construction produces the right answer on all 512 graphs. It also passed the project’s Lean checker. Open the construction.
Can 13 work?
The written restriction argument and both executable checks rule out 13 for binary AND/OR circuits with wire reuse. The version that allows NOT gates remains open. Get both checkers and their replay instructions.
What has Lean verified?
Alongside the construction, Lean checks the general accounting step for gates that disappear when wires become constant. Connecting the entire finite calculation to one end-to-end Lean lower-bound theorem remains open. Read the elimination lemma.

For the other studies, including wire reuse on trees and the cost of equality over different fields, visit the small-circuits research index.

Related project · P vs NP: Small Circuits