Hardwiring a prefix of a Boolean circuit code #
prefixCode r n code replaces the first r.length inputs by r and leaves n live inputs.
Two shared constant gates precede the original gates. The transformation is the raw code of
ordinary circuit composition, with exactly two additional gates. Its constructor runs in
polynomial time, with n in binary and all wire numbers in binary.
Main definitions #
Cslib.Circuits.Boolean.prefixCode: hardwiring on raw circuit codes.Cslib.Circuits.Boolean.prefixCircuit: the corresponding typed circuit.
Main results #
Cslib.Circuits.Boolean.code_prefixCircuit: the raw and typed constructions agree.Cslib.Circuits.Boolean.eval_prefixCircuit: hardwiring preserves evaluation.Cslib.Circuits.Boolean.computableInPolyTime_prefixCode: constructor efficiency.
References #
@[simp]
theorem Cslib.Circuits.Boolean.eval_prefixCircuit {n m : ℕ} (r : List Bool) (c : Circuit signature (r.length + n) m) (x : Fin n → Bool) :
(prefixCircuit r c).eval interpretation x = c.eval interpretation (Fin.append (fun (i : Fin r.length) => r[↑i]) x)
Hardwiring a prefix supplies its bits before the live inputs.
theorem Cslib.Circuits.Boolean.evalOutputs_prefixCode {n m : ℕ} (r : List Bool) (c : Circuit signature (r.length + n) m) (x : Fin n → Bool) :
List.map (evalOutput (List.ofFn x) (prefixCode r n c.code).1) (prefixCode r n c.code).2 = List.ofFn (c.eval interpretation (Fin.append (fun (i : Fin r.length) => r[↑i]) x))
Reading the hardwired raw code's output wires gives the original circuit's outputs.
theorem Cslib.Circuits.Boolean.computableInPolyTime_prefixWire {α : Type} {encIn : α ↪ List Bool} {r : α → List Bool} {n i : α → ℕ} (hr : Turing.MultiTapeTM.ComputableInPolyTime r encIn Turing.MultiTapeTM.encBits) (hn : Turing.MultiTapeTM.ComputableInPolyTime n encIn Turing.MultiTapeTM.encNat) (hi : Turing.MultiTapeTM.ComputableInPolyTime i encIn Turing.MultiTapeTM.encNat) :
Turing.MultiTapeTM.ComputableInPolyTime (fun (a : α) => prefixWire (r a) (n a) (i a)) encIn Turing.MultiTapeTM.encNat
Rewriting one wire is polynomial-time even when wire numbers and n are binary.
theorem Cslib.Circuits.Boolean.computableInPolyTime_prefixCode {α : Type} {encIn : α ↪ List Bool} {r : α → List Bool} {n : α → ℕ} {code : α → List (Op × List ℕ) × List ℕ} (hr : Turing.MultiTapeTM.ComputableInPolyTime r encIn Turing.MultiTapeTM.encBits) (hn : Turing.MultiTapeTM.ComputableInPolyTime n encIn Turing.MultiTapeTM.encNat) (hcode : Turing.MultiTapeTM.ComputableInPolyTime code encIn encCode) :
Turing.MultiTapeTM.ComputableInPolyTime (fun (a : α) => prefixCode (r a) (n a) (code a)) encIn encCode
Construct hardwired raw codes in polynomial time, with binary live-input and wire counts.