Documentation

CslibFrontier.Computability.Circuit.InnerSize

Inner gates and multiary gates #

A gate of arity zero is a constant: like an input, it is a leaf of the circuit. The inner gates of a program are its gates of positive arity, and the inner size of a circuit counts them. A lower bound that holds over every basis can only count inner gates, since every value of the alphabet may be a constant gate of the basis.

Over a finite alphabet U, gates of arity one can also be made free without changing the basis: every wire of arity at most one computes either a constant in U or a unary function U → U of an input or a gate of arity at least two. The multiary gates of a program are its gates of arity at least two, and the multiary size of a circuit counts them (Circuit.multiarySize). By deduplicating gates of arity at most one that compute the same constant or the same unary function of the same input or multiary gate (Circuit.exists_eval_eq_multiarySize_size_le), every circuit over any signature σ and interpretation on U is equivalent to one over σ with at most c.multiarySize multiary gates and total gate count O_{|U|}(c.multiarySize + n).

Main definitions #

Main results #

def Cslib.Circuits.Program.innerGates {σ : Signature} {n g : ℕ} (p : Program σ n g) :

The inner gates of a program: those of positive arity. A gate of arity zero is a constant, a leaf of the circuit like an input.

@[simp]
theorem Cslib.Circuits.Program.mem_innerGates {σ : Signature} {n g : ℕ} {p : Program σ n g} {k : Fin g} :
k ∈ p.innerGates ↔ σ.Arity (p.lines k).op ≠ 0

A gate k belongs to p.innerGates if and only if its operation has nonzero arity.

def Cslib.Circuits.Circuit.innerSize {σ : Signature} {n m : ℕ} (c : Circuit σ n m) :

The inner size of a circuit: the number of its gates of positive arity. Constant gates are free. For arithmetic circuits this counts the additions and multiplications.

Constant gates are free: the inner size is at most the size.

Without arguments every gate is a constant, so a circuit of fan-in zero has inner size zero.

@[simp]
theorem Cslib.Circuits.Circuit.innerSize_wiring {σ : Signature} {n m : ℕ} (select : Fin m → Fin n) :
(wiring σ select).innerSize = 0

A pure input-wiring circuit has 0 inner gates.

theorem Cslib.Circuits.Circuit.innerSize_eq_size_of_forall_arity_ne_zero {σ : Signature} {n m : ℕ} (c : Circuit σ n m) (h : ∀ (op : σ.Op), σ.Arity op ≠ 0) :

In a signature without nullary operations, every gate has positive arity, so the inner size is the full gate count.

theorem Cslib.Circuits.Program.fanInAtMost_of_forall_arity_le {σ : Signature} {n g : ℕ} (p : Program σ n g) {r : ℕ} (h : ∀ (op : σ.Op), σ.Arity op ≤ r) :

If every operation symbol has arity at most r, every program over the signature has fan-in at most r.

theorem Cslib.Circuits.Circuit.fanInAtMost_of_forall_arity_le {σ : Signature} {n m : ℕ} (c : Circuit σ n m) {r : ℕ} (h : ∀ (op : σ.Op), σ.Arity op ≤ r) :

If every operation symbol has arity at most r, every circuit over the signature has fan-in at most r.

Every circuit over the full basis of arity r has fan-in at most r.

Multiary gates and finite-alphabet unary deduplication #

The multiary gates of a program: those of arity at least two. Gates of arity zero (constants) and arity one (unary operations such as negations) are excluded.

@[simp]
theorem Cslib.Circuits.Program.mem_multiaryGates {σ : Signature} {n g : ℕ} {p : Program σ n g} {k : Fin g} :

A gate k belongs to p.multiaryGates if and only if its operation has arity at least two.

The multiary size of a circuit: the number of its gates of arity at least two. Both constant gates and unary gates are free.

Multiary gates are inner gates, so multiarySize ≤ innerSize.

With fan-in at most one every gate is nullary or unary, so the multiary size is zero.

@[simp]
theorem Cslib.Circuits.Circuit.multiarySize_wiring {σ : Signature} {n m : ℕ} (select : Fin m → Fin n) :
(wiring σ select).multiarySize = 0

A pure input-wiring circuit has 0 multiary gates.

In a signature without unary operations, every inner gate has arity at least two, so the multiary size equals the inner size.

theorem Cslib.Circuits.Circuit.exists_eval_eq_multiarySize_size_le {σ : Signature} {n m : ℕ} {U : Type u_1} [Finite U] (I : Interpretation σ U) (c : Circuit σ n m) :
∃ (c' : Circuit σ n m), c'.eval I = c.eval I ∧ (∀ (r : ℕ), c.FanInAtMost r → c'.FanInAtMost r) ∧ c'.multiarySize ≤ c.multiarySize ∧ c'.size ≤ c.multiarySize + Nat.card U + (c.multiarySize + n) * Nat.card U ^ Nat.card U

Deduplicating unary and constant gates over a finite alphabet. Over a finite alphabet U, every circuit c over any signature σ can be replaced by a circuit c' over the same signature σ that computes the same function under I, preserves every fan-in bound of c, uses at most c.multiarySize multiary gates, and has total gate count at most c.multiarySize + |U| + (c.multiarySize + n) * |U| ^ |U|.