Circuits as lists of gates #
A circuit 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). 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). All of this is defined for an
arbitrary signature.
For the De Morgan basis, an operation is written as its number Boolean.Op.toNat in unary and a
wire number in binary (Boolean.encGate). A circuit with n inputs and m outputs is encoded by
n in unary, then its framed gates in program order, then its framed output wires
(Boolean.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. Gates may read wires of any number below their own, so wire numbers take
logarithmically many bits.
Main definitions #
Cslib.Circuits.Wire.toNat,Cslib.Circuits.Wire.ofNat: wire numbers.Cslib.Circuits.Line.code,Cslib.Circuits.Program.code,Cslib.Circuits.Circuit.code: circuits as lists of gates.Cslib.Circuits.Line.ofCode,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.Boolean.encOp,Cslib.Circuits.Boolean.encGate,Cslib.Circuits.Boolean.encCode,Cslib.Circuits.Boolean.encCircuit: binary encodings of De Morgan circuits.
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.Boolean.le_length_encCircuit: the encoding is at least as long as the number of inputs.
References #
Wire numbers #
The number of a wire: input i is i and gate j is inputCount + j.
Instances For
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
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.
Encodings of De Morgan circuits #
The number of an operation of the De Morgan basis: 0 and 1 for the constants false and
true, then 2, 3, 4 for NOT, AND, OR.
Instances For
Binary encoding of De Morgan circuits with m outputs and any number n of inputs: n in
unary, then the code of the circuit (encCode), that is, its gates in program order and its output
wires, with wire numbers in binary.
Instances For
The encoding of a circuit is at least as long as its number of inputs.