Documentation

CslibFrontier.Computability.Circuit.Quantum.PhaseOracle

Phase oracles and the reflection about zero #

Conjugating NOT by Hadamard gives the phase flip Z = diag(1, -1) (Cslib.Quantum.Gate.hadamard_mul_not_mul_hadamard), so the gate codes H, X, H on qubit t negate the amplitudes of the basis strings with bit t set (Cslib.Quantum.Circuit.eval_ofCodes_zCodes). Computing a bit with classical codes, flipping its phase and uncomputing gives the phase oracle of the computation (Cslib.Quantum.Circuit.eval_ofCodes_phaseOracleCodes): the amplitude of |y⟩ is negated when the computed bit is one, and nothing else changes. For arbitrary quantum codes, the amplitude of returning to the input after this construction on the output qubit is one minus twice the original acceptance probability (Cslib.Quantum.Circuit.run_phaseOracleCodes_input).

Toffoli gates compute the AND of any number of qubits into a qubit, given zeroed scratch qubits (Cslib.Quantum.GateCode.readBit_classicalRun_andCodes). After NOT gates on the inputs they test whether the inputs are all zero (Cslib.Quantum.GateCode.readBit_classicalRun_zeroTestCodes). The phase oracle of this test is the reflection about the all-zero string of a set of qubits (Cslib.Quantum.Circuit.eval_ofCodes_reflectZeroCodes), the operator Λ̄(σ_z) of Shi, §4.2, realized with Λ₂(σ_x) and σ_z as Shi indicates. Here σ_z is exactly H σ_x H, so the approximate phase flip of Shi's §4.1 is not needed with the Hadamard gate.

Main definitions #

Main results #

References #

H X H = Z: conjugating NOT by Hadamard gives the phase flip diag(1, -1).

theorem Cslib.Quantum.unitaryEquiv_place_of_diagonal {m k : ℕ} (A : Fin k ↪ Fin m) (U : ↥(Gate k)) (d : (Fin k → Bool) → ℂ) (hU : ↑U = Matrix.diagonal d) (ψ : Qubits m) (y : Fin m → Bool) :
((unitaryEquiv ((place A) U)) ψ).ofLp y = d (y ∘ ⇑A) * ψ.ofLp y

A placed diagonal unitary acts pointwise: it multiplies each amplitude by the diagonal entry at the qubits it acts on.

The codes H, X, H on qubit t: the phase flip Z on t.

theorem Cslib.Quantum.GateCode.wellFormed_zCodes {m t : ℕ} (ht : t < m) (g : GateCode) :
g ∈ zCodes t → WellFormed m g

Apply the circuit, flip the phase on qubit t, then uncompute. For classical codes this is the phase oracle of bit t of classicalRun gs.

theorem Cslib.Quantum.Circuit.eval_ofCodes_zCodes {m t : ℕ} (ht : t < m) (ψ : Qubits m) (y : Fin m → Bool) :
((ofCodes m (GateCode.zCodes t)).eval ψ).ofLp y = (if readBit y t = true then -1 else 1) * ψ.ofLp y

The phase flip Z = H X H on qubit t negates the amplitudes of the basis strings with bit t set.

theorem Cslib.Quantum.Circuit.eval_ofCodes_phaseOracleCodes {m : ℕ} {gs : List GateCode} (h : GateCode.IsClassical m gs) {t : ℕ} (ht : t < m) (ψ : Qubits m) (y : Fin m → Bool) :

The phase oracle of a classical computation: phaseOracleCodes gs t negates the amplitude of each basis string y for which bit t of classicalRun gs y is set.

theorem Cslib.Quantum.Circuit.run_phaseOracleCodes_input {m : ℕ} {gs : List GateCode} (hgs : ∀ g ∈ gs, GateCode.WellFormed m g) (hm : 0 < m) (x : List Bool) :
((ofCodes m (GateCode.phaseOracleCodes gs 0)).run (inputState m x)).ofLp (inputState m x) = 1 - 2 * ↑(acceptProb m gs x)

The amplitude of returning to the initial basis state after applying a circuit, flipping the phase of its accepting subspace, and running it backwards is its rejection probability minus its acceptance probability. This also applies when the circuit prepares a superposition.

Toffoli gates computing into qubit w the AND of the qubits cs, using the qubits w + 1, …, w + |cs| as scratch: andCodes [] w is NOT on w, and andCodes (c :: cs) w computes the AND of cs into w + 1 and then applies Λ₂(σ_x)[c, w + 1; w].

theorem Cslib.Quantum.GateCode.target_mem_andCodes {cs : List ℕ} {w : ℕ} (b : Bool) (t : ℕ) (d : List ℕ) :
(b, t, d) ∈ andCodes cs w → w ≤ t ∧ t ≤ w + cs.length

The codes of andCodes cs w target only the qubits w, …, w + |cs|.

theorem Cslib.Quantum.GateCode.isClassical_andCodes {m : ℕ} {cs : List ℕ} {w : ℕ} (hc : ∀ c ∈ cs, c < w) (hw : w + cs.length < m) :
theorem Cslib.Quantum.GateCode.readBit_classicalRun_andCodes {m : ℕ} {cs : List ℕ} {w : ℕ} (hc : ∀ c ∈ cs, c < w) (hw : w + cs.length < m) (x : Fin m → Bool) (hx : ∀ (i : ℕ), w ≤ i → i ≤ w + cs.length → readBit x i = false) :

andCodes cs w computes the AND of cs into qubit w when the scratch qubits w, …, w + |cs| start at zero.

NOT gates on the qubits cs, then andCodes: computes into qubit w whether all the qubits cs are zero.

A polynomial-time generator of control indices and a scratch base gives a polynomial-time generator of the elementary gates testing those controls for zero.

theorem Cslib.Quantum.GateCode.isClassical_zeroTestCodes {m : ℕ} {cs : List ℕ} {w : ℕ} (hc : ∀ c ∈ cs, c < w) (hw : w + cs.length < m) :
theorem Cslib.Quantum.GateCode.readBit_classicalRun_zeroTestCodes {m : ℕ} {cs : List ℕ} (hnd : cs.Nodup) {w : ℕ} (hc : ∀ c ∈ cs, c < w) (hw : w + cs.length < m) (x : Fin m → Bool) (hx : ∀ (i : ℕ), w ≤ i → i ≤ w + cs.length → readBit x i = false) :
readBit (classicalRun (zeroTestCodes cs w) x) w = cs.all fun (c : ℕ) => !readBit x c

zeroTestCodes cs w computes into qubit w whether the qubits cs are all zero, when the scratch qubits w, …, w + |cs| start at zero.

The reflection about the all-zero string of the qubits cs: negate the amplitudes of the basis strings on which every qubit of cs is zero, computing the test into the scratch qubits w, …, w + |cs|.

theorem Cslib.Quantum.Circuit.eval_ofCodes_reflectZeroCodes {m : ℕ} {cs : List ℕ} (hnd : cs.Nodup) {w : ℕ} (hc : ∀ c ∈ cs, c < w) (hw : w + cs.length < m) (ψ : Qubits m) (y : Fin m → Bool) (hy : ∀ (i : ℕ), w ≤ i → i ≤ w + cs.length → readBit y i = false) :
((ofCodes m (GateCode.reflectZeroCodes cs w)).eval ψ).ofLp y = (if (cs.all fun (c : ℕ) => !readBit y c) = true then -1 else 1) * ψ.ofLp y

The reflection about the all-zero string: on basis strings whose scratch qubits w, …, w + |cs| are zero, reflectZeroCodes cs w negates the amplitude exactly when every qubit of cs is zero.