Documentation

CslibFrontier.Computability.Circuit.Boolean.WeightedThreshold.DepthTwo

Depth-two weighted threshold circuits and wire counts #

This module defines the canonical depth-two weighted threshold circuit constructor WeightedThreshold.depthTwo (THR ∘ THR) and aggregated wire-count measures for weighted threshold programs and circuits.

For any program p : Program signature n g, lineSupport (p.lines gate) is the set of wires (original inputs and earlier gates) with nonzero aggregated coefficient in gate, decomposing disjointly into inputSupport p gate and gateSupport p gate. The total active wire count wireCount p is the sum of #(lineSupport (p.lines gate)) over all gates, and inputWireCount p is the sum of #(inputSupport p gate) over all gates. Both are bounded by the syntactic slot count p.cost Op.arity.

Main definitions #

Main results #

References #

Active wire supports and wire counts #

The wires with nonzero aggregated coefficient in line.

@[simp]

A wire belongs to lineSupport line if and only if its aggregated weight lineWeight line w is nonzero.

The number of active wires of a line is at most the syntactic arity of its operation.

The active wires of a program gate decompose disjointly into its active original inputs and its active predecessor gates.

Total number of active direct-input wires across all gates of a weighted threshold program.

Total number of active wires (both direct-input and gate-to-gate) across all gates of a weighted threshold program.

The total active wire count of a program splits into its direct-input wire count and its internal gate-to-gate wire count.

The direct-input wire count of a program is at most its total active wire count.

The active wire count of a program is at most its syntactic argument-slot count p.cost Op.arity.

@[reducible, inline]

Total number of active direct-input wires across all gates of a weighted threshold circuit.

@[reducible, inline]

Total number of active wires across all gates of a weighted threshold circuit.

The direct-input wire count of a circuit is at most its total active wire count.

The active wire count of a circuit is at most its syntactic argument-slot count c.program.cost Op.arity.

Depth-two weighted threshold circuits (THR ∘ THR) #

def Cslib.Circuits.Boolean.WeightedThreshold.depthTwo {n : ℕ} (top : Op) (bottom : Fin top.arity → Op) (args : (j : Fin top.arity) → Fin (bottom j).arity → Fin n) :

A depth-two weighted threshold circuit (THR ∘ THR) with top.arity bottom threshold gates bottom j on input selections args j, feeding into the single output threshold gate top.

@[simp]
theorem Cslib.Circuits.Boolean.WeightedThreshold.eval_depthTwo {n : ℕ} (top : Op) (bottom : Fin top.arity → Op) (args : (j : Fin top.arity) → Fin (bottom j).arity → Fin n) (x : Fin n → Bool) (o : Fin 1) :
(depthTwo top bottom args).eval interpretation x o = interpretation top fun (j : Fin (signature.Arity top)) => interpretation (bottom j) fun (a : Fin (signature.Arity (bottom j))) => x (args j a)

Evaluating depthTwo top bottom args applies each bottom threshold gate bottom j to its selected inputs x ∘ args j and feeds their Boolean outputs into top.

@[simp]
theorem Cslib.Circuits.Boolean.WeightedThreshold.size_depthTwo {n : ℕ} (top : Op) (bottom : Fin top.arity → Op) (args : (j : Fin top.arity) → Fin (bottom j).arity → Fin n) :
(depthTwo top bottom args).size = top.arity + 1

A depth-two circuit depthTwo top bottom args has top.arity bottom gates and one top gate, for top.arity + 1 gates in total.

theorem Cslib.Circuits.Boolean.WeightedThreshold.depth_depthTwo_le {n : ℕ} (top : Op) (bottom : Fin top.arity → Op) (args : (j : Fin top.arity) → Fin (bottom j).arity → Fin n) :
(depthTwo top bottom args).depth ≤ 2

A depth-two circuit depthTwo top bottom args has depth at most 2.

theorem Cslib.Circuits.Boolean.WeightedThreshold.cost_arity_depthTwo {n : ℕ} (top : Op) (bottom : Fin top.arity → Op) (args : (j : Fin top.arity) → Fin (bottom j).arity → Fin n) :
(depthTwo top bottom args).program.cost Op.arity = ∑ j : Fin top.arity, (bottom j).arity + top.arity

The syntactic argument-slot count of depthTwo top bottom args is the sum of the bottom-gate arities plus top.arity.

theorem Cslib.Circuits.Boolean.WeightedThreshold.wireCount_depthTwo_le {n : ℕ} (top : Op) (bottom : Fin top.arity → Op) (args : (j : Fin top.arity) → Fin (bottom j).arity → Fin n) :
(depthTwo top bottom args).wireCount ≤ ∑ j : Fin top.arity, (bottom j).arity + top.arity

The active wire count of depthTwo top bottom args is at most the sum of the bottom-gate arities plus top.arity.

theorem Cslib.Circuits.Boolean.WeightedThreshold.lines_depthTwo_bottom_or_top {n : ℕ} (top : Op) (bottom : Fin top.arity → Op) (args : (j : Fin top.arity) → Fin (bottom j).arity → Fin n) (k : Fin (depthTwo top bottom args).size) :
(∃ (j : Fin top.arity), (depthTwo top bottom args).program.lines k = { op := bottom j, wires := fun (a : Fin (signature.Arity (bottom j))) => Wire.input (args j a) }) ∨ ∃ (ws : Fin top.arity → Fin (depthTwo top bottom args).size), (depthTwo top bottom args).program.lines k = { op := top, wires := fun (a : Fin (signature.Arity top)) => Wire.gate (ws a) }

Every gate of depthTwo top bottom args is either a bottom gate bottom j, reading the original inputs args j, or the top gate top, reading only gates.

Alternating linear function and integer interval telescoping #

The alternating linear function φ(u) = (-1) ^ u * u, defined via Int.negOnePow.

theorem Cslib.Circuits.Boolean.WeightedThreshold.negOnePow_sum {α : Type u_1} (s : Finset α) (f : α → ℤ) :
↑(∑ x ∈ s, f x).negOnePow = ∏ x ∈ s, ↑(f x).negOnePow

Int.negOnePow sends a finite sum of integers to the product of their powers of -1.

Alternating linear shift identity: for all integers X and t, (-1) ^ X * φ(X + t) - φ(t) = X * (-1) ^ t. For even X this is φ(X + t) - φ(t) = X * (-1) ^ t.

The discrete derivative of altLinear at u is (-1) ^ (u + 1) * (2 * u + 1).

altLinear preserves squares: φ(u)² = u².

Truncating altLinear #

The truncation f_R(u) = φ(u) [|u| ≤ R] of the alternating linear function φ(u) = (-1) ^ u u (altLinear) to the window [-R, R].

The truncation error of the pair of reflected forms x + d and x - d: (f_R - φ)(x + d) + (f_R - φ)(x - d). It is odd in x.

The squared truncation error of one form is u² [|u| > R].

theorem Cslib.Circuits.Boolean.WeightedThreshold.sum_sub_mul_decide_le (f : ℤ → ℤ) {ℓ u : ℤ} {L : ℕ} (hlo : ℓ ≤ u) (hhi : u ≤ ℓ + ↑L) :
f ℓ + ∑ k : Fin L, (f (ℓ + ↑↑k + 1) - f (ℓ + ↑↑k)) * ↑(decide (ℓ + ↑↑k + 1 ≤ u)).toNat = f u

Integer interval telescoping: any function f : ℤ → ℤ on an integer u ∈ [ℓ, ℓ + L] equals f ℓ plus the sum of its step differences weighted by threshold indicators decide (ℓ + k + 1 ≤ u).

theorem Cslib.Circuits.Boolean.WeightedThreshold.altLinearTrunc_eq_sum (R : ℕ) (u : ℤ) :
altLinearTrunc R u = ∑ k : Fin (2 * R + 2), (altLinearTrunc R (-↑R - 1 + ↑↑k + 1) - altLinearTrunc R (-↑R - 1 + ↑↑k)) * ↑(decide (-↑R - 1 + ↑↑k + 1 ≤ u)).toNat

The staircase of f_R: f_R(u) = ∑_{k < 2 R + 2} (f_R(θ_k) - f_R(θ_k - 1)) [θ_k ≤ u] for every integer u, with thresholds θ_k = -R + k.

The threshold θ_k = -R + k of step k of the staircase of f_R.

The height f_R(θ_k) - f_R(θ_k - 1) of step k of the staircase of f_R.

Twice the sum of subset cardinalities over Finset (Fin b) is b * 2 ^ b.

Linear threshold functions on general finite domains and depth-one gate decomposition #

@[simp]

The active coordinate support of inputWeight p gate is inputSupport p gate.

theorem Cslib.Circuits.Boolean.WeightedThreshold.gateWeight_eq_zero_of_depths_le_one {n g : ℕ} (p : Program signature n g) {gate : Fin g} (hd : p.depths gate ≤ 1) (k : Fin g) :
gateWeight p gate k = 0

Any gate of depth at most 1 in a weighted threshold program has zero aggregated weight from every gate k : Fin g.

Any gate of depth at most 1 in a weighted threshold program has empty gateSupport.

Any gate of depth at most 1 in a weighted threshold program evaluates as the linear threshold function ltfEval (inputWeight p gate) (p.lines gate).op.threshold on the primary inputs x.