0% found this document useful (0 votes)
16 views5 pages

The Bernstein-Vazirani Algorithm: F X A X A X N F

Uploaded by

skuparth08
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)
16 views5 pages

The Bernstein-Vazirani Algorithm: F X A X A X N F

Uploaded by

skuparth08
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/ 5

The Bernstein-Vazirani Algorithm

Peter Young
(Dated: October 29, 2019)

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 assignment.
Consider a function

f (x) = a · x (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 . (2)

The problem is to determine a.


Let’s make sure that we understand the “dot”. 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. (3)

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 representation of a:

a = a0 + a1 21 + · · · + ak 2k + · · · an−1 2n−1 , (4)

and similarly for x. 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.
2

x n n x
n n
Uf
y m m y + f(x)
m m

FIG. 1: Schematic diagram of a general unitary transformation Uf for an n-bit input x and an m-bit output
f (x). The upper register in the figure has n qubits and contains the input value x. The lower register has
m qubits and contains information about the function value f (x). The registers are shown as single lines.
To ensure the transformation is reversible we have n + m qubits in both the initial state (to the left) and
final state (to the right). For the Bernstein-Vazirani Algorithm m = 1.

The quantum algorithm succeeds in determining a with just one call!


For the Bernstein-Vazirani Algorithm there are n input qubits and 1 output qubit. A schematic
diagram of a general reversible unitary transformation which takes an n-bit input and generates
an m-bit output is shown in Fig. 1. (For the Bernstein-Vazirani algorithm, m = 1.)
In the Bernstein-Vazirani algorithm the unitary Uf is surrounded by Hadamards, as shown in
Fig. 2. The upper register is set to |0in and the lower qubit to |1i. This is the same circuit as for
the Deutsch-Josza algorithm.

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

FIG. 2: 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 off 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 n−1
⊗n 1 X |0i − |1i
H |0in ⊗ H|1i = √ |xin ⊗ √ . (5)
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 https://young.physics.ucsc.edu/150/deutsch.pdf. The lower qubit is
3

flipped if f (x) = 1, which is the same as changing the sign of the state. This sign change is called
phase kickback by Vathsan1 . 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 the action of Uf is

2 n−1
1 X ( |0i − |1i )
√ (−1)f (x) |xin ⊗ √ . (6)
2n x=0 2

Next consider the effect of the Hadamards acting after Uf . The action on the lower qubit is to

convert ( |0i − |1i )/ 2 to |1i. However, the effect 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|xi1 = √ ( |0i + (−1)x |1i ) = √ (−1)xy |yi . (7)
2 2 y=0

Hence the effect of applying H ⊗n on an n-qubit computational basis state is


1 1 X
1 Pn−1
x j yj
X X
H ⊗n |xin = ··· (−1) j=0 |yn−1 i · · · |y1 i|y0 i ,
yn−1 =0 y1 =0 y0 =0
n −1
2X
1
= (−1)x·y |yin , (8)
2n/2 y=0

where x · y is the bitwise inner product defined in Eq. (2), and we have used that we only need to
Pn−1
know whether j=0 xj yj is even or odd. Hence, combining Eqs. (6) and (8), the amplitude to find
the upper register in state |yi ≡ |yn−1 i · · · |y1 i|y0 i is
2 −1 n
1 X
cy = n (−1)f (x)+x·y
2
x=0
 
n−1 1
1 Y X
= n  (−1)(aj +yj )xj  . (9)
2
j=0 xj =0

Let us evaluate this for the state where yj = aj for all j. Then (aj + yj )xj = 2 or 0 and, since
this quantity is the power of −1 we only need it modulo 2, so all the factors of (−1)(aj +yj )xj are
+1, and consequently all 2n terms from the sums over the xj add up in phase. The result is that
the amplitude for y = a is 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 is a product
over terms for each qubit and so we get zero, as required.
Including the output qubit, the final state is

|ain ⊗ |1i , (10)


4

and a measurement of the upper register in Fig. 2 gives a, 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 analagous 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.
Following Mermin2 and Vathsan1 it is useful to give an alternative derivation of how the circuit
in Fig. 2 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 x0 = 0, x1 = 1, x2 = 0, x3 = 1, x4 = 1. The
function a · x can be implemented by the gates shown in Fig. 3.

a = 11010

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

FIG. 3: 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 or x3
or x4 is 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) as required.

To incorporate Uf into the Bernstein-Vazirani algorithm, we sandwich it in between


Hadamards, see Fig. 2, and note that the Hadamards interchange control and target qubits
in the CNOT (control-X) gates, see Fig. 5(f) in the handout on the Deutsch algorithm,
https://young.physics.ucsc.edu/150/deutsch.pdf. As before, the initial upper register is
|0in and the lower register is |1i. We see immediately from Fig. 4 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 different. To quote
Mermin2 :

2
To understand the reason for the quotation marks see footnote 3 in the handout on the Deutsch algorithm,
https://young.physics.ucsc.edu/150/deutsch.pdf
5

0 H H 0 X 1
0 H H 0 X 1
0 H H 0 0

0 H H = 0 X 1

0 H H 0 0

1 H X X X H 1 1

FIG. 4: Sandwiching the circuit for Uf in Fig. 3 between Hadamards, and realizing that the effect 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 input register contains a = 11010.

“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 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”.)

1
R. Vathsan, Introduction to Quantum Physics and Information Processing (CRC Press, Boca Raton,
2016).
2
N. D. Mermin, Quantum Computer Science (Cambridge University Press, Cambridge, 2007).

You might also like