PHYS483: Quantum information processing—Lecture Notes

V Quantum Computation

This section discusses the most important quantum-computation algorithms, associated with the names Deutsch and Josza, Shor, and Grover. To get a feeling of algorithms we start with the simple, classical example of adding two numbers.

V.1 Adding numbers

Figure 10: Classical adder circuits.

The discussion in Section III implies that quantum computers can achieve, at least, the same tasks as a classical computer. Since this requires reversible logics, we first illustrate this by an example, namely, the computation of the sum of two numbers.

Binary numbers can be added just like decimal numbers, bit by bit starting with the least significant bits, and carrying over bits to the next more significant bit. Consider, e.g., the sum 3+3, which in binary code is 11+11. We first add the last two bits (i.e., the least significant bits), resulting in 1+1=10. The last bit of this (0) is the last bit of our result, while the first bit needs to be carried over. We then add the first two bits, and to this the carry-on bit, giving 1+1+1=11. This again results in a carry-on bit. There are no further bits to be processed, so the carry-on bit becomes the most significant bit. Our result now has three bits: 110, which is the same as 4+2+0=6.

Figure 11: Reversible half adder and full adder circuits.

In classical computers, these operations can be carried out using half-adder and full-adder components, which can be realized using elementary binary gates as shown in Fig. 10. Because of x+y=y+x, the depicted circuit is irreversible (furthermore, it requires to copy bits). Figure 11 shows that the same operations can also be achieved quantum mechanically using a combination of reversible CNOT and CCNOT gates, which generate additional outputs that can be used to reverse the calculation.

Adding two numbers with reversible gates does not increase the efficiency of the algorithm. This is in contrast to the following examples, which concern true quantum algorithms that solve specific tasks more efficiently than classical algorithms.

V.2 Deutsch-Josza algorithm

Efficient quantum algorithms generally exploit the quantum parallelism to carry out many calculations in one step, which is particularly useful if one is interested in a global property of these calculations. This is nicely illustrated by the Deutsch-Josza algorithm, which allows to establish a specific feature of certain Boolean functions f:x{0,1} that specifically fall into one of the following two classes: either the function is constant (i.e., the output bit f is either always 1, or always 0), or it is balanced (i.e., the output bit is 0 for one half of the input values, and 1 for the remaining half).

Figure 12: Deutsch and Deutsch-Josza algorithms.

Assume that we are given a function f(x) which is guaranteed to be either constant or balanced, but at the outset we do not know to which of the two classes it belongs. Classically, we need at least two function evaluations to find out that a function is balanced—and this is only in the fortunate case that we immediately pick two inputs for which the outputs differ. In order to certify that a function is constant we need 2N/2+1=2N-1+1 function evaluations—that’s because if the function is balanced, we may by chance first pick 2N/2 inputs that all result in the same output. In contrast, using quantum gates, the Deutsch-Josza algorithm, shown in Fig. 12, requires only a single function evaluation to determine whether the function is constant or balanced. (The upper panel of the figure shows the Deutsch algorithm, the special case of a function f(x) with single-bit input, which is addressed on worksheet 3.)

Starting from the initial state |ψ0=|0001, Hadamard gates are used to form the superposition

|ψ1=nHn|ψ0=2-N/2x|x|0-|12=|Ψ|0-|12

(see also Fig. 6(b)). If f(x)=1, the function gate changes the state of the last qubit into |1-|02=-|0-|12; for f(x)=0, the state of this qubit remains |0-|12. Therefore, the function gate introduces factors (-1)f(x) in front of each basis state |x, resulting in

|ψ2=Uf|ψ1=2-N/2x(-1)f(x)|x|0-|12.

In the final step, Hadamard gates are applied to all but the last qubit. Using the result shown in Fig. 6(c), this delivers the final state

|ψ3=2-Nzx(-1)xz+f(x)|z|0-|12.

Let us now have a look at the amplitude of the state with |z=|0, which is given by 2-Nx(-1)f(x). If f(x) is balanced, this amplitude vanishes. On the other hand, if f(x)=c is constant, this amplitude takes the value ±1 (depending on whether c=0 or c=1). Therefore, if f is constant, a measurement of all qubits will find them all taking the value 0, while this will never happen if the function is balanced. Remarkably, using quantum parallelism, the distinction of both cases has been achieved with a single operation of the function gate.

A notable ingredient of the Deutsch-Josza is the introduction of conditional phase factors (such as (-1)f(x)) in front of each of the computational basis states. This strategy is also at the core of the practically more important algorithms discussed next.

V.3 Grover’s quantum search algorithm

Grover’s quantum search algorithm exploits quantum parallelism to speed up the search for solutions among a large set of candidate solutions. A prime example is the search for entries in a database which match to a given key. Let us enumerate all entries by an integer index x, and assume for simplicity that the size of the database is 𝒩=2N. The entries matching the key can then be characterized by an oracle function f(x), which is a Boolean function that returns f(x)=1 if entry x matches to the key; otherwise, f(x)=0.

Figure 13: Grover search algorithm.

Assume that there are 𝒩 entries matching the key. Classically, we need to make 𝒩/1 queries of the database (or calls of the oracle function) to find one of these entries. The Grover algorithm, shown in Fig. 13, only requires O(𝒩/) calls of the oracle function—not an exponential speedup, but still sizeable when the database is large.

The first step initializes the index register in the now very familiar equal-superposition state |Ψ. This is followed by a sequence of operations G, known as the Grover iterate, in which the oracle gate O^ is called once. Its action is defined to flip the phase of all solutions: O^|x=(-1)f(x)|x. As we have seen in the Deutsch-Josza algorithm, this can be achieved with a function gate acting as O^f|x|q=|x|f(x)q, where the oracle qubit q is initialized as 1/2(|0-|1) (Fig. 13 reserves N workspace qubits for the implementation of the oracle). The Grover iterate also contains a conditional phase gate P=2|00|-I^, which inverts the phase of all computational basis states with exception of the state |0. This is embedded into Hadamard gates, resulting into

P=(nHn)(2|00|-I^)(nHn)=2|ΨΨ|-I^.

The Grover iterate can therefore be written as

G=(2|ΨΨ|-I^)O^.
Figure 14: Geometric interpretation of the Grover search.

The purpose of the Grover iterate is to rotate the initial state into the direction of the equal superposition of solutions |X1m=1|xm, where we have enumerated all solutions as xm, m=1,2,3,,. This rotation takes place in a plane spanned by |X and |Y=1𝒩-m=1𝒩-|ym, the equal superposition of all non-solutions ym, m=1,2,3,,𝒩-. Figure 14 illustrates how this works. The initial state can be written as

|Ψ=/𝒩|X+1-/𝒩|Y,

and therefore lies in the X,Y plane. The unit vector

Ψ=(/𝒩,1-/𝒩)=(sinθ/2,cosθ/2)

can be parameterized in terms of the angle θ/2 between Ψ and the Y axis. For 𝒩, θ=2arccos1-/𝒩2/𝒩 is small, such that Ψ is almost parallel to the Y axis.

Figure 15: Two-bit Grover search algorithm.

Per definition, the oracle function acts as

O^(α|X+β|Y)=-α|X+β|Y,

which amounts to a reflection about the Y axis. The phase gate P performs another reflection, now about the Ψ axis. As a result, the state is rotated by an angle θ towards the X axis. Repeating this rotation (π/4)𝒩/ times rotates the state vector close to the X axis—the misalignment will be less than θ/2. With high probability, a measurement of the final state will therefore deliver a solution xm of the search problem.

Figure 16: Quantum Fourier transformation. The indicated swap gates simply invert the order of the output qubits, which is convenient for subsequent applications.

An instructive example is a two-bit search with one solution x1, depicted in Fig. 15. Panel (a) shows a realization of the P gate with H, X, and CNOT gates (as a matter of fact, this realizes -P, but an overall phase factor of a quantum state is non-detectable). Depending on the binary representation of x1, the oracle function takes one of four possible forms, which can be implemented using Toffoli (CCNOT) and X (NOT) gates as shown in panel (b). For 𝒩=4=22, =1, the angle of the initial state vector Ψ with the Y axis is θ/2=30. The Grover iterate rotates the state by θ=60. A single iteration therefore rotates the state onto the X axis, which immediately identifies the matching entry x1. In contrast, a classical search would on average require 2.25 oracle calls before the solution is found.

V.4 Quantum Fourier transformation

Consider the Fourier transformation

f~(z)=2-N/2x=02N-1ωxzf(x)

of an N-bit function f. Here, we abbreviated ω=e2πi/2N, such that ωxz=e2πixz/2N (where xz is an ordinary, not bitwise, multiplication). Classically, implementation of the Fourier transformation takes O(2N) elementary gate operations. In contrast, its quantum-mechanical analogue, the quantum Fourier transformation

UQFT|x=2-N/2z=02N-1ωxz|z|x~,

can be implemented with O(N2) gate operations, which constitutes an exponential increase in efficiency that can be exploited in a range of algorithms.

Figure 17: Three-bit quantum Fourier transformation.

The corresponding circuit is shown in Fig. 16. The verification that the depicted circuit computes the quantum Fourier transformation can be based on the product representation

|x~=|zN-1|zN-2|z0,

where |zn=1/2(|0+ω2nx|1). Because of the 2π periodicity of the phase, the phase factors can be written as ω2N-nx=ei2π0.xn-1xn-2x0, where we introduced the binary fractions

x/2n=k=0N-1xk2k-nxN-1xn.xn-1x0

in a notation analogous to the one denoting fractional decimal numbers. As shown in the figure, the required transformation of each qubit can be achieved efficiently by first applying a Hadamard gate, followed by phase rotation gates

Rn=(100exp(2πi/2n))

that are controlled by the less significant qubits.

An instructive example is the three-bit quantum Fourier transformation, where ω=exp(2πi/8)=i. In this case, R1=T is the π/8 gate, and R2=S is the phase gate. The corresponding circuit is shown in Fig. 17.

V.5 Applications: From phase estimation to prime factorization

Phase estimation.—A key application of the quantum Fourier transformation is the estimation of the (reduced) phase ϕ of an eigenvalue λ=e2πiϕ of a unitary operator U, where 0ϕ<1. This can be used for a problem called order finding, which in itself is a central step in the prime factorization of numbers. Phase estimation can also be used for a problem know as quantum counting. These problems are briefly discussed later; at the moment it suffices to know that they involve different operators U.

Figure 18: Phase estimation circuit.

Given the eigenstate |u corresponding to λ, ϕ can be estimated efficiently as an N bit binary fraction ϕ0.ϕN-1ϕN-2ϕ0 using the circuit shown in Fig. 18. Since U|u=λ|u and λ=ω2Nϕ, where ω=e2πi/2N, the controlled-U2n operations in the first part of the algorithm transform the qubits into the state 1/2(|0+ω2n(2Nϕ)|1). With N-bit precision, 2Nϕϕ, where the integer number ϕ has the N-bit representation ϕ=ϕN-1ϕN-2ϕ0. The intermediate state can therefore be approximated by the product representation

|zN-1|zN-2|z0=UQFT|ϕ=|ϕ~

of the Fourier-transformed N-bit estimate of 2Nϕ, whose binary digits ϕn are then recovered by an inverse Fourier transformation.

Quantum counting.—A straightforward application of the phase estimation algorithm is the determination of the number of solutions in an 𝒩-item search problem, as encountered in the Grover search. In the X-Y plane, the rotation by one Grover iteration can written as the

G=(cosθsinθ-sinθcosθ),

which is a unitary matrix with eigenvalues e±iθ. We also know that |Ψ lies in the X-Y plane, and therefore is a superposition of the two corresponding eigenstates, which can be fed into the slot for |u.

Order finding.—Phase estimation can also be used to solve the following number-theoretic problem: given two numbers a and M without common divisors, what is the order r of amodM, defined as the smallest positive integer r such that armodM=1? Here, the modulo operation determines the remainder of the division by M. The order can be obtained by estimating the phase of the eigenvalues λn=exp(2πin/r) of the operator U|x=|axmodM (for x<M; otherwise U|x=|x, which guarantees that U is unitary). Conveniently, the sum of eigenfunctions

|un=1rz=0r-1exp(-2πinz/r)|azmodM

is independent of r, n|un=|1. Therefore, initializing |u=|1, the phase estimation algorithm will deliver an approximation of n/r, where each value n in the range 0n<r appears with equal probability 1/r. This suffices to reconstruct the order r (most efficiently, by a method based on continued fractions).

Period finding.—Note that the order r is the period of the function f(x)=axmodM, i.e., f(x)=f(x+r). It is noteworthy that a variant of the procedure above can be used to find the period of any integer-valued function. The corresponding circuit is shown in Fig. 19. The indicated intermediate states are |ψ1=|Ψ|0 and

|ψ2=2-N/2x=02N-1|x|f(x)=1rn=0r-1|(n/r)~|f^(n),

where, as before, (n/r) denotes the N-bit estimate of 2N(n/r), and the tilde indicates the Fourier-transformed state. Furthermore, we abbreviated

|f^(n)=1rx=0r-1exp(-2πnix/r)|f(x).

The inverse Fourier transformation converts this into the final state

|ψ3=1rn=0r-1|(n/r)|f^(n),

so that the measurement of the output qubits in the first register delivers an N-bit approximation of 2N(n/r).

Figure 19: Period finding circuit. The indicated states are specified in the text.

Prime factorization.—In a loose mathematical sense, the factors of an integer number M can also be interpreted as ’periods’ of that number. Indeed, it turns out that the order-finding problem is equivalent to the problem of prime number factorization, and therefore can be solved efficiently using phase estimation. This is embodied in Shor’s factorization algorithm. Because the accurate description of this algorithm requires various number-theoretic concepts, we here only mention one key ingredient: assume we have randomly chosen a number a and found that the order r of amodM is even (otherwise, start again with another randomly chosen a). Then b=ar/2 is still an integer, which fulfills

b2modM=1(b+1)(b-1)modM=0.

Furthermore assume that bmodM-1 (otherwise, start again…). It then follows that b+=(b+1) or b-=(b-1) shares a nontrivial factor with M. The largest factor (the greatest common divisor, gcd) can be found efficiently using Euclid’s algorithm: given c>d, iterate the identity gcd(c,d)=gcd(d,cmodd) until the smaller number is a divisor of the larger number; the smaller number is then the gcd of c and d, which delivers a factor of M.