Reversible compilation of Boolean circuits #
A De Morgan gate list (CslibFrontier/Computability/Circuit/Boolean/Encoding.lean) on n inputs is
compiled into NOT, CNOT and Toffoli gate codes (Cslib.Quantum.Reversible.codes). Input i sits on
qubit i and gate j writes its value onto the fresh qubit n + j, the numbering of wires in
circuit codes. A constant gate is a NOT or nothing, a negation is a CNOT followed by a NOT, a
conjunction is a Toffoli gate, and a disjunction a ∨ b = a ⊕ b ⊕ (a ∧ b) is two CNOT gates and a
Toffoli gate. An argument that is missing, or that names a wire not computed before the gate, is
read from a qubit z that no gate writes, which stays zero; this matches Cslib.Circuits.evalCode,
which reads such arguments as false, so the compilation is correct for every gate list
(Cslib.Quantum.Reversible.readBit_classicalRun_codes). Nothing is uncomputed: the circuit is
measured once at the end, and only one qubit matters.
Wire numbers in circuit codes are binary; the compiler caps each argument by the unary number of its
gate before converting it, so it runs in polynomial time
(Cslib.Quantum.Reversible.computableInPolyTime_codes).
Main definitions #
Cslib.Quantum.Reversible.gateCodes: the gate codes of one De Morgan gate.Cslib.Quantum.Reversible.codes: the gate codes of a De Morgan gate list.
Main results #
Cslib.Quantum.Reversible.isClassical_codes: the compiled circuit is classical.Cslib.Quantum.Reversible.readBit_classicalRun_codes: it computes the wire values of the gate list.Cslib.Quantum.Reversible.computableInPolyTime_codes: it is compiled in polynomial time.
The gate codes computing the De Morgan gate g onto the fresh qubit t, reading missing or
not yet computed arguments from the zero qubit z.
The reversible compilation of a De Morgan gate list on n inputs: gate j is computed
onto qubit n + j, with z the zero qubit.
The qubit holding a Boolean output wire o when z is the compiler's zero qubit. Malformed
wire numbers at or above z read that zero qubit, matching evalCode's default-false semantics.
Correctness #
The qubit read for an argument holds its value, when the qubits hold the wire values
vals computed before the gate.
One compiled gate appends its value: if the qubits hold the wire values vals computed
before the gate g and zeros after them, its codes add the value of g on qubit t.
The compiled circuit computes the gate list's wire values: started from the input bits
xs and zeros, qubit p ends with the value of wire p (false past the last wire).
Polynomial time #
The reversible compilation runs in polynomial time.