Quantum counting algorithm explained
Quantum counting algorithm is a quantum algorithm for efficiently counting the number of solutions for a given search problem.The algorithm is based on the quantum phase estimation algorithm and on Grover's search algorithm.
Counting problems are common in diverse fields such as statistical estimation, statistical physics, networking, etc.As for quantum computing, the ability to perform quantum counting efficiently is needed in order to use Grover's search algorithm (because running Grover's search algorithm requires knowing how many solutions exist). Moreover, this algorithm solves the quantum existence problem (namely, deciding whether any solution exists) as a special case.
The algorithm was devised by Gilles Brassard, Peter Høyer and Alain Tapp in 1998.
The problem
Consider a finite set
of size
and a set
of "solutions" (that is a subset of
). Define:
\begin{cases}f:\left\{0,1\right\}n\to\{0,1\}\ f(x)=\begin{cases}1&x\inB\ 0&x\notinB\end{cases}\end{cases}
In other words,
is the
indicator function of
.
Calculate the number of solutions
M=\left\vertf-1(1)\right\vert=\vertB\vert
.
[1] Classical solution
Without any prior knowledge on the set of solutions
(or the structure of the function
), a classical deterministic solution cannot perform better than
, because all the
elements of
must be inspected (consider a case where the last element to be inspected is a solution).
The algorithm
Setup
The input consists of two registers (namely, two parts): the upper
qubits comprise the
first register, and the lower
qubits are the
second register.
Create superposition
The initial state of the system is
. After applying multiple bit Hadamard gate operation on each of the registers separately, the state of the
first register is
and the state of the second register is
(|0\rangle+|1\rangle) ⊗ =
}\sum_^|x\rangle
an equal superposition state in the computational basis.
Grover operator
Because the size of the space is
\left\vert\{0,1\}n\right\vert=2n=N
and the number of solutions is
, we can define the normalized states:
} \sum_
, \qquad \text \qquad |\beta\rangle = \frac \sum_
.
Note that
}|\alpha\rangle + \sqrt|\beta\rangle = \frac\sum_^
,
which is the state of the second register after the Hadamard transform.
Geometric visualization of Grover's algorithm shows that in the two-dimensional space spanned by
and
, the Grover operator is a counterclockwise rotation; hence, it can be expressed as
G=\begin{bmatrix}\cos\theta&-\sin\theta\ \sin\theta&\cos\theta\end{bmatrix}
\{|\alpha\rangle,|\beta\rangle\}
.
[2] [3] From the properties of rotation matrices we know that
is a
unitary matrix with the two
eigenvalues
.
Estimating the value of θ
From here onwards, we follow the quantum phase estimation algorithm scheme: we apply controlled Grover operations followed by inverse quantum Fourier transform; and according to the analysis, we will find the best
-bit approximation to the
real number
(belonging to the eigenvalues
of the Grover operator) with probability higher than
.
[4] Note that the second register is actually in a superposition of the eigenvectors of the Grover operator (while in the original quantum phase estimation algorithm, the second register is the required eigenvector). This means that with some probability, we approximate
, and with some probability, we approximate
; those two approximations are equivalent.
Analysis
Assuming that the size
of the space is at least twice the number of solutions (namely, assuming that
), a result of the analysis of Grover's algorithm is:
} = \sqrt.
Thus, if we find
, we can also find the value of
(because
is known).
The error
=\left\vert\sin2\left(
\right)-\sin2\left(
\right)\right\vert
is determined by the error within estimation of the value of
. The quantum phase estimation algorithm finds, with high probability, the best
-bit approximation of
; this means that if
is large enough, we will have
, hence
.
Uses
Grover's search algorithm for an initially-unknown number of solutions
In Grover's search algorithm, the number of iterations that should be done is
}.
Thus, if
is known and
is calculated by the quantum counting algorithm, the number of iterations for Grover's algorithm is easily calculated.
Speeding up NP-complete problems
The quantum counting algorithm can be used to speed up solution to problems which are NP-complete.
has a
Hamiltonian cycle.
A simple solution to the Hamiltonian cycle problem is checking, for each ordering of the vertices of
, whether it is a Hamiltonian cycle or not. Searching through all the possible orderings of the graph's vertices can be done with quantum counting followed by Grover's algorithm, achieving a speedup of the square root, similar to Grover's algorithm. This approach finds a Hamiltonian cycle (if exists); for determining whether a Hamiltonian cycle exists, the quantum counting algorithm itself is sufficient (and even the quantum existence algorithm, described below, is sufficient).
Quantum existence problem
Quantum existence problem is a special case of quantum counting where we do not want to calculate the value of
, but we only wish to know whether
or not.
[5] A trivial solution to this problem is directly using the quantum counting algorithm: the algorithm yields
, so by checking whether
we get the answer to the existence problem. This approach involves some overhead information because we are not interested in the value of
. Quantum phase estimation can be optimized to eliminate this overhead.
If you are not interested in the control of error probability then using a setup with small number of qubits in the upper register will not produce an accurate estimation of the value of
, but will suffice to determine whether
equals zero or not.
Quantum relation testing problem
Quantum relation testing
. is an extension of quantum existence testing, it decides whether at least one entry can be found in the data base which fulfils the relation to a certain reference value.
[6] E.g.
gives back YES if the data base contains any value larger than 5 else it returns NO. Quantum relation testing combined with classical logarithmic search forms an efficient quantum min/max searching algorithm.
[7] See also
Notes and References
- Book: Automata, Languages and Programming. July 13–17, 1998. Springer Berlin Heidelberg. ICALP'98 Aalborg, Denmark. 978-3-540-64781-2. 820–831. 25th International Colloquium. quant-ph/9805082. 10.1007/BFb0055105. Brassard . Gilles . Hoyer . Peter . Tapp . Alain. 14147978.
- Book: Chuang. Michael A. Nielsen & Isaac L.. Quantum computation and quantum information. 2001. Cambridge Univ. Press. Cambridge [u.a.]. 978-0521635035. Repr..
- Book: Benenti . Guiliano. Strini. Giulio Casati, Giuliano. Principles of quantum computation and information. 2004. World Scientific. New Jersey [u.a.]. 978-9812388582. Reprinted..
- Cleve. R.. Ekert. A.. Macchiavello. C.. Mosca. M.. Quantum algorithms revisited. Proceedings of the Royal Society A: Mathematical, Physical and Engineering Sciences. 8 January 1998. 454. 1969. 339–354. quant-ph/9708016. 10.1098/rspa.1998.0164. 1998RSPSA.454..339C. 16128238.
- Book: Imre. Sandor. Balazs. Ferenc. Quantum Computing and Communications - An Engineering Approach. January 2005. Wiley. 978-0470869024.
- Elgaily . Sara. Imre. Sandor. Constrained Quantum Optimization for Resource Distribution Management. International Journal of Advanced Computer Science and Applications. 2021. 12. 8.
- Imre. Sandor. Quantum Existence Testing and its Application for Finding Extreme Values in Unsorted Databases. IEEE Transactions on Computers. 2007. 56. 5. 706–710. 10.1109/TC.2007.1032. 29588344.