Circuits as lists of gates #
A circuit over an arbitrary Signature is written down as data by listing its gates in program
order. Wires are numbered as in Cslib.Circuits.Circuit.trace: input i is wire i and gate j
is wire n + j, where n is the number of inputs (Wire.toNat, from
CslibFrontier.Computability.Circuit.WireNumber). A line is written as its operation and the
numbers of the wires it reads (Line.code), a program as the list of its lines (Program.code),
and a circuit as its program and the numbers of its output wires (Circuit.code). The size of a
circuit is the length of its gate list (Program.length_code).
Decoding (Program.ofCode, Circuit.ofCode) checks that every line has as many arguments as its
operation's arity and reads only inputs and earlier gates, and that the outputs are wires of the
circuit. It inverts coding (Circuit.ofCode_code), and every list it accepts is the code of the
circuit it returns (Circuit.code_of_ofCode_eq_some); so a list of gates that passes these checks
is a circuit, with the usual semantics. The lists it accepts are described by Program.IsCodeFrom
(Program.isSome_ofCode_iff, Circuit.isSome_ofCode_iff).
Given an encoding encOp : σ.Op ↪ List Bool of operations, a gate is encoded by its operation and
framed binary wire numbers (Circuit.encGate), a raw code by its framed gates and framed output
wire numbers (Circuit.encCode), and a circuit with m outputs and n inputs by n in unary
followed by its code (Circuit.encCircuit). Writing n in unary makes the encoding at least as
long as the number of inputs, as when inputs are counted as vertices of the circuit Arora and
Barak, Section 6.1.
Main definitions #
Cslib.Circuits.Line.code,Cslib.Circuits.Program.code,Cslib.Circuits.Circuit.code: circuits as lists of gates.Cslib.Circuits.Line.ofCode,Cslib.Circuits.Program.pushCode,Cslib.Circuits.Program.ofCode,Cslib.Circuits.Circuit.ofCode: decoding, with the well-formedness checks.Cslib.Circuits.Program.IsCodeFrom: the lists of gates that are codes of programs.Cslib.Circuits.Circuit.encGate,Cslib.Circuits.Circuit.encCode,Cslib.Circuits.Circuit.encCircuit: binary encodings of circuits over an arbitrary signature given an operation encoding.
Main results #
Cslib.Circuits.Program.ofCode_code,Cslib.Circuits.Circuit.ofCode_code: decoding inverts coding.Cslib.Circuits.Program.code_of_ofCode_eq_some,Cslib.Circuits.Circuit.code_of_ofCode_eq_some: an accepted list is the code of the decoded circuit.Cslib.Circuits.Program.isSome_ofCode_iff,Cslib.Circuits.Circuit.isSome_ofCode_iff: the lists that decode.Cslib.Circuits.Program.IsCodeFrom.getElem,Cslib.Circuits.Program.isCodeFrom_of_getElem: elementwise characterization ofProgram.IsCodeFrom.Cslib.Circuits.Circuit.code_injective: coding is injective.Cslib.Circuits.Circuit.code_wiring,Cslib.Circuits.Circuit.code_wiring_eq_map,Cslib.Circuits.Circuit.code_wiring_id: serialized codes of pure wirings.Cslib.Circuits.Circuit.le_length_encCircuit,Cslib.Circuits.Circuit.size_le_length_encCircuit: the encoding is at least as long as the number of inputs and the gate count.
References #
Lines #
Programs #
IsCodeFrom σ n k gates: every entry of gates has the arity of its operation and reads only
the n inputs and the gates before it, the first entry being gate k. Such lists, with k = 0,
are exactly the codes of programs (Program.isSome_ofCode_iff).
Instances For
IsCodeFrom σ n k gates is decidable.
The empty gate list satisfies IsCodeFrom σ n k for every starting gate index k.
g :: gates satisfies IsCodeFrom σ n k iff g is a valid line at index k and gates
satisfies IsCodeFrom σ n (k + 1).
A concatenation gates ++ gates' satisfies IsCodeFrom σ n k iff gates satisfies
IsCodeFrom σ n k and gates' satisfies IsCodeFrom σ n (k + gates.length).
In a list satisfying IsCodeFrom σ n k, entry j has the arity of its operation and reads
only the first n + k + j wires.
A list of gates satisfies IsCodeFrom σ n k when every entry j has the arity of its
operation and reads only the first n + k + j wires.
Circuits #
Different circuits have different codes.
Wiring serialization #
The serialized code of the identity wiring on n wires is ([], List.range n).
The serialized code of the wiring that keeps the first m of m + k wires is
([], List.range m).
Binary encodings of circuits over an arbitrary signature #
Binary encoding of circuits with m outputs over an arbitrary signature σ equipped with
encOp : σ.Op ↪ List Bool: the dependent pair (Turing.MultiTapeTM.encSigma) of the input count
n in unary and the circuit, which is encoded by its code (encCode encOp).
Unfolding formula for encCircuit encOp m c.