Documentation

CslibFrontier.Computability.Circuit.Quantum.Controlled

Controlled circuits #

A circuit whose gates never act on qubit j never changes it: its entries vanish between basis strings that differ at j (Cslib.Quantum.Circuit.matrix_eq_zero_of_ne). Such a circuit therefore commutes with projecting onto a value of j (Cslib.Quantum.Circuit.eval_projOutcomes_bit). Every well-formed gate code is its own inverse, so running a list of codes backwards undoes it (Cslib.Quantum.Circuit.eval_ofCodes_reverse).

A circuit C is the circuit D controlled by qubit c (Cslib.Quantum.Circuit.IsControlled) when it does nothing on the basis strings with c = 0 and runs D on those with c = 1. Adding the control c to classical codes (NOT becomes CNOT, CNOT becomes Toffoli) controls their circuit (Cslib.Quantum.Circuit.isControlled_addControl). Conjugating a controlled circuit by codes that do not touch c gives the controlled conjugate (Cslib.Quantum.Circuit.IsControlled.conj). This is how Shi, §4.2, realizes Λ(T_θ) from Λ₂(σ_x) and single-qubit gates: with T = H[a] Λ(σ_x)[a, b] H[a], the codes H[a] Λ₂(σ_x)[c, a; b] H[a] are T controlled by c. This T is a variant of Shi's T_{π/4} = U_{-π/4}[a] Λ(σ_x)[a, b] U_{π/4}[a] = σ_x[b] T, without the final σ_x on the target: a real involution with the same entry ⟨00|T|00⟩ = cos² (π/4). Controlled circuits compose (Cslib.Quantum.Circuit.IsControlled.append).

Main definitions #

Main results #

References #

Qubits a circuit does not act on #

theorem Cslib.Quantum.PlacedGate.matrix_eq_zero_of_ne {m : ℕ} (g : PlacedGate m) {j : Fin m} (hj : ∀ (i : Fin g.arity), g.wires i ≠ j) {y x : Fin m → Bool} (h : y j ≠ x j) :
↑g.matrix y x = 0

A placed gate's entry vanishes between basis strings that differ at a qubit it does not act on.

theorem Cslib.Quantum.Circuit.matrix_eq_zero_of_ne {m : ℕ} {C : Circuit m} {j : Fin m} (hC : ∀ g ∈ C, ∀ (i : Fin g.arity), g.wires i ≠ j) {y x : Fin m → Bool} (h : y j ≠ x j) :
↑C.matrix y x = 0

A circuit never changes a qubit none of its gates acts on: its entries vanish between basis strings that differ there.

theorem Cslib.Quantum.Circuit.eval_projOutcomes {m : ℕ} {C : Circuit m} (p : (Fin m → Bool) → Prop) [DecidablePred p] (hp : ∀ (y x : Fin m → Bool), ↑C.matrix y x ≠ 0 → (p y ↔ p x)) (ψ : Qubits m) :
C.eval ((projOutcomes p) ψ) = (projOutcomes p) (C.eval ψ)

A circuit commutes with projecting onto p when its nonzero entries connect only basis strings on which p agrees.

theorem Cslib.Quantum.Circuit.eval_projOutcomes_bit {m : ℕ} {C : Circuit m} {j : Fin m} (hC : ∀ g ∈ C, ∀ (i : Fin g.arity), g.wires i ≠ j) (b : Bool) (ψ : Qubits m) :
C.eval ((projOutcomes fun (y : Fin m → Bool) => y j = b) ψ) = (projOutcomes fun (y : Fin m → Bool) => y j = b) (C.eval ψ)

A circuit none of whose gates acts on qubit j commutes with projecting onto a value of j.

theorem Cslib.Quantum.GateCode.wires_mem_of_toPlacedGate? {m : ℕ} {b : Bool} {t : ℕ} {cs : List ℕ} {pg : PlacedGate m} (h : toPlacedGate? m (b, t, cs) = some pg) (i : Fin pg.arity) :
↑(pg.wires i) ∈ t :: cs

The qubits of the gate denoted by a code are among the qubits the code names.

theorem Cslib.Quantum.GateCode.eval_eval_of_toPlacedGate? {m : ℕ} {g : GateCode} {pg : PlacedGate m} (hg : WellFormed m g) (h : toPlacedGate? m g = some pg) (ψ : Qubits m) :
pg.eval (pg.eval ψ) = ψ

A well-formed gate is its own inverse.

Classical codes run backwards #

Undoing classical codes is running them backwards.

Undoing classical codes run backwards is running them.

theorem Cslib.Quantum.GateCode.readBit_classicalUnrun_of_forall_ne {m : ℕ} {gs : List GateCode} {q : ℕ} (h : ∀ (b : Bool) (t : ℕ) (cs : List ℕ), (b, t, cs) ∈ gs → t ≠ q) (y : Fin m → Bool) :

Classical codes none of which targets q leave bit q unchanged when undone.

theorem Cslib.Quantum.Circuit.wires_ne_of_ofCodes {m : ℕ} {gs : List GateCode} {j : Fin m} (h : ∀ (b : Bool) (t : ℕ) (cs : List ℕ), (b, t, cs) ∈ gs → ↑j ∉ t :: cs) (pg : PlacedGate m) :
pg ∈ ofCodes m gs → ∀ (i : Fin pg.arity), pg.wires i ≠ j

The gates of ofCodes m gs act only on qubits that the codes gs name.

theorem Cslib.Quantum.Circuit.eval_ofCodes_reverse {m : ℕ} {gs : List GateCode} (h : ∀ g ∈ gs, GateCode.WellFormed m g) (ψ : Qubits m) :
(ofCodes m gs.reverse).eval ((ofCodes m gs).eval ψ) = ψ

Running well-formed codes backwards undoes them.

theorem Cslib.Quantum.Circuit.eval_ofCodes_of_reverse {m : ℕ} {gs : List GateCode} (h : ∀ g ∈ gs, GateCode.WellFormed m g) (ψ : Qubits m) :
(ofCodes m gs).eval ((ofCodes m gs.reverse).eval ψ) = ψ

Running well-formed codes forwards undoes running them backwards.

Controlled circuits #

The circuit C is the circuit D controlled by qubit c: it does nothing on the basis strings with c = 0 and runs D on those with c = 1.

theorem Cslib.Quantum.Circuit.IsControlled.append {m : ℕ} {c : Fin m} {C₁ C₂ D₁ D₂ : Circuit m} (h₁ : IsControlled c C₁ D₁) (h₂ : IsControlled c C₂ D₂) (hD₁ : ∀ g ∈ D₁, ∀ (i : Fin g.arity), g.wires i ≠ c) :
IsControlled c (C₁ ++ C₂) (D₁ ++ D₂)

Controlled circuits compose, provided the first circuit being controlled does not act on the control.

theorem Cslib.Quantum.Circuit.IsControlled.conj {m : ℕ} {c : Fin m} {A : List GateCode} {C D : Circuit m} (hA : ∀ g ∈ A, GateCode.WellFormed m g) (hAc : ∀ (b : Bool) (t : ℕ) (cs : List ℕ), (b, t, cs) ∈ A → ↑c ∉ t :: cs) (h : IsControlled c C D) :

Conjugating a controlled circuit by well-formed codes that do not touch the control qubit gives the conjugated circuit, controlled.

The classical code g with the extra control qubit c: NOT becomes CNOT and CNOT becomes Toffoli.

An extra control qubit c makes a classical code act only when c is one.

theorem Cslib.Quantum.GateCode.classicalUnrun_addControl {m : ℕ} {gs : List GateCode} {c : Fin m} (h : ∀ (b : Bool) (t : ℕ) (cs : List ℕ), (b, t, cs) ∈ gs → t ≠ ↑c) (y : Fin m → Bool) :
theorem Cslib.Quantum.GateCode.isClassical_of_addControl {m : ℕ} {gs : List GateCode} {c : ℕ} (h : IsClassical m (List.map (addControl c) gs)) :
IsClassical m gs ∧ ∀ (b : Bool) (t : ℕ) (cs : List ℕ), (b, t, cs) ∈ gs → t ≠ c

Classical codes with an extra control are classical only if the codes without it are, and then no code targets the control.

Adding a control qubit to classical codes controls their circuit.