Documentation

CslibFrontier.Computability.Circuit.Quantum.Code

Quantum circuits over Hadamard and Toffoli gates, written as data #

This file fixes the gate set of the class BQP (Cslib.Complexity.BQP): the Hadamard gate and the classical reversible gates NOT, CNOT and Toffoli of CslibFrontier/Computability/Circuit/Quantum/Basic.lean. Their matrix entries lie in {0, ±1, ±1/√2}.

A gate is written as a triple (h, t, cs) : Bool × ℕ × List ℕ (Cslib.Quantum.GateCode): (true, t, []) is the Hadamard gate on qubit t, and (false, t, cs) with at most two control qubits cs flips qubit t when every qubit of cs is one, that is NOT, CNOT or Toffoli. A code is well formed on m qubits when its qubits are distinct and below m (Cslib.Quantum.GateCode.WellFormed); it then denotes a placed gate (Cslib.Quantum.GateCode.toPlacedGate?), and a list of codes denotes a circuit (Cslib.Quantum.Circuit.ofCodes). Codes are what a polynomial-time machine outputs in the definition of uniform circuit families.

A run starts in the basis state |x 0^{m - n}⟩ holding the input word x of length n on the first qubits (Cslib.Quantum.inputState), and accepts when the final measurement finds qubit 0 in state 1 (Cslib.Quantum.accepting, Cslib.Quantum.acceptProb), as in Arora, Barak, Chapter 10. More generally, Cslib.Quantum.onesProb is the probability that the final measurement finds every qubit of a list S in state 1, the events on which postselected classes condition.

Classical reversible gates permute basis states, updating the bit of their target (Cslib.Quantum.GateCode.eval_toPlacedGate_ket). Appending a NOT gate on qubit 0 exchanges acceptance and rejection (Cslib.Quantum.acceptProb_append_not).

Main definitions #

Main results #

References #

theorem Cslib.Quantum.splitEquiv_symm_update {m k : ℕ} (A : Fin k ↪ Fin m) (x : Fin m → Bool) (i : Fin k) (b : Bool) :
(splitEquiv A).symm (Function.update (x ∘ ⇑A) i b, ((splitEquiv A) x).2) = Function.update x (A i) b

Placing a bit string that differs from x ∘ A only at position i changes x only at the qubit A i.

theorem Cslib.Quantum.PlacedGate.eval_ofPerm_ket_of_update {m k : ℕ} (σ : Equiv.Perm (Fin k → Bool)) (A : Fin k ↪ Fin m) (i : Fin k) (f : (Fin k → Bool) → Bool) (hσ : ∀ (z : Fin k → Bool), σ z = Function.update z i (f z)) (x : Fin m → Bool) :
{ arity := k, gate := Gate.ofPerm σ, wires := A }.eval (ket x) = ket (Function.update x (A i) (f (x ∘ ⇑A)))

A classical reversible gate that changes only its bit i, to f z on input z, maps |x⟩ to the basis state that changes only the qubit A i, to f (x ∘ A).

Gate codes #

@[reducible, inline]

A gate code (h, t, cs): (true, t, []) is the Hadamard gate on qubit t, and (false, t, cs) with at most two controls cs flips qubit t when every qubit in cs is one (the NOT, CNOT and Toffoli gates).

The placed gate denoted by a gate code on m qubits, or none when the code is not well formed: its qubits must be distinct and below m.

A gate code is well formed on m qubits: a Hadamard gate without controls, or a classical gate with at most two controls, on distinct qubits below m.

Instances For

    Exactly the well-formed codes denote gates.

    theorem Cslib.Quantum.GateCode.eval_toPlacedGate_ket {m t : ℕ} {cs : List ℕ} {g : PlacedGate m} (hg : toPlacedGate? m (false, t, cs) = some g) (ht : t < m) (x : Fin m → Bool) :
    g.eval (ket x) = ket (Function.update x ⟨t, ht⟩ (x ⟨t, ht⟩ ^^ cs.all fun (c : ℕ) => (List.ofFn x).getD c false))

    A classical gate code updates its target bit: the well-formed code (false, t, cs) maps |x⟩ to the basis state that changes only qubit t, flipping it when every control is one.

    theorem Cslib.Quantum.GateCode.eval_toPlacedGate_hadamard_ket {m t : ℕ} {g : PlacedGate m} (hg : toPlacedGate? m (true, t, []) = some g) (ht : t < m) (x : Fin m → Bool) :
    g.eval (ket x) = ∑ c : Bool, ((if (x ⟨t, ht⟩ && c) = true then -1 else 1) * ↑(√2)⁻¹) • ket (Function.update x ⟨t, ht⟩ c)

    The Hadamard gate code branches on its target: the well-formed code (true, t, []) maps |x⟩ to ∑_c (-1)^{x_t c} / √2 · |x[t ↦ c]⟩.

    noncomputable def Cslib.Quantum.Circuit.ofCodes (m : ℕ) (gs : List GateCode) :

    The circuit on m qubits denoted by a list of gate codes, applied first to last. Codes that are not well formed are skipped.

    Input, acceptance and acceptance probability #

    def Cslib.Quantum.inputState (m : ℕ) (x : List Bool) :
    Fin m → Bool

    The basis state |x 0^{m - n}⟩ of an m-qubit register holding the input word x on its first qubits (truncated when x is longer than m).

    def Cslib.Quantum.onesAt (m : ℕ) (S : List ℕ) :
    Finset (Fin m → Bool)

    The outcomes in which every qubit of S reads 1.

    noncomputable def Cslib.Quantum.onesProb (m : ℕ) (gs : List GateCode) (S : List ℕ) (x : List Bool) :

    The probability that the final measurement of the circuit with gate codes gs on m qubits, started in |x 0^{m - n}⟩, finds every qubit of S in state 1. The acceptance probability is the case S = [0] (Cslib.Quantum.acceptProb_eq_onesProb).

    theorem Cslib.Quantum.onesProb_nonneg (m : ℕ) (gs : List GateCode) (S : List ℕ) (x : List Bool) :
    0 ≤ onesProb m gs S x
    theorem Cslib.Quantum.onesProb_le_one (m : ℕ) (gs : List GateCode) (S : List ℕ) (x : List Bool) :
    onesProb m gs S x ≤ 1
    @[simp]
    theorem Cslib.Quantum.onesProb_nil (m : ℕ) (gs : List GateCode) (x : List Bool) :
    onesProb m gs [] x = 1

    The event of no condition is certain.

    The accepting outcomes: qubit 0 reads 1.

    noncomputable def Cslib.Quantum.acceptProb (m : ℕ) (gs : List GateCode) (x : List Bool) :

    The acceptance probability of the circuit with gate codes gs on m qubits on input x: started in |x 0^{m - n}⟩, the final measurement finds qubit 0 in state 1.

    theorem Cslib.Quantum.mem_accepting {m : ℕ} (hm : 0 < m) {y : Fin m → Bool} :
    theorem Cslib.Quantum.acceptProb_append_not {m : ℕ} (hm : 0 < m) (gs : List GateCode) (x : List Bool) :
    acceptProb m (gs ++ [(false, 0, [])]) x = 1 - acceptProb m gs x

    A final NOT on qubit 0 exchanges acceptance and rejection.