Documentation

CslibFrontier.Computability.Circuit.Frontier.Closure

Forward DAG closure, 2-SAT frontier states, and fan-out slicing #

This module develops three structural refinements of the frontier compiler:

  1. Forward DAG closure (Program.DagSpan, Program.depthOneDetermined, Program.forwardDetermined). Along any cut P of Compiler.graph c, a gate wire on the cut whose arguments are already functionally determined by cutWires c P carries zero independent information across the cut. Removing any subset D ⊆ c.program.forwardDetermined (cutWires c P) (in particular D = c.program.depthOneDetermined (cutWires c P)) preserves exact trace agreement on cutWires c P (Program.eqOn_of_eqOn_sdiff_forwardDetermined) and full output splicing (eval_splice_of_eqOn_cutWires_sdiff).
  2. 2-SAT independent-set frontier bound (ForbidsOutputPair, u2ClauseGraph, ncard_frontierValues_le_indepSetCount). In a Boolean circuit, every gate argument a whose operation forbids at least one (arg, out) value pair (ForbidsOutputPair, satisfied on both inputs of every AND-type U₂ gate (u ⊕ c₁) ∧ (v ⊕ c₂) ⊕ c₃) induces a 2-SAT clause across every wire subset R. By SimpleGraph.ncard_le_indepSetCount_of_forall_adj, the number of distinct frontier states at step t is bounded by (u2ClauseGraph c.program I R).indepSetCount on the reduced cut R = cutWires c (π.initial t) \ D (F_{k + 2} on paths, 2 ^ d + 1 on stars).
  3. Unary elimination and universal fan-out slicing (Program.arityExcess, Program.gateConsumers, exists_sliced_fanout_lt, eventually_slicing_surplus). Eliminating nullary and unary gates and deduplicating repeated arguments inside each gate reduces any fan-in-r circuit to one whose gates all have arity in [2, r] and injective argument wires, with gate count bounded by c.program.arityExcess (so unary NOT gates are free). Repeatedly fixing by pigeonhole any wire (input or gate) read by ≥ k binary gates yields a multi-output residual circuit in which every wire feeds < k gates (≤ 4 at k = 5) and proves the fan-out surplus lower bound (1 + 1/A - ε) n + (k - (1 + 1/A)) t < c.program.arityExcess.

Main definitions #

Main results #

Forward DAG closure (D₀ and D*) #

inductive Cslib.Circuits.Program.DagSpan {σ : Signature} {n s : ℕ} (p : Program σ n s) (B : Set (Wire n s)) :
Wire n s → Prop

Wires functionally determined by a base set B along the forward gate equations of p.

def Cslib.Circuits.Program.depthOneDetermined {σ : Signature} {n s : ℕ} (p : Program σ n s) (W : Set (Wire n s)) :
Set (Wire n s)

Depth-one determined wires D₀(W): gate wires in W all of whose arguments also lie in W.

def Cslib.Circuits.Program.forwardDetermined {σ : Signature} {n s : ℕ} (p : Program σ n s) (W : Set (Wire n s)) :
Set (Wire n s)

Full forward-determined wires D*(W): gate wires in W all of whose arguments lie in p.DagSpan W.

theorem Cslib.Circuits.Program.forwardDetermined_subset {σ : Signature} {n s : ℕ} (p : Program σ n s) (W : Set (Wire n s)) :

p.forwardDetermined W is a subset of W.

D₀(W) ⊆ D*(W): depth-one determined wires are forward-determined.

theorem Cslib.Circuits.Program.DagSpan.mono {σ : Signature} {n s : ℕ} {p : Program σ n s} {A B : Set (Wire n s)} (hAB : A ⊆ B) {w : Wire n s} (h : p.DagSpan A w) :
p.DagSpan B w

Monotonicity of Program.DagSpan in the base set.

theorem Cslib.Circuits.Program.dagSpan_sdiff_forwardDetermined {σ : Signature} {n s : ℕ} (p : Program σ n s) (W : Set (Wire n s)) {w : Wire n s} :
p.DagSpan W w → p.DagSpan (W \ p.forwardDetermined W) w

Acyclic basis reduction (DagSpan W = DagSpan (W \ D*(W))). Because p is topologically ordered, removing all forward-determined wires from W leaves the forward DAG span unchanged.

theorem Cslib.Circuits.Program.trace_eq_of_dagSpan {σ : Signature} {n s : ℕ} {U : Type u} {p : Program σ n s} {I : Interpretation σ U} {x y : Fin n → U} {B : Set (Wire n s)} (hB : Set.EqOn (p.trace I x) (p.trace I y) B) {w : Wire n s} (hw : p.DagSpan B w) :
p.trace I x w = p.trace I y w

Two inputs agreeing on B agree on every wire in p.DagSpan B.

theorem Cslib.Circuits.Program.eqOn_of_eqOn_sdiff_forwardDetermined {σ : Signature} {n s : ℕ} {U : Type u} {p : Program σ n s} {I : Interpretation σ U} {W D : Set (Wire n s)} (hD : D ⊆ p.forwardDetermined W) {x y : Fin n → U} (heq : Set.EqOn (p.trace I x) (p.trace I y) (W \ D)) :
Set.EqOn (p.trace I x) (p.trace I y) W

Forward closure soundness (D*). If D ⊆ p.forwardDetermined W, trace agreement on W \ D forces trace agreement on all of W.

theorem Cslib.Circuits.Program.eqOn_of_eqOn_sdiff_depthOneDetermined {σ : Signature} {n s : ℕ} {U : Type u} {p : Program σ n s} {I : Interpretation σ U} {W : Set (Wire n s)} {x y : Fin n → U} (heq : Set.EqOn (p.trace I x) (p.trace I y) (W \ p.depthOneDetermined W)) :
Set.EqOn (p.trace I x) (p.trace I y) W

Depth-one closure soundness (D₀). Trace agreement on W \ p.depthOneDetermined W forces trace agreement on all of W.

theorem Cslib.Circuits.Program.ncard_sdiff_add_ncard_of_subset_forwardDetermined {σ : Signature} {n s : ℕ} {p : Program σ n s} {W D : Set (Wire n s)} (hD : D ⊆ p.forwardDetermined W) :
(W \ D).ncard + D.ncard = W.ncard

Removing D ⊆ p.forwardDetermined W reduces the wire count by D.ncard.

Splicing and 2-SAT independent-set bounds across reduced cuts #

noncomputable def Cslib.Circuits.Frontier.cutWires {σ : Signature} {n m : ℕ} (c : Circuit σ n m) (P : Set (Compiler.Vertex c)) :
Set (Wire n c.size)

The set of circuit wires carried by the edges crossing a vertex cut P.

theorem Cslib.Circuits.Frontier.eval_splice_of_eqOn_cutWires_sdiff {σ : Signature} {n m : ℕ} {U : Type u} {c : Circuit σ n m} {I : Interpretation σ U} {P : Set (Compiler.Vertex c)} {D : Set (Wire n c.size)} (hD : D ⊆ c.program.forwardDetermined (cutWires c P)) {x y z : Fin n → U} (hcut : Set.EqOn (c.program.trace I x) (c.program.trace I y) (cutWires c P \ D)) (hzx : Set.EqOn z x ((Compiler.network c I fun (x : Fin m) => Set.univ).readIn P)) (hzy : Set.EqOn z y ((Compiler.network c I fun (x : Fin m) => Set.univ).readIn P)ᶜ) (o : Fin m) :
(Compiler.Vertex.output o ∈ P → c.eval I z o = c.eval I x o) ∧ (Compiler.Vertex.output o ∉ P → c.eval I z o = c.eval I y o)

Splicing across a forward-reduced cut. If D ⊆ c.program.forwardDetermined (cutWires c P) and x and y agree on cutWires c P \ D, then splicing x inside P with y outside P produces outputs matching x inside P and y outside P.

theorem Cslib.Circuits.Frontier.frontierValues_eq_of_eqOn_cutWires_sdiff {σ : Signature} {n m : ℕ} {U : Type u} {c : Circuit σ n m} {I : Interpretation σ U} {Acc : Fin m → Set U} (π : Layout (Compiler.Vertex c)) {t : ℕ} {D : Set (Wire n c.size)} (hD : D ⊆ c.program.forwardDetermined (cutWires c (π.initial t))) {x y : Fin n → U} (heq : Set.EqOn (c.program.trace I x) (c.program.trace I y) (cutWires c (π.initial t) \ D)) :
((Compiler.network c I Acc).frontierValues π t fun (e : Compiler.Edge c) => c.program.trace I x ↑e.signal) = (Compiler.network c I Acc).frontierValues π t fun (e : Compiler.Edge c) => c.program.trace I y ↑e.signal

Frontier edge values at layout step t are uniquely determined by the trace restricted to cutWires c (π.initial t) \ D for any D ⊆ c.program.forwardDetermined (cutWires c (π.initial t)).

def Cslib.Circuits.Frontier.ForbidsOutputPair {k : ℕ} (f : (Fin k → Bool) → Bool) (a : Fin k) :

A Boolean operation f : (Fin k → Bool) → Bool forbids an output pair on argument a when some pair (ba, bz) ∈ Bool × Bool never occurs as (v a, f v). Every AND-type binary gate (v 0 ⊕ c₁) && (v 1 ⊕ c₂) ⊕ c₃ satisfies this on both arguments, whereas XOR and XNOR do not.

theorem Cslib.Circuits.Frontier.forbidsOutputPair_u2 (c₁ c₂ c₃ : Bool) (a : Fin 2) :
ForbidsOutputPair (fun (v : Fin 2 → Bool) => (v 0 ^^ c₁) && (v 1 ^^ c₂) ^^ c₃) a

Every AND-type U₂ operation (v 0 ⊕ c₁) && (v 1 ⊕ c₂) ⊕ c₃ forbids a pair on each of its two arguments ((c₁, !c₃) on argument 0, (c₂, !c₃) on argument 1).

theorem Cslib.Circuits.Frontier.forbidsOutputPair_and (a : Fin 2) :
ForbidsOutputPair (fun (v : Fin 2 → Bool) => v 0 && v 1) a

Conjunction (&&) forbids (false, true) on both arguments.

theorem Cslib.Circuits.Frontier.forbidsOutputPair_or (a : Fin 2) :
ForbidsOutputPair (fun (v : Fin 2 → Bool) => v 0 || v 1) a

Disjunction (||) forbids (true, false) on both arguments (!( !u && !w )).

def Cslib.Circuits.Frontier.ClauseEdge {σ : Signature} {n s : ℕ} (p : Program σ n s) (I : Interpretation σ Bool) (u w : Wire n s) :

Directed forbidden-pair edge between wires u and w in p: w = .gate g reads u in some slot a whose gate operation forbids an output pair on a.

def Cslib.Circuits.Frontier.u2ClauseGraph {σ : Signature} {n s : ℕ} (p : Program σ n s) (I : Interpretation σ Bool) (R : Set (Wire n s)) :

The 2-SAT clause graph on a wire set R. Two wires in R are adjacent when one is a gate reading the other through an argument slot satisfying ForbidsOutputPair.

@[simp]
theorem Cslib.Circuits.Frontier.u2ClauseGraph_adj {σ : Signature} {n s : ℕ} (p : Program σ n s) (I : Interpretation σ Bool) (R : Set (Wire n s)) (u w : ↑R) :
(u2ClauseGraph p I R).Adj u w ↔ ClauseEdge p I ↑u ↑w ∨ ClauseEdge p I ↑w ↑u
theorem Cslib.Circuits.Frontier.ncard_trace_domRestrict_le_indepSetCount {σ : Signature} {n s : ℕ} (p : Program σ n s) (I : Interpretation σ Bool) (R : Set (Wire n s)) (X : Set (Fin n → Bool)) :
((fun (x : Fin n → Bool) => R.domRestrict (p.trace I x)) '' X).ncard ≤ (u2ClauseGraph p I R).indepSetCount

Trace projections on R are bounded by i(u2ClauseGraph p I R). Every edge of u2ClauseGraph p I R forbids at least one pair of Boolean values across all program traces, so at most (u2ClauseGraph p I R).indepSetCount distinct restrictions occur on R.

theorem Cslib.Circuits.Frontier.ncard_frontierValues_le_indepSetCount {σ : Signature} {n m : ℕ} (c : Circuit σ n m) (I : Interpretation σ Bool) (Acc : Fin m → Set Bool) (π : Layout (Compiler.Vertex c)) (t : ℕ) {D : Set (Wire n c.size)} (hD : D ⊆ c.program.forwardDetermined (cutWires c (π.initial t))) (X : Set (Fin n → Bool)) :
((fun (x : Fin n → Bool) => (Compiler.network c I Acc).frontierValues π t fun (e : Compiler.Edge c) => c.program.trace I x ↑e.signal) '' X).ncard ≤ (u2ClauseGraph c.program I (cutWires c (π.initial t) \ D)).indepSetCount

Combined D*(∂) + 2-SAT i(H) frontier state bound. Along any layout π of a Boolean circuit c, after dropping any forward-determined wire subset D ⊆ c.program.forwardDetermined (cutWires c (π.initial t)) (including D₀), the number of distinct frontier states at step t across X is at most (u2ClauseGraph c.program I (cutWires c (π.initial t) \ D)).indepSetCount.

Universal graded signature, arity excess, and fan-out slicing #

@[reducible, inline]

The universal graded signature on U, with an a-ary operation symbol for every a : ℕ and every function (Fin a → U) → U.

Total arity excess ∑ g, (arity(g) - 1) of a program. Nullary constants and unary operations (such as NOT) contribute 0; binary gates contribute 1; r-ary gates contribute r - 1.

@[simp]
theorem Cslib.Circuits.Program.arityExcess_gate {σ : Signature} {n s : ℕ} (p : Program σ n s) (line : Line σ n s) :
(p.gate line).arityExcess = p.arityExcess + (σ.Arity line.op - 1)
theorem Cslib.Circuits.Program.arityExcess_le_mul_innerGates {σ : Signature} {n s : ℕ} {p : Program σ n s} {r : ℕ} (hfan : p.FanInAtMost r) :

For fan-in at most r, p.arityExcess ≤ (r - 1) * p.innerGates.card.

def Cslib.Circuits.Program.gateConsumers {σ : Signature} {n s : ℕ} (p : Program σ n s) (w : Wire n s) :

The number of gates in p that read wire w in at least one argument slot.

def Cslib.Circuits.Program.excessConsumers {σ : Signature} {n s : ℕ} (p : Program σ n s) (w : Wire n s) :

Excess drop when w is fixed across p: each gate g drops by min #{a | wires g a = w} (arity(g) - 1).

theorem Cslib.Circuits.Program.gateConsumers_le_excessConsumers {σ : Signature} {n s : ℕ} {p : Program σ n s} (h2 : ∀ (g : Fin s), 2 ≤ σ.Arity (p.lines g).op) (w : Wire n s) :

When every gate of p has arity at least 2, every gate reading w contributes at least 1 to p.excessConsumers w.

Eliminating nullary/unary gates and deduplicating parallel gate inputs #

Currying a fixed wire across a program #

Universal fan-out slicing and multi-output surplus bounds #

def Cslib.Circuits.Frontier.allWiresCircuit {τ : Signature} {n g : ℕ} (p : Program τ n g) :
Circuit τ n (n + g)

Build a circuit exposing every wire of p : Program τ n g as one of its n + g outputs.

theorem Cslib.Circuits.Frontier.exists_sliced_fanout_lt {σ : Signature} {U : Type u} [Finite U] [Nonempty U] {n m r k : ℕ} (hk : 1 ≤ k) (c : Circuit σ n m) (I : Interpretation σ U) (Acc : Fin m → Set U) (hfan : c.FanInAtMost r) (hS : {x : Fin n → U | ∀ (o : Fin m), c.eval I x o ∈ Acc o}.Nonempty) :
∃ (t : ℕ) (g' : ℕ) (q : Program (allOpsSignature U) n g') (Acc' : Fin (n + g') → Set U) (S' : Set (Fin n → U)), q.FanInAtMost r ∧ (∀ (j : Fin g'), 2 ≤ (allOpsSignature U).Arity (q.lines j).op) ∧ (∀ (j : Fin g'), Function.Injective (q.lines j).wires) ∧ (∀ (w : Wire n g'), q.gateConsumers w < k) ∧ g' ≤ q.arityExcess ∧ (r = 2 → g' = q.arityExcess) ∧ q.arityExcess + k * t ≤ c.program.arityExcess ∧ S' ⊆ {x : Fin n → U | ∀ (o : Fin m), c.eval I x o ∈ Acc o} ∧ S'.Nonempty ∧ (Compiler.network (allWiresCircuit q) (allOpsInterpretation U) Acc').accepted = S' ∧ {x : Fin n → U | ∀ (o : Fin m), c.eval I x o ∈ Acc o}.ncard ≤ Nat.card U ^ t * S'.ncard

Universal fan-out slicing (gateConsumers < k). Given any circuit c : Circuit σ n m of fan-in at most r over a finite nonempty alphabet U, if the accepted set S is nonempty and 1 ≤ k, repeatedly slicing wires with gateConsumers ≥ k at their most popular value yields t steps, a subset S' ⊆ S, and a program q : Program (allOpsSignature U) n g' with wire constraints Acc' such that:

  • every gate of q has arity in [2, r] and injective argument wires (c_q.innerSize = g'),
  • every wire w : Wire n g' (both input and internal gate) satisfies q.gateConsumers w < k,
  • q.arityExcess + k * t ≤ c.program.arityExcess (with g' ≤ q.arityExcess, and g' = q.arityExcess when r = 2),
  • S' = (Compiler.network (allWiresCircuit q) (allOpsInterpretation U) ...).accepted and S.ncard ≤ Nat.card U ^ t * S'.ncard.
theorem Cslib.Circuits.Frontier.exists_sliced_fanout_le_four {σ : Signature} {U : Type u} [Finite U] [Nonempty U] {n m : ℕ} (c : Circuit σ n m) (I : Interpretation σ U) (Acc : Fin m → Set U) (hfan : c.FanInAtMost 2) (hS : {x : Fin n → U | ∀ (o : Fin m), c.eval I x o ∈ Acc o}.Nonempty) :
∃ (t : ℕ) (g' : ℕ) (q : Program (allOpsSignature U) n g') (Acc' : Fin (n + g') → Set U) (S' : Set (Fin n → U)), q.FanInAtMost 2 ∧ (∀ (j : Fin g'), (allOpsSignature U).Arity (q.lines j).op = 2) ∧ (∀ (j : Fin g'), Function.Injective (q.lines j).wires) ∧ (∀ (w : Wire n g'), q.gateConsumers w ≤ 4) ∧ g' + 5 * t ≤ c.program.arityExcess ∧ S' ⊆ {x : Fin n → U | ∀ (o : Fin m), c.eval I x o ∈ Acc o} ∧ S'.Nonempty ∧ (Compiler.network (allWiresCircuit q) (allOpsInterpretation U) Acc').accepted = S' ∧ {x : Fin n → U | ∀ (o : Fin m), c.eval I x o ∈ Acc o}.ncard ≤ Nat.card U ^ t * S'.ncard

Fan-in-two slicing to gate fan-out ≤ 4. Specializing exists_sliced_fanout_lt to r = 2 and k = 5, every nonempty fan-in-two accepted set S admits t wire slices to a residual strictly-binary program q of size g' where every wire (input or gate) feeds ≤ 4 gates, g' + 5 * t ≤ c.program.arityExcess ≤ c.innerSize, and S.ncard ≤ |U| ^ t * S'.ncard.

Componentwise frontier counting on allWiresCircuit #

theorem Cslib.Circuits.Frontier.eventually_slicing_surplus {U : Type u} {r : ℕ} (hr : 2 ≤ r) {A : ℝ} (hA : 0 < A) (hlayout : LayoutBound (r + 1) A) {S : (n : ℕ) → Set (Fin n → U)} {K : ℕ → ℕ} [Finite U] [Nontrivial U] (hSK : DenseRectangleFree S K) {k : ℕ} (hk : 1 ≤ k) {ε : ℝ} (hε : 0 < ε) :
∀ᶠ (n : ℕ) in Filter.atTop, ∀ (σ : Signature) (I : Interpretation σ U) (Acc : Set U) (c : Circuit σ n 1), c.FanInAtMost r → c.Decides I Acc (S n) → ∃ (t : ℕ) (g' : ℕ) (q : Program (allOpsSignature U) n g'), q.FanInAtMost r ∧ (∀ (w : Wire n g'), q.gateConsumers w < k) ∧ g' ≤ q.arityExcess ∧ q.arityExcess + k * t ≤ c.program.arityExcess ∧ (1 + 1 / A - ε) * ↑n + (↑(r - 1) * ↑k - (1 + 1 / A)) * ↑t < ↑(r - 1) * ↑c.program.arityExcess

Asymptotic fan-out slicing surplus lower bound. Fix r ≥ 2, LayoutBound (r + 1) A with A > 0, a dense K_n-rectangle-free family S_n ⊆ U^n, and a slicing threshold k ≥ 1. For every ε > 0 and all large n, every circuit c of fan-in at most r deciding S_n admits a slicing count t : ℕ (witnessing t wires of gateConsumers ≥ k sliced down to a residual circuit where every wire has gateConsumers < k and g' + k * t ≤ c.program.arityExcess) such that:

(1 + 1 / A - ε) * n + ((r - 1) * k - (1 + 1 / A)) * t < (r - 1) * c.program.arityExcess.

At r = 2 ((r - 1) = 1), this reads (1 + 1 / A - ε) * n + (k - (1 + 1 / A)) * t < c.program.arityExcess ≤ c.innerSize, simultaneously making unary (NOT) gates free (at t = 0 or k large) and charging + (k - (1 + 1 / A)) gates of surplus per high-fan-out slice when k > 1 + 1 / A.

theorem Cslib.Circuits.Frontier.eventually_switched_slicing_surplus {U : Type u} {S : (n : ℕ) → Set (Fin n → U)} {K : ℕ → ℕ} [Finite U] [Nontrivial U] (hSK : DenseRectangleFree S K) {ε : ℝ} (hε : 0 < ε) :
∀ᶠ (n : ℕ) in Filter.atTop, ∀ (σ : Signature) (I : Interpretation σ U) (Acc : Set U) (c : Circuit σ n 1), c.FanInAtMost 2 → c.Decides I Acc (S n) → ∃ (t : ℕ) (g' : ℕ) (q : Program (allOpsSignature U) n g'), q.FanInAtMost 2 ∧ (∀ (w : Wire n g'), q.gateConsumers w ≤ 4) ∧ q.arityExcess + 5 * t ≤ c.program.arityExcess ∧ c.program.arityExcess ≤ c.innerSize ∧ (1 + 2 * Real.pi / (3 * Real.arccos (5 / 6)) - ε) * ↑n + (5 - (1 + 2 * Real.pi / (3 * Real.arccos (5 / 6)))) * ↑t < ↑c.program.arityExcess

Unconditional median-switched fan-out-≤ 4 surplus bound (L₃ ≈ 4.575972). For every dense K_n-rectangle-free family S_n ⊆ U^n and every ε > 0, eventually every fan-in-two circuit c deciding S_n slices (t times, killing ≥ 5 binary consumers per slice) to a residual program q with gateConsumers ≤ 4 on every wire and

(L₃ - ε) * n + (5 - L₃) * t < c.program.arityExcess ≤ c.innerSize,

where L₃ = 1 + 2π / (3 arccos (5 / 6)) ≈ 4.575972 and 5 - L₃ > 0.424.