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 #
Cslib.Quantum.Counter.level,Cslib.Quantum.Counter.stage,Cslib.Quantum.Counter.codes.Cslib.Quantum.Counter.count: the number of input bits that are one.
Main results #
Cslib.Quantum.Counter.isClassical_codes: the counter is a classical circuit.Cslib.Quantum.Counter.readBit_classicalRun_codes: it computes the threshold function and leaves the qubits belowbaseunchanged.
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.
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.
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.