Documentation

CslibFrontier.Computability.Circuit.CriticalPath

Critical paths, dead-gate elimination, and the 2n - 2m structure theorem #

Signature-generic wire out-degrees, syntactic dead-gate elimination, isolated variables, critical paths, and two-variable intersection bottlenecks for bounded-fan-in circuits, following Section 7.1 of Fan, Li, and Yang [FLY22].

For each input wire x of a circuit C, the critical path C.criticalPath x walks forward along unique outgoing gate slots until reaching a wire C.criticalEndpoint x whose out-degree in C is not 1 (Definition 7.1). A circuit has no dead gates (C.NoDeadGates, called normalized in [FLY22]) when every internal gate of out-degree 0 is a designated output wire; syntactic dead-gate elimination (C.exists_noDeadGates) removes unused internal gates without increasing gate count or fan-in. An isolated variable (C.HasIsolatedVar) is an input wire of out-degree 0 that is not a designated output wire.

When a fan-in-2 circuit has no dead gates, no isolated variables, and pairwise disjoint critical paths, counting outgoing gate slots against critical endpoints gives 2 * n - 2 * m ≤ C.size (Lemma 7.4). Conversely, if two distinct inputs x ≠ y of a single-output fan-in-2 circuit with no dead gates have intersecting critical paths, every 2-variable restriction to (x, y) factors through a single binary gate operation opG via unary pre- and post-processing (C.exists_bottleneck_of_not_disjoint_criticalPath).

Main definitions #

Main results #

References #

Wire ranks and gate input slots #

def Cslib.Circuits.Wire.rank {n g : ℕ} :
Wire n g → ℕ

Topological rank of a wire: 0 for original inputs and k + 1 for internal gate k.

@[simp]
theorem Cslib.Circuits.Wire.rank_input {n g : ℕ} (i : Fin n) :
(input i).rank = 0
@[simp]
theorem Cslib.Circuits.Wire.rank_gate {n g : ℕ} (k : Fin g) :
(gate k).rank = ↑k + 1
theorem Cslib.Circuits.Wire.rank_le {n g : ℕ} (w : Wire n g) :
w.rank ≤ g

Every wire in a g-gate namespace has topological rank at most g.

@[reducible, inline]
abbrev Cslib.Circuits.Circuit.Slot {σ : Signature} {n m : ℕ} (C : Circuit σ n m) :

An input slot (k, a) of gate k in a circuit C.

def Cslib.Circuits.Circuit.slotWire {σ : Signature} {n m : ℕ} (C : Circuit σ n m) (s : C.Slot) :

The wire read by gate input slot s of C.

def Cslib.Circuits.Circuit.allSlots {σ : Signature} {n m : ℕ} (C : Circuit σ n m) :

All gate input slots of C, listed in gate and argument order.

@[simp]
theorem Cslib.Circuits.Circuit.mem_allSlots {σ : Signature} {n m : ℕ} (C : Circuit σ n m) (s : C.Slot) :

Every gate input slot occurs in C.allSlots.

Each gate input slot occurs at most once in C.allSlots.

def Cslib.Circuits.Circuit.slotReaders {σ : Signature} {n m : ℕ} (C : Circuit σ n m) (v : Wire n C.size) :

The gate input slots of C that read wire v.

@[simp]
theorem Cslib.Circuits.Circuit.mem_slotReaders {σ : Signature} {n m : ℕ} (C : Circuit σ n m) {s : C.Slot} {v : Wire n C.size} :

Membership in C.slotReaders v characterizes slots reading v.

theorem Cslib.Circuits.Circuit.nodup_slotReaders {σ : Signature} {n m : ℕ} (C : Circuit σ n m) (v : Wire n C.size) :

C.slotReaders v contains no duplicate slots.

theorem Cslib.Circuits.Circuit.rank_lt_of_slotWire_eq {σ : Signature} {n m : ℕ} (C : Circuit σ n m) {s : C.Slot} {v : Wire n C.size} (hs : C.slotWire s = v) :

Every slot reading v belongs to a gate of strictly larger topological rank than v.

def Cslib.Circuits.Circuit.outDeg {σ : Signature} {n m : ℕ} (C : Circuit σ n m) (v : Wire n C.size) :

The out-degree of wire v in C: the number of gate input slots that read v.

theorem Cslib.Circuits.Circuit.outDeg_eq_card_filter {σ : Signature} {n m : ℕ} (C : Circuit σ n m) (v : Wire n C.size) :
C.outDeg v = {s : C.Slot | C.slotWire s = v}.card

Out-degree equals the cardinality of the fiber of C.slotWire over v.

theorem Cslib.Circuits.Circuit.outDeg_eq_zero_iff {σ : Signature} {n m : ℕ} (C : Circuit σ n m) {v : Wire n C.size} :
C.outDeg v = 0 ↔ ∀ (s : C.Slot), C.slotWire s ≠ v

Wire v has out-degree 0 precisely when no gate slot reads v.

theorem Cslib.Circuits.Circuit.outDeg_eq_one_iff {σ : Signature} {n m : ℕ} (C : Circuit σ n m) {v : Wire n C.size} :
C.outDeg v = 1 ↔ ∃ (s : C.Slot), C.slotReaders v = [s]

Wire v has out-degree 1 precisely when C.slotReaders v is a singleton list.

theorem Cslib.Circuits.Circuit.sum_outDeg {σ : Signature} {n m : ℕ} (C : Circuit σ n m) :
∑ v : Wire n C.size, C.outDeg v = ∑ k : Fin C.size, σ.Arity (C.program.lines k).op

Summing C.outDeg over all wires counts every gate input slot of C.

theorem Cslib.Circuits.Circuit.sum_outDeg_le_of_fanInAtMost {σ : Signature} {n m : ℕ} (C : Circuit σ n m) {r : ℕ} (h : C.FanInAtMost r) :
∑ v : Wire n C.size, C.outDeg v ≤ r * C.size

Under fan-in bound r, the sum of wire out-degrees is at most r * C.size.

Output wires, dead-gate freedom, and isolated variables #

The finite set of designated output wires of C.

theorem Cslib.Circuits.Circuit.mem_outputsFinset {σ : Signature} {n m : ℕ} (C : Circuit σ n m) {v : Wire n C.size} :
v ∈ C.outputsFinset ↔ ∃ (j : Fin m), C.outputs j = v

A circuit has no dead gates if every internal gate of out-degree 0 is a designated output wire (called normalized in Fan–Li–Yang [FLY22], Definition 7.1; named NoDeadGates here to distinguish syntactic dead-gate freedom from semantic duplicate-gate merging in Cslib.Circuits.Circuit.Irredundant).

Instances For
    @[instance_reducible]

    A circuit has an isolated variable if some input wire has out-degree 0 and is not a designated output wire (Fan–Li–Yang [FLY22], Definition 7.1).

    Instances For
      @[instance_reducible]
      theorem Cslib.Circuits.Circuit.exists_noDeadGates {σ : Signature} {n m : ℕ} (C : Circuit σ n m) :
      ∃ (C' : Circuit σ n m), C'.NoDeadGates ∧ C'.size ≤ C.size ∧ (∀ {U : Type u} (I : Interpretation σ U) (x : Fin n → U), C'.eval I x = C.eval I x) ∧ ∀ (r : ℕ), C.FanInAtMost r → C'.FanInAtMost r

      Dead-gate elimination: every circuit has an equivalent circuit with NoDeadGates (normalized in [FLY22], Definition 7.1), no more gates, and the same fan-in bounds.

      theorem Cslib.Circuits.Circuit.eval_update_of_outDeg_input_eq_zero {σ : Signature} {n m : ℕ} {U : Type u} [DecidableEq (Fin n)] (C : Circuit σ n m) (I : Interpretation σ U) {i : Fin n} (hout : C.outDeg (Wire.input i) = 0) (hnotOut : Wire.input i ∉ C.outputsFinset) (ρ : Fin n → U) (b : U) :
      C.eval I (Function.update ρ i b) = C.eval I ρ

      An input wire of out-degree 0 that is not a designated output wire has no effect on circuit evaluation under any interpretation.

      Critical paths and Lemma 7.4 #

      def Cslib.Circuits.Circuit.uniqueReaderSlot {σ : Signature} {n m : ℕ} (C : Circuit σ n m) (v : Wire n C.size) :

      If v has a unique outgoing slot s, return some s; otherwise none.

      def Cslib.Circuits.Circuit.criticalPathAux {σ : Signature} {n m : ℕ} (C : Circuit σ n m) :
      ℕ → Wire n C.size → List (Wire n C.size)

      Follow unique outgoing gate slots starting from v for at most fuel steps.

      theorem Cslib.Circuits.Circuit.criticalPathAux_ne_nil {σ : Signature} {n m : ℕ} (C : Circuit σ n m) (fuel : ℕ) (v : Wire n C.size) :

      C.criticalPathAux is never empty.

      @[simp]
      theorem Cslib.Circuits.Circuit.head_criticalPathAux {σ : Signature} {n m : ℕ} (C : Circuit σ n m) (fuel : ℕ) (v : Wire n C.size) :
      (C.criticalPathAux fuel v).head ⋯ = v

      The first wire of C.criticalPathAux fuel v is v.

      theorem Cslib.Circuits.Circuit.rank_lt_of_mem_tail_criticalPathAux {σ : Signature} {n m : ℕ} (C : Circuit σ n m) (fuel : ℕ) (v w : Wire n C.size) :
      w ∈ (C.criticalPathAux fuel v).tail → v.rank < w.rank

      Every wire in the tail of C.criticalPathAux fuel v has strictly larger rank than v.

      theorem Cslib.Circuits.Circuit.gate_of_mem_tail_criticalPathAux {σ : Signature} {n m : ℕ} (C : Circuit σ n m) (fuel : ℕ) (v w : Wire n C.size) (hw : w ∈ (C.criticalPathAux fuel v).tail) :
      ∃ (k : Fin C.size), w = Wire.gate k

      Every wire in the tail of C.criticalPathAux fuel v is an internal gate wire.

      theorem Cslib.Circuits.Circuit.rank_lt_criticalPathAux_getElem {σ : Signature} {n m : ℕ} (C : Circuit σ n m) (fuel : ℕ) (v : Wire n C.size) {i j : ℕ} (hi : i < (C.criticalPathAux fuel v).length) (hj : j < (C.criticalPathAux fuel v).length) :
      i < j → (C.criticalPathAux fuel v)[i].rank < (C.criticalPathAux fuel v)[j].rank

      Along C.criticalPathAux fuel v, topological ranks strictly increase with list index.

      theorem Cslib.Circuits.Circuit.nodup_criticalPathAux {σ : Signature} {n m : ℕ} (C : Circuit σ n m) (fuel : ℕ) (v : Wire n C.size) :

      C.criticalPathAux fuel v contains no duplicate wires.

      theorem Cslib.Circuits.Circuit.criticalPathAux_step {σ : Signature} {n m : ℕ} (C : Circuit σ n m) (fuel : ℕ) (v : Wire n C.size) {i : ℕ} (hi : i + 1 < (C.criticalPathAux fuel v).length) :
      ∃ (s : C.Slot), C.slotReaders (C.criticalPathAux fuel v)[i] = [s] ∧ (C.criticalPathAux fuel v)[i + 1] = Wire.gate s.fst

      Every consecutive pair (p[i], p[i + 1]) in C.criticalPathAux fuel v witnesses a unique outgoing slot reading p[i] at gate p[i + 1].

      theorem Cslib.Circuits.Circuit.outDeg_getLast_criticalPathAux_ne_one {σ : Signature} {n m : ℕ} (C : Circuit σ n m) (fuel : ℕ) (v : Wire n C.size) :
      C.size ≤ fuel + v.rank → C.outDeg ((C.criticalPathAux fuel v).getLast ⋯) ≠ 1

      When C.size ≤ fuel + v.rank, the last wire of C.criticalPathAux fuel v does not have out-degree 1.

      def Cslib.Circuits.Circuit.criticalPath {σ : Signature} {n m : ℕ} (C : Circuit σ n m) (x : Fin n) :
      List (Wire n C.size)

      The critical path starting at input x in C (Fan–Li–Yang [FLY22], Definition 7.1).

      theorem Cslib.Circuits.Circuit.criticalPath_ne_nil {σ : Signature} {n m : ℕ} (C : Circuit σ n m) (x : Fin n) :

      Every critical path is nonempty.

      def Cslib.Circuits.Circuit.criticalEndpoint {σ : Signature} {n m : ℕ} (C : Circuit σ n m) (x : Fin n) :

      The terminal wire of the critical path starting at input x.

      @[simp]
      theorem Cslib.Circuits.Circuit.head_criticalPath {σ : Signature} {n m : ℕ} (C : Circuit σ n m) (x : Fin n) :
      @[simp]
      theorem Cslib.Circuits.Circuit.gate_of_mem_tail_criticalPath {σ : Signature} {n m : ℕ} (C : Circuit σ n m) (x : Fin n) {w : Wire n C.size} (hw : w ∈ (C.criticalPath x).tail) :
      ∃ (k : Fin C.size), w = Wire.gate k

      The terminal wire of every critical path has out-degree different from 1.

      theorem Cslib.Circuits.Circuit.two_mul_sub_two_mul_le_size {σ : Signature} {n m : ℕ} (C : Circuit σ n m) (hfan : C.FanInAtMost 2) (hnoDead : C.NoDeadGates) (hiso : ¬C.HasIsolatedVar) (hdisj : Pairwise fun (x y : Fin n) => Disjoint (C.criticalPath x).toFinset (C.criticalPath y).toFinset) :
      2 * n - 2 * m ≤ C.size

      Fan–Li–Yang Lemma 7.4: every circuit of fan-in at most 2 with n inputs, m outputs, no dead gates (normalized in [FLY22]), no isolated variable, and pairwise disjoint critical paths has at least 2 * n - 2 * m gates.

      Two-variable bottleneck at intersecting critical paths #

      In a single-output circuit with NoDeadGates, the designated output wire has out-degree 0.

      An input wire lies on the critical path from input y only if it is y itself: every later wire of the path is a gate.

      theorem Cslib.Circuits.Circuit.exists_bottleneck_of_not_disjoint_criticalPath {σ : Signature} {n : ℕ} {U : Type u} [DecidableEq (Fin n)] (C : Circuit σ n 1) (I : Interpretation σ U) (hfan : C.FanInAtMost 2) (hnoDead : C.NoDeadGates) {x y : Fin n} (hxy : x ≠ y) (hinter : ¬Disjoint (C.criticalPath x).toFinset (C.criticalPath y).toFinset) :
      ∃ (opG : U → U → U), ∀ (ρ : Fin n → U), ∃ (f₁ : U → U) (f₂ : U → U) (f₃ : U → U), ∀ (bx by_ : U), C.eval I (Function.update (Function.update ρ x bx) y by_) 0 = f₁ (opG (f₂ bx) (f₃ by_))

      Critical-path bottleneck lemma: if two distinct input variables x ≠ y of a single-output fan-in-2 circuit C with NoDeadGates have intersecting critical paths, then there exists a single binary operation opG : U → U → U (determined by the first shared gate G and independent of the restriction ρ) such that for every assignment ρ : Fin n → U there exist unary functions f₁, f₂, f₃ : U → U satisfying C.eval I (Function.update (Function.update ρ x bx) y by_) 0 = f₁ (opG (f₂ bx) (f₃ by_)) for all bx, by_ : U.