Skip to content

About

Lean 4 formalization: moral path decompositions of Boolean circuits, exact #SAT counting, and a size lower bound for self-linked circuits

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Moral pathwidth of Boolean circuits, exact #SAT counting, and self-linkage in Lean 4

Lean build Lean 4.36.0-rc2 License: Apache 2.0

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 $n$ inputs and $s$ gates, each gate having two distinct children, with every vertex reaching the output. Its moral graph joins each gate to its two children and the two children to each other, so every gate contributes a triangle. The project proves, conditional on one published graph-theoretic theorem:

  • 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.

What is verified

Throughout, C : Circuit V is a circuit on a finite vertex type V with input set C.X. Write $n$ for C.X.card and $s$ for Fintype.card V - C.X.card. The definitions are in Selflinked/TheoremD.lean.

1. Wire expansion and the reduction to subcubic layouts

The wire expansion $Q$ (Circuit.expansionGraph in HCore.lean) replaces each vertex by a centre and one port per outgoing wire. It has $n + 3s$ nodes and the following properties.

Statement Declaration
$Q$ has maximum degree at most 3 Circuit.expansionGraph_deg_le_three
$Q$ is connected when every vertex reaches the output Circuit.expansion_conn
$Q$ has cycle rank $s - n + 1$ Circuit.expansionGraph_cycle_rank

Peeling leaves and suppressing degree-two vertices reduces $Q$ to a cubic kernel on $2(s - n)$ vertices (HPeel, HPeelOrder, HSuppress, HCoreOrder, HKernel). A low-boundary order of the kernel lifts back to an order of $Q$ with a logarithmic loss (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.

2. Moral path decompositions covering every gate triangle

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 $n \ge 2$. Then C has a moral path decomposition with exactly $n + 3s$ bags, each of size at most

$$2a(s - n + 1) + b + 50 + 3\lceil \log_2 (n + 5s + 2)\rceil .$$

With $a = 1/6 + \delta$ the leading term is $(1/3 + 2\delta)(s - n)$. Circuit.exists_pathDecomp_of_subcubicPathwidth states the same bound directly from the pathwidth hypothesis.

3. Exact #SAT counting by dynamic programming

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 $(3L + 2) \cdot 2^k$ row operations for $L$ bags of size at most $k$ MoralPathDecomp.rowOps_le HCountRun.lean
Under LayoutBound a b, some decomposition costs at most $(3(n + 3s) + 2) \cdot 2^k$ row operations, with $k$ the bag bound of Theorem H Circuit.exists_counting_decomp HCountBound.lean
For every size cap $s \le cn$ and every $\varepsilon > 0$, all large enough circuits have a decomposition costing at most $2^{(s-n)/3 + \varepsilon n}$ row operations exists_counting_decomp_eventually HCountAsymptotics.lean

4. A size lower bound for self-linked circuits

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

$$n \le 2a(s - n + 1) + b + 50 + 3\lceil \log_2 (n + 5s + 2)\rceil .$$

Theorem H′, asymptotic form (selfLinked_size_eventually in HAsymptotics.lean). Assume the pathwidth hypothesis with coefficient $1/6 + \delta$ for every $\delta > 0$. Then for every $\varepsilon > 0$ there is an $N$ such that every self-linked circuit with $n \ge N$, in which every vertex reaches the output, has $s \ge (4 - \varepsilon)n$. That is, $s \ge (4 - o(1))n$.

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 $n$ vertices (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 $n$ (Strat.card_X_le_exponent).

5. Superconcentrators are self-linked

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

Building

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 build

lake 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 and external hypotheses

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 &gt; 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 + 1

This 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 b for arbitrary a and b. 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.

Scope and limits

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.rowOps counts 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 RouteRealization certificates 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.SelfLinked and Circuit.gainStar in TheoremD.lean; TreeDecomp in TheoremsEF.lean; MoralPathDecomp, Circuit.AllReach and LayoutBound in TheoremH.lean; SimplePathBags and SubcubicPathwidth in HLayoutTransfer.lean; Circuit.eval and Circuit.bagCheck in HCountCircuit.lean; and MoralPathDecomp.count and MoralPathDecomp.rowOps in HCountRun.lean.

Related work

The counting exponent $(s - n)/3$ is not new to this project. S. Schlesinger's manuscript SAT and Exact Counting Below Four Gates per Input (September 2026) obtains it by tensor contraction, also from cycle rank and the Fomin–Høie theorem. This repository is a formalization. It makes no priority claim.

Layout

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 $Q$
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 $Q$ to bags of the moral graph
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

AI assistance

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.

License

Copyright 2026 Nikhil Gopal. Released under the Apache License 2.0, the license used by Mathlib.

About

Lean 4 formalization: moral path decompositions of Boolean circuits, exact #SAT counting, and a size lower bound for self-linked circuits

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages