Documentation

CslibFrontier.Computability.Circuit.Quantum.PhaseCode

Quantum circuits with phase gates, simulated by real circuits #

The gate set of Cslib.Complexity.BQP consists of the Hadamard gate and the classical reversible gates NOT, CNOT and Toffoli, whose matrices are real. This file adds the controlled phase gates (Cslib.Quantum.Gate.ctrlPhase): the phase gate S = P(i) = diag(1, i), the controlled phase gate Λ(P(i)) = diag(1, 1, 1, i), and their inverses. A gate code of the extended set (Cslib.Quantum.PhaseGateCode) is either a gate code (false, g) (Cslib.Quantum.GateCode) or a controlled phase gate (true, (inv, t, cs)) on the qubits t :: cs, with at most one control. Uniform families over the extended set (Cslib.Quantum.UniformPhaseCircuitFamily) are defined as uniform families of circuits are. The extended set contains {Λ(P(i)), H}, which Kitaev proved universal [Kit97]; this is Theorem 1 of Aharonov.

The real simulation. A circuit is turned into a real one by adding a qubit that records whether a real or an imaginary part is stored; Aharonov attributes this to Bernstein, Vazirani. The real version of a gate U is Definition 1 of Aharonov, and its entries are the blocks Cslib.Quantum.realEntry. Through this encoding (CslibFrontier/Computability/Circuit/Quantum/RealEncoding.lean), with the encoding qubit r after the register, the real gates simulate themselves, and a controlled phase gate on the qubits qs becomes the rotation J = [[0, -1], [1, 0]] of r controlled by qs. Since J = X Z and Z = H X H, it is the gate sequence H_r, X_{qs → r}, H_r, X_{qs → r}, where the middle gates are CNOT or Toffoli gates flipping r; its inverse J⁻¹ = Z X is the reversed sequence (Cslib.Quantum.PhaseGateCode.phaseCodes). For Λ(P(i)) this is the decomposition Λ²[XZ] = T(1, 2, 3) H(3) T(1, 2, 3) H(3) in the proof of Theorem 2 of Aharonov.

So every circuit with controlled phase gates is simulated exactly by a circuit of at most four times as many Hadamard, NOT, CNOT and Toffoli gates on one more qubit (Cslib.Quantum.PhaseGateCode.realSimulates_toRealCodes), which measures the original qubits with the same probabilities (Cslib.Quantum.PhaseGateCode.onesProb_toRealCodes). For uniform families the translation is computed in polynomial time and preserves acceptance probabilities exactly (Cslib.Quantum.UniformPhaseCircuitFamily.realify, Cslib.Quantum.UniformPhaseCircuitFamily.acceptProb_realify).

Scope. This is the reduction step of Aharonov's proof that {T, H} is computationally universal (her Theorem 2). Its other ingredient, Kitaev's universality of {Λ(P(i)), H}, and the Solovay–Kitaev theorem behind computational universality are not formalized here. The simulation is stated for the gates of the extended set; the real version of an arbitrary gate is not constructed as a placed gate.

Main definitions #

Main results #

References #

Controlled phase gates #

noncomputable def Cslib.Quantum.Gate.ctrlPhase (k : ℕ) :
↥(Gate k)

The controlled phase gate on k qubits: it multiplies |x⟩ by i when every qubit is one. For k = 1 this is the phase gate S = P(i) = diag(1, i), and for k = 2 the controlled phase gate Λ(P(i)) = diag(1, 1, 1, i).

theorem Cslib.Quantum.Gate.ctrlPhase_cond_apply (k : ℕ) (inv : Bool) (y x : Fin k → Bool) :
↑(bif inv then (ctrlPhase k)⁻¹ else ctrlPhase k) y x = if y = x then if ∀ (i : Fin k), x i = true then bif inv then -Complex.I else Complex.I else 1 else 0

The entries of the controlled phase gate (inv = false) and of its inverse (inv = true): the diagonal entry of |x⟩ is i, respectively -i, when every qubit of x is one, and 1 otherwise.

noncomputable def Cslib.Quantum.PlacedGate.ctrlPhase {m : ℕ} (inv : Bool) {k : ℕ} (e : Fin k ↪ Fin m) :

The controlled phase gate, or for inv its inverse, on the qubits e.

@[simp]
theorem Cslib.Quantum.PlacedGate.mapWires_ctrlPhase {m N k : ℕ} (e : Fin m ↪ Fin N) (inv : Bool) (A : Fin k ↪ Fin m) :
mapWires e (ctrlPhase inv A) = ctrlPhase inv (A.trans e)

Moving a controlled phase gate to a larger register composes its wire placement.

theorem Cslib.Quantum.PlacedGate.ctrlPhase_matrix_apply {m : ℕ} (inv : Bool) {k : ℕ} (e : Fin k ↪ Fin m) (y x : Fin m → Bool) :
↑(ctrlPhase inv e).matrix y x = if y = x then if ∀ (i : Fin k), x (e i) = true then bif inv then -Complex.I else Complex.I else 1 else 0

The entries of a placed controlled phase gate: it multiplies |x⟩ by i (for inv, by -i) when every qubit of e is one.

theorem Cslib.Quantum.PlacedGate.eval_ctrlPhase_ket {m : ℕ} (inv : Bool) {k : ℕ} (e : Fin k ↪ Fin m) (x : Fin m → Bool) :
(ctrlPhase inv e).eval (ket x) = (if ∀ (i : Fin k), x (e i) = true then bif inv then -Complex.I else Complex.I else 1) • ket x

A controlled phase gate multiplies a basis state by i (for inv, by -i) when every qubit of e is one.

Gate codes on a larger register #

theorem Cslib.Quantum.GateCode.im_toPlacedGate?_gate {m : ℕ} {g : GateCode} {p : PlacedGate m} (hp : toPlacedGate? m g = some p) (y x : Fin p.arity → Bool) :
(↑p.gate y x).im = 0

The gates of gate codes are real: the Hadamard gate and the classical reversible gates have real entries.

A gate code simulates itself through the real encoding, on one more qubit.

Gate codes with controlled phase gates #

@[reducible, inline]

A gate code with phase gates: (false, g) is the gate code g (Cslib.Quantum.GateCode), and (true, (inv, t, cs)) with at most one control cs is the controlled phase gate on the qubits t :: cs (Cslib.Quantum.Gate.ctrlPhase): the phase gate S = diag(1, i) on qubit t when cs = [], and the controlled phase gate Λ(S) on the qubits c and t when cs = [c]; inverted when inv is true.

The placed gate denoted by a gate code with phase gates on m qubits, or none when the code is not well formed.

A gate code with phase gates is well formed on m qubits: a well-formed gate code, or a phase gate with at most one control, on distinct qubits below m.

Instances For

    Exactly the well-formed codes denote gates.

    theorem Cslib.Quantum.PhaseGateCode.exists_toPlacedGate?_eq_ctrlPhase {m : ℕ} {inv : Bool} {t : ℕ} {cs : List ℕ} (hc : WellFormed m (true, inv, t, cs)) :
    ∃ (k : ℕ) (e : Fin k ↪ Fin m), toPlacedGate? m (true, inv, t, cs) = some (PlacedGate.ctrlPhase inv e) ∧ ∀ (w : Fin (m + 1) → Bool), ((t :: cs).all fun (c : ℕ) => (List.ofFn w).getD c false) = decide (∀ (i : Fin k), Fin.init w (e i) = true)

    A well-formed phase gate code denotes a controlled phase gate on qubits e whose conjunction is the one read by the classical gate code with the controls t :: cs, on a register with one more qubit.

    theorem Cslib.Quantum.PhaseGateCode.wellFormed_ctrlCode {m : ℕ} {inv : Bool} {t : ℕ} {cs : List ℕ} (hc : WellFormed m (true, inv, t, cs)) :

    The classical gate code that flips the encoding qubit m under the controls t :: cs of a well-formed phase gate code is well formed on m + 1 qubits.

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

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

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

    The acceptance probability of the circuit with phase gate codes gs on m qubits on input x: the final measurement finds qubit 0 in state 1.

    The real translation #

    The four Hadamard and classical gate codes that simulate a controlled phase gate on the qubits qs (for inv, its inverse) with the encoding qubit r: the gate acts on the encoding qubit as J = [[0, -1], [1, 0]] = X Z controlled by qs, with Z = H X H, and its inverse as J⁻¹ = Z X.

    The real translation of a gate code with phase gates, with the encoding qubit r: a gate code is kept, and a controlled phase gate on t :: cs becomes four Hadamard and CNOT or Toffoli gate codes (phaseCodes).

    The real translation of a list of gate codes with phase gates, with the encoding qubit r.

    The real translation has at most four gate codes per gate code.

    theorem Cslib.Quantum.PhaseGateCode.realSimulates_phaseCodes {m : ℕ} (inv : Bool) {k : ℕ} (e : Fin k ↪ Fin m) {qs : List ℕ} (hqs : GateCode.WellFormed (m + 1) (false, m, qs)) (hall : ∀ (w : Fin (m + 1) → Bool), (qs.all fun (c : ℕ) => (List.ofFn w).getD c false) = decide (∀ (i : Fin k), Fin.init w (e i) = true)) :

    Four Hadamard and classical gates simulate a controlled phase gate through the real encoding: the phase gate on the qubits e is simulated by phaseCodes m inv qs, when the controls qs of the classical gate read the conjunction of the qubits e.

    theorem Cslib.Quantum.PhaseGateCode.wellFormed_toRealCodes {m : ℕ} {gs : List PhaseGateCode} (hgs : ∀ c ∈ gs, WellFormed m c) (g : GateCode) :

    The real translation of well-formed codes is well formed on one more qubit.

    The real translation simulates the circuit: through the real encoding, with the encoding qubit m, the translation of well-formed codes on m qubits simulates the circuit they denote.

    theorem Cslib.Quantum.inputState_succ {m : ℕ} {x : List Bool} (hx : x.length ≤ m) :

    The input x on m + 1 qubits is the input on m qubits followed by a zero, when x fits into m qubits.

    theorem Cslib.Quantum.onesAt_succ {m : ℕ} {S : List ℕ} (hS : ∀ j ∈ S, j < m) :
    onesAt (m + 1) S = {z : Fin (m + 1) → Bool | Fin.init z ∈ onesAt m S}

    The outcomes of m + 1 qubits in which the qubits S below m read one are those whose first m bits do.

    theorem Cslib.Quantum.PhaseGateCode.onesProb_toRealCodes {m : ℕ} {gs : List PhaseGateCode} (hgs : ∀ c ∈ gs, WellFormed m c) {S : List ℕ} (hS : ∀ j ∈ S, j < m) {x : List Bool} (hx : x.length ≤ m) :
    Quantum.onesProb (m + 1) (toRealCodes m gs) S x = onesProb m gs S x

    The real translation measures the original qubits as the circuit does: for well-formed codes on m qubits, an input that fits into them, and measured qubits below m, the real translation on m + 1 qubits finds the qubits S all one with the same probability.

    theorem Cslib.Quantum.PhaseGateCode.acceptProb_toRealCodes {m : ℕ} {gs : List PhaseGateCode} (hgs : ∀ c ∈ gs, WellFormed m c) (hm : 0 < m) {x : List Bool} (hx : x.length ≤ m) :

    The real translation accepts as the circuit does.

    The circuit of gate codes without phase gates, read as gate codes with phase gates.

    Treating ordinary gate codes as phase-gate codes preserves acceptance probability.

    Uniform families with phase gates #

    @[reducible, inline]

    The encoding of gate codes with phase gates (p, g): the phase flag, then the gate code g (Cslib.Quantum.encGateCode).

    A polynomial-time uniform family of quantum circuits with phase gates: as Cslib.Quantum.UniformCircuitFamily, over the Hadamard, NOT, CNOT and Toffoli gates and the phase gates S, Λ(S) and their inverses. On inputs of length n it uses a register of width n qubits, at least n and at least one, and the well-formed codes gates n; both are computed from n in unary in polynomial time.

    The acceptance probability of the family on the input word x: its circuit for inputs of length |x|, started in |x 0^{m - |x|}⟩, ends with qubit 0 measured in state 1.

    The real simulation of a family with phase gates: one more qubit, the encoding qubit, and each controlled phase gate replaced by four Hadamard and CNOT or Toffoli gates (Cslib.Quantum.PhaseGateCode.realCodes).

    @[simp]

    The real simulation accepts as the family does, on every input.

    The circuits of the real simulation have at most four times as many gates.

    A family over the Hadamard, NOT, CNOT and Toffoli gates, as a family with phase gates that uses none.