Quantum counting algorithm

From HandWiki
Short description: Quantum algorithm for counting solutions to search problems

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 [math]\displaystyle{ \{0,1\}^n }[/math] of size [math]\displaystyle{ N=2^n }[/math] and a set [math]\displaystyle{ B }[/math] of "solutions" (that is a subset of [math]\displaystyle{ \{0,1\}^n }[/math]). Define:

[math]\displaystyle{ \begin{cases} f : \left\{0,1\right\}^n \to \{0,1\} \\ f(x) = \begin{cases} 1 & x \in B \\ 0 & x \notin B \end{cases} \end{cases} }[/math]

In other words, [math]\displaystyle{ f }[/math] is the indicator function of [math]\displaystyle{ B }[/math].

Calculate the number of solutions [math]\displaystyle{ M = \left\vert f^{-1}(1) \right\vert = \vert B \vert }[/math].[1]

Classical solution

Without any prior knowledge on the set of solutions [math]\displaystyle{ B }[/math] (or the structure of the function [math]\displaystyle{ f }[/math]), a classical deterministic solution cannot perform better than [math]\displaystyle{ \Omega(N) }[/math], because all the [math]\displaystyle{ N }[/math] elements of [math]\displaystyle{ \{0,1\}^n }[/math] must be inspected (consider a case where the last element to be inspected is a solution).

The algorithm

Quantum counting circuit

Setup

The input consists of two registers (namely, two parts): the upper [math]\displaystyle{ p }[/math] qubits comprise the first register, and the lower [math]\displaystyle{ n }[/math] qubits are the second register.

Create superposition

The initial state of the system is [math]\displaystyle{ |0\rangle^{\otimes p}|0\rangle^{\otimes n} }[/math]. After applying multiple bit Hadamard gate operation on each of the registers separately, the state of the first register is

[math]\displaystyle{ \frac{1}{2^{p/2}}(|0\rangle + |1\rangle)^{\otimes p} }[/math]

and the state of the second register is

[math]\displaystyle{ \frac{1}{2^{n/2}}(|0\rangle + |1\rangle)^{\otimes n} = \frac{1}{\sqrt{N}}\sum_{x=0}^{N-1}|x\rangle }[/math]

an equal superposition state in the computational basis.

Grover operator

Because the size of the space is [math]\displaystyle{ \left\vert \{0,1\}^n \right\vert = 2^n = N }[/math] and the number of solutions is [math]\displaystyle{ \left\vert B \right\vert = M }[/math], we can define the normalized states:[2]:252

[math]\displaystyle{ |\alpha\rangle = \frac{1}{\sqrt{N-M}} \sum_{x \notin B}{|x\rangle}, \qquad \text{and} \qquad |\beta\rangle = \frac{1}{\sqrt{M}} \sum_{x \in B}{|x\rangle}. }[/math]

Note that

[math]\displaystyle{ \sqrt{\frac{N-M}{N}}|\alpha\rangle + \sqrt{\frac{M}{N}}|\beta\rangle = \frac{1}{\sqrt{N}}\sum_{x=0}^{N-1}{|x\rangle}, }[/math]

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 [math]\displaystyle{ |\alpha\rangle }[/math] and [math]\displaystyle{ |\beta\rangle }[/math], the Grover operator is a counterclockwise rotation; hence, it can be expressed as

[math]\displaystyle{ G = \begin{bmatrix} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta\end{bmatrix} }[/math]

in the orthonormal basis [math]\displaystyle{ \{|\alpha\rangle, |\beta\rangle\} }[/math].[2]:252[3]:149

From the properties of rotation matrices we know that [math]\displaystyle{ G }[/math] is a unitary matrix with the two eigenvalues [math]\displaystyle{ e^{\pm i \theta} }[/math].[2]:253

Estimating the value of [math]\displaystyle{ \theta }[/math]

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 [math]\displaystyle{ p }[/math]-bit approximation to the real number [math]\displaystyle{ \theta }[/math] (belonging to the eigenvalues [math]\displaystyle{ e^{\pm i \theta} }[/math] of the Grover operator) with probability higher than [math]\displaystyle{ \frac{4}{\pi^2} }[/math].[4]:348[3]:157

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 [math]\displaystyle{ \theta }[/math], and with some probability, we approximate [math]\displaystyle{ 2\pi - \theta }[/math]; those two approximations are equivalent.[2]:224–225

Analysis

Assuming that the size [math]\displaystyle{ N }[/math] of the space is at least twice the number of solutions (namely, assuming that [math]\displaystyle{ M \leq \tfrac{N}{2} }[/math]), a result of the analysis of Grover's algorithm is:[2]:254

[math]\displaystyle{ \sin {\frac{\theta}{2}} = \sqrt{\frac{M}{N}}. }[/math]

Thus, if we find [math]\displaystyle{ \theta }[/math], we can also find the value of [math]\displaystyle{ M }[/math] (because [math]\displaystyle{ N }[/math] is known).

The error

[math]\displaystyle{ \frac{\vert \Delta M \vert}{N} = \left \vert \sin^2 \left( \frac{\theta + \Delta \theta}{2} \right) - \sin^2 \left( \frac{\theta}{2} \right) \right \vert }[/math]

is determined by the error within estimation of the value of [math]\displaystyle{ \theta }[/math]. The quantum phase estimation algorithm finds, with high probability, the best [math]\displaystyle{ p }[/math]-bit approximation of [math]\displaystyle{ \theta }[/math]; this means that if [math]\displaystyle{ p }[/math] is large enough, we will have [math]\displaystyle{ \Delta \theta \approx 0 }[/math], hence [math]\displaystyle{ \vert \Delta M \vert \approx 0 }[/math].[2]:263

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 [math]\displaystyle{ \frac{\pi}{4}\sqrt{\frac{N}{M}} }[/math].[2]:254 [3]:150

Thus, if [math]\displaystyle{ N }[/math] is known and [math]\displaystyle{ M }[/math] 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.

An example of an NP-complete problem is the Hamiltonian cycle problem, which is the problem of determining whether a graph [math]\displaystyle{ G=(V,E) }[/math] has a Hamiltonian cycle.

A simple solution to the Hamiltonian cycle problem is checking, for each ordering of the vertices of [math]\displaystyle{ G }[/math], 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.[2]:264 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 [math]\displaystyle{ M }[/math], but we only wish to know whether [math]\displaystyle{ M \neq 0 }[/math] or not.[5]:147

A trivial solution to this problem is directly using the quantum counting algorithm: the algorithm yields [math]\displaystyle{ M }[/math], so by checking whether [math]\displaystyle{ M \neq 0 }[/math] we get the answer to the existence problem. This approach involves some overhead information because we are not interested in the value of [math]\displaystyle{ M }[/math]. Quantum phase estimation can be optimized to eliminate this overhead.[5]:148

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 [math]\displaystyle{ \theta }[/math], but will suffice to determine whether [math]\displaystyle{ M }[/math] equals zero or not.[2]:263

Quantum relation testing problem

Quantum relation testing [math]\displaystyle{ QRT(value,relation) }[/math]. 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. [math]\displaystyle{ QRT(5,\gt ) }[/math] 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. [5]:152 [7]

See also

References

  1. Brassard, Gilles; Hoyer, Peter; Tapp, Alain (July 13–17, 1998). Automata, Languages and Programming (25th International Colloquium ed.). ICALP'98 Aalborg, Denmark: Springer Berlin Heidelberg. pp. 820–831. doi:10.1007/BFb0055105. ISBN 978-3-540-64781-2. 
  2. 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 Chuang, Michael A. Nielsen & Isaac L. (2001). Quantum computation and quantum information (Repr. ed.). Cambridge [u.a.]: Cambridge Univ. Press. ISBN 978-0521635035. 
  3. 3.0 3.1 3.2 Benenti, Guiliano; Strini, Giulio Casati, Giuliano (2004). Principles of quantum computation and information (Reprinted. ed.). New Jersey [u.a.]: World Scientific. ISBN 978-9812388582. 
  4. Cleve, R.; Ekert, A.; Macchiavello, C.; Mosca, M. (8 January 1998). "Quantum algorithms revisited". Proceedings of the Royal Society A: Mathematical, Physical and Engineering Sciences 454 (1969): 339–354. doi:10.1098/rspa.1998.0164. Bibcode1998RSPSA.454..339C. 
  5. 5.0 5.1 5.2 Imre, Sandor; Balazs, Ferenc (January 2005). Quantum Computing and Communications - An Engineering Approach. Wiley. ISBN 978-0470869024. 
  6. Elgaily, Sara; Imre, Sandor (2021). "Constrained Quantum Optimization for Resource Distribution Management". International Journal of Advanced Computer Science and Applications 12 (8). 
  7. Imre, Sandor (2007). "Quantum Existence Testing and its Application for Finding Extreme Values in Unsorted Databases". IEEE Transactions on Computers 56 (5): 706–710. doi:10.1109/TC.2007.1032.