4 CHAPTER III. QUANTUM COMPUTATION Figure III.: Quantum circuit for Deutsch algorithm. [fig. from Nielsen & Chuang (00)] D Quantum algorithms D. Deutsch-Jozsa algorithm D..a Deutsch s algorithm In this section you will encounter your first examle of a quantum algorithm that can comute faster than a classical algorithm for the same roblem. This is a simlified version of Deutsch s original algorithm, which shows how it is ossible to extract global information about a function by using quantum arallelism and interference (Fig. III.). 8 Suose we have a function f :!, asinsec.c.5. Thegoalisto determine whether f(0) = f() with a single function evaluation. This is not a very interesting roblem (since there are only four such functions), but it is a warmu for the Deutsch-Jozsa algorithm. Simle as it is, it could be exensive to decide on a classical comuter. For examle, suose f(0) = the billionth bit of and f() = the billionth bit of e. Thentheroblemis to decide if the billionth bits of and e are the same. It is mathematically simle, but comutationally comlex. To see how we might solve this roblem, suose we have a quantum gate array U f for f; thatis,u f xi yi = xi y f(x)i. In articular, U f xi 0i = 8 This is the 998 imrovement by Cleve et al. to Deutsch s 985 algorithm (Nielsen & Chuang, 00,. 59).
D. QUANTUM ALGORITHMS 5 xi f(x)i and U f xi i = xi f(x)i. Usually we set y =0togettheresult f(x)i, buthereyouwillseeanalicationinwhichwewanty =. Now consider the result of alying U f to xi in the data register and to the suerosition i = ( 0i i) inthetargetregister. U f xi i = xi f(x)i xi f(x)i = xi[ f(x)i f(x)i]. Now the rightmost square bracket is 0i i if f(x) =0or i 0i if f(x) =. Therefore,wecanwrite U f xi i = xi( ) f(x) ( 0i i) =( ) f(x) xi i. (III.) [Here, ( ) x is an abbreviation for ( ) x when we want to emhasize that the sign is all that matters.] Since U f xi i =( ) f(x) xi i, theresultof alying it to an equal suerosition of x =0andx =is: U f xi i = ( ) f(x) xi i. x If f is a constant function, then f(0) = f(), and the summation is ± ( 0i+ i) i = ± +i i because both comonents have the same sign.. On the other hand, if f(0) 6= f(), then the summation is ± ( 0i i) i = ± i i because the comonents have oosite signs. That is, a constant function gives the 0i and i comonents of the data qubit the same hase, and otherwise gives them the oosite hase. Therefore, we can determine whether the function is constant or not by measuring the first qubit in the sign basis; we get +i if f(0) = f() and i otherwise. With this background, we can state Deutsch s algorithm. x algorithm Deutsch: Initial state: Begin with the qubits 0 i def = 0i. Suerosition: Transform it to a air of suerositions i def = ( 0i + i) ( 0i i) = + i. (III.)
6 CHAPTER III. QUANTUM COMPUTATION by a air of Hadamard gates. Recall that H 0i = ( 0i + i) = +i and H i = ( 0i i) = i. Function alication: Next aly U f to i = + i. As we ve seen, U f xi 0i = xi 0 f(x)i = xi f(x)i, and U f xi i = xi f(x)i = xi f(x)i. Therefore,exandEq.III.andalyU f : i def = U f i = U f ale ( 0i + i) ( 0i i) = [U f 00i U f 0i + U f 0i U f i] = [ 0,f(0)i 0, f(0)i +,f()i, f()i] There are two cases: f(0) = f() and f(0) 6= f(). Equal (constant function): If f(0) = f(), then i = [ 0,f(0)i 0, f(0)i +,f(0)i, f(0)i] = [ 0i( f(0)i f(0)i)+ i( f(0)i f(0)i)] = ( 0i + i)( f(0)i f(0)i) = ± ( 0i + i)( 0i i) = ± ( 0i + i) i = + i. The last line alies because global hase (including ±) doesn tmatter. Unequal (balanced function): If f(0) 6= f(), then i = [ 0,f(0)i 0, f(0)i +, f(0)i,f(0)i]
D. QUANTUM ALGORITHMS 7 = [ 0i( f(0)i f(0)i)+ i( f(0)i f(0)i)] = [ 0i( f(0)i f(0)i) i( f(0)i f(0)i)] = ( 0i i)( f(0)i f(0)i) = ± ( 0i i)( 0i i) = ± ( 0i i) i = i Clearly we can discriminate between the two cases by measuring the first qubit in the sign basis. In articular, note that in the unequal case, the i comonent has the oosite hase from the 0i comonent. Measurement: Therefore we can determine whether f(0) = f() or not by measuring the first bit of i in the sign basis, which we can do with the Hadamard gate (recall H +i = 0i and H i = i): 3 i def = (H I) i ± 0i i, if f(0) = f() = ± i i, if f(0) 6= f() = ± f(0) f()i i. Notice that the information we need is in the data register, not the target register. This technique is called hase kick-back (i.e., kicked back into the hase of the data register). In conclusion, we can determine whether or not f(0) = f() with a single evaluation of f, whichisquiteremarkable.ine ect,weareevaluatingf on asuerositionof 0i and i and determining how the results interfere with each other. As a result we get a definite (not robabilistic) determination of aglobalroertywithasingleevaluation. This is a clear examle where a quantum comuter can do something faster than a classical comuter. However, note that U f has to uncomute
8 CHAPTER III. QUANTUM COMPUTATION Figure III.3: Quantum circuit for Deutsch-Jozsa algorithm. [fig. from NC] f, whichtakesasmuchtimeascomutingit,butwewillseeothercases (Deutsch-Jozsa) where the seedu is much more than. D..b The Deutsch-Jozsa algorithm The Deutsch-Jozsa algorithm is a generalization of the Deutsch algorithm to n bits, which they ublished it in 99; here we resent the imroved version of Nielsen & Chuang (00,. 59). This is the roblem: Suose we are given an unknown function f : n! in the form of a unitary transform U f L(H n+, H) (Fig. III.3). We are told only that f is either constant or balanced, whichmeansthatitis0on half its domain and on the other half. Our task is to determine into which class the given f falls. Consider first the classical situation. We can try di erent inut bit strings x. We might (if we re lucky) discover after the second query of f that it is not constant. But we might require as many as n /+queriestoanswer the question. So we re facing O( n )functionevaluations. algorithm Deutsch-Jozsa: Initial state: As in the Deutsch algorithm, reare the initial state 0 i def = 0i n i.
D. QUANTUM ALGORITHMS 9 Suerosition: Use the Walsh-Hadamard transformation to create a suerosition of all ossible inuts: i def =(H n H) 0 i = x, i. x n n Claim: Similarly to the single qubit case (Eq. III.), we can see that U f x, i =( ) f(x) xi i, where( ) n is an abbreviation for ( ) n. From the definition of i and U f, U f x, i = xi ( f(x)i f(x)i). Since f(x), ( f(x)i f(x)i) = i if f(x) =0,andit= i if f(x) =. This establishes the claim. Function alication: Therefore, you can see that: i def = U f i = x n n ( )f(x) xi i. (III.3) In the case of a constant function, all the comonents of the data state have the same hase, otherwise they do not. To see how we can make use of this information, let s consider the state in more detail. For a single bit you can show (Exer. III.4): H xi = ( 0i +( ) x i) = z( ) xz zi = z ( ) xz zi. (This is just another way of writing H 0i = ( 0i+ i) andh i = ( 0i i).) Therefore, the general formula for the Walsh transform of n bits is: H n x,x,...,x n i = = n n z,...,z n ( ) x z + +x nz n z,z,...,z n i z n ( ) x z zi, (III.4) where x z is the bitwise inner roduct. (It doesn t matter if you do addition or since only the arity of the result is significant.) Remember this formula! Combining this and the result in Eq. III.3, 3 i def =(H n I) i = ( n z n x n )x z+f(x) zi i.
30 CHAPTER III. QUANTUM COMPUTATION Measurement: Consider the first n qubits and the amlitude of one articular basis state, z = 0i = 0i n,whichwesearatefromtherestofthe summation: 3 i = x n n ( )f(x) 0i i + z n {0} x n n ( )x z+f(x) zi i Hence, the amlitude of 0i n,theall- 0i qubit string, is P x n n ( ) f(x). Recall how in the basic Deutsch algorithm we got a sum of signs (either all the same or not) for all the function evaluations. The result is similar here, but we have n values rather than just two. We now have two cases: Constant function: If the function is constant, then all the exonents of willbethesame(eitherall0orall),andsotheamlitudewillbe±. Therefore all the other amlitudes are 0 and any measurement must yield 0 for all the qubits (since only 0i n has nonzero amlitude). Balanced function: If the function is not constant then (ex hyothesi) it is balanced, but more secifically, if it is balanced, then there must be an equal number of + and contributionstotheamlitudeof 0i n,soits amlitude is 0. Therefore, when we measure the state, at least one qubit must be nonzero (since the all-0s state has amlitude 0). The good news about the Deutsch-Jozsa algorithm is that with one quantum function evaluation we have got a result that would require between and O( n )classicalfunctionevaluations(exonentialseedu!). Thebad news is that the algorithm has no known alications! Even if it were useful, however, the roblem could be solved robabilistically on a classical comuter with only a few evaluations of f: foranerrorrobabilityof, ittakes O(log ) function evaluations. However, it illustrates rinciles of quantum comuting that can be used in more useful algorithms.