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 with fewer than2^N / (5N)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): Any fan-in-2 AND/OR circuit computing N-input XOR (or its complement) requires at least2(N − 1)internal gates.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.
Module structure #
Public modules (definitions a reviewer should read):
Complexitylib.Circuits.Basic—BitString,BoolFunFamily,Circuit,Basis,Gate,CompleteBasis,Realizable,sizeComplexityWithTop,sizeComplexity,wireDepth,depthComplexitylib.Circuits.BitString— canonical bridges betweenBitString nandList BoolComplexitylib.Circuits.Composition— serial circuit composition with exact additive size, exact semantics, and additive depthComplexitylib.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.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.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, andTChierarchies, and the aliasesNC0,NC1,AC0, andTC0Complexitylib.Circuits.AC0— theAC0class plus finite nonuniform negation-normal formulas, circuit normalization, exact restrictions, width-sensitive switching, finite staged iteration, and the exact parity counting obstructionComplexitylib.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.LowerBound— gate elimination lower boundComplexitylib.Circuits.Schnorr— Schnorr's XOR lower boundComplexitylib.Circuits.Nondeterminism— nondeterministic quantification complexity boundsComplexitylib.Circuits.Valiant— Valiant's depth reduction lemma for digraphs
Internal modules contain proof machinery (CircDesc, DNF construction, restriction/elimination arguments) and are not intended for direct use.