C/CS/Phys C191 Grover s Quantum Search Algorithm 11/06/07 Fall 2007 Lecture 21 1 Readings Benenti et al, Ch 310 Stolze and Suter, Quantum Computing, Ch 84 ielsen and Chuang, Quantum Computation and Quantum Information, Ch 6 Literature: Grover, quant-ph/9605043, quant-ph/9706033; diffusion transform and other motivations from physics, quant-ph/0109116 2 Introduction The problem is to search for an item in an unstructured database For eample, suppose you are given a telephone number in LA and need to find out who it belongs to You will have to go through all the phone numbers and check the names of the registered owners in each case Searching an item in an unsorted database with size costs a classical computer O() running time, since on average /2 entries need to be checked Can a quantum computer search for a needle in a haystack much more efficiently than its classical counterpart? Grover, in 1996, affirmatively answered this question by proposing a search algorithm that consults the database only O( ) times In contrast to algorithms based on the quantum Fourier transform, with eponential speedups, the search algorithm only provides a quadratic improvement However, the algorithm is quite important because it has broad applications, and because the same technique can in principle be used to improve solutions of P-complete problems One might think of having better improvements over the search algorithm However, it turns out that Grover s search algorithm is optimal At least Ω( ) queries are needed to solve the problem Grover s algorithm uses parallelism and amplitude amplification We will discuss the amplitude amplification aspect in detail in the net lecture In the current lecture we will present a geometrical analysis of the quantum search algorithm 21 The quantum oracle Here s the search problem: You are given a boolean function f : {1,, } {0, 1}, and are promised that for eactly one a {1,,}, f(a) = 1 Think of this as a table of size, where eactly one element has value 1, and all the others are 0 f is effectively an oracle that can check/recognize the solution when this is given it as input So f acts like a detector of the target solution In the current analysis we shall assume that there is only 1 solution, but the arguments can be generalized to a finite number of solutions We construct a two register state, with the database register first and the oracle register second Then our oracle acts as follows (cf the Deutsch-Jozsa algorithm) O q = q f(), where we assume f can be computed classically in polynomial time Then we can also apply the oracle with C/CS/Phys C191, Fall 2007, Lecture 21 1
1 the database register in superposition: and α 0 α f() 2 with the oracle register in superposition: ( ) 0 α 1 2 ( ) f() f() α 2 ( ) = α f() f() 2 = α ( 1) f() ( 0 1 2 ) Here f() means the binary complement of f(), ie, if f() = 1, then f() = 0 ote that we have used the same phase kick-back as in Deutsch-Jozsa to go from lines 2 to 3 (Check: if f() = 0 the oracle qubit is 0 1 = ( 1) f(0) ( ) 0 1, while if f() = 1 the oracle qubit is 1 0 = ( 1) f(1) ( ) 0 1 ) So the oracle marks the solutions to the search problem by a minus sign, ie, by a phase (note, no measurement) While it is quite sloppy, we will follow many authors and summarize the action of the oracle on an arbitrary state ν = α as O ν ( 1) f() α, where we have omitted the oracle register on both sides of the equation because it is in the same state But don t forget that the oracle register is essential for this action of O on the database register to be realized! 22 Geometric analysis of search Grover s algorithm finds a in O( ) steps Consider the two dimensional subspace that consists of two states: a and the uniform superposition ψ 0 = 1 Let θ be the angle between ψ 0 and e, where e is the vector that is orthogonal to a (in the direction of ψ 0 ) in this subspace See Figure 1 a is the target and we can regard ψ 0 as the least biased initial state So we want to increase θ to go from ψ 0 to a How do we accomplish this? One way to rotate a vector is to make two reflections In particular, we can rotate a vector v by 2θ to the new vector v1 by first reflecting about e and then reflecting about ψ 0 This transformation is also illustrated in Figure 1 The first reflection transforms an arbitrary vector v to v2 and the second reflection transforms v2 to v1 C/CS/Phys C191, Fall 2007, Lecture 21 2
Figure 1: To rotate v by 2θ to v1, we reflect around e, reaching v2, and then reflect around ψ 0 Each step of our algorithm is thus a rotation by 2θ (we discuss the implementation of the two rotations involved in a step below) This means that we need at most π/2 2θ iterations for the algorithm to complete ow, what is θ? ψ 0 a = cos(π/2 θ) = sin(θ) but ψ 0 a = 1 a 1 = δ a = 1 Then since sin θ θ, we know that θ 1 Thus, we need O( )=O( ) iterations for the algorithm 2/ () to complete In the end, we get very close to a, and then with high probability, a measurement of the state in the computational basis (all qubits) yields a ote that one must not iterate beyond this point Subsequent iterations will rotate the vector v away from a again For large, we need to iterate r = π /4 times and the corresponding probability of error is O(1 cos 2 θ) = O(sin 2 θ) = O( 1 ) How do we implement the two reflections? 1 Reflection about e is easy e is the vector orthogonal to a so all we need to do is flip the phase of the component of the database wavefunction in the direction of a, ie, we send any component π/2 C/CS/Phys C191, Fall 2007, Lecture 21 3
a to a and leave all other components as is To accomplish this, we just act with the oracle: O v = ( 1) f() α α αa a = a = α 2αa a Ô a = Î 2 a a = R e The notation R e means a reflection about the vector e 2 What about the reflection about ψ 0? This uniform superposition state is just the zero vector from the computational basis transformed to the Hadamard basisso we first apply H 2 n, which maps ψ 0 000, then reflect around 00 0, and finally, apply H2 n to return to the original basis The reflection about the zero vector in the computation basis can easily be seen to be given by O 0 = I + 2 0 0 using similar analysis to that above for reflection about e The overall reflection about ψ 0 is then given by the product of the three transformations: D = (H n ) [ I + 2 0 0 ]H n = I + 2 ψ 0 ψ0 = R ψ0 where we have used the fact that H is self-adjoint (H = H ) and that ψ 0 = H n 0 This operator is referred to as the diffusion operator for reasons that will be eplained below To make one iteration step we combine the two reflections, yielding the Grover operator G = DO a = R ψ0 R a We apply this Grover operator O( ) times to rotate from ψ 0 to a otice the difference between the two reflections which arises from the fact that we have written one in terms of the vector about which we reflect (R ψ0 ) and the other in terms of the vector perpendicular to the vector about which we reflect (R a ) What about efficiency of implementation? Observe that D is epressed as the product of three unitary matrices: two Hadamard matrices separated by a conditional phase shift matri (minus one times a diagonal matri with values everywhere one ecept for the uniform superposition state when the value gains a relative phase shift e iπ ) Therefore, D is also unitary Regarding the implementation, both the Hadamard and the conditional phase shift transforms can be efficiently realized within O(n) gates 3 Amplitude amplification in Grover search The Diffusion operator D has two properties: C/CS/Phys C191, Fall 2007, Lecture 21 4
1 It is unitary and can be efficiently realized 2 It can be seen as an inversion about the mean We discussed the first property above We now analyze the second property For = 2 n, we can eplicitly evaluate D = I + 2 ψ 0 ψ0 = (H n ) [ I + 2 0 0 ]H n as: D +1 0 0 0 1 0 = H H 0 0 1 +2 0 0 0 0 0 = H + I H 0 0 0 +2 0 0 0 0 0 = H H I 0 0 0 2/ 2/ 2/ 2/ 2/ 2/ = I 2/ 2/ 2/ +2/ 1 +2/ +2/ +2/ +2/ 1 +2/ = +2/ +2/ +2/ 1 The indeing here is such that the first state (top left hand corner of the matrices) is the uniform superposition state ψ 0 Recall that the central matri in D is a conditional phase shift matri, ie, it puts a phase shift in front of all states ecept the target ow for large, the matri D has diagonal elements appro equal to (1 2/) and very small, positive and constant off-diagonal elements (2/) So in each step the amplitude of every basis state contributes by a small amount to all other basis states This is a generalization of the phenomenon of diffusion on a lattice Consider the action of D on a vector α to generate another vector β : C/CS/Phys C191, Fall 2007, Lecture 21 5
Figure 2: Inversion of amplitudes α i about their mean value µ D α 1 α i α = β 1 β i β Define µ = i α i / as the mean amplitude Then β i = 2 j α j α i = 2(µ α i ) = µ +(µ α i ) which corresponds to a reflection of α i about the mean value µ This is illustrated in Figure 1 below (note that if we start from the uniform superposition, the non-target states will have equal amplitude, we have just illustrated the principle for a general state here) Thus, the amplitude of β i = 2 j α j α i = 2µ α i can be considered an inversion about the mean with respect to α i ow if we first change the sign of the amplitude of the target state, by applying the oracle as in the previous lecture, the target state is now significantly further away from the mean The inversion about the mean further amplifies this, as shown in Figure 2 below This shows how quantum search algorithm iteratively improves the probability of measuring a solution by increasing the component of the target state at each iteration The overall procedure is summarized as follows 1 Start state is ψ 0 = 1 2 Invert the phase of a using f 3 Then invert about the mean using D C/CS/Phys C191, Fall 2007, Lecture 21 6
Figure 3: Application of oracle to invert sign of target state followed by Inversion of amplitudes α i about their mean value µ gives rise to amplification of the target component C/CS/Phys C191, Fall 2007, Lecture 21 7
Figure 4: The first three steps of Grover s algorithm We start with a uniform superposition of all basis vectors in the top panel In the middle panel we have used the function f to invert the phase of α k After running the diffusion operator D in the bottom panel, we have amplified α k while decreasing all other amplitudes C/CS/Phys C191, Fall 2007, Lecture 21 8
4 Repeat steps 2 and 3 O( ) times, so in each iteration α a increases by 2 Suppose we just want to find a with probability 1 2 Until this point, the rest of the basis vectors will have 1 amplitude at least 2 2 In each iteration of the algorithm, α a increases by at least 2 2 = Eventually, α a = 1 2 The number of iterations to get to this α a is C/CS/Phys C191, Fall 2007, Lecture 21 9