# What is proved about direct-encoded pigeonhole

The scaling results in `RESULTS.md` are measurements. For one family, direct-encoded pigeonhole, the computation can be
derived: which orders the method picks, the exact size of every state it builds, and an O(n^4) bound on the whole
proof. `theory.py` checks each statement below against the code (`results/theory.json`); what remains measured is
said at the end.

**The formula.** n holes, n + 1 pigeons, variables p(i, j) ("pigeon j is in hole i"). Pigeon clauses
p(1, j) ∨ … ∨ p(n, j), one per pigeon; hole clauses ¬p(i, a) ∨ ¬p(i, b), one per hole and pair of pigeons.

## 1. The spectrum

The variable graph gives each pair in a clause of k variables the weight 1/(k − 1): weight 1/(n − 1) between
variables of the same pigeon, weight 1 between variables of the same hole.

**Lemma 1.** The Laplacian's eigenvalues are 0 (once), n/(n − 1) (n − 1 times), n + 1 (n times) and
n/(n − 1) + n + 1 (the rest, n(n − 1) times). The eigenvectors for n/(n − 1) are the functions f(i) of the hole
alone with Σ f = 0 ("hole modes"); those for n + 1 are the functions g(j) of the pigeon alone with Σ g = 0 ("pigeon
modes").

*Proof.* For f depending on the hole only, the same-hole edges contribute nothing, and each variable has n − 1
same-pigeon neighbours of weight 1/(n − 1): (Lf)(i, j) = Σ_{i' ≠ i} (f(i) − f(i'))/(n − 1) = n f(i)/(n − 1). For g
depending on the pigeon only, the same-pigeon edges contribute nothing and each variable has n same-hole neighbours of
weight 1: (Lg)(i, j) = Σ_{j' ≠ j} (g(j) − g(j')) = (n + 1) g(j). The graph is the Cartesian product of a complete graph
on the holes (weight 1/(n − 1)) and a complete graph on the pigeons (weight 1), so the products f(i)g(j) give the
remaining eigenvalue, and the dimensions add up to n(n + 1). ∎

`theory.py` confirms the multiplicities numerically for n = 4 to 24 (at n = 24: 24/23 = 1.04348, 25, 26.04348).

## 2. The orders the method picks

**Lemma 2.** On any renaming and reordering of the formula, `spectral.py` (protocol 3) makes the time direction a
generic combination of the hole modes and the transverse direction a generic combination of the pigeon modes. Hence
the elimination order lists the holes one after another, the √N slices are exactly the n holes
(round(√(n(n + 1))) = n), and the BDD order lists the pigeons one after another, each pigeon's variables in the
holes' slice order.

*Proof.* The first non-zero cluster is the hole modes (Lemma 1, and n/(n − 1) < n + 1). A generic combination t takes
distinct values on distinct holes and is constant on each hole, so slices of equal t are holes, and the hole modes
other than t have no variance inside them. The next cluster, the pigeon modes, varies inside every hole: its variance
lies entirely within the slices, so it is chosen. ∎ (Genericity holds with probability 1 for the fixed random
combination; `theory.py` checks it on two shuffles at each of n = 6, 10, 16 and 24.)

These are the orders Bryant reports as the best of the four he tried by hand (hole-major elimination, pigeon-major
BDD order; arXiv:2306.10337).

## 3. The states

Order the holes 1, …, n as the sweep meets them. For an assignment to the variables of holes i + 1, …, n, let
Z_i be the number of pigeons that have no true variable among those holes.

**Theorem.** After the sweep has processed hole i, its state is exactly the function [Z_i ≤ i].

*Proof.* Every pigeon clause has its earliest variable in hole 1, and every hole clause lies inside one hole, so the
first slice conjoins all pigeon clauses with hole 1's clauses and the i-th slice conjoins hole i's clauses. Before any
hole is processed the pigeon clauses say Z_0 = 0, i.e. [Z_0 ≤ 0]. Suppose the state after hole i − 1 is
[Z_{i−1} ≤ i − 1]. Slice i conjoins "at most one pigeon in hole i" and quantifies hole i's variables. Fix the
variables of the later holes: Z_i pigeons then have nothing true after hole i. Choosing hole i's column with at most
one 1 can lower the count of pigeons with nothing true from hole i on by at most one, and by one exactly when Z_i ≥ 1
(put the 1 on one of those pigeons). So a choice satisfying Z_{i−1} ≤ i − 1 exists if and only if Z_i ≤ i. ∎

At i = n no variables remain, Z_n = n + 1 > n, and the state is FALSE: the proof ends.

**Proposition.** In the BDD order of Lemma 2 the BDD of [Z_i ≤ i] has exactly

    N(n, i) = (n − i)(i + 1)(n + 1 − i)

nodes, and Σ_{i=1}^{n−1} N(n, i) = n^4/12 + O(n^3).

*Proof.* Read the pigeons' blocks of n − i variables in order. Before block b, the only thing that matters is c, the
number of empty blocks so far: the function is FALSE once c > i and TRUE once c + (n + 1 − b) ≤ i (too few blocks
remain to exceed i), and otherwise depends on c, so these values of c are pairwise distinct functions. Inside a
block the function also depends on whether a true variable has been seen; once one has, the rest of the block is
skipped, so each live c needs one node per variable of the block, n − i nodes, none of them redundant. Summing over
blocks: a value c is live before block b exactly when c ≤ i and c ≤ b ≤ c + n − i, so each of the i + 1 values of c
is live before n + 1 − i blocks, (i + 1)(n + 1 − i) pairs in all, each with n − i nodes. Summing the cubic over i
gives n^4/12 + O(n^3). ∎

`theory.py` compares N(n, i) with the state the sweep actually builds after every hole, for n = 6, 10, 16 and 24
under two shuffles each: they agree at every i. The largest state of every protocol-3 run (n = 8 to 56) also equals
max_i N(n, i) (`RESULTS.md`). Σ_i N(n, i)/n^4 is 0.0989 at n = 32, 0.0872 at n = 128 and 0.0853 at n = 256 (limit
1/12).

## 4. The size of the proof

**Theorem 2.** On direct-encoded pigeonhole with n holes, the automatic sweep (orders of Lemma 2, schedule `sweep2`,
compact proof steps) writes a proof of O(n^4) clauses.

The proof counts the prover's memoised calls. Each call writes at most two proof clauses and creates at most one BDD
node, which brings four defining clauses; so it suffices to show that each slice makes O(n^3) calls.

*Pair lemma.* The recursions `and_(u, v)`, `or_(u, v)` and `imp(u, v)` split on the higher of the two top variables
and recurse on the two cofactors, memoising each pair. By induction every call is on a pair (u|π, v|π), where π
assigns the variables above the split level (a node that does not test a variable is its own cofactor). So the number
of calls is at most Σ_ℓ N_ℓ, where N_ℓ is the number of distinct pairs (u|π, v|π) over assignments π to the first ℓ
variables. In particular, if both residuals are determined by some statistic κ(π), N_ℓ is at most the number of values
κ takes at level ℓ.

*The statistic.* Fix slice i ≥ 2; L_i = m(n − i + 1) variables remain (m = n + 1), in the order of Lemma 2: pigeon by
pigeon, the hole-i variable first in each pigeon's block. For a prefix π let ζ be the number of completed blocks whose
variables are all 0, α the number of hole-i variables set to 1 (capped at 2), and φ the state of the current block
(its hole-i variable 0, 1 or not yet read; whether another of its variables is 1): at most 18(m + 1) values per level.
The slice computes S ∧ T, where S = [Z ≤ i − 1] (Theorem 1) and T is "at most one pigeon in hole i"; then
W = ∃(hole-i variables) (S ∧ T), which is [E ≤ i] (Theorem 1); then a proof that S ∧ T implies W.

- *Conjunction.* S|π depends only on (ζ, φ) and T|π only on α, so the conjunction makes at most 18(m + 1) calls per
  level, and S ∧ T has at most that many nodes per level.
- *Quantification.* `exists` makes one call per node of S ∧ T. At a node that tests a hole-i variable it calls
  `or_` on the quantified children. A quantified child, restricted to the variables that follow, is a threshold
  function: since at most one more hole-i variable may be 1, and putting it on a pigeon whose other variables are all
  0 lowers Z by one, ∃(hole-i variables)(S ∧ T)|ρ = [ζ(ρ) + c + E' − [α(ρ) = 0 and some later block is empty]
  ≤ i − 1], with c ∈ {0, 1} from the current block and E' the number of later blocks whose other variables are all 0.
  Its residual after further variables σ depends only on ζ(ρ) + (empty blocks in σ), on α(ρ) = 0, on whether σ has
  completed an empty block, and on the current block's state; the two children of one node share ρ and differ only
  in the branch. So the `or_` calls see O(m) distinct pairs per level.
- *Implication.* In `imp(S ∧ T, W)`, W does not depend on the hole-i variables; W|π is determined by the number ε of
  completed blocks whose other variables are all 0, and ε − ζ counts completed blocks whose hole-i variable is 1, at
  most α ≤ 2. So the pair is determined by (ζ, α, φ, ε − ζ): at most 54(m + 1) values per level.
- *Building T.* The hole's m(m − 1)/2 pairwise clauses are sorted by their variables' levels and conjoined as a
  balanced tree, so every subtree conjoins a contiguous run of pairs (a, b) in lexicographic order. Such a run forbids
  two ones among the pairs it contains, and its residual depends only on which of its at most three kinds of row (the
  first row, part of whose pairs is in the run; the full rows; the last row) has met a 1: at most 5 states per level.
  Each conjunction therefore costs O(m) calls and the tree O(m^2 log m).

Each slice therefore makes O(m · L_i + m^2 log m) = O(n^3) calls, and the first slice (all pigeon clauses with hole
1's clauses, then hole 1 quantified) is bounded in the same way. Summed over the n slices, the proof has O(n^4)
clauses. ∎

*Checks.* `theory.py` counts the calls in every slice (`results/theory.json`, n = 8 to 32): after the first slice
the AND, OR and implication calls and the new nodes are each at most 2.17 per (level × m), against the 54 the proof
allows, and the ratio does not grow with n. The measured proofs of protocols 4 and 5 divided by m² · n(n + 1)/2
(Σ_i m · L_i) fall from 6.46 at n = 8 to 4.45 at n = 56.

The bound matches Cook's hand-built extended-resolution proof, O(n^4), and improves on the O(n^5) that Bryant measured
with hand-chosen orders. The best known proof, Grosof, Zhang and Heule's, has O(n^3) clauses, the size of the formula
itself. Nothing comparable is proved here for the chessboard or the Tseitin families: for them the polynomial growth is
measured.
