Circuit Complexity Library #
A Lean 4 formalization of classical results in Boolean circuit complexity, built on Mathlib.
The circuit model #
A Circuit B N M G is an acyclic Boolean circuit over basis B with N
primary inputs, M outputs, and G internal gates. The circuit's size
is G + M: internal and output gates are counted, while primary-input
vertices and per-edge negation flags are not. For an arbitrary basis,
sizeComplexityWithTop is the minimum size of any circuit computing a Boolean
function, with ⊤ for an unrealizable function. The natural-valued
sizeComplexity interface is available for complete bases.
Main results #
Functional completeness (
CompleteBasis Basis.unboundedAndOr): Unbounded fan-in AND/OR (with free negation) can compute every Boolean function, via DNF construction.Shannon counting lower bound (
shannon_lower_bound_circuit): ForN ≥ 6, there exists a Boolean function onNinputs that cannot be computed by any fan-in-2 AND/OR circuit of total sizeG + 1at most⌊2^N / (5N)⌋, whereGcounts internal gates.Essential-input lower bound (
Circuit.card_essentialInputs_le_totalFanIn): Over every basis, essential inputs are bounded by total fan-in. For bounded fan-inkAND/OR this yieldsn' ≤ k · size.Schnorr's XOR lower bound (
schnorr_lower_bound_circuit,parity_size_ge_three_mul): Any fan-in-2 AND/OR circuit computing N-input XOR (or its complement) requires at least2(N − 1)internal gates, and has size at least3(N − 1)by three-gate elimination.CNF/DNF lower bound for XOR (
DNF.two_pow_le_complexity_of_xorBool,CNF.two_pow_le_complexity_of_xorBool): Any DNF (resp. CNF) computing N-input XOR requires at least2^{N-1}terms (resp. clauses).Nondeterministic quantification (
sizeComplexity_existsQuantify_le): Iffhas circuit complexitys, then∃ x ∈ {0,1}^k, f(x,y)has circuit complexity at most2^k · (s + 1). Combined with the Shannon upper bound (sizeComplexity_existsQuantify_le_min).Valiant's depth reduction (
Valiant.depth_reduction): In any acyclic digraph withSedges and depth at most2^k, for anyr ≤ kone can remove a set of at mostr · S / kedges so that the remaining digraph has depth at most2^k / 2^r.Barrington's theorem (
barrington_equivalence): Variable-bounded logarithmic-depth formula families are exactly variable-bounded polynomial-length width-5permutation branching-program families as sets of typedBoolFunFamily. The finite forward theorembarrington_representation_depth_fourgives the textbook length bound4 ^ depth, andbarrington_quadratic_of_log_depthspecializes it ton²at depth at mostlog₂ n.barringtonCompile_representationsupplies the same finite theorem through an explicit executable compiler rather than an existential choice.NC1_subset_Width5BPapplies the typed theorem directly to actual nonuniformNC1circuit families. The olderbarrington_equivalence_onTotalAssignmentsremains as an explicitly named theorem for syntax families whose domain really isℕ → Bool.Spira formula balancing (
BoolFormula.exists_spira_balanced): Every finite Boolean formula has an equivalent formula of logarithmic depth and polynomial tree size, with explicit quantitative bounds.Monotone Karchmer--Wigderson correspondence (
KarchmerWigderson.Protocol.exists_protocol_depth_iff_formula_depth): root communication protocols and monotone formulas exist at exactly the same depth.Threshold simulation (
AC_subset_TC): Exact basis transport embeds every nonuniformAC^ifamily in nonuniformTC^iwithout changing circuit size or depth.Finite AC0 obstruction for parity (
AC0Formula.parity_counting_obstruction): Iterated width switching, exact staged-restriction semantics, and the decision-tree lower bound for parity yield a division-free finite counting inequality for every depth-bounded unbounded AND/OR formula computing parity.Parity separates
AC0fromTC0(xorBool_not_mem_AC0,xorBool_mem_TC0,AC0_ssubset_TC0): parity is not computed by any polynomial-size constant-depth unbounded AND/OR family, but depth-two threshold circuits of sizeN + 1compute it, soAC0 ⊂ TC0. Strict majority is not inAC0either (majority_not_mem_AC0), by the top-down gate-count bound.Razborov–Smolensky (
xorBool_not_mem_AC0Mod_three,Smolensky.parity_size_lower_bound): parity is not inAC0[3]; a depth-dAND/OR/MOD_3circuit computingn-bit parity has size at least(2/5) · 2^ℓwhenever(40ℓ)^{2d} ≤ n, by approximation with low-degree functions overZMod 3. HenceTC0 ⊄ AC0[3](not_TC0_subset_AC0Mod_three).Exponentially small correlation (
Correlation.eventually_correlation_hardForm_le): fan-in-two circuits over any basis with at mostc ngates of positive arity, for anyc < 1 + π/(6 arccos((1 + 2√2)/4)) ≈ 2.78, have correlation2^{-Ω(n)}with an explicit family of bilinear forms overGF(2), by Lindsey's lemma on the rectangles of the frontier method.
Module structure #
Public modules (definitions a reviewer should read):
Complexitylib.Circuits.Basis.Defs—BitString,BoolFunFamily,Arity,Basis, and a basis as a CSLib signature (Basis.GateKind,Basis.signature,Basis.interpretation)Complexitylib.Circuits.Typed.Defs—Gate,Circuit,eval,wireDepth,depth,size,CompleteBasisComplexitylib.Circuits.Basic—Realizable,sizeComplexityWithTop,sizeComplexity; re-exportsBasis.DefsandTyped.DefsComplexitylib.Circuits.BitString— canonical bridges betweenBitString nandList BoolComplexitylib.Circuits.Composition— serial circuit composition with exact additive size, exact semantics, and additive depthComplexitylib.Circuits.OracleInlining— exact one-step adaptive oracle replacement with explicit size accountingComplexitylib.Circuits.OracleInlining.Adaptive— fixed-round adaptive oracle programs and exact compilation to ordinary circuitsComplexitylib.Circuits.Dependency— the finite circuit dependency DAG, its canonical topological order, and its edge bound by total fan-inComplexitylib.Circuits.DecisionTree.Restriction— semantic restriction with nonincreasing decision-tree depthComplexitylib.Circuits.DecisionTree.Finite— arity-indexed decision trees with exact finite restriction semanticsComplexitylib.Circuits.DecisionTree.NormalForm— exact decision-tree compilation to CNF and DNF with depth-controlled widthComplexitylib.Circuits.RandomRestriction— the finite sparse-restriction sample space with exact cardinalitiesComplexitylib.Circuits.Spira— finite nonuniform formula balancing with explicit logarithmic-depth and polynomial-size boundsComplexitylib.Circuits.CircuitFormula— exact selected-output unfolding from fan-in-two circuit DAGs to Boolean formulas, with a factor-two depth boundComplexitylib.Circuits.FormulaEncoding— canonical iterative postfix formula codec with exact round trips and code lengthComplexitylib.Circuits.CircuitFormula.Family— family-level unfolding and the typed-NC1bridge to width-5branching programsComplexitylib.Circuits.Family— circuit families, list semantics, pointwise size/depth bounds, and the polynomial-size characterizationComplexitylib.Circuits.BarringtonConverse— balanced branching-program evaluation and the explicitly total-assignment equivalenceComplexitylib.Circuits.BarringtonTyped— variable-bounded fixed-arity formula/program families and the typed nonuniform Barrington equivalenceComplexitylib.Circuits.BarringtonCompiler— executable finiteS₅search and formula-to-program compilation with the4 ^ depthboundComplexitylib.Circuits.BranchingProgramEncoding— canonical seven-bit permutation ranks, instruction/program codecs, and exact size boundsComplexitylib.Circuits.BarringtonCodeGenerator— the total bitstring-level formula-code-to-program-code target for the remainingFLimplementationComplexitylib.Circuits.Encoding— canonical proof-free encoding, validation, and iterative evaluation of fan-in-two AND/OR circuitsComplexitylib.Circuits.Encoding.Family— tagged encoding and evaluation at every input length, including the explicit empty-input answerComplexitylib.Circuits.Encoding.Machine— total linear-time validation and tape staging plus the verified end-to-end quadratic serialized circuit-family evaluatorComplexitylib.Circuits.Encoding.Machine.NatCode— framed, one-way terminated-unary natural-code emission from a preserved binary value, with reusable zero scratch and explicit time/all-prefix-space boundsComplexitylib.Circuits.AndOrNot.Defs—AndOrOp,Basis.unboundedAndOr,Basis.boundedAndOr,Basis.andOr2Complexitylib.Circuits.AndOrNot— functional completeness and a semantic, total-fan-in size bound for compiling unbounded AND/OR to fan-in twoComplexitylib.Circuits.AndOrMod.Defs—AndOrModOp,Basis.unboundedAndOrMod(unbounded AND, OR, andMOD_mgates)Complexitylib.Circuits.BasisHom— exact semantics-, size-, depth-, and topology-preserving circuit transport between compatible basesComplexitylib.Circuits.Threshold— unweighted threshold gates, strict majority, and exact unbounded-AND/OR simulationComplexitylib.Circuits.Threshold.Parity— depth-two threshold circuits for parity and parity inTC0Complexitylib.Circuits.Monotone— typed monotone formulas, locality, monotonicity, and essential-input leaf lower boundsComplexitylib.Circuits.KarchmerWigderson— rectangle-indexed deterministic protocols and the depth-exact monotone formula correspondenceComplexitylib.Circuits.NormalForm.Defs—Literal,CNF,DNF, clause/term count, and widthComplexitylib.Circuits.NormalForm— CNF/DNF lower bound for XOR (two_pow_le_complexity_of_xorBool)Complexitylib.Circuits.NormalForm.Operations— semantic negation, conjunction, and disjunction operations on CNFs and DNFsComplexitylib.Circuits.NormalForm.Restriction— semantic CNF/DNF simplification with nonincreasing width and clause/term countComplexitylib.Circuits.XOR—Schnorr.xorBool(N-input parity)Complexitylib.Circuits.EssentialInput—IsEssentialInput,essentialInputsComplexitylib.Circuits.DepthClasses—DEPTH, the nonuniformNC,AC,ACMod, andTChierarchies, and the aliasesNC0,NC1,AC0,AC0Mod, andTC0Complexitylib.Circuits.AC0— theAC0class plus finite nonuniform negation-normal formulas, circuit normalization, exact restrictions, width-sensitive switching, finite staged iteration, the exact parity counting obstruction, parity outsideAC0, andAC0 ⊂ TC0Complexitylib.Circuits.Smolensky.Defs—Smolensky.monomialandSmolensky.lowDegree, low-degree functions{0,1}^n → ZMod 3Complexitylib.Circuits.Correlation.Defs—Correlation.correlation, quadratic forms overGF(2)(Correlation.quadForm,Correlation.bilinForm), block and cut ranks, and submatrix-robust matricesComplexitylib.Circuits.Nondeterminism.Defs—existsQuantify,forallQuantifyComplexitylib.Circuits.Hardwiring— exact-size prefix hardwiringComplexitylib.Circuits.Unrolling— bounded machine-configuration layouts, initialization, verified trace tiling, typed acceptance circuits, exact-size fixed-choice hardwiring, and parallel strict-majority amplification
Theorem modules (re-export definitions + main results):
Complexitylib.Circuits.AndOrNot— functional completeness of AND/ORComplexitylib.Circuits.Shannon— Shannon counting lower boundComplexitylib.Circuits.Shallow— the Lecomte--Ramakrishnan shallow-circuit upper bound for symmetric functions, directly in CSLib's circuit modelComplexitylib.Circuits.LowerBound— gate elimination lower boundComplexitylib.Circuits.Frontier— the frontier method: circuit lower bounds from graph layouts over any finite alphabet, basis, and fan-inComplexitylib.Circuits.Correlation— exponentially small correlation of fan-in-two circuits with fewer than2.78 ngates with explicit quadratic forms overGF(2)Complexitylib.Circuits.Schnorr— Schnorr's XOR lower boundComplexitylib.Circuits.Smolensky— the Razborov–Smolensky lower bound forAC0[3]Complexitylib.Circuits.Nondeterminism— nondeterministic quantification complexity boundsComplexitylib.Circuits.Valiant— Valiant's depth reduction lemma for digraphsComplexitylib.Circuits.StraightLine— typed circuits as CSLib straight-line programs, with the same function and size
Internal modules contain proof machinery (CircDesc, DNF construction, restriction/elimination arguments) and are not intended for direct use.