The n-Queens problem, placing mutually non-attacking queens on an chessboard, is a standard benchmark in constraint programming and artificial intelligence. As a decision problem it is trivial: a solution exists for every other than and and can be written down in closed form, and the input has only bits. This has repeatedly led to criticism of its use as a benchmark.
The variant n-Queens Completion, posed in 1850, asks whether a board on which some queens are already placed can be completed to a full solution. Gent, Jefferson and Nightingale (JAIR 2017) show that this variant is genuinely hard: deciding it is NP-complete and counting its completions is #P-complete. This gives benchmark designers a version of the puzzle with a provable hardness guarantee, and it makes the n-Queens literature (Pólya's modular construction, Rivin–Zabih exchanges) a source of reduction gadgets.
Timeline:
A queen is a pair of non-negative integers, its column and row. Its sum-diagonal is and its difference-diagonal is the integer . It fits on board size if . Two distinct queens attack each other if they share a column, a row, a sum-diagonal or a difference-diagonal. A solution to the -Queens problem () is a set of queens that fit on board size , no two attacking.
An instance of n-Queens Completion (Problem 2) is a pair : a board size and a set of queens that fit on board size , no two in the same row or column. may contain two queens on a common diagonal; such an instance simply has no solution. A completion is an -Queens solution with .
The proof passes through four intermediate problems. In Problem 3 the extra queens must use prescribed columns and rows . In Problem 4 (Excluded Diagonals) sets , of difference- and sum-diagonals are forbidden. Problem 5 is a family of Problem 4 instances that interact only through their sum-diagonals. Problem 6 is Restricted 1-in-3-SAT: clauses of three distinct positive variables, every variable in at most three clauses, and an assignment must make exactly one variable of every clause true.
Complexity is measured on the published CookLevin machine model: a language is a set of binary strings, CookLevin.NPComplete is NP-completeness under polynomial-time many-one reductions, and a function from strings to is in #P if it counts the accepted certificates of an NP verifier. Every instance is coded with its board size in unary, as the paper assumes (p. 820). is the language of codes of instances that have a completion, and is the number of completions of the instance coded by .
Here #P-completeness means membership in #P together with hardness under parsimonious reductions: polynomial-time maps with for every string . The statement is unconditional.
Each reduction theorem states both halves of "parsimonious": the paper's construction preserves the number of solutions instance by instance, and a polynomial-time map on codes implements it.
The result. Theorem 37 shows that the hardness of n-Queens Completion is not an artefact of a particular solver. The same chain shows that Excluded Diagonals and Blocked n-Queens are NP- and #P-complete (Corollary 38), and Corollary 15 (from Lemma 12) shows that every non-attacking set of queens occurs inside some full solution of a larger board. Because the reductions are parsimonious, they also transfer counting hardness: counting completions exactly is as hard as #SAT.
Formalizing it. The result is proved on paper; no part of it is machine-checked. The mission adds the platform's first #P layer (#P, parsimonious reductions, #P-completeness) on top of the published CookLevin NP framework, and the first chessboard objects. Four printed slips are corrected, each with a counterexample: Lemma 8 needs ; Problem 3 needs (Theorem 13 fails otherwise); Definition 20's overshoots ; Definition 20 is undefined for the empty family.
The obvious argument fails in two places.
First, each reduction is a bijection between solution sets whose correctness depends on exhaustive diagonal bookkeeping: that the 19-queens frame and the embedded modular solutions leave exactly the intended squares free, that the blockers of Definition 16 rule out exactly the chosen diagonals, and that gadgets on a long diagonal interact only through sum-diagonals. Each is a case analysis over many families of squares, with integer arithmetic on both diagonals.
Second, Theorem 4 is cited, not proved, for its hard part. A proof from scratch needs #P-hardness of a 1-in-3-SAT variant, i.e. a parsimonious version of the Cook–Levin theorem. The published CookLevin.sat_npComplete gives the decision half only, and many standard reductions from SAT are not parsimonious. In addition, every map must be shown polynomial-time on the CookLevin machine model, which the paper asserts "by inspection".
Lean conventions:
ℕ × ℕ (column, row), the difference-diagonal is computed in ℤ, and sets of queens are Finset (ℕ × ℕ);List of Problem 4 instances, and its sum-diagonal condition applies to distinct indices;Set.ncard of solution sets, which are finite.The constructions (Definitions 10, 16, 20, 24, 26–28, 31) are transcribed as defs, never chosen by Classical.choice. Each reduction theorem fixes its output to the code of the paper's construction.
Trivializing formalizations are ruled out explicitly:
List Bool languages, not Prop-valued predicates;ncard of an infinite set is ;CookLevin.IsPolyTimeComputable;Infrastructure that is reusable beyond this mission: the #P definitions and their closure under composition of parsimonious reductions, and polynomial-time computability of list and arithmetic manipulations on unary codes, for which the published WordRAM simulation (CookLevin.ramPolyTime_to_tm_poly, CookLevin.polyTimeComputable_comp) is the intended route. A parsimonious Cook–Levin theorem would serve every future #P-completeness result. Contributions are welcome on any milestone; the gadget lemmas (33–35) and the arithmetic facts (Lemma 9, Observations 6 and 29, Lemma 30) are self-contained and decidable on finite data.
namespace NQueensComp.NPC /-- Theorem 37, p. 836: the n-Queens Completion problem (Problem 2) is NP-complete and #P-complete. -/ theorem theorem_37 : CookLevin.NPComplete NQC ∧ SharpPComplete countNQC := by sorry end NQueensComp.NPC
In n-Queens Completion (Problem 2) an instance is a board size and a set of queens on the board, no two in the same row or column; a solution is a placement of mutually non-attacking queens on the board that contains .
Theorem 37. The n-Queens Completion problem is NP-complete and #P-complete:
where is the language of codes of instances that have a completion and is the number of completions of the instance coded by ( if codes no instance).
The plain n-Queens problem is trivial as a decision problem; the theorem shows that its 1850 completion variant is as hard as any problem in NP, and that counting completions is as hard as any problem in #P. It is the main result of the paper.
Formalization Note NP-completeness is CookLevin.NPComplete on the published CookLevin machine model. #P-completeness is SharpPComplete: the count equals the number of accepted certificates of a CookLevin NP verifier, and every #P function reduces to it by a polynomial-time map preserving the count exactly. The board size is written in unary, so the code of an instance has at least bits (p. 820). The statement assumes nothing about the hardness of any other problem.
Differences from the source:
InSharpP); #P-hardness: every #P function reduces to it by a polynomial-time map that preserves the count exactly (SharpPHard); reason: the strongest standard reading; it implies #P-hardness under polynomial-time Turing reductions, and the paper's chain of reductions is parsimoniousCookLevin.encodeNat / encodeListNat; a finite set is coded by a duplicate-free list of its elements (any order); strings that code no valid instance are no-instances with count 0; reason: meets the p. 820 assumption; a string codes at most one instance, so the count is the instance's number of solutionsInst2.Valid asks n ≥ 1; reason: Problem 1 requires n ≥ 1, so ⟨0, P⟩ has no solution in either reading; the language and the count are unchangedNo open leaves. Every sub-goal is proved or awaiting decomposition.