Documentation

CslibFrontier.Computability.Circuit.Quantum.Reversible

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 #

Main results #

Argument i of a gate whose wire is t, capped at t; t when the argument is missing.

def Cslib.Quantum.Reversible.argQubit (z t : ℕ) (args : List ℕ) (i : ℕ) :

The qubit read for argument i of a gate writing qubit t: the wire it names, when that wire is computed before the gate, and the zero qubit z otherwise.

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 #

theorem Cslib.Quantum.Reversible.argQubit_lt_or_eq (z t : ℕ) (args : List ℕ) (i : ℕ) :
argQubit z t args i < t ∨ argQubit z t args i = z
theorem Cslib.Quantum.Reversible.readBit_argQubit {W z t : ℕ} (hz : t ≤ z) {Y : Fin W → Bool} {vals : List Bool} (hvals : vals.length = t) (hY : ∀ (p : ℕ), readBit Y p = vals.getD p false) (args : List ℕ) (i : ℕ) :
readBit Y (argQubit z t args i) = args[i]?.elim false fun (x : ℕ) => vals.getD x false

The qubit read for an argument holds its value, when the qubits hold the wire values vals computed before the gate.

theorem Cslib.Quantum.Reversible.readBit_classicalRun_gateCodes {W z t : ℕ} (htz : t < z) (hz : z < W) {Y : Fin W → Bool} {vals : List Bool} (hvals : vals.length = t) (hY : ∀ (p : ℕ), readBit Y p = vals.getD p false) (g : Circuits.Boolean.Op × List ℕ) (p : ℕ) :

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.

theorem Cslib.Quantum.Reversible.isClassical_codes {W n z : ℕ} {gates : List (Circuits.Boolean.Op × List ℕ)} (hz : n + gates.length ≤ z) (hW : z < W) :
theorem Cslib.Quantum.Reversible.readBit_classicalRun_codes {W n z : ℕ} {gates : List (Circuits.Boolean.Op × List ℕ)} (hz : n + gates.length ≤ z) (hW : z < W) {xs : List Bool} (hxs : xs.length = n) {X : Fin W → Bool} (hX : ∀ (p : ℕ), readBit X p = xs.getD p false) (p : ℕ) :

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 #