Documentation

CslibFrontier.Computability.Circuit.Encoding.Simulation

Circuit codes for constant-size gate replacements #

When each gate is replaced by a block of the same positive size and each block returns its last gate, the location of every simulated wire follows from its original wire number. The simulating program concatenates the replacement blocks in source order and substitutes the relocated source wires for each block's inputs.

Main definitions #

Main results #

Relocate a wire when each source gate becomes a block of B gates returning its last gate.

theorem Cslib.Circuits.Program.toNat_simulateRenaming_uniform {σ : Signature} {τ : Signature} {n g B : ℕ} (p : Program σ n g) (impl : (op : σ.Op) → Circuit τ (σ.Arity op) 1) (hB : 0 < B) (h : ∀ (i : Fin g), (impl (p.lines i).op).size = B ∧ ((impl (p.lines i).op).outputs 0).toNat = σ.Arity (p.lines i).op + B - 1) (w : Wire n g) :

An original program wire is relocated to its fixed block position in the simulation.

theorem Cslib.Circuits.Circuit.code_simulate_uniform {σ : Signature} {τ : Signature} {n m B : ℕ} (c : Circuit σ n m) (impl : (op : σ.Op) → Circuit τ (σ.Arity op) 1) (hB : 0 < B) (h : ∀ (i : Fin c.size), (impl (c.program.lines i).op).size = B ∧ ((impl (c.program.lines i).op).outputs 0).toNat = σ.Arity (c.program.lines i).op + B - 1) :
(c.simulate impl).code = (List.flatMap (fun (i : Fin c.size) => have line := c.program.lines i; List.map (fun (row : τ.Op × List ℕ) => (row.1, List.map (fun (w : ℕ) => if w < σ.Arity line.op then simulateWireNumber n B (line.code.2.getD w 0) else n + ↑i * B + (w - σ.Arity line.op)) row.2)) (impl line.op).program.code) (List.finRange c.size), List.map (simulateWireNumber n B) c.code.2)

Replace each gate by a block of B gates whose sole output is the block's last gate. Input references in a block read the corresponding relocated source wire. Internal references read earlier gates of that same block. Output references use the same relocation as input references. Operations absent from the circuit can have arbitrary implementations.