Documentation

CslibFrontier.Computability.Circuit.Quantum.RealEncoding

The real encoding of quantum circuits #

A complex amplitude a + ib can be stored in two real amplitudes on one extra qubit. The real encoding of an m-qubit state ψ is the (m + 1)-qubit state whose amplitude on |x 0⟩ is Re ψ_x and on |x 1⟩ is Im ψ_x (Cslib.Quantum.realEncode); the last qubit says which part is stored. A matrix entry a acts on such pairs as the real block [[Re a, -Im a], [Im a, Re a]] (Cslib.Quantum.realEntry), so a matrix whose entries are these blocks acts on encoded states as the original matrix does on states (Cslib.Quantum.mulVec_realEncode). Aharonov attributes the encoding to Bernstein and Vazirani Bernstein, Vazirani; the blocks are the real version Ũ of a gate U in Definition 1 of Aharonov, with the encoding qubit last.

A circuit C' on m + 1 qubits simulates a circuit C on m qubits through the encoding when it maps the encoding of every state to the encoding of its image under C (Cslib.Quantum.Circuit.RealSimulates). Simulation is preserved by running circuits in sequence, and a circuit started in |x 0⟩ then ends in the encoding of the final state of the simulated circuit started in |x⟩ (Cslib.Quantum.Circuit.RealSimulates.run_snoc_false). The encoding preserves the probability of every measurement of the first m qubits, since (Re a)² + (Im a)² = |a|² (Cslib.Quantum.measureProb_realEncode).

A gate with real entries simulates itself: placed on the same qubits of the larger register, away from the encoding qubit (Cslib.Quantum.PlacedGate.mapWires along Fin.castSuccEmb), it acts on the real and the imaginary parts separately (Cslib.Quantum.PlacedGate.realSimulates_mapWires_castSuccEmb). The Hadamard, NOT, CNOT and Toffoli gates are real, and CslibFrontier/Computability/Circuit/Quantum/PhaseCode.lean simulates the controlled phase gates by four of them.

Main definitions #

Main results #

References #

The real encoding of states #

noncomputable def Cslib.Quantum.realEncode {m : ℕ} (ψ : Qubits m) :
Qubits (m + 1)

The real encoding of a state: on m + 1 qubits, the amplitude a + ib of |x⟩ becomes the amplitude a of |x 0⟩ and the amplitude b of |x 1⟩.

theorem Cslib.Quantum.realEncode_apply {m : ℕ} (ψ : Qubits m) (z : Fin (m + 1) → Bool) :
(realEncode ψ).ofLp z = if z (Fin.last m) = true then ↑(ψ.ofLp (Fin.init z)).im else ↑(ψ.ofLp (Fin.init z)).re
@[simp]
theorem Cslib.Quantum.realEncode_apply_snoc {m : ℕ} (ψ : Qubits m) (x : Fin m → Bool) (b : Bool) :
(realEncode ψ).ofLp (Fin.snoc x b) = if b = true then ↑(ψ.ofLp x).im else ↑(ψ.ofLp x).re
theorem Cslib.Quantum.eq_snoc_iff {m : ℕ} {z : Fin (m + 1) → Bool} {x : Fin m → Bool} {b : Bool} :
z = Fin.snoc x b ↔ Fin.init z = x ∧ z (Fin.last m) = b

A bit string on m + 1 qubits is x b exactly when its first m bits are x and its last bit is b.

@[simp]

The encoding of a basis state |x⟩ is |x 0⟩.

theorem Cslib.Quantum.sum_bitString_succ {m : ℕ} {M : Type u_1} [AddCommMonoid M] (f : (Fin (m + 1) → Bool) → M) :
∑ z : Fin (m + 1) → Bool, f z = ∑ x : Fin m → Bool, (f (Fin.snoc x false) + f (Fin.snoc x true))

A sum over the bit strings of m + 1 qubits, split along the last qubit.

theorem Cslib.Quantum.measureProb_realEncode {m : ℕ} (ψ : Qubits m) (S : Finset (Fin m → Bool)) :
measureProb (realEncode ψ) {z : Fin (m + 1) → Bool | Fin.init z ∈ S} = measureProb ψ S

The encoding preserves the measurement probabilities of the first m qubits: measuring the encoding of ψ gives first m bits in S with the probability that measuring ψ gives an outcome in S.

The real encoding of matrices #

noncomputable def Cslib.Quantum.realEntry (a : ℂ) :
Bool → Bool → ℂ

The real block of a matrix entry: the entry a acts on the pair of real and imaginary parts as [[Re a, -Im a], [Im a, Re a]]; the arguments are the encoding bits of the output (row) and of the input (column).

theorem Cslib.Quantum.realEntry_of_im_eq_zero {a : ℂ} (ha : a.im = 0) (b c : Bool) :
realEntry a b c = if b = c then a else 0

The real block of a real entry is the entry on the diagonal.

theorem Cslib.Quantum.mulVec_realEncode {m : ℕ} {M' : Matrix (Fin (m + 1) → Bool) (Fin (m + 1) → Bool) ℂ} {M : Matrix (Fin m → Bool) (Fin m → Bool) ℂ} (h : ∀ (z z' : Fin (m + 1) → Bool), M' z z' = realEntry (M (Fin.init z) (Fin.init z')) (z (Fin.last m)) (z' (Fin.last m))) (ψ : Qubits m) :

A matrix of real blocks acts on encoded states as the original matrix acts on states.

Simulation of circuits #

The circuit C' on m + 1 qubits simulates the circuit C on m qubits through the real encoding: it maps the encoding of every state to the encoding of its image under C.

theorem Cslib.Quantum.Circuit.realSimulates_of_matrix {m : ℕ} {C' : Circuit (m + 1)} {C : Circuit m} (h : ∀ (z z' : Fin (m + 1) → Bool), ↑C'.matrix z z' = realEntry (↑C.matrix (Fin.init z) (Fin.init z')) (z (Fin.last m)) (z' (Fin.last m))) :

A circuit whose unitary consists of the real blocks of another's simulates it.

theorem Cslib.Quantum.Circuit.RealSimulates.append {m : ℕ} {C' D' : Circuit (m + 1)} {C D : Circuit m} (hC : C'.RealSimulates C) (hD : D'.RealSimulates D) :
(C' ++ D').RealSimulates (C ++ D)

Simulation of sequences: running two simulating circuits in sequence simulates running the simulated circuits in sequence.

theorem Cslib.Quantum.Circuit.RealSimulates.run_snoc_false {m : ℕ} {C' : Circuit (m + 1)} {C : Circuit m} (h : C'.RealSimulates C) (x : Fin m → Bool) :

Simulation of runs: a simulating circuit started in |x 0⟩ ends in the encoding of the final state of the simulated circuit started in |x⟩.

Gates with real entries #

The entries of a gate placed on the first m of m + 1 qubits: it leaves the last qubit alone.

A gate with real entries simulates itself through the real encoding, placed on the same qubits away from the encoding qubit.