Documentation

CslibFrontier.Computability.Circuit.Quantum.Output

Computational-basis output patterns #

An output pattern specifies the bits on a list of wires. Its probability uses the existing computational-basis measurement. Flipping the wires specified as zero converts a pattern on distinct wires into the all-one event of onesProb, without adding Hadamard gates.

The partition identities below are the elementary measurement facts used by exact output sampling. These are original implementation lemmas for the circuit model, not a new simulation algorithm.

Main definitions #

Main results #

def Cslib.Quantum.patternAt (m : ℕ) (ps : List (ℕ × Bool)) :
Finset (Fin m → Bool)

The output outcomes agreeing with every specified wire and bit. An out-of-range wire makes an event impossible.

noncomputable def Cslib.Quantum.patternProb (m : ℕ) (gs : List GateCode) (ps : List (ℕ × Bool)) (x : List Bool) :

The probability of a specified output pattern in the existing final measurement.

The wires specified by a pattern, in its order.

The wires that a pattern specifies as zero.

@[simp]
theorem Cslib.Quantum.mem_patternAt {m : ℕ} {ps : List (ℕ × Bool)} {y : Fin m → Bool} :
y ∈ patternAt m ps ↔ ∀ p ∈ ps, p.1 < m ∧ readBit y p.1 = p.2
theorem Cslib.Quantum.mem_patternAt_append {m : ℕ} {ps : List (ℕ × Bool)} {j : ℕ} {b : Bool} {y : Fin m → Bool} :
y ∈ patternAt m (ps ++ [(j, b)]) ↔ y ∈ patternAt m ps ∧ j < m ∧ readBit y j = b

Appending one specified bit intersects the previous event with that bit's event.

@[simp]
theorem Cslib.Quantum.patternProb_nil (m : ℕ) (gs : List GateCode) (x : List Bool) :
patternProb m gs [] x = 1
theorem Cslib.Quantum.patternProb_nonneg (m : ℕ) (gs : List GateCode) (ps : List (ℕ × Bool)) (x : List Bool) :
0 ≤ patternProb m gs ps x

Pattern probabilities are nonnegative.

A NOT gate on each wire of S, in order.

theorem Cslib.Quantum.GateCode.isClassical_flipCodes {m : ℕ} {S : List ℕ} (hS : ∀ j ∈ S, j < m) :

Flipping valid wires is a well-formed classical circuit.

theorem Cslib.Quantum.GateCode.wellFormed_append_flipCodes {m : ℕ} {gs : List GateCode} (hgs : ∀ g ∈ gs, WellFormed m g) {S : List ℕ} (hS : ∀ j ∈ S, j < m) (g : GateCode) :
g ∈ gs ++ flipCodes S → WellFormed m g

Appending NOT gates on valid wires keeps every gate well formed.

theorem Cslib.Quantum.GateCode.readBit_classicalRun_flipCodes {m : ℕ} {S : List ℕ} (hS : S.Nodup) (hvalid : ∀ j ∈ S, j < m) (x : Fin m → Bool) (c : ℕ) :

A list of distinct NOT gates flips exactly the selected bits.

@[simp]

Terminal NOT gates use no Hadamards.

The zero wires form a sublist of the pattern's wires.

Converting a pattern to all-one form adds at most one gate per specified bit.

theorem Cslib.Quantum.patternZeros_lt {m : ℕ} {ps : List (ℕ × Bool)} (hvalid : ∀ p ∈ ps, p.1 < m) (j : ℕ) :
j ∈ patternZeros ps → j < m

The zero wires of a pattern on valid wires are valid.

Zero wires are distinct when the pattern's wires are distinct.

theorem Cslib.Quantum.mem_patternZeros_iff {ps : List (ℕ × Bool)} (hps : (patternWires ps).Nodup) {p : ℕ × Bool} (hp : p ∈ ps) :

For a pattern on distinct wires, a specified wire is flipped exactly when its bit is zero.

Appending a list of NOT gates does not change the Hadamard denominator.

theorem Cslib.Quantum.mem_onesAt_iff {m : ℕ} {S : List ℕ} {y : Fin m → Bool} :
y ∈ onesAt m S ↔ ∀ j ∈ S, j < m ∧ readBit y j = true

The existing all-one event, expressed through numbered-wire reads.

theorem Cslib.Quantum.classicalRun_flipCodes_mem_onesAt_iff {m : ℕ} {ps : List (ℕ × Bool)} (hps : (patternWires ps).Nodup) (hvalid : ∀ p ∈ ps, p.1 < m) (y : Fin m → Bool) :

Flipping each desired-zero wire converts a valid pattern with distinct wires to an all-one event.

theorem Cslib.Quantum.onesProb_append_flipCodes_eq_patternProb {m : ℕ} (gs : List GateCode) {ps : List (ℕ × Bool)} (hps : (patternWires ps).Nodup) (hvalid : ∀ p ∈ ps, p.1 < m) (x : List Bool) :

The probability of an arbitrary pattern is the existing all-one probability after terminal NOTs on its desired-zero wires.

theorem Cslib.Quantum.measureProb_patternAt_eq_sum {m : ℕ} (ψ : Qubits m) (ps : List (ℕ × Bool)) :
measureProb ψ (patternAt m ps) = ∑ y : Fin m → Bool, if y ∈ patternAt m ps then ‖ψ.ofLp y‖ ^ 2 else 0

A pattern event is a sum over its indicator on all measurement outcomes.

theorem Cslib.Quantum.measureProb_patternAt_partition {m : ℕ} (ψ : Qubits m) (ps : List (ℕ × Bool)) {j : ℕ} (hj : j < m) :

Splitting a pattern on the next valid wire partitions its probability exactly. This also holds if that wire was already specified.

theorem Cslib.Quantum.patternProb_partition {m : ℕ} (gs : List GateCode) (ps : List (ℕ × Bool)) {j : ℕ} (hj : j < m) (x : List Bool) :
patternProb m gs ps x = patternProb m gs (ps ++ [(j, false)]) x + patternProb m gs (ps ++ [(j, true)]) x

Circuit pattern probabilities partition under the next valid output bit.

theorem Cslib.Quantum.mem_patternAt_cons {m : ℕ} {ps : List (ℕ × Bool)} {j : ℕ} {b : Bool} {y : Fin m → Bool} :
y ∈ patternAt m ((j, b) :: ps) ↔ (j < m ∧ readBit y j = b) ∧ y ∈ patternAt m ps

Prepending a specified bit intersects the corresponding events.

theorem Cslib.Quantum.mem_patternAt_zip_iff {m : ℕ} {S : List ℕ} {bs : List Bool} (hS : ∀ j ∈ S, j < m) (hlen : bs.length = S.length) (y : Fin m → Bool) :
y ∈ patternAt m (S.zip bs) ↔ List.map (readBit y) S = bs

A complete pattern on a wire list is exactly a fiber of reading those wires.

theorem Cslib.Quantum.measure_map_readBit_apply {m : ℕ} (gs : List GateCode) (x : List Bool) {S : List ℕ} {bs : List Bool} (hS : ∀ j ∈ S, j < m) (hlen : bs.length = S.length) :
(PMF.map (fun (y : Fin m → Bool) => List.map (readBit y) S) ((Circuit.ofCodes m gs).measure (inputState m x))) bs = ENNReal.ofReal (patternProb m gs (S.zip bs) x)

The marginal of the existing measurement on a list of valid wires agrees with the pattern probability.

theorem Cslib.Quantum.patternProb_eq_onesGap {m : ℕ} (gs : List GateCode) (hgs : ∀ g ∈ gs, GateCode.WellFormed m g) {ps : List (ℕ × Bool)} (hps : (patternWires ps).Nodup) (hvalid : ∀ p ∈ ps, p.1 < m) (x : List Bool) :

An arbitrary valid pattern has the existing projected signed-gap representation. Its terminal NOT gates leave the denominator unchanged.