Composing quantum query algorithms #
Constructions that build query algorithms (Cslib.Quantum.run) from others: classical control,
which realizes classical randomness, parking, checking an output with one more query, and
running an algorithm twice.
Classical control. A query algorithm is a deterministic sequence of isometries, but its
workspace and initial state are arbitrary, so classical randomness fits inside it. Let the
workspace be W × G, where G is a classical register that the algorithm reads but never
changes. The isometry controlled V applies V g to the slice ψ_g of the state where the
register holds g (Cslib.Quantum.slice, Cslib.Quantum.controlled). The oracle never touches the
workspace, so the slices evolve separately: the slice at g of the final state is the final state
of the algorithm V g started from the slice at g of the initial state
(Cslib.Quantum.slice_run), and measuring adds up the slices
(Cslib.Quantum.measureProb_eq_sum_slice, Cslib.Quantum.regProb_eq_sum_slice). So preparing the
register in the superposition ∑_g √(p_g) |g⟩ makes every outcome probability the average, with
weights p_g, of the outcome probabilities of the algorithms V g: a classical mixture of query
algorithms, with the coin replaced by its purification.
Parking. To let algorithms with different numbers of queries share one query count, an
algorithm whose state after k queries has control bit 1 can be parked (Cslib.Quantum.park):
after its k-th query the control bit is flipped to 0 (Cslib.Quantum.flipCtrl), where the
controlled oracle acts as the identity, and nothing happens afterwards (Cslib.Quantum.run_park).
Parking does not change the probability of any query index.
Checking an output. If the state after T queries has control bit 0, a Hadamard gate on the
control bit (Cslib.Quantum.hadCtrl), one more query and another Hadamard gate write the queried
bit x_i of the query index i into the control bit (Cslib.Quantum.check,
Cslib.Quantum.run_check). The control bit is then 1 with the probability that measuring the
query register gives an index i with x_i = 1 (Cslib.Quantum.measureProb_run_check). On an
arbitrary state the same three steps are the bit oracle |i, b, w⟩ ↦ |i, b ⊕ x_i, w⟩
(Cslib.Quantum.bitFlip, Cslib.Quantum.hadCtrl_phaseOracle_hadCtrl_eq_permute).
Running twice. Cslib.Quantum.twice runs an algorithm with T queries twice, on two copies of
its registers: the second copy waits in the workspace during the first run, then the copies are
exchanged by a permutation of the basis (Cslib.Quantum.permute), and the outcome of the first run
waits in the workspace during the second. After 2T queries the state is the product of two
copies of the final state of the algorithm (Cslib.Quantum.run_twice), so accepting when either
outcome is accepting succeeds with probability 1 - (1 - a)²
(Cslib.Quantum.measureProb_run_twice).
These constructions are standard; their formulation in this query model is original.
Main definitions #
Cslib.Quantum.QueryBasis: named(index, ctrl, work)coordinates of a basis state ofState N W.Cslib.Quantum.slice,Cslib.Quantum.controlled: slices at a classical register, and the isometry applyingV gto the slice atg.Cslib.Quantum.permute,Cslib.Quantum.flipCtrl,Cslib.Quantum.hadCtrl: a permutation of the basis, the flip of the control bit and the Hadamard gate on it.Cslib.Quantum.bitFlip: the basis permutation of the bit oracle.Cslib.Quantum.park: an algorithm stopped afterkqueries.Cslib.Quantum.check: an algorithm followed by a check of its output.Cslib.Quantum.twice,Cslib.Quantum.twiceInit: an algorithm run twice.
Main results #
Cslib.Quantum.slice_run: classically controlled algorithms run slice by slice.Cslib.Quantum.measureProb_eq_sum_slice: outcome probabilities add up over the slices.Cslib.Quantum.run_park: a parked algorithm keeps its state afterkqueries.Cslib.Quantum.run_add: a run splits into two runs.Cslib.Quantum.hadCtrl_phaseOracle_hadCtrl_eq_permute: Hadamard gates around a query give the bit oracle.Cslib.Quantum.run_check,Cslib.Quantum.measureProb_run_check: the state and acceptance probability after a check.Cslib.Quantum.run_twice,Cslib.Quantum.measureProb_run_twice: running twice gives two independent copies.
Named basis configurations, slices and classical control #
Named computational-basis configuration of Cslib.Quantum.State N W: the queried index in
Fin N, the phase-kickback control bit, and the workspace value.
- index : Fin N
The queried input position.
- ctrl : Bool
The phase-kickback control bit.
- work : W
The workspace register value.
Instances For
Equivalence between QueryBasis N W and the raw basis tuple Fin N × Bool × W of
State N W.
Classically controlled algorithms run slice by slice: if the isometry after s queries
applies V g s to the slice at g, then the slice at g of the state after t queries is the
state after t queries of the algorithm V g started from the slice at g.
Outcome probabilities add up over the slices: the probability of an outcome set S is the
sum over g of the probability, in the slice at g, of the outcomes whose extension by g lies
in S.
Scaling #
Permutations of the basis and parking #
The basis permutation of the bit oracle |i, b, w⟩ ↦ |i, b ⊕ x_i, w⟩, which adds the
queried bit to the control bit. Hadamard gates around a query realize it
(Cslib.Quantum.hadCtrl_phaseOracle_hadCtrl_eq_permute).
A parked algorithm keeps its state: if the state of U after k queries has control bit
1, then after t ≥ k queries the parked algorithm is in that state with the control bit
flipped.
Agreement and splitting of runs #
Splitting a run: if V does nothing before its first query and then follows U from the
T-th query on, then running U for T + s queries is running V for s queries from the
state of U after T queries.
Checking an output #
Hadamard gates around a query give the bit oracle: a Hadamard gate on the control bit, a
query and another Hadamard gate permute the basis by |i, b, w⟩ ↦ |i, b ⊕ x_i, w⟩.
Checking a parked output: if φ has control bit 0, then a Hadamard gate on the control
bit, a query and another Hadamard gate write the queried bit into the control bit: the result has
amplitude φ(i, 0, w) at |i, x_i, w⟩ and 0 elsewhere.
The algorithm U followed by a check of its output after T queries: a Hadamard gate on
the control bit, one more query and another Hadamard gate, which write the queried bit x_i of
the measured index i into the control bit.
The state after a check: if the state of U after T queries has control bit 0, then
after the check the control bit holds the queried bit x_i of the query index i.
The acceptance probability of a check: if the state of U after T queries has control
bit 0, then after the check the control bit is 1 with the probability that measuring the state
of U gives a marked query index.
Running an algorithm twice #
The basis permutation exchanging the query register, control bit and workspace with a copy of
them (QueryBasis N W) held in the workspace.
The algorithm U with T queries run twice, on two copies of its registers: the second
copy waits in the workspace while the first run makes its T queries; then the copies are
exchanged, and the second run makes T more queries while the outcome of the first waits in the
workspace.
The initial state of twice: two copies of ψ₀.
Running twice gives two independent copies: after T + T queries, the state of twice is
the product of two copies of the state of U after T queries.
The acceptance probability of running twice: accepting when the outcome of either run lies
in S, twice accepts with probability 1 - (1 - a)², where a is the probability that the
outcome of one run lies in S.