Documentation

CslibFrontier.Computability.Circuit.Boolean.WeightedThreshold

Weighted threshold circuits and their input-reading transcripts #

Real-weight threshold gates form a signature for CSLib's existing Program and Circuit. A gate returns true exactly when its weighted sum is at least its threshold. The model allows arbitrary real coefficients, repeated argument wires, and nullary gates.

Coefficients are aggregated by actual wire before determining which gates read original inputs. In particular, repeated weights may cancel. The values of these input-reading gates determine all internal gate values. Circuit outputs are therefore determined when they select gate wires; an output selecting an original input is not covered by that conclusion.

These are semantic results. Comparing arbitrary real numbers is noncomputable, and this module does not assert an algorithm for evaluating rationally encoded circuits.

Main definitions #

Main results #

References #

A real-weight threshold operation with arbitrary finite arity.

  • arity : ℕ

    The number of argument slots.

  • weight : Fin self.arity → ℝ

    The coefficient of each argument slot.

  • threshold : ℝ

    Equality at the threshold returns true.

@[reducible, inline]

The signature of real-weight threshold gates.

A gate is true exactly when its weighted sum is at least its threshold.

Instances For

    Unweighted thresholds have unit coefficients, and negation has coefficient -1 and threshold zero.

    The existing unweighted threshold basis embeds gate for gate.

    Instances For

      Translating the existing threshold basis preserves its Boolean interpretation.

      The combined coefficient of an actual wire, summing all slots that read it.

      theorem Cslib.Circuits.Boolean.WeightedThreshold.line_eval_eq {n g : ℕ} (line : Line signature n g) (x : Fin n → Bool) (z : Fin g → Bool) :
      line.eval interpretation x z = decide (line.op.threshold ≤ ∑ i : Fin n, lineWeight line (Wire.input i) * ↑(x i).toNat + ∑ j : Fin g, lineWeight line (Wire.gate j) * ↑(z j).toNat)

      A line's value splits into its aggregated input and gate contributions.

      The direct coefficient of an original input in a program gate.

      The coefficient of an internal gate in another gate.

      theorem Cslib.Circuits.Boolean.WeightedThreshold.eval_gate_eq {n g : ℕ} (p : Program signature n g) (x : Fin n → Bool) (gate : Fin g) :
      p.eval interpretation x gate = decide ((p.lines gate).op.threshold ≤ ∑ i : Fin n, inputWeight p gate i * ↑(x i).toNat + ∑ j : Fin g, gateWeight p gate j * ↑(p.eval interpretation x j).toNat)

      A native program gate satisfies the usual dense threshold equation. Coefficients of the current gate and of later gates are zero by the program's topological order.

      theorem Cslib.Circuits.Boolean.WeightedThreshold.gateWeight_eq_zero_of_le {n g : ℕ} (p : Program signature n g) (gate prior : Fin g) (h : gate ≤ prior) :
      gateWeight p gate prior = 0

      A gate has zero coefficient on its own output and on later gate outputs.

      theorem Cslib.Circuits.Boolean.WeightedThreshold.sum_mul_toNat_congr_of_lt {g : ℕ} {w : Fin g → ℝ} {gate : Fin g} (hw : ∀ (j : Fin g), gate ≤ j → w j = 0) {u v : Fin g → Bool} (h : ∀ j < gate, u j = v j) :
      ∑ j : Fin g, w j * ↑(u j).toNat = ∑ j : Fin g, w j * ↑(v j).toNat

      A gate's weighted sum over gate values reads only the gates before it: if its coefficients vanish from gate on, two valuations agreeing before gate give the same sum. Instantiate w with gateWeight p gate and gateWeight_eq_zero_of_le p gate.

      theorem Cslib.Circuits.Boolean.WeightedThreshold.eval_gate_eq_of_forall_lt {n g : ℕ} (p : Program signature n g) (x : Fin n → Bool) (gate : Fin g) {v : Fin g → Bool} (hv : ∀ j < gate, p.eval interpretation x j = v j) :
      p.eval interpretation x gate = decide ((p.lines gate).op.threshold ≤ ∑ i : Fin n, inputWeight p gate i * ↑(x i).toNat + ∑ j : Fin g, gateWeight p gate j * ↑(v j).toNat)

      The dense gate equation, evaluated on any valuation v of the gates that agrees with the program before gate.

      The gates with a nonzero aggregated direct-input coefficient. Gates that depend on inputs only through earlier gates are not counted.

      @[simp]
      theorem Cslib.Circuits.Boolean.WeightedThreshold.mem_inputGates {n g : ℕ} (p : Program signature n g) (gate : Fin g) :
      gate ∈ inputGates p ↔ ∃ (i : Fin n), inputWeight p gate i ≠ 0

      A gate belongs to inputGates p if and only if it has a nonzero aggregated coefficient on some original input.

      theorem Cslib.Circuits.Boolean.WeightedThreshold.inputWeight_eq_zero_of_not_mem {n g : ℕ} (p : Program signature n g) {gate : Fin g} (h : gate ∉ inputGates p) (i : Fin n) :
      inputWeight p gate i = 0

      Every input coefficient vanishes at a gate outside the input-reading set.

      noncomputable def Cslib.Circuits.Boolean.WeightedThreshold.transcript {n g : ℕ} (p : Program signature n g) (x : Fin n → Bool) :
      ↥(inputGates p) → Bool

      The restricted activation transcript, indexed by the input-reading gates.

      theorem Cslib.Circuits.Boolean.WeightedThreshold.eval_eq_of_forall_mem_inputGates_lt {n g : ℕ} (p : Program signature n g) {x y : Fin n → Bool} (bound : ℕ) (h : ∀ gate ∈ inputGates p, ↑gate < bound → p.eval interpretation x gate = p.eval interpretation y gate) (gate : Fin g) :
      ↑gate < bound → p.eval interpretation x gate = p.eval interpretation y gate

      Agreement on input-reading gates before a given bound forces agreement on every gate before that bound.

      Agreement on all input-reading gates forces agreement on every gate.

      The restricted transcript determines the complete gate valuation.

      theorem Cslib.Circuits.Boolean.WeightedThreshold.circuit_eval_eq_of_transcript_eq {n m : ℕ} (c : Circuit signature n m) (houtputs : ∀ (output : Fin m), ∃ (gate : Fin c.size), c.outputs output = Wire.gate gate) {x y : Fin n → Bool} (h : transcript c.program x = transcript c.program y) :

      Gate-valued designated outputs are determined by the restricted transcript. The output hypothesis is necessary: native circuits may select original inputs without any gates.