Documentation

DescriptiveComplexity

Descriptive complexity in Lean 4 #

A library for descriptive complexity built on Mathlib's ModelTheory: machine-model-free hardness reductions and a logically-defined polynomial hierarchy, in the style of Immerman's Descriptive Complexity (Immerman 1999).

Complexity theory is largely absent from Mathlib because formalizing a model of computation with resource bounds is hard. The observation this library rests on is that many classical NP-hardness reductions do not need the full strength of a Turing machine: they are first-order expressible. Classically, an FO reduction is computable in AC⁰ ⊆ LOGSPACE ⊆ PTIME, so exhibiting one is strictly stronger than exhibiting a Karp reduction (Karp 1972), while needing no machine model at all – only first-order logic, which Mathlib already provides.

This page is the high-level map of the library, part by part. The README gives the general pitch; the worked examples in DescriptiveComplexity.Examples.ConjunctiveQueries (conjunctive-query evaluation and containment) and DescriptiveComplexity.Examples.GraphCrawling (Web data acquisition, with a cardinality threshold, a reachability certificate and an ordered reduction) are the hands-on tutorials; individual declarations are documented on their own pages.

The framework: problems, interpretations, reductions #

The abstract complexity layer #

The polynomial hierarchy, defined logically #

Polynomial time, by the Horn fragment #

Nondeterministic logarithmic space, by the Krom fragment #

Polynomial space, by second-order transitive closure #

Value invention, towards the recursively enumerable #

Shared encodings #

The bridge to Mathlib's computability layer #

Every class of this development is defined by a logic, and every problem is an isomorphism-closed property of finite structures. ComputablePred and REPred, on the other hand, are predicates on a Primcodable type, so relating the two needs a passage from isomorphism classes to data. It is built once for the catalog rather than once per problem.

The problem catalog #

DescriptiveComplexity.Problems holds one decision problem per file, each with its vocabulary, FO reductions and a completeness theorem. Every class in the table below is defined logically; each problem listed is proved complete for it – both a member and hard under FO reductions. The catalog covers all of Karp's 21 NP-complete problems. Each problem's own module page documents its reduction and certificate in full.

Complexity classLogical characterizationMachine modelProblems proved complete
LOGSPACE (L)FO(DTC): first-order logic with a deterministic transitive closuredeterministic two-way k-head automaton †REACHd · UNREACHd
NLSO-Krom: ∃SO with a Krom kernel, at most two second-order literals per clause; equivalently FO(TC), first-order logic with a transitive closuretwo-way k-head automaton †REACH · UNREACH · 2SAT
PTIME = Σ₀ᵖ = Π₀ᵖSO-Horn: ∃SO with a Horn kernel; equivalently FO(LFP), first-order logic with a least fixed pointdeterministic polynomial-time Turing machineHORN-SAT
NP = Σ₁ᵖ∃SO: existential second-order logicnondeterministic polynomial-time Turing machineSAT-family: SAT · 3SAT · NAE-SAT · NAE-3SAT · 1-in-SAT<br>Coloring: 3-Colorability · k-Colorability (k ≥ 3) · Chromatic Number · Clique Cover<br>Cliques & subgraphs: Clique · Independent Set · Vertex Cover · Subgraph Isomorphism<br>Sets & hypergraphs: Set Cover · Hitting Set · Set Packing · Exact Cover · Set Splitting · Dominating Set · 3-Dimensional Matching<br>Graphs: Feedback Vertex Set · Feedback Arc Set · Steiner Tree (node- & edge-weighted) · Max Cut · Hamilton Circuit (directed & undirected)<br>Numbers (in binary): Knapsack · Partition · 0-1 Integer Programming · Job Sequencing<br>Machines: acceptance by a nondeterministic polynomial-time Turing machine
coNP = Π₁ᵖ∀SO: universal second-order logicnondeterministic polynomial-time Turing machine, accepting when every run doesTAUT · 3-DNF-TAUT · 3-UNSAT (and QBF∀ at one block) · ATMAccept 1 false
DPa Σ₁ and a Π₁ sentence conjoinedSAT-UNSAT
Σₖᵖ (k ≥ 1)Σₖ¹: k alternating second-order quantifier blocks, existential firstalternating polynomial-time Turing machine, k blocks, existential firstQBF k – at k = 1, NP · ATMAccept k true
Πₖᵖ (k ≥ 1)Πₖ¹: k alternating second-order quantifier blocks, universal firstthe same machine, universal firstQBF∀ k – at k = 1, coNP · ATMAccept k false
PHfull second-order logic
PSPACESO(TC): second-order logic with a transitive closure over assignments of a block of relation variablespolynomial-space Turing machine, deterministic or notSUCCINCT-REACH · QSAT · space-bounded machine acceptance (deterministic & not)
RE∃SO[new]: ∃SO with value invention, the relation variables ranging over the universe extended by finitely many invented valuesTuring machine with no step bound and no space boundFINSAT (Trakhtenbrot's theorem) · CODEHALT · HALT · PCP (Post's correspondence problem)

Each entry of the machine model column is an equivalence proved here between the logical definition of the class and acceptance by that model: DescriptiveComplexity.mem_LOGSPACE_iff_automaton and DescriptiveComplexity.mem_NL_iff_automaton (†), and, through the completeness of an acceptance problem, DescriptiveComplexity.mem_PTIME_iff_le_dtmAccept, DescriptiveComplexity.mem_NP_iff_le_ntmAccept, DescriptiveComplexity.le_dtmAcceptSpace_of_mem_PSPACE and DescriptiveComplexity.mem_RE_iff_rePred. A dash marks a class for which no such equivalence is proved here.

† Capture theorems, both directions: DescriptiveComplexity.mem_NL_iff_automaton for NL, and DescriptiveComplexity.mem_LOGSPACE_iff_automaton for LOGSPACE, where the machine is required to be deterministic.

Headline results and cross-references:

Worked examples #