Documentation

CslibFrontier.Computability.Circuit.Quantum.Counter

A reversible threshold counter #

A classical circuit of NOT, CNOT and Toffoli gates that counts, in unary, how many of k input bits are one, up to a threshold T (Cslib.Quantum.Counter.codes). Its ancillas start at zero: qubit base is set to one, and stage s has T fresh qubits, its levels (Cslib.Quantum.Counter.level). After stage s, level i reads whether more than i of the first s input bits are one. Stage s + 1 reads the next input bit b and sets each new level to the old level i - 1 when b is one and to the old level i otherwise, with three gates: the multiplexer t ⊕ (b ∧ u) ⊕ (b ∧ t) of the old levels t and u. No gate reads a qubit written in the same stage, so each stage is computed from the previous one (Cslib.Quantum.GateCode.readBit_classicalRun_of_forall_notMem).

The last level of the last stage is the threshold function of the input bits (Cslib.Quantum.Counter.readBit_classicalRun_codes); with k = 2 r inputs and T = r + 1 levels it is their strict majority. This is the reversible majority vote used to amplify the success probability of quantum circuits.

Main definitions #

Main results #

def Cslib.Quantum.Counter.level (base T s i : ℕ) :

The qubit of level i of stage s: after stage s it reads whether more than i of the first s input bits are one.

def Cslib.Quantum.Counter.below (base T s i : ℕ) :

The qubit of level i - 1 of stage s, where level -1 is the qubit base, set to one.

Stage s + 1 of the counter, reading the input bit at b: level i becomes level i - 1 of stage s when the bit is one, and level i of stage s otherwise.

def Cslib.Quantum.Counter.codes (base T : ℕ) (src : ℕ → ℕ) (k : ℕ) :

The counter for the input bits at src 0, …, src (k - 1), with T levels and ancillas from base on: set qubit base to one, then run the stages.

def Cslib.Quantum.Counter.count {N : ℕ} (x : Fin N → Bool) (src : ℕ → ℕ) (s : ℕ) :

The number of input bits that are one among the first s.

theorem Cslib.Quantum.Counter.count_succ {N : ℕ} (x : Fin N → Bool) (src : ℕ → ℕ) (s : ℕ) :
count x src (s + 1) = count x src s + if readBit x (src s) = true then 1 else 0
theorem Cslib.Quantum.Counter.isClassical_stage {N base T b s : ℕ} (hb : b < base) (hN : base + 1 + (s + 2) * T ≤ N) :
theorem Cslib.Quantum.Counter.isClassical_codes {N base T k : ℕ} {src : ℕ → ℕ} (hsrc : ∀ s < k, src s < base) (hN : base + 1 + (k + 1) * T ≤ N) :
GateCode.IsClassical N (codes base T src k)
theorem Cslib.Quantum.Counter.readBit_classicalRun_codes {N base T k : ℕ} {src : ℕ → ℕ} (hsrc : ∀ s < k, src s < base) (hN : base + 1 + (k + 1) * T ≤ N) (x : Fin N → Bool) (hx : ∀ (p : ℕ), base ≤ p → readBit x p = false) :
(∀ p < base, readBit (GateCode.classicalRun (codes base T src k) x) p = readBit x p) ∧ ∀ i < T, readBit (GateCode.classicalRun (codes base T src k) x) (level base T k i) = decide (i < count x src k)

The counter computes the threshold function: started with zero ancillas from base on, it leaves the qubits below base unchanged, and level i of stage k reads whether more than i of the k input bits are one.