A machine-checked formalization, in Lean 4 with Mathlib, of a structural bound on fan-in-two Boolean circuits and two of its consequences.
Take a circuit with
- the moral graph has a path decomposition with
$n + 3s$ bags, each of size about$(s - n)/3$ ; - a dynamic program over those bags counts the satisfying inputs exactly, in about
$2^{(s-n)/3}$ table-row operations; - a self-linked circuit, where disjoint input sets can always be joined by vertex-disjoint routes, must
have
$s \ge (4 - o(1))n$ gates.
The project has 28 modules and about 6,800 lines. It has no sorry and declares no axioms. The one
external ingredient, Fomin and Høie's pathwidth bound for graphs of maximum degree three, enters as an
explicit hypothesis. See Axioms and external hypotheses.
Throughout, C : Circuit V is a circuit on a finite vertex type V with input set C.X. Write
C.X.card and Fintype.card V - C.X.card. The definitions are in
Selflinked/TheoremD.lean.
The wire expansion Circuit.expansionGraph in HCore.lean) replaces each
vertex by a centre and one port per outgoing wire. It has
| Statement | Declaration |
|---|---|
|
|
Circuit.expansionGraph_deg_le_three |
|
|
Circuit.expansion_conn |
|
|
Circuit.expansionGraph_cycle_rank |
Peeling leaves and suppressing degree-two vertices reduces HPeel, HPeelOrder, HSuppress, HCoreOrder, HKernel). A low-boundary order of the kernel lifts
back to an order of HBlob, HLinearize, HOrderBasic, HBridge,
HSpine).
HLayoutTransfer.lean connects this to the literature. It defines
path decompositions of a simple graph (SimplePathBags), states the published pathwidth bound in that
form (SubcubicPathwidth), and proves in SubcubicPathwidth.exists_layoutBound that it gives the
vertex-order hypothesis LayoutBound used by the rest of the project.
A MoralPathDecomp C is a list of bags in which every vertex occupies an interval of positions and
every gate lies in a common bag with both of its children.
Theorem H (Circuit.exists_pathDecomp_length in TheoremH.lean).
Assume LayoutBound a b, an output o that every vertex reaches, and C has a moral
path decomposition with exactly
With Circuit.exists_pathDecomp_of_subcubicPathwidth states the same bound directly from the pathwidth
hypothesis.
| Statement | Declaration | File |
|---|---|---|
| Sweeping the bags with per-bag gate checks returns the number of input assignments on which the circuit outputs true. Gates may carry arbitrary binary Boolean operations. | MoralPathDecomp.count_circuit |
HCountCircuit.lean |
| One scatter pass over the old table computes the projection used by each transition | scatterRows_eq_projectTable |
HScatter.lean |
| A sweep costs at most |
MoralPathDecomp.rowOps_le |
HCountRun.lean |
Under LayoutBound a b, some decomposition costs at most |
Circuit.exists_counting_decomp |
HCountBound.lean |
| For every size cap |
exists_counting_decomp_eventually |
HCountAsymptotics.lean |
Circuit.SelfLinked is property P: for all disjoint input sets A and B of equal size there are
pairwise vertex-disjoint child-to-parent paths, one from each member of A, each ending at a co-child of
a member of B.
Theorem H′, finite form (Circuit.selfLinked_size_bound in HPrime.lean).
Under the hypotheses of Theorem H, a self-linked circuit satisfies
Theorem H′, asymptotic form (selfLinked_size_eventually in
HAsymptotics.lean). Assume the pathwidth hypothesis with coefficient
The proof combines Theorem H with a width obstruction proved in
TheoremsEF.lean: every tree decomposition of the moral graph of a
self-linked circuit has a bag with at least Circuit.exists_bag_card_ge). Two related
results about cuts are also proved there and in TheoremD.lean: no cut of a
self-linked circuit has positive gain (Circuit.deltaStar_eq_zero), and every recursive cut strategy has
exponent at least Strat.card_X_le_exponent).
| Statement | Declaration | File |
|---|---|---|
| A circuit that routes every pair of equal-size input sets by vertex-disjoint paths to designated outputs, with a tie gate joining each output to its input, is self-linked | Circuit.selfLinked_of_superconcentrates |
Superconcentrator.lean |
| Replacing each wire of a routing network by a private path segment preserves the routes and their disjointness, so a realized superconcentrator with ties is self-linked | Circuit.selfLinked_of_realization |
RouteRealization.lean |
You need elan, the Lean toolchain manager. It installs the
version named in lean-toolchain the first time lake runs.
curl -sSfL https://elan.lean-lang.org/elan-init.sh | sh # skip if elan is installed
git clone https://github.com/ng4567/circuit-moral-pathwidth.git
cd circuit-moral-pathwidth
lake exe cache get # download prebuilt Mathlib
lake buildlake exe cache get fetches compiled Mathlib, about 7 GB on disk, so that only this project is
compiled. lake build then takes about two minutes on a ten-core laptop and ends with
Build completed successfully. It also prints style-linter warnings (long lines, missing file
headers, unused variable names, deprecated lemma names). These do not affect correctness.
Versions are pinned. lean-toolchain fixes Lean at v4.36.0-rc2, lakefile.toml requires the
matching Mathlib tag, and lake-manifest.json records the exact commit of Mathlib and of every
transitive dependency.
The CI workflow runs the same steps on every push and pull request, and
fails if the build log reports a sorry.
Axioms. The project contains no axiom declarations, no sorry, and no native_decide. Every
headline theorem depends only on Lean's three standard axioms:
propext(propositional extensionality),Classical.choice(the axiom of choice),Quot.sound(soundness of quotients).
Selflinked/AxiomAudit.lean checks this during the build. It runs
#print axioms under #guard_msgs on the twenty theorems named in the sections above, so the build
fails if any of them gains an axiom, sorryAx included. To inspect another declaration, add
#print axioms <name> to any file.
The external hypothesis. One published theorem is used and not proved here:
F. V. Fomin and K. Høie, Pathwidth of cubic graphs and exact algorithms, Information Processing Letters 97(5):191–196, 2006. doi:10.1016/j.ipl.2005.10.012
For every
$\delta > 0$ , every sufficiently large graph of maximum degree at most three on$m$ vertices has pathwidth at most$(1/6 + \delta)m$ (Theorem 5 and Section 4).
It appears as the proposition SubcubicPathwidth a in
HLayoutTransfer.lean:
def SubcubicPathwidth (a : ℝ) : Prop :=
∃ threshold : ℕ, ∀ (W : Type) [Fintype W] [DecidableEq W]
(G : SimpleGraph W) [DecidableRel G.Adj],
(∀ v, (Finset.univ.filter fun u => G.Adj v u).card ≤ 3) →
threshold < Fintype.card W →
∃ D : SimplePathBags G, ∀ i < D.length, ((D.bag i).card : ℝ) ≤ a * Fintype.card W + 1This is a definition, not an axiom. The theorems that need it take it as a hypothesis, and each says which form it needs:
- The finite statements (Theorem H, the row-operation bound, the finite Theorem H′) assume
LayoutBound a bfor arbitraryaandb. They are parametric in the width coefficient, so any other bound on subcubic pathwidth can be substituted. - The asymptotic statements assume
∀ δ > 0, SubcubicPathwidth (1/6 + δ), which is the Fomin–Høie theorem.
A formal proof of the Fomin–Høie theorem would need their partition construction and the Monien–Preis bisection bound. Neither is formalized here.
What a reader should not infer from the build passing:
- The results are conditional. Nothing here proves the Fomin–Høie theorem.
-
Cost is counted in row operations, not time.
MoralPathDecomp.rowOpscounts table rows initialized, scattered and looked up. The project does not model a machine, so it does not prove a running time or a bit complexity, and it does not prove that the decomposition can be computed efficiently. Theorem H is an existence statement. -
Circuit hypotheses. The two children of a gate are distinct (
Circuit.c_ne). Theorem H and its consequences assume$n \ge 2$ and that every vertex reaches the output (Circuit.AllReach). -
Superconcentrators. The project proves that a circuit with superconcentrator routing and tie
gates is self-linked. It does not construct a superconcentrator, and it does not build the
RouteRealizationcertificates from a concrete network. -
Definitions need human reading. Lean checks that the proofs match the statements. Whether the
statements say what is intended is for the reader to judge. The definitions to read are
Circuit,Circuit.Adj,Circuit.SelfLinkedandCircuit.gainStarinTheoremD.lean;TreeDecompinTheoremsEF.lean;MoralPathDecomp,Circuit.AllReachandLayoutBoundinTheoremH.lean;SimplePathBagsandSubcubicPathwidthinHLayoutTransfer.lean;Circuit.evalandCircuit.bagCheckinHCountCircuit.lean; andMoralPathDecomp.countandMoralPathDecomp.rowOpsinHCountRun.lean.
The counting exponent
| Path | Contents |
|---|---|
Selflinked.lean |
Root module, imports everything |
Selflinked/TheoremD.lean |
Circuit model, moral graph, property P, Theorem D |
Selflinked/TheoremsEF.lean |
Tree decompositions, Theorems E and F |
Selflinked/HCore.lean |
Multigraphs, signal bags, the wire expansion |
Selflinked/HLayout.lean, HKernel.lean, HOrderBasic.lean, HLinearize.lean
|
From a layout hypothesis to low-cut orders of subcubic multigraphs |
Selflinked/HPeel.lean, HPeelOrder.lean, HSuppress.lean, HCoreOrder.lean, HBlob.lean
|
Leaf peeling, degree-two suppression, the cubic kernel |
Selflinked/HBridge.lean, HSpine.lean, HPathDecomp.lean
|
From an order of |
Selflinked/TheoremH.lean |
Lemma W and Theorem H |
Selflinked/HLayoutTransfer.lean |
The pathwidth hypothesis and its transfer to LayoutBound
|
Selflinked/HCount.lean, HCountRun.lean, HCountCircuit.lean, HScatter.lean
|
The counting recurrence and its correctness |
Selflinked/HCountBound.lean, HCountAsymptotics.lean
|
Row-operation bounds |
Selflinked/HPrime.lean, HAsymptotics.lean
|
Theorem H′ |
Selflinked/Superconcentrator.lean, RouteRealization.lean
|
Superconcentrators and property P |
Selflinked/AxiomAudit.lean |
Build-time axiom check |
This formalization was developed with AI assistance (T3 Code, Codex and Antigravity), which wrote much of the Lean code. Every proof is checked by the Lean kernel, so the proofs do not rest on trusting those tools. The kernel cannot vouch for the definitions and statements, which is why they are listed under Scope and limits for inspection.
Copyright 2026 Nikhil Gopal. Released under the Apache License 2.0, the license used by Mathlib.