0% found this document useful (0 votes)
13 views8 pages

Phys 150 All

Quantum physics

Uploaded by

Bhushan Waghade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views8 pages

Phys 150 All

Quantum physics

Uploaded by

Bhushan Waghade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Chapter 11

The Bernstein-Vazirani Algorithm

11.1 The Algorithm


Like the Deutsch algorithm, the Bernstein-Vazirani algorithm finds information about a black box
function, but has a bigger speedup. It is very similar to the Deutsch-Josza algorithm which is set as a
homework problem.
Consider a function
f (x) = a · x (11.1)
where a and x have n bits while the function itself, f , has one bit. The dot indicates a bitwise inner
product with modulo 2 addition:

a · x ⌘ a0 x0 a1 x1 ··· an 1 xn 1 . (11.2)

The problem is to determine a.


Let’s make sure that we understand the “dot”. We have ai xi = 0 or 1. Hence

a · x = a 0 x0 a 1 x1 · · · a n 1 xn 1 (11.3)

1 if an odd number of terms is 1
= (11.4)
0 if an even number of terms is 1

For example for n = 4, if the bits of a are 1101 and the bits of x are 1110 (recall that the zeroth bit is
the least significant, i.e. the rightmost one) then1

a · x = (1 ⇥ 0) + (0 ⇥ 1) + (1 ⇥ 1) + (1 ⇥ 1) mod 2 = 0 + 0 + 1 + 1 mod 2 = 2 mod 2 = 0. (11.5)

Hence, for these values of a and x, f (x) = 0. If we take x = 1000 then f (x) = 0 + 0 + 0 + 1 mod 2 = 1.
Classically we can only determine the bits of a one at a time. The k-th bit of a can be determined
by feeding in x = 2k . To see this, consider the binary representations of a and x:

a = a0 + a1 21 + · · · + ak 2k + · · · + an 12
n 1
,
(11.6)
x = x0 + x1 21 + · · · + xk 2k + · · · + xn 1 2n 1
.

Hence if x = 2k then xk = 1 while, for l 6= k, xl = 0, so a · x = ak . Consequently f (2k ) = ak . We have


to do this for each bit, k = 0, 1, 2, · · · , n 1, so it requires n calls of the function.
1
One can either do the mod 2 operation after each addition or add up in the normal way and apply the mod 2 operation
at the end. In either case, the result is 0 if an even number of terms in the sum are 1, and 1 if an odd number of terms
are 1.

97
98 CHAPTER 11. THE BERNSTEIN-VAZIRANI ALGORITHM

We will see that the quantum algorithm succeeds in determining a with just one call!
A schematic diagram of a general reversible unitary transformation which takes an n-bit input x
in the upper register and generates an m-bit output f (x) in the lower register is shown in Fig. 9.2. For
the Bernstein-Vazirani Algorithm there are n qubits in the upper register but only 1 qubit in the lower
register. In addition, the unitary Uf is surrounded by Hadamards, as shown in Fig. 11.1. The upper
register is set to |0in and the lower qubit to |1i. This is the same circuit as for the Deutsch-Josza
algorithm, see problem 11.1.

n xn n xn n
0 H H a
n n
Uf
1 H H 1

Figure 11.1: Circuit diagram for the Bernstein-Vazirani algorithm. In the final state the upper (input)
register contains |ai while the lower (output) qubit reverts to its initial state |1i. The desired value of
a can therefore be read o↵ by measuring the upper register.

Acting with H on |0i gives an equal linear superposition of the two basis states. Similarly acting
with H ⌦n on |0in gives an equal superposition of the 2n basis states. Hence, including the lower
register, the state inputted to Uf is

2 1 n
⌦n 1 X |0i |1i
H |0in ⌦ H|1i = p |xin ⌦ p . (11.7)
n
2 x=0 2

For each term in the superposition, the function Uf acts in the same way as for the Deutsch algorithm
described in Chapter 10. The lower qubit is flipped if f (x) = 1, which is the same as changing the sign
of the state. If f (x) = 0 there is no change. Hence each term in the superposition acquires a factor of
( 1)f (x) , so the state of the system immediately after the action of Uf is

2 1n
1 X ( |0i |1i )
p ( 1)f (x) |xin ⌦ p . (11.8)
n
2 x=0 2

Next consider the


p e↵ect of the Hadamards acting after Uf . The action on the lower qubit is to
convert ( |0i |1i )/ 2 to |1i. However, the e↵ect of H ⌦n acting on an arbitrary computational basis
state |xin needs more thought. Consider first just one qubit. Then
1
1 1 X
H|xi = p ( |0i + ( 1)x |1i ) = p ( 1)xy |yi . (11.9)
2 2 y=0

Hence the e↵ect of applying H ⌦n on an n-qubit computational basis state is


1
X 1 X
X 1 Pn
1 1
xj yj
H ⌦n |xin = ··· ( 1) j=0 |yn 1 i · · · |y1 i|y0 i ,
2n/2 yn 1 =0 y1 =0 y0 =0
n 1
2X
1
= ( 1)x·y |yin , (11.10)
2n/2 y=0
11.2. AN ALTERNATIVE DERIVATION 99

where x · y is the bitwise inner product with moduloP2n addition defined in Eq. (11.2), and we have
1
used the fact that we only need to know whether j=0 xj yj is even or odd. All the amplitudes,
P
cy ⌘ (1/2 )( 1) , are equal in magnitude and the sign is +1 if nj=01 xj yj is even (note that each
n x·y
P
term in the sum is 1 or 0) and the sign is 1 if nj=01 xj yj is odd.
Hence, combining Eqs. (11.8) and (11.10), the amplitude to find the upper register in state |yin ⌘
|yn 1 i · · · |y1 i|y0 i is
2 1n
1 X
cy = n ( 1)f (x)+x·y
2
x=0
2 3
n 1 1
1 Y 4X
= n ( 1)(aj +yj )xj 5 . (11.11)
2
j=0 xj =0

Let us evaluate this for the state where yj = aj for all j, in which case P aj + yj = 2 or 0. If xj = 0
then ( 1)(aj +yj )xj = 1 and if xj = 1 we also get ( 1)(aj +yj )xj = 1, so 1xj =0 ( 1)(aj +yj )xj = 2, i.e. the
two terms add up in phase. Hence, from Eq. (11.11), we have ca = 1. Since the total probability must
add up to 1 this means that all the other amplitudes must be zero. To see that this is indeed the case,
note that for each qubit where yj 6= aj , aj + yj = 1 and so the sum over xj for these qubits gives zero.
The final result in Eq. (11.11) is a product over terms for each qubit and so we get zero, as required.
Including the lower (output) qubit, the final state is

|ain ⌦ |1i , (11.12)

and a measurement of the upper register in Fig. 11.1 gives a, with probability one, even though we
made just one call to the function.
Since a classical computation of a requires n function calls, we have obtained a “quantum speedup”
of n. Note that the procedure is analogous to Deutsch’s algorithm. The first set of Hadamards
generates a superposition of inputs to the gate Uf which “evaluates”2 the function for all 2n inputs
using quantum parallelism, and then the second set of Hadamards destroys all the outputs apart from
a, using quantum interference.

11.2 An Alternative Derivation


Following Mermin [Mer07] and Vathsan [Vat16] it is useful to give an alternative derivation of how the
circuit in Fig. 11.1 works, by giving an explicit construction of the black box Uf . It is convenient to
illustrate by a specific example. We take n = 5 and a = 11010 so a0 = 0, a1 = 1, a2 = 0, a3 = 1, a4 = 1
(recall we read the bits from right, the least significant, to left, the most significant). The function
a · x can be implemented by the gates shown in Fig. 11.2.
To incorporate Uf into the Bernstein-Vazirani algorithm, we sandwich it in between Hadamards,
see Fig. 11.1, and note that the Hadamards interchange control and target qubits in the CNOT
(control-X) gates, see Fig. 10.5(f) in Chapter 10. As before, the initial upper register is |0in and the
lower register is |1i. We see immediately from Fig. 11.3 that a is directly imprinted in the final state
of the input register. There does not appear to be any parallelism and interference.
Hence these two explanations of the Bernstein-Vazirani algorithm are quite di↵erent. To quote
Mermin [Mer07]:
“The first applies Uf to the quantum superposition of all possible inputs and then applies
operations which leads to perfect destructive interference of all states in the superposition
2
To understand the reason for the quotation marks see the discussion at the end of Sec. 9.2.
100 CHAPTER 11. THE BERNSTEIN-VAZIRANI ALGORITHM

a = 11010

x4
x3
Uf = x2
x1
x0
y X X X y + a x

Figure 11.2: A circuit diagram for n = 5 to implement the function f (x) = a · x with a = 11010,
i.e. f (x) = x1 + x3 + x4 mod 2. The circuit flips the output qubit, the lowest one, initialized to y,
whenever x1 x3 x4 = 1. (Note that flipping y is equivalent to adding 1 to y mod 2.) Hence the
final value of the output qubit is y (a · x) = y x1 x3 x4 as required.

x4 0 H H 0 X 1
x3 0 H H 0 X 1
x2 0 H H 0 0

x1 0 H H = 0 X 1

x0 0 H H 0 0

y 1 H X X X H 1 1

Figure 11.3: Sandwiching the circuit for Uf in Fig. 11.2 between Hadamards, and realizing that the
e↵ect of the Hadamards is to interchange the control and target qubits in the CNOT (control-X) gates,
we see immediately that the final state of the upper (input) register contains a = 11010.

except for the one in which the upper (input) register is in the state |ai. The second
suggests a specific mechanism for representing the subroutine that executes Uf and then
shows that sandwiching such a mechanism between Hadamards automatically (my italics)
imprints a on the upper register. Interestingly, quantum mechanics appears in the second
method only because it allows the reversal of the control and target qubits of a cNOT
operation solely by means of 1-qubit (Hadamard) gates.”

(I have used the conventional spelling of “qubit” rather than Mermin’s idiosyncratic “Qbit”.)

Problems
11.1. The Deutsch-Josza Algorithm
This is an extension of the Deutsch algorithm discussed in class. Recall that in Deutsch’s
algorithm the input is one bit and the output is also one bit. In the Deutsch-Josza algorithm,
the output is still one bit but the input has n bits, so there are 2n distinct inputs. We are told
that either the function is “constant” (in which case the function outputs the same value for all
2n inputs) or is “balanced” (in which case an equal number of inputs give the results 1 and 0).
11.2. AN ALTERNATIVE DERIVATION 101

Clearly this is a very artificially constructed problem but it will be our first quantum algorithm
with more than a one-bit input. Note that it is precisely the Deutsch algorithm for n = 1.
The circuit for the Deutsch-Josza is almost identical to that for the Deutsch algorithm except
that the upper qubit in the Deutsch algorithm (sometimes called the “input” qubit) is replaced
by a n-qubit register. The circuit is shown in the figure below.

ψ ψ ψ
0 1 2

0 x nn xn
n H H n y
n
Uf
1 H H 1

The function Uf acts as follows on computational basis states |xin and |zi:

Uf |xin |zi = |xin |z f (x)i , (11.13)

where x is an n-bit integer, |xi is the state of the n-qubit upper register in the figure, z and f (x)
are 1-bit integers, and |zi is the lower qubit in the figure.
As in the Deutsch algorithm, the lower qubit is initialized to |1i. In the Deutsch algorithm, the
upper qubit is initialized to |0i. Here the single qubit is replaced by an n-qubit register which,
by analogy, is initialized to |0in .

(i) Show that


2 1 n
⌦n 1 X
| 0 in =H |0in = p |xin , (11.14)
2n x=0
so the input to the function Uf is the uniform superposition of all 2n basis states.
(ii) Show that after the action of Uf the state of the upper register is
2 1 n
1 X
| 1 in = p ( 1)f (x) |xin . (11.15)
2n x=0

The fact that the value of f (x) only changes the overall sign of the state is called the phase
kickback trick by Vathsan.
(iii) Show that after the action of the second set of Hadamards on the n-qubit register, the state
of that register is
2n 1
⌦n 1 X
| 2 in = H | 1 in = n ( 1)[f (x)+x·y] |yin , (11.16)
2
x,y=0

where x · y is the bitwise inner product of x and y with modulo 2 addition:

x · y = x 0 y0 x 1 y1 ... xn 1 yn 1 . (11.17)

(iv) The upper register is then measured, and an n-bit integer y is obtained. Show that if
the function is a constant then y = 0 with probability 1. Show also that if the function
is balanced then one must get a non-zero value of y. Hence the Deutsch-Josza algorithm
succeeds with just one function call.
102 CHAPTER 11. THE BERNSTEIN-VAZIRANI ALGORITHM

(v) How does this compare with a classical approach? The only thing one can do classically is
keep computing f (x) for di↵erent values of x and seeing if one gets more than one value
for the output. If the function is balanced, one would probably get di↵erent outputs quite
quickly. If the function is constant one would need to evaluate half the inputs (plus 1),
i.e. 2n 1 + 1, to be 100% sure that the function is not balanced. This is exponentially (in
n) worse than the quantum algorithm.
However, this is arguably not fair. We may well be content to establish that the function is
constant with some high probability3 , a bit less than one. If the function is constant, how
many function calls would you need classically to rule out the possibility that it is balanced
with a probability of error of no more than (i) 10 3 and (ii) 10 6 .
Note: For simplicity, assume that the number of function calls is much less than 2n/2 , the
number of values of x which give the same result if the function is balanced.

11.2. Consider the Deutsch-Josza algorithm for n = 2, and assume a constant function f (x) = 0 for
all x, i.e. x = 0, 1, 2, 3. Compute explicitly the state of the system at each stage and show that
you get the state |yi = |00i in the upper register at the end.
Hint: Evaluate explicitly Eqs. (11.14)–(11.16) for this situation.

11.3. Consider again the Deutsch-Josza algorithm for n = 2 but this time assume that f (00) = f (01) =
0, f (10) = f (11) = 1. Show that at least one of the two qubits in the upper register ends up as
1.
Hint: See the hint for Qu. 11.2.

11.4. The To↵oli Gate.


We stated in Sec. 7.1 that for classical reversible computation we need three-bit gates, such as the
To↵oli gate, in addition to 1-bit and 2-bit gates, to be able to perform universal computation.
However, three qubit gates are, fortunately, not needed in quantum computation because the
appropriate three-bit gates can be constructed out of 1-qubit and 2-qubit gates.
Here we consider the quantum To↵oli gate, which is a control-control-NOT (C-C-NOT) gate:

x x
y y

z z + xy

The target qubit z is flipped if both the control qubits, x and y, are 1 and is otherwise unchanged.

(i) Consider the following circuit for an arbitrary unitary operator V :

x x
y X X y

z V V V

3
For later quantum algorithms we will only be able to solve the problem with high probability. Since we have to give
up 100% certainty in the quantum case, we we should not insist on 100% certainty here from the classical algorithm.
11.2. AN ALTERNATIVE DERIVATION 103

Show that it acts with V 2 on |zi if both x and y are 1 and otherwise does nothing.
Hint: One possible way of approaching this question (though not the only way) is to consider
separately what happens for the four possible input values of the control qubits x and y,
namely 00, 01, 10, and 11.
Another, more elegant, way is to note that the e↵ect of a Ctrl-V gate in which |zi is the
target and |xi is the contol is V |xi|zi ! |xiV x |zi.
(ii) Now take V to be the following 1-qubit gate:

( + i X)
V = (1 i) . (11.18)
2
Show that V † V = , and hence V is unitary. Show also that V 2 = X and hence the above
circuit is a quantum To↵oli gate.
Note: One sometimes says that V is the “square root of X”.
104 CHAPTER 11. THE BERNSTEIN-VAZIRANI ALGORITHM

You might also like