Quantum Computing
Quantum Computing
An Introduction
With Quantum
Simulators on
CD-ROM
Vishal Sahni
Chapter 2 14
Qubits, Quantum Mechanics and Computer Science Perspectives
2.1 Quantum Algebra
2.2 Quantum Bits (Qubits) 14
2.2.1 Bloch Sphere : Geometric Representation of a Qubit 21
2.2.2 Rotations about the X, Y and Z axis 23
2.3 Multiple Qubits 25
2.4 Computer Science Perspectives 26
Chapter 3 31
Quantum Gates
3.1 Single Qubit Gates 31
3.1.1 Quantum NOT Gate 31
3.1.2 Z Gate 34
3.1.3 Hadamard gate 35
3.1.4 Pauli Matrices 38
3.1.5 Phase Gate (or S Gate) 44
3.1.6 T Gate 46
3.2 Multiple Qubit Gates 47
3.2.1 Controlled NOT (CNOT gate) 48
3.2.2 Swap Gate 50
3.2.3 Controlled-Z Gate 52
3.2.4 Toffoli Gate 53
3.2.5 Fredkin (controlled-swap) Gate 56
3.3 Matrix Representation of Quantum Gates and Circuits 58
3.3.1 Matrix Representation of Quantum Gates 58
3.3.2 Matrix Representation of Quantum Circuits 63
3.4 Bell States 67
3.5 Can a Qubit Copying Circuit Work 70
3.6 Quantum Measurement 72
3.7 Qubit Half-Adder and Subtractor 78
3.7.1 Half-Adder 78
3.7.2 Subtractor 80
Chapter 4
Applications of Quantum Computing
4.1 Quantum Teleportation 82
4.2 Quantum Parallelism 88
4.2.1 Deutsch’s Algorithm 90
4.2.2 Deutsch-Jozsa Algorithm 94
4.3 Superdense Coding 97
4.4 Quantum Communication 99
Chapter 5 105
Shor’s Algorithm and Quantum Fourier Transform
5.1 Shor’s Algorithm Simplified through examples 105
5.2 Quantum Fourier Transform 109
5.3 Implementation of Quantum Fourier Transform using Quantum Gates 112
5.4 Phase Estimation 121
5.5 Shor’s Algorithm using Phase Estimation 122
5.6 Order-Finding and Factoring Explained Further 126
Chapter 6 129
Grover’s Algorithm (Quantum Search Algorithms)
6.1 What is an Oracle? 129
6.2 Steps in Grover’s Search Algorithm 131
6.3 Geometric Visualization of Grover’s Iterations 137
6.4 Order of Grover’s Algorithm 140
6.5 Grover’s search applied to an unstructured database 143
Chapter 7 147
Physical Realization of Quantum Computers
7.1 Basic Requirements for Quantum Computation 147
7.2 Harmonic Oscillator Quantum Computer 148
7.3 Optical Photon Quantum Computer 149
7.4 Optical Cavity Quantum Electrodynamics 151
7.5 Ion Traps 152
7.6 Nuclear Magnetic Resonance 154
7.7 Silicon Quantum Computers 155
Chapter 8 158
Quantum Simulators
8.1 Quantum QUDIT Simulator 158
8.2 CAD for Quantum Computer Simulator (QCAD) 162
8.3 QUACK (Quantum Computer Simulator for MATLAB) 170
8.4 Quantum Circuit Viewer (qasm2circ) 177
Lov K. Grover
Room 1D-435
Bell Labs / Lucent Technologies
600-700 Mountain Avenue
Murray Hill, NJ 07974
(908)-582-2677
Fax: (908)-582-5145
[email protected]
FOREWORD
A few years ago when a Professor from a Computer Science Department in India asked me
whether they should have a course on quantum computation, I wondered why such a course
would be useful. After all why spend time & energy on something that was so speculative. That
was about 10 years ago. However, things have changed since then. The two main changes are:
first, quantum computers seem much closer to reality than anyone would have thought 10 years
ago. Second, India has made major strides in technology so that it should be making every
attempt to keep on top of the technological revolutions that are likely to take place in the next
few decades. Having missed the boat, in the silicon revolution in the 70’s and 80’s, India should
make every attempt, not to let it happen again even if it means spending some resources on
technologies like quantum computing which are speculative but hold tremendous potential.
Just like classical computers, quantum computers have two sides to them, hardware and
software. Software often doesn’t get the recognition it deserves. The non-specialist frequently
underestimates the importance of software. One should hardly pick on non-specialists when fully
trained lawyers at the world’s leading computer maker have been guilty of the same mistake. In
one of the biggest blunders in corporate history, IBM gave Microsoft an unrestricted license to
develop and market the operating system for the IBM PC.
The IBM-Microsoft deal took place almost two decades ago. When computers were first being
developed, hardware was the stumbling block; programmers wrote software around the
hardware. Nowadays, most often, software is the bottleneck: it is generally the hardware that is
planned around the software. Successive generations of Intel microprocessors are designed to be
able to run existing software. Often, most of the time taken to develop a new high-technology
product that involves computers involves writing the software that enables the product.
Today, in the new paradigm of quantum computing, the stumbling block is clearly the hardware,
we do not yet have the technology to manipulate individual quantum states. Yet advances in this
direction have taken place at a breathtaking pace in the last decade. However, the field of
software has more or less been stagnant despite considerable interest. It takes considerable effort
to devise software for quantum computers that harnesses their power. One of the hottest fields in
physics and computer science is to devise hardware techniques for implementing quantum
computers and to devise applications in which they greatly outperform classical computers. The
power of quantum computers lies not in providing faster hardware to carry out the same
applications but in enabling an entirely new class of applications using fundamentally new
programming procedures, known to computer scientists as algorithms. If we do not give due
importance to this field, we will have working quantum computers and not know ways to harness
their tremendous powers.
Algorithms are basically recipes that tell a computer how to go about solving a particular
problem quickly. A good algorithm drastically reduces the time taken to solve a problem.
Finding good and efficient algorithms is very important because algorithms tend to be used over
and over again for tasks routinely performed by computers. In the last 25 years, the theory of
algorithms has been quantitatively developed by computer scientists using extremely
sophisticated mathematics. Just in the last decade, two powerful algorithms have been discovered
for quantum computing – these are the algorithms for factorization and those for searching
unsorted databases. Peter Shor discovered the factorization algorithm in 1994; it is often called
the first “killer application” of quantum computing. Much of today’s excitement in quantum
computing was triggered by Peter Shor’s factorization algorithm. The searching algorithm was
invented by me a couple of years later. Rudimentary versions of both have been recently
implemented in hardware and tested.
This book elucidates the ideas and concepts of quantum computing. The author has a good grasp
of the needs of a first-time learner of quantum computing having learnt the field himself through
self study. I admire the flow of the book from a gentle introduction to quantum computing to its
core of qubits and quantum gates and finally algorithms, applications, physical realizations and
simulators.
As mentioned earlier, having a desktop quantum computer with quantum software is a challenge
that might become a reality in the future. With that perspective, the chapter on Quantum
Simulators is interesting as it enables learners to have practical experience of working with
qubits and quantum gates on a desktop PC. The software and codes of the examples are included
in the CD-ROM accompanying the book. It should make you sit down and start making your
own quantum computer. This is one very nice feature that distinguishes this book from many of
the others in the field.
The author has done a very nice job of describing concretely the large number of ideas and
insights that go into quantum computing. I am hopeful that this book shall become an invaluable
source of information to everyone interested in quantum computing. He deserves congratulations
for the effort.
Lov K. Grover
Quantum Computing
CHAPTER 1
This chapter presents the fundamental concepts in quantum computing. Section 1.1 gives an
introduction to quantum computing. Section 1.2 introduces the idea of qubits and Section 1.3
presents some of the startling speedups obtained with quantum algorithms. Section 1.4 presents
how quantum physics differs radically from classical physics. Section 1.5 presents the obstacles
in quantum computing and research going on to overcome them. The future outlook of quantum
computing is outlined in Section 1.6.
A truly parallel computer, in contrast, would have simultaneity built into its very nature. It would
be able to carry out many operations at once, to search instantly through a long list of
possibilities and point out the one that solves a problem.
Such computers do exist. They are called quantum computers -- not so much because they are
inherently small, but because they operate according to the bizarre rules of quantum mechanics,
which do indeed govern the world of the very small: the waves and particles of subatomic
physics. One quantum rule in particular creates an enormous incentive to apply quantum
mechanics to computing: the startling discovery by twentieth-century physicists that elementary
particles such as protons, neutrons and electrons can persist in two or more states at once. That
makes it possible, at least in principle, for them to be harnessed as processing units in a machine
more efficient than any conventionally designed "classical" computer could ever be.
In the past few years, simple quantum computers have been built in the laboratory. Meanwhile,
in the theory of quantum computation, investigators are eagerly describing what the more
sophisticated machines will be like if they can ever be constructed. We are writing the software
for a device that does not yet exist. Yet on paper, at least, the prospects are stunning: an
1
Quantum Computing
algorithm that could factor 140-digit-long numbers a billion (109) times faster than is currently
possible with the best non-quantum methods; a search engine that could examine every nook and
cranny of the Internet in half an hour; a "brute-force" decoder that could unscramble a Data DES
(Data Encryption Standard) transmission in five minutes.
In 1965, Gordon Moore observed a trend of increasing performance in the first few generations
of integrated-circuit technology. He predicted that in fact it would continue to improve at an
exponential rate - with the performance per unit cost increasing by a factor of 2 every 18 months
or so - for at least the next 10 years. The computer industry has followed his prediction
throughout for 45 years (Fig. 1.1). Increased power of computers has created a new civilization
affecting everything from communications, manufacturing, finance, and all manner of products
and services.
The question that arises is that how long can Moore's law continue to hold. What are the ultimate
limits, if any, to computing technology? How will the technology need to change in order to
improve as much as possible? What will happen to our civilization if the Moore Law will stop to
work?
Figure 1.1 Moore’s law showing increasing number of transistors on silicon “real-estate”
Quantum computers will perform computations at the atomic scale. We might ask at this point
how close conventional computations are to this scale already? Fig. 1.2 shows a survey made by
Keyes in 1988: The number of dopant impurities in the bases of bipolar transistors used for
digital logic against the year. This plot may be thought of as showing the number of electrons
2
Quantum Computing
required to store a single bit of information. An extrapolation of the plot suggests that we might
be within reach of the atomic-scale computations within a decade.
Figure 1.2 Graph showing number of dopant impurities over the years in silicon transistors
Another way of viewing this plot is perhaps even more relevant for the development of quantum
computation. Conventional computers have been improving in speed and miniaturization at an
exponential rate since their earliest days. Clearly there is a bound to our ability to miniaturize
conventional electronics and we will likely be touching that limit within the next ten to twenty
years. The question is raised, can we continue to expect to see an exponential improvement in
performance twenty and more years from now? As we approach some of the physical limits to
conventional computational construction we may begin to see a slow-down of this exponential
rate. A detailed study of quantum computation may help us understand the fundamental physical
limitations upon computation, conventional or otherwise.
Providing a complete history of ideas relevant to quantum computing is a formidable task. Our
subject brings together what are arguably two of the greatest revolutions in twentieth-century
science, namely quantum mechanics and information science (including computer science). Fig.
1.3 attempts to give a relationship between these two giants.
3
Quantum Computing
While quantum information science is a broad and rapidly expanding field, there are a few
underlying recurrent themes. The theory of classical information, computation, and
communication developed extensively during the twentieth century. Though undeniably useful,
this theory cannot fully characterize how information can be used and processed in the physical
world — a quantum world. Some achievements of quantum information science can be described
as generalizations or extensions of the classical theory that apply when information is
represented as a quantum state rather than in terms of classical bits. The well-established theory
of classical information and computation is actually a subset of a much larger topic, the emerging
theory of quantum information and computation (Fig. 1.4).
4
Quantum Computing
(Classical)
Information
Information Technology
Quantum Information
Could subatomic particles store bits? Could they form gates? Consider the electron. Every
electron acts as if it were a little magnet, spinning about an axis, whose magnetic moment can
point in only one of two directions, up or down. Thus the spin of the electron is quantized: it has
just two possible states, which can readily be identified with the 0's and 1's of an ordinary
computer processor. And we can flip the bit -- that is, change a down, or 0, to an up, or l, by
adding just a smidgen of energy.
Suppose, however, we give it less energy than that -- say, half a smidgen. Once again, when we
observe the electron's spin state, we will find that the spin is quantized: it points either up or
down. But now there is an important, though subtle, difference. According to the rules of
quantum mechanics, the probability of observing the spin in one or the other state will change.
That change arises from a qualitatively new state, with no analogue in the ordinary, nonquantum,
laws of physics, called a super position of the two spin states: a combined, in-between condition
that can be, say, 60 percent up and 40 percent down, or 22 percent up and 78 percent down.
5
Quantum Computing
A Historical Note
In the 1970s and early 1980s physicists and computer scientists began to investigate how the
properties of quantum superpositions might be applied to computing. Early workers in the field -
- including the physicists Charles H. Bennett of the IBM Thomas J. Watson Research Center in
Yorktown Heights, New York, Paul A. Benioff of Argonne National Laboratory in Illinois,
David Deutsch of the University of Oxford and the late Richard P. Feynman -- showed that
particles in superposed states can function as quantum bits, or qubits, and can undergo operations
analogous to the NOT, OR and AND operations of classical computing. But that is not all.
Quantum computers, if they can be built, could achieve results that would seem almost magical -
- and quite different from anything a classical system has to offer.
In principle, for 500 particles, we could create a quantum system that is a superposition of as
many as 2500 states. Each state would be a single list of 500 1's and 0's. Any quantum operation
on that system-a particular pulse of radio waves, for instance, whose action was, say, to execute a
controlled-NOT operation on the 175th and 176th qubits-would simultaneously operate on all
2500 states. Hence with one machine cycle, one tick of the computer clock, a quantum operation
could compute not just on one machine state, as serial computers do, but on 2500 machine states
at once! That number, which is approximately equal to a 1 followed by 150 zeros, is far larger
than the number of atoms in the known universe. Eventually, of course, observing the system
would cause it to collapse into a single quantum state corresponding to a single answer. a single
list of 500 1's and 0's -- but that answer would have been derived from the massive parallelism of
quantum computing.
The consequence is that for some purposes quantum computers would be so much faster than
classical computers are that they could solve problems the classical computers cannot touch. If
functioning quantum computers can be built, harnessing their potential will be just a matter of
creating algorithms that carry out the right operations in the right order.
What makes this quest intellectually compelling is that the results are so surprising. At first
glance, quantum effects seem to compromise our efforts to store, transmit, and process
information, because quantum states are highly unstable and cannot be observed without being
disturbed. Indeed, as the components of integrated circuits continue to shrink toward the atomic
6
Quantum Computing
scale, quantum phenomena will pose increasingly serious limitations on the performance of
information processing hardware, and one important task of quantum information science will be
to illuminate whether and how such obstacles can be overcome. But the great surprise is that the
news about quantum effects is not all bad — far from it! The fragility of quantum information
becomes a very positive feature when it is recognized that eavesdropping on a quantum
communication channel necessarily leaves a detectable imprint, so that communicating with
qubits provides better privacy than communicating with classical bits. Far more astonishing, the
intrinsic complexity of quantum information ensures that quantum systems of modest size are
endowed with truly vast computational power, so that a quantum computer acting on just
hundreds of qubits is capable in principle of performing tasks that could never be performed by
conventional digital computers.
A subtle approach has been devised for factoring large numbers. Factoring is what computer
scientists call a one-way problem: hard in one direction but easy in the other. Suppose we ask the
question, "Which two integers can be multiplied to obtain the number 40,301?" Systematically
testing all the candidates might keep us busy for fifteen minutes or so. But if we are asked to
multiply 191 by 211, it would take only about twenty seconds with pencil and paper to determine
that the answer is 40,301. The lopsided difficulty of factoring compared with multiplication
forms the basis for practical data encryption schemes such as the RSA protocol. Large prime
numbers -- say, a hundred digits each or so -- make good "passwords" for such systems because
they are easy to verify: just multiply them together and see whether their product matches a
number that is already stored or that might even be made publicly available. Extracting the
passwords from a 200-digit composite product of two large primes, however, is equivalent to
factoring the large composite number -- a problem that is very hard, indeed. The largest number
that ordinary supercomputers have been able to factor with non-quantum algorithms is "only"
140 digits long. Table 1.1 gives an interesting comparison between classical and quantum
computers.
Execution Time on a
Algorithm Type Order Steps Terahertz (THz)
computer
150,000 years
Best Classical
Algorithm 1/ 3
O 2n log( n) 2 / 3 1024 (Classical THz
computer)
< 1 second
Shor’s Quantum O n3 1010 (Quantum THz
algorithm
computer)
7
Quantum Computing
In computer science, one often tries to solve hard problems by converting them into simpler
problems that one already knows how to solve. In that spirit, Shor started by employing well-
known results from number theory to convert the problem of factoring into one of estimating the
periodicity of a long sequence. Periodicity is the number of elements in the repeating unit of a
sequence. The sequence 0, 3, 8, 5, 0, 3, 8, 5, . . ., for instance, has a periodicity of four. To
estimate periodicity, a classical algorithm must observe at least as many elements as there are in
the period. Shor's algorithm does much better. It sets up a quantum system made up of a large
number of superposed states. Each state is identified with an element of the repeating sequence.
A single quantum mechanical operation then transforms each superposed state in a way that
depends on the value of the sequence to which the state corresponds. A series of such quantum
mechanical operations, mathematically analogous to X-ray diffraction, is carried out on the
superposed states.
Suppose we want to look up a phone number in a telephone directory that has a million entries.
Suppose, too, that we have forgotten the person's name; all the information to search with is an
address. In that case, our only recourse is trial and error. On average, we will read the names of
500,000 strangers before we find the one we want; on a very bad day, we might have to look at
999,999 of them. A computer could search much faster, but algorithmically it would be in the
same boat: in general, a list of N items takes, on average, N/2 steps to search.
A quantum computer could do much better, thanks to its ability to carry out many operations at
the same time. Assuming we had access to a quantum system, here is how we could do the
search: First choose enough particles (some number q) so that there are enough quantum states in
the system (2q) to assign at least one state to each name in the phone book. (To get a million
names, for instance, we would need twenty particles, since 220 is slightly more than a million.)
Place the information from the phone book into quantum memory, and match each name to a
different quantum state. Put the system into a superposition of the million or so states. Now the
system can do a computation that checks whether each of the names is the right name. Thanks to
quantum superposition, the computation takes place on all states simultaneously. Table 1.2
illustrates some “quantum” type algorithms giving a startling speedup over classical algorithms.
This is just an insight into some of the startling applications of quantum computing illustrating
their immense power and capability. Many more applications of quantum computing are
discussed in detail in the later chapters.
8
Quantum Computing
9
Quantum Computing
V
single particle
H
B
beamsplitter
mirror beamsplitter
B
H
mirror
beamsplitter
Here a light source emits a photon along a path towards a half-silvered mirror. This mirror splits
the light, reflecting half vertically toward detector A and transmitting half toward detector B. A
photon, however, is a single quantized packet of light and cannot be split, so it is detected with
equal probability at either A or B. Intuition would say that the photon randomly leaves the
mirror in either the vertical or horizontal direction. However, quantum mechanics predicts that
the photon actually travels both paths simultaneously! This is more clearly demonstrated in Fig.
5(b).
In an experiment like that in Fig. 5(a), where a photon is fired at a half-silvered mirror, it can be
shown that the photon does not actually split by verifying that if one detector registers a signal,
then no other detector does. With this piece of information, one might think that any given
photon travels either vertically or horizontally, randomly choosing between the two paths.
However, quantum mechanics predicts that the photon actually travels both paths
simultaneously, collapsing down to one path only upon measurement. This effect, known as
single-particle interference, can be better illustrated in a slightly more elaborate experiment,
outlined in Fig. 5(b).
10
Quantum Computing
In this experiment, the photon first encounters a half-silvered mirror, then a fully silvered mirror,
and finally another half-silvered mirror before reaching a detector, where each half-silvered
mirror introduces the probability of the photon traveling down one path or the other. Once a
photon strikes the mirror along either of the two paths after the first beam splitter, the
arrangement is identical to that in Fig. 5(a), and so one might hypothesize that the photon will
reach either detector A or detector B with equal probability. However, experiment shows that in
reality this arrangement causes detector A to register 100% of the time, and never at detector B!
How can this be?
Fig. 5(b) depicts an interesting experiment that demonstrates the phenomenon of single-particle
interference. In this case, experiment shows that the photon always reaches detector A, never
detector B! If a single photon travels vertically and strikes the mirror, then, by comparison to the
experiment in Fig. 5(a), there should be an equal probability that the photon will strike either
detector A or detector B. The same goes for a photon traveling down the horizontal path.
However, the actual result is drastically different. The only conceivable conclusion is therefore
that the photon somehow traveled both paths simultaneously, creating an interference at the point
of intersection that destroyed the possibility of the signal reaching B. This is known as quantum
interference and results from the superposition of the possible photon states, or potential paths.
So although only a single photon is emitted, it appears as though an identical photon exists and
travels the 'path not taken,' only detectable by the interference it causes with the original photon
when their paths come together again. If, for example, either of the paths are blocked with an
absorbing screen, then detector B begins registering hits again just as in the first experiment!
This unique characteristic, among others, makes the current research in quantum computing not
merely a continuation of today's idea of a computer, but rather an entirely new branch of
thought. And it is because quantum computers harness these special characteristics that gives
them the potential to be incredibly powerful computational devices.
11
Quantum Computing
must devise a way to maintain decoherence and other potential sources of error at an acceptable
level. Thanks to the theory (and now reality) of quantum error correction, first proposed in 1995
and continually developed since, small scale quantum computers have been built and the
prospects of large quantum computers are looking up. Probably the most important idea in this
field is the application of error correction in phase coherence as a means to extract information
and reduce error in a quantum system without actually measuring that system. In 1998,
researches at Los Alamos National Laboratory and MIT led by Raymond Laflamme managed to
spread a single bit of quantum information (qubit) across three nuclear spins in each molecule of
a liquid solution of alanine or trichloroethylene molecules. They accomplished this using the
techniques of nuclear magnetic resonance (NMR). This experiment is significant because
spreading out the information actually made it harder to corrupt. Quantum mechanics tells us
that directly measuring the state of a qubit invariably destroys the superposition of states in
which it exists, forcing it to become either a 0 or 1. The technique of spreading out the
information allows researchers to utilize the property of entanglement to study the interactions
between states as an indirect method for analyzing the quantum information. Rather than a direct
measurement, the group compared the spins to see if any new differences arose between them
without learning the information itself. This technique gave them the ability to detect and fix
errors in a qubit's phase coherence, and thus maintain a higher level of coherence in the quantum
system. This milestone has provided argument against skeptics, and hope for believers.
Currently, research in quantum error correction continues with groups at Caltech (Preskill,
Kimble), Microsoft, Los Alamos, and elsewhere.
At this point, only a few of the benefits of quantum computation and quantum computers are
readily obvious, but before more possibilities are uncovered theory must be put to the test. In
order to do this, devices capable of quantum computation must be constructed. Quantum
computing hardware is, however, still in its infancy. As a result of several significant
experiments, nuclear magnetic resonance (NMR) has become the most popular component in
quantum hardware architecture. Groups from Los Alamos National Laboratory and MIT
constructed the first experimental demonstrations of a quantum computer using nuclear magnetic
resonance (NMR) technology. Currently, research is underway to discover methods for battling
the destructive effects of decoherence, to develop an optimal hardware architecture for designing
and building a quantum computer, and to further uncover quantum algorithms to utilize the
immense computing power available in these devices. Naturally this pursuit is intimately related
to quantum error correction codes and quantum algorithms, so a number of groups are doing
simultaneous research in a number of these fields. To date, designs have involved ion traps,
cavity quantum electrodynamics (QED), and NMR. Though these devices have had mild
success in performing interesting experiments, the technologies each have serious limitations.
Ion trap computers are limited in speed by the vibration frequency of the modes in the trap.
NMR devices have an exponential attenuation of signal to noise as the number of qubits in a
system increases. Cavity QED is slightly more promising; however, it still has only been
demonstrated with a few qubits. All-silicon quantum computers are also in the vogue nowadays.
These devices are discussed in detail in Chapter 7. The future of quantum computer hardware
architecture is likely to be very different from what we know today; however, the current
research has helped to provide insight as to what obstacles the future will hold for these devices.
12
Quantum Computing
13
Quantum Computing
CHAPTER 2
This chapter delves into the basic ideas of quantum computing and presents both quantum
mechanical as well as computer science perspectives. Section 2.1 presents the quantum
mechanical understanding and Section 2.2 presents a detailed study of qubits with their
geometrical representation through the Bloch sphere.. Multiple qubits are dealt with in Section
2.3 and basic concepts of computer science relevant to quantum computing are presented in
Section 2.4.
Hilbert Space
In the finite dimensional complex vector spaces that we deal with in quantum computing, Hilbert
pace is the finite dimensional inner product space. In infinite dimensions, Hilbert spaces satisfy
additional technical restrictions above and beyond inner product space, which we need not deal
with.
We are concerned with quantum mechanics to use its standard notation for our concepts. The
standard quantum mechanical notation for a vector in vector space is . This Bra-ket notation
is used for describing quantum states in the theory of quantum mechanics. It can also be used to
denote abstract vectors and linear functionals in pure mathematics. It has got its name because it
the inner product of two states is denoted by a bracket , consisting of a left part called
the bra and a right part called the ket. The notation was invented by Paul Dirac, and is also
known as Dirac notation. It has now become very popular in quantum computing.
Every ket has a dual bra, written as . The bra is simply the conjugate transpose (also
called the Hemritian conjugate) of the ket and vice versa.
14
Quantum Computing
Applying the bra to the ket results in a complex number, called a “bra-ket” or “bracket”
which is written as
.
w1
.
v w v1* ... vn* . . (2.1)
.
wn
In quantum mechanics, this is the probability amplitude for the state to collapse into the state
.
Properties
c1 1 c2 2 c1 1 c2 2 . . (2.2)
2. Given any ket , bras 1 and 2 and complex numbers c1 and c2 , then by definition of
addition and scalar multiplication of linear functionals
c1 1 c2 2 c1 1 c2 2 . . (2.3)
3. Given any kets 1 and 2 , and complex numbers c1 and c2 , then from the properties of
the inner product (with c * denoting the complex conjugate of c ),
4. Given any bra and ket , axiomatic property of the inner product gives
*
. . (2.4)
15
Quantum Computing
Linear Operators
If A is a linear operator, we can apply A to the ket to obtain the ket A . Operators can
also be viewed as acting on bras from the right hand side. Applying the operator A to the bra
results in the bra A , defined as a linear functional on H by the rule
A A . . (2.5)
A
A convenient way to define linear operators on H is given by the outer product. If is a bra
and is a ket, the outer product
denotes the rank one operator that maps the ket to the ket .
Two Hilbert spaces A and B may form a third space A B by a tensor product. In quantum
mechanics, this is used for describing composite systems. If a systems is composed of two
subsystems described by A and B respectively, then the Hilbert space of the entire system is the
tensor product of the two spaces.
Tensor product
If 1 is a ket in A and 2 is a ket in B, the tensor product of the two kets is a ket in A B .
This is variously written as
1 2 or 1 2 or 1 2 or 1 , 2 .
Let A be an m n matrix and B be an r s matrix. Then the tensor product for a finite-
dimensional Hilbert space, or Kronecker product is defined as the mr ns matrix
16
Quantum Computing
A B . . . . . . (2.6)
. . . .
am1 B am 2 B ... amn B
1
1
0
0
2
1
1
0
1 1
0
0
0
1
1 2
0
0
0
0
2 1
1
0
0
0
2 2
0
1
We can generalize
17
Quantum Computing
ac
a c ad a c
b d bc b d
bd
a c
b d
Notation Description
z* Complex conjugate of the complex number z
(1 i )* 1 i
Vector. Also known as a ket
Vector dual to . Also known as a bra
Inner product between the vectors and
Tensor product of and
Abbreviated notation for tensor product of and
A* Complex conjugate of the A matrix
AT Transpose of the A matrix
A† Hermitian conjugate or adjoint of the A matrix,
A† ( AT )*
a b a * c*
c d * *
b d
A Inner product between and A
Table 2.1 Summary of Dirac notation
Example 2.1
0 1
X
1 0
1 0
Z
0 1
18
Quantum Computing
0 0 1 0
0 0 0 1
X Z
1 0 0 0
0 1 0 0
0 1 0 0
1 0 0 0
ZX
0 0 0 1
0 0 1 0
We note that X Z Z X
Example 2.2
2
Let
6i
3
and
4
3
2 6i 6 24i
4
23 6
2 3 2 4 8
6i 4 6i 3 18i
6i 4 24i
2 6 8
3 4
6i 18i 24i
19
Quantum Computing
The eigenvalue is found be finding all the roots to the characteristic equation
det A I 0
The difference between qubits and classical bits is that a qubit can be in a linear combination or
superposition of the two states 0 and 1 as :
0 1
The numbers and are complex, but are generally taken as real without any loss. In other
words, a qubit is a vector in a two-dimensional complex vector space.
20
Quantum Computing
1 1
0 1
2 2
sum
1
2 2
since the probabilities must sum to one. So we can interpret this as the condition that the qubit’s
state can be normalized to length 1. A qubit’s state is therefore, a unit vector in a two-
dimensional complex vector space.
We come to the important conclusion that a qubit can exist in a coherent superposition of
states 0 and 1 only till it is measured. Upon measurement, it gives only one of the states 0 or
1.
cos 0 ei sin 1 . . (2.7)
2 2
and define a point on the unit three-dimensional sphere as shown in Fig. 2.2.
21
Quantum Computing
The sphere provides a useful means of visualizing the state of a single qubit and serves as an
excellent testbed for ideas about quantum computation.
x r cos
y r sin
Suppose a 0 b 1 and a b 1
2 2
Let a ei cos and b ei ( ) sin
2 2
Then another way to express an arbitrary single qubit is
ei cos 0 ei ( ) sin 1 . . (2.8)
2 2
or
ei cos 0 ei sin 1 . . (2.9)
2 2
22
Quantum Computing
Under measurement ei , the global phase is not observable. Therefore it is sufficient to
write a quantum bit as
cos 0 ei sin 1 . . (2.10)
2 2
Any single qubit state is a point on the surface of the Bloch sphere and any unitary transform is a
rotation across some arbitrary angle.
Since there are an infinite number of points on the unit sphere, can we store an infinite amount of
information in a qubit? The answer is no since from a single measurement, one obtains only a
single bit of information about the state of a qubit, resolving this paradox.
However, when Nature evolves a closed quantum system of qubits, not performing any
‘measurement’ she apparently keeps tracks of all the continuous variables describing the state,
like and . Understanding this hidden quantum information is what lies at the heart of
harnessing the power of quantum information processing.
0 1 0 i 1 0
X Y Z . . (2.11)
1 0 i 0 0 1
These Pauli matrices give rise to three useful classes of unitary matrices when they are
exponentiated, classed rotation operators about the x, y and the z axes, defined by the equations
cos i sin
Rx ei X / 2 cos I i sin X 2 2
. . (2.12)
2 2 i sin cos
2 2
cos 2 sin
Ry ei Y / 2 cos I i sin Y 2
. . (2.13)
2 2 sin cos
2 2
23
Quantum Computing
e i / 2 0
Rz e i Z / 2 cos I i sin Z
i / 2
. . (2.14)
2 2 0 e
Example 2.3
Solution
The matrix triple product is evaluated as
0 1 0 i 0 1
XYX
1 0 i 0 1 0
0 1 i 0
1 0 0 i
0 i
i 0
Example 2.4
Prove XRy X Ry .
Solution
cos sin
0 1 2 0 1
XRy X
2
1 0 sin 1 0
cos
2 2
sin cos
0 1 2 2
1 0 cos sin
2 2
cos 2 sin
2
sin cos
2 2
24
Quantum Computing
cos 2 sin cos sin
Ry 2
2 2
sin cos
sin
cos
2 2 2 2
00 00 01 01 10 10 11 11
Similar to the case for a single qubit, probability has to sum up to 1 and therefore the
normalization condition that holds is
00 01 10 11 1
2 2 2 2
For a two qubit system, suppose we measure the first qubit. Then the chances of getting a 0 are
00 01 .
2 2
So after measurement, we can remove the terms with coefficient 10 and 11 and the state of the
qubits becomes
00 00 01 01
'
00 01
2 2
00 01
2 2
We have had to renormalize the state by the factor so that the probability again
sums up to 1.
Another very important two qubit state is the Bell state or EPR pair
00 11
2
If we measure the first qubit, then with 50% probability, we obtain the result 0. The resulting
post-measurement state will be 00 , so measuring the second qubit will also give a result of 0.
25
Quantum Computing
On the other hand, if we measure the first qubit as 1 with 50% probability, then resulting post-
measurement state will be 11 , so measuring the second qubit will now give a result of 1.
Thus measurement of the second qubit always gives the same result as the measurement of the
first qubit, or in other words the measurement outcomes are correlated.
It is responsible for many more surprises in quantum communication and is dealt with in detail
later.
A Note on Measurement
M
0 1
It is important to note that the classical bit output is shown as a double-line wire as distinct from
a single line wire for a qubit.
One thing that all computers have in common, from Charles Babbage's analytical engine (1936)
to Pentium based PC's, is the theory of classical computation as described by the work of Alan
Turing.
In its simplest form, a Turing machine is composed of a "tape", a ribbon of paper of indefinite
length (Fig. 2.4). There is a "head" that can read the symbol, chose to write a new symbol in
place, and then move left or right. The Turing machine is said to be in a certain "state". Finally,
the program is a list of "transitions", that is a list that says, given a current state and a symbol
currently under the head, what should be written on the tape, what state the machine should go,
and whether the head should move left or right.
26
Quantum Computing
The tape is used to store data. In addition, it can also store a series of transitions (a small
programs) and thus, the head can run "sub-programs". We then say a Turing machine is
emulating another one (the one on the tape).
By analogy with modern computers, the tape is the memory and the head is the microprocessor.
Although it is composed of pretty simple capabilities, Turing argued that this simple machine
could performed any computation, that is, could realize anything that results from operations. In
1950, he discussed that the mind is itself the results of operations (at the neural level) and thus is
the creator of the artificial intelligence studies.
In essence, Turing's work describes the idea of the universal turing machine, a very simple model
of a computer that can be programmed to perform any operation that "would naturally be
considered to be computable". All computers are essentially implementations of a universal
turing machine. They are all functionally equivalent and although some may be quicker, larger or
more expensive than others, they can all perform the same set of computational tasks.
A great deal of time has been spent on investigating whether quantum theory places any
fundamental limits on computing machines. As a result, it is now believed that physics does not
place any absolute limits on the speed, reliability or memory capacity of computing machines.
One consideration that needs to be made however, concerns the information that may be 'lost' in
a computation. In order for a computer to run arbitrarily fast, its operation must be reversible (i.e.
it's inputs must be entirely deducible from its outputs). This is because irreversible computations
involve a 'loss' of information which can be equated to a loss in heat, and thus the restricted
ability of the system to dissipate heat will in turn limit the performance of the computer. An
example of information being lost can be seen in an ordinary AND gate. An AND gate has two
inputs and only one output, which means that in the process of moving from the input to the
output of the gate, we lose one bit of information.
27
Quantum Computing
In 1976, Charles Bennett proved that it is possible to build a universal computer entirely from
reversible gates, and that expressing a program in terms of primitive reversible operations does
not significantly slow it down.
A number of key advances have been made in the theory of quantum computation, the first being
the discovery that a simple class of 'universal simulator' can mimic the behaviour of any finite
physical object, by Richard Feynman in 1982. David Albert made the second discovery in 1984
when he described a 'self measuring quantum automaton' that could perform tasks that no
classical computer can simulate. By instructing the automaton to measure itself, it can obtain
'subjective' information that is absolutely inaccessible by measurement from the outside. The
final and perhaps most important discovery was made by David Deutsch in 1989, he proved that
all the computational capabilities of any finite machine obeying the laws of quantum
computation are contained in a single machine, a 'universal quantum computer'. Such a computer
could be built from the quantum equivalent of the Toffoli gate and by adding a few extra
operations that can bring about linear superpositions of 0 and 1 states, the universal quantum
computer is complete. This discovery requires a slight alteration to the Church-Turing principle –
“There exists or can be built a universal quantum computer that can be programmed
to perform any computational task that can be performed by any physical object.”
Artificial intelligence
The theories of quantum computation have some interesting implications in the world of
artificial intelligence. The debate about whether a computer will ever be able to be truly
artificially intelligent has been going on for years and has been largely based on philosophical
arguments. Those against the notion suggest that the human mind does things that aren't, even in
principle, possible to perform on a Turing machine.
The theory of quantum computation allows us to look at the question of consciousness from a
slightly different perspective. The first thing to note is that every physical object, from a rock to
the universe as a whole, can be regarded as a quantum computer and that any detectable physical
process can be considered a computation. Under these criteria, the brain can be regarded as a
computer and consciousness as a computation. The next stage of the argument is based in the
Church-Turing principle and states that since every computer is functionally equivalent and that
any given computer can simulate any other, therefore, it must be possible to simulate conscious
rational thought using a quantum computer.
28
Quantum Computing
Some believe that quantum computing could well be the key to cracking the problem of artificial
intelligence but others disagree. Roger Penrose of Oxford University believes that consciousness
may require an even more exotic (and as yet unknown) physics.
In order to appreciate the power of quantum algorithms and quantum computing, it is essential to
have an idea of the computational complexity of algorithms. These can then be used for
comparing the complexity of algorithms used for quantum computing in order to appreciate their
power.
The tool that has been developed for analysis of computational complexity is the asymptotic
notation which can be used to summarize the essential behaviour of a function. This asymptotic
notation can be used to get an idea of how many time steps it takes a given algorithm to run
without too much detail about the exact time count.
As an example, we are interested in the number of gates necessary to add together two n-bit
numbers, Exact counts of the number of gates required for a specific algorithm might be
24n 2[log n] 16 to perform the task. However, in the limit of a large problem size, the only
term which matters is the 24n term. We disregard constant factors as being of secondary
importance to the analysis of the algorithm.
The asymptotic notation consists of three tools which make this specification precise.
The big O notation is used to set upper bounds on the behaviour of a function. Suppose f ( n )
and g (n) are two functions on the non-negative integers. We say f ( n ) is in the class of
functions O( g (n)) , if there are constants c and n0 such that for all values of n greater than n0 ,
f ( n) cg (n) . That is, for sufficiently large n, the function g (n) is an upper bound on f ( n ) , up
to an unimportant constant factor. The big O notation is particularly useful for studying the
worst-case behaviour of specific algorithms, where we are often satisfied with an upper bound on
the resources consumed by an algorithm.
When studying the behaviours of a class of algorithms – say the entire class of algorithms which
can be used to multiply two numbers – it is interesting to set lower bounds on the resources
required. For this the (‘big Omega’) notation is used. A function f ( n ) is said to be ( g (n))
if there exist constants c and n0 such that for all n greater than n0 , cg (n) f (n) . That is, for
sufficiently large n, g (n) is a lower bound on f ( n ) , up to an unimportant constant factor.
Finally, the (‘big Theta’) notation is used to indicate that f ( n ) behaves the same as g (n)
asymptotically up to unimportant constant factors. That is, we say f ( n ) is ( g (n)) if it is both
O( g (n)) and ( g (n)) .
29
Quantum Computing
Suppose we are interested in whether a particular n bit number is prime or not. The chief
distinction made in computational complexity is between problems which can be solved using
resources which are bounded by a polynomial in n, or which require resources which grow faster
than any polynomial than n. In the latter case, we say that the resources required are exponential
in the problem size, although strictly speaking there are functions like n log n which grow faster
than any polynomial (and are thus ‘exponential’ according to this convention), yet which grow
slower than any true exponential. A problem is regarded as easy, tractable or feasible if an
algorithm for solving the problem using polynomial resources exists, and as hard, intractable or
infeasible if the best possible algorithm requires exponential resources.
The polynomial versus exponential classification is rather coarse. In practice, an algorithm that
solves a problem using 2n /1000 operations is probably more useful than one which runs in n1000
operations. Only for very large input sizes ( n 108 ) will the ‘efficient polynomial algorithm be
preferable to the ‘inefficient’ exponential algorithm, and for many purposes it may be more
practical to prefer the ‘inefficient’ algorithm. The relation between polynomial, non-polynomial
and exponential algorithms is shown in Fig. 2.5(a) with execution time comparison between
polynomial and exponential algorithms shown in Fig. 2.5(b).
In practice, computer scientists are not only interested in the polynomial versus exponential
classification of problems. This is merely the first and coarsest way of understanding how
difficult a computational problem is. It is easy to give non-constructive proofs that most
problems require exponential resources and furthermore many interesting problems are
conjectured to require exponential resources for their solution, but rigorous proofs seem very
hard to come by, at least with the present state of knowledge. This failure of computational
complexity has important implications for quantum computation, because it turns out that the
computation power of quantum computers can be related to some major open problems in
classical computational complexity theory. Until these problems are resolved, it cannot be stated
with certainty how computationally powerful quantum computer is, or even whether it is more
powerful than a classical computer!
EXP
NP
30
Quantum Computing
CHAPTER 3
Quantum Gates
“I can safely say that nobody understands quantum mechanics.”
- Neils Bohr
A classical computer is built using an electrical circuit having wires and logic gates. Similarly, a
quantum computer is built from a quantum circuit containing wires and elementary quantum
gates to transmit and manipulate quantum information. This chapter presents basic ideas of
quantum gates starting from single qubit gates in Section 3.1. Section 3.2 describes multiple
qubit gates. Matrix representation of quantum gates and circuit is spelt out in Section 3.3. The
extremely important Bell states of quantum computing are discussed in Section 3.4. The no-
cloning theorem of quantum information is presented in Section 3.5. Section 3.6 presents the
principles of quantum measurement. Section 3.7 describes quantum half-adder and subtractor
circuits.
0 1
X 1 0
Input Output
0 1
1 0
0 1 1 0
31
Quantum Computing
There is an easy way of representing the quantum NOT gate in matrix form which follows from
the linearity of quantum gates. It is represented by the matrix X as follows :
0 1
X . . (3.1)
1 0
0 1
X
1 0
or 1 0
1 0
Fig. 3.1 shows a quantum NOT gate and Table 3.1 givers the truth table for it.
Quantum gates on a single qubit can be described by 2 x 2 matrices as seen above. There is a
constraint though, on the matrices that can be used. The normalization condition requires that in
case of any and in 0 1 , the sum of 1 because of the requirement that
2 2
probability be conserved to 1 . In general it can be said that if the quantum gate is defined by the
matrix U, then
adj (U ).U I
32
Quantum Computing
0 1
X
1 0
0 1
adj ( X )
1 0
and
1 0
adj ( X ). X I
0 1
A more important implication is that unlike classical gates, where there is only a single non-
trivial single bit gate, i.e. the NOT gate, in case of single qubit gates, several cases are possible
as long as the unitarity constraint is satisfied. Some of these are the Z gate and the Hadamard
gate.
Example 3.1
cos 1 cos 2
sin , sin
1 2
cos 1 cos 2
sin sin is normalized.
1 2
Solution
In order that the above state be normalized, the unitarity condition must hold for
cos 1 cos 2
sin sin
1 2
Thus we have
(sin 1 sin 2 )2 (cos1 cos2 )2 1
1
sin 1 sin 2 cos 1 cos 2
2
It follows that
33
Quantum Computing
1
cos(1 2 )
2
Therefore, 1 2 2 / 3 or 1 2 4 / 3 .
3.1.2 Z gate
1 0
Z . . (3.2)
0 1
or
1 0 0 0
0 1 1 1
Fig. 3.2 shows a Z gate and Table 3.2 gives the truth table.
34
Quantum Computing
0 1
Z 0 1
Input Output
0 0
1 1
0 1 0 1
It can be verified that the Z gate satisfies the unitarity condition that
adj ( Z ).Z I
as
1 0 1 0 1 0
0 1 0 1 0 1 I
1 1 1
H . . (3.3)
2 1 1
The Hadamard gate is at times considered as the ‘square-root’ of NOT gate as it transforms a 0
into
0 1 , which may be considered mid-way between 0 and 1 . Similarly, it transforms
2
a 1 into
0 1 , which can also be described as mid-way between 0 and 1 .
2
35
Quantum Computing
1 1 1 1
2 1 1 2
or 0 1 which can be rearranged to give
2 2
0 1 0 1
to .
2 2
The Hadamard gate action for various inputs is explained in Table 3.3 and it is shown in Fig. 3.3.
1 1 1 1 1 1 0 1
0
2 1 1 0 2 1 2
1 1 1 0 1 1 0 1
1
2 1 1 1 2 1 2
0 1
2 2
1 1 1 1
0 1 or
2 1 1 2
0 1 0 1
2 2
0 1 1 1 1 1 1 1 2 1
0
2 2 2 1 1 1 2 0 0
0 1 1 1 1 1 1 1 0 0
1
2 2 2 1 1 1 2 2 1
36
Quantum Computing
0 1 0 1
0 1 H
2
2
1 1 1 1 1 1 1 2 0 1 0
I
2 2 1 1 1 1 2 0 2 0 1
The Hadamard gate is one of the most useful quantum gates and it turns out that the Hadamard
operation s just a rotation of the sphere about the y-axis by 90°, followed by a reflection through
the xy plane, as illustrated in Figure below.
37
Quantum Computing
0 1
Fig 3.4(a) shows on the Bloch sphere with the angles being and being / 2 ,
2
0.
Fig 3.4(b) is obtained by rotating the sphere about the y-axis by 90° to obtain 1 , the angles
being , 0 .
Fig. 3.4(c) is obtained by reflection of 1 through the xy plane to obtain 0 , the Bloch sphere
angles being 0 , 0 .
There are four extremely useful matrices by the name of Pauli matrices which are often used in
quantum computing. There are several notations for them which are also listed below.
1 0
0 I . . (3.4)
0 1
0 1
1 x X . . (3.5)
1 0
0 i
2 y Y
0
. . (3.6)
i
1 0
3 z Z . . (3.7)
0 1
Sometimes, I is omitted from the list and only X, Y and Z are known as the Pauli matrices.
The truth tables for the X, Y and Z Pauli matrices are given in Table 3.4.
38
Quantum Computing
Input Output
0 1
1 0
0 1 1 0
Input Output
0 i1
1 i 0
0 1 i 0 i 1
Input Output
0 0
1 1
0 1 0 1
It can be easily verified that these Pauli matrices also satisfy the unitarity condition.
It is useful to note that there is an algebraic relation between the Hadamard and Pauli matrices,
H (X Z) / 2
since
1 0 1 1 1 0 1 1 1
H
2 1 0 2 0 1 2 1 1
39
Quantum Computing
Example 3.2
0 1 0 i
Find the eigenvectors and eigenvalues of the three Pauli matrices X , Y i 0 ,
1 0
1 0
Z .
0 1
Solution
a)
0 1
X
1 0
1
det X I 2 1 0
1
This gives
1, 1
x
We use the value 1 to get the eigenvector 1 as
x2
0 1 x1 x1
1 0 x x
2 2
which gives
x1 x2
x1 x2 1
1
which gives the eigenvector as
1
1 1
or in normalized form
2 1
40
Quantum Computing
x1 1
x2 1
1 1
This gives the normalized eigenvector as
2 1
b)
0 i
Y
i 0
i
det Y I 2 i2 0
i
This gives
2 1
or
1, 1
x1
We use the value 1 to get the eigenvector as
x2
0 i x1 x1
i 0 x x
2 2
which gives
ix1 x2
A possible solution is
x1 1
x2 i
41
Quantum Computing
1
i
or normalized form as
1 1
2 i
i
If we use the other eigenvalue 1 , we get the normalized eigenvector as
1
1 i
or normalized form as .
2 1
c)
1 0
Z
0 1
1 0
det Z I 2 1 0
0 1
2 1
which gives
1, 1
x1
Taking the value 1 , we get the eigenvector as
x2
1 0 x1 x1
0 1 x x
2 2
or
x2 0
1
A possible eigenvector is
0
42
Quantum Computing
1 1
or normalized form as 0
2
1 0
If we take the other eigenvalue 1 , we get the normalized eigenvector as 1 .
2
Example 3.3
a) HXH Z
Solution
1 1 1 0 1 1 1 1
HXH
2 1 1 1 0 2 1 1
1 1 1 1 1
2 1 1 1 1
1 2 0
2 0 2
1 0
0 1
Z
b) HYH Y
Solution
1 1 1 0 i 1 1 1
HYH
2 1 1 i 0 2 1 1
1 1 1 i i
2 1 1 i i
1 0 2i
2 2i 0
43
Quantum Computing
0 i
i 0
Y
c) HZH X
Solution
1 1 1 1 0 1 1 1
HZH
2 1 1 0 1 2 1 1
1 1 1 1 1
2 1 1 1 1
1 0 2
2 2 0
0 1
1 0
X
Its effect on 0 is
1 0 1 1
0 i 0 0
44
Quantum Computing
Its effect on 1 is
1 0 0 0
0 i 1 i
1 0
0 i i
to the state 0 i 1 .
Table 3.5 gives the truth table and Fig. 3.5 shown an S gate.
Input Output
0 0
1 i1
0 1 0 i 1
0 1 0 i 1
S
Figure 3.5 S gate
1 0
adj (S )
0 i
and
1 0 1 0 1 0
adj (S ).S
0 i 0 i 0 1
45
Quantum Computing
3.1.6 T Gate
1 0
T . . (3.9)
0 exp(i / 4)
exp(i / 8) 0
T exp(i / 8)
0 exp(i / 8)
1 0 1 1
0 exp(i / 4) 0 0
1 0 0 0
0 exp(i / 4) 1 exp(i / 4)
1 0
0 exp(i / 4) exp(i / 4)
to 0 exp(i / 4) 1 .
Table 3.6 gives the truth table and Fig. 3.6 shown a T gate.
46
Quantum Computing
Input Output
0 0
1 exp(i / 4) 1
0 1 0 exp(i / 4) 1
0 1 0 exp(i / 4) 1
S
Figure 3.6 S gate
S T2
as
1 0 1 0 1 0
0 exp(i / 4) 0 exp(i / 4) 0 i S
A controlled gate is one in which the operation is of the kind ‘If A is true, then do B’. A is
usually referred to as the control qubit and B as the target qubit. If the control qubit is 0, then the
target qubit is not altered. If the control qubit is 1, then the target qubit is transformed. However,
the control qubit remains unaltered in both the cases.
47
Quantum Computing
The prototypical multi-qubit quantum logic gate is the controlled-NOT or CNOT gate. The
circuit of the CNOT gate is shown in figure. The gate has two input qubits :
If the control qubit of gate is set to 0, then the target qubit is not altered. If the control qubit is
set to 1, then the target qubit is inverted. Fig. 3.7 shows a control gate with the control qubit
being A and target qubit B.
A A
B B A
a) Input state 00 (Control qubit = 0, Target qubit = 0) : Both the bits remain unaltered.
Hence, the output state is the same as the input state or
00 00
b) Input state 01 (Control qubit = 0, Target qubit = 1) : Both the bits remain unaltered.
Again, the output state is the same as the input state or
01 01
c) Input state 10 (Control qubit = 1, Target qubit = 0) : The target qubit is flipped to 1.
Therefore, the output state has both qubits 1, or
10 11
d) Input state 11 : (Control qubit = 1, Target qubit = 1) : The target qubit is flipped to 0.
Therefore, the output state has becomes 10 , or
11 10
48
Quantum Computing
Input Output
00 00
01 01
10 11
11 10
1 0 0 0
0 1 0 0
U CN . . (3.10)
0 0 0 1
0 0 1 0
The matrix representations is written with respect to the amplitudes for 00 , 01 , 10 and 11
in that order. Thus the first column describes the transformation that occurs to 00 and so on.
The output state Y can also be understood as
00 1 0 0 0 00
01 0 1 0 0 01
Y
10 0 0 0 1 10
11 0 0 1 0 11
The CNOT gate can be regarded as a type of generalized XOR gate since the action of the gate
can be considered as
A, B A, B A
where stands for modulo-2 addition, which is the same as achieved by a XOR gate. In other
words, the control qubit and the target qubit are XORed and stored in the target qubit.
49
Quantum Computing
Since probability is conserved, the unitarity constraint holds for multiple qubit gates too.
Thus
adj (U CN ).U CN I
1 0 0 0 1 0 0 0 1 0 0 0
0 1 0 0 0 1 0 0 0 1 0 0
0 0 0 1 0 0 0 1 0 0 1 0
0 0 1 0 0 0 1 0 0 0 0 1
Irreversibility or Non-Invertibility
Classical XOR and NAND gates are essentially irreversible or non-invertible. It means that given
the output, say a b , it is not possible to determine what the inputs a and b were. So there is a
permanent loss of information associated with the irreversible action of such gates. On the other
hand, unitary quantum gates are always invertible since the inverse of a unitary matrix is also a
unitary matrix.
Any multiple qubit logic gate may be composed from CNOT and single qubit gates. This is the
quantum parallel of the universality of the NAND gate.
The Swap gate is a simple quantum circuit containing 3 quantum gates. The circuit is read from
left to right and each line represents a quantum passage, maybe of time, perhaps a physical
particle such as photon or a particle of light to move from one location to another through space.
1 0 0 0
0 0 1 0
U SWAP . . (3.11)
0 1 0 0
0 0 0 1
≡
Figure 3.8 Swap Gate
50
Quantum Computing
Fig. 3.8 shows a Swap gate as well an equivalent schematic symbol notation
This is fed to the second gate as input which also does modulo 2 addition but the result is placed
in the first qubit now.
This is now fed to the third gate which performs modulo 2 addition and places the result in the
second qubit.
Thus, the overall effect is that the two qubits have been swapped. Table 3.8 summarizes the
action of a Swap gate and Table 3.9 gives the truth table.
Input Output
00 00
01 10
10 01
11 11
51
Quantum Computing
This is a good point to observe the differences between classical and quantum gates.
1. Quantum gates don’t allow feedback loops from one part of the quantum circuit to another like
classical circuits. So quantum circuits are acyclic.
2. There is no Fan-In in quantum circuits. Classical circuits allow wires to be joined together
with the resulting single wire containing the bitwise OR of the inputs. This operation is not
reversible and hence, not unitary. So it is not possible in quantum circuits.
3. There is no Fan-Out in quantum circuits. In classical circuits, Fanout implies that several
copies of a bit are produced. We shall see at the end of the chapter that copying a qubit is not
possible!
Some examples are an inverter (the NOT gate), a two-input, two-output gate which swaps the
values on the input wires (the SWAP gate), an (n+1)-input, (n+1)-output gate which leaves the
first n wires unchanged, and flips the last if the first n were all 1 (the n-CNOT gate)
Controlled–Z gate is another example of controlled gate i.e. gates in which the operation is of the
kind ‘If A is true, then do B’. Figure 3.9 shows a controlled-Z gate.
Z
Figure 3.9 Controlled-Z gate
52
Quantum Computing
1 0 0 0
0 1 0 0
UZ . . (3.12)
0 0 1 0
0 0 0 1
Input Output
00 00
01 01
10 10
11 11
Any classical logic circuit can be built using a quantum circuit. This is especially true as
physicists believe that all aspects of the world around us, including classical logic circuits can
ultimately be explained using quantum mechanics. Any classical circuit can be replaced by an
equivalent circuit containing only reversible elements, by making use of a reversible gate known
as Toffoli gate. Fig. 3.10 shows a Toffoli gate.
a a
b b
c c ab
Figure 3.10 Toffoli Gate
The Toffoli gate has three input bits (a, b, c) and three output bits (a ', b ', c ') . The first two bits
are control bits which remain unaffected by the action of the Toffoli gate. The third is the target
bit which is inverted only if both the control bits are 1, else it is left unchanged.
53
Quantum Computing
Inputs Outputs
a b c a' b' c'
0 0 0 0 0 0
0 0 1 0 0 1
0 1 0 0 1 0
0 1 1 0 1 1
1 0 0 1 0 0
1 0 1 1 0 1
1 1 0 1 1 1
1 1 1 1 1 0
1 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 0
UT . . (3.13)
0 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 1
0 0 0 0 0 0 1 0
It can be verified that this matrix is unitary and thus Toffoli gate is a legitimate quantum gate.
The quantum Toffoli gate can be used to simulate irreversible classical logic gates and ensures
that that quantum gates are capable of performing any computation which a classical computer
may do.
Toffoli Gate is its own inverse since applying it once to the input (a, b, c) gives the output
(a, b, c ab) .
a, b, c ab ab a, b, c
as modulo-2 sum of a number with itself gives 0.
54
Quantum Computing
NAND Operation
The Toffoli gate can be used for NAND gate simulation by use of special ancilla inputs
as shown in the figure below. The two top bits represent the input to the NAND and the third bit
is in the standard state 1, also known as the ancilla state. The output from the NAND is on the
third bit. Fig. 3.11 shows a classical circuit implementing a NAND gate using a Toffoli gate.
a a
b b
c 1 ab ab
Figure 3.11 Classical circuit implementing a NAND gate using a Toffoli gate
The output is 1 ab which is equal to NAND of a and b as modulo-2 sum of a number with 1
inverts it.
1 ab ab
Fanout
The Toffoli gate can also be used for Fanout, with the second bit being the input to the Fanout
and the other two bits in standard states 1 and 0 as shown. The output from the Fanout appears
on the second and third bits. Fig. 3.12 shows a Toffoli gate used for Fanout.
55
Quantum Computing
1 1
a a
0 a
Figure 3.12 FANOUT with the Toffoli gate
Since Toffoli gates can implement NAND and Fanout, they are universal for computation in that
any arbitrary circuit can be simulated using only Toffoli gates and ancilla bits.
Like Toffoli gate, Fredkin gate also has three input bits (a, b, c) and three output bits (a ', b ', c ') .
However, now bit c is the control bit, whose value is not changed by the action of the gate.
If bit c is 0, then the other two bits a and b are left unchanged
Hence
a' a
b' b
a a'
b b'
c c'
56
Quantum Computing
Inputs Outputs
a b c a' b' c'
0 0 0 0 0 0
0 0 1 0 0 1
0 1 0 0 1 0
0 1 1 1 0 1
1 0 0 1 0 0
1 0 1 0 1 1
1 1 0 1 1 0
1 1 1 1 1 1
1 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 0
U Fredkin . . (3.14)
0 0 0 0 1 0 0 0
0 0 0 0 0 0 1 0
0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 1
It can be verified that matrix is also unitary, hence Fredkin gate is also a valid quantum gate.
57
Quantum Computing
The matrix representation of single as well as multiple qubit gates is a convenient mathematical
way of expressing their input-output relationship. If the ith truth-table combinations of a gate be
denoted as inputi and outputi , then the matrix representation of the gate can be computed as
input
i
i outputi . . (3.15)
This holds for single as well as multiple qubit gates as illustrated by several examples below.
Example 3.4
0 1, 1 0
Solution
U NOT 0 1 1 0
1 0
0 1 1 0
0 1
0 1 0 0
0 0 1 0
0 1
1 0
Example 3.5
Solution
58
Quantum Computing
0
1
0 1
2
1
1
0 1
2
Therefore,
UH 0
1
0 1 1 1 0 1
2 2
1
0 0 0 1 1 0 1 1
2
1 1 1 0 0
1 0 0 1 1 0 0 1
2 0 0 1 1
1 1 0 0 1 0 0 0 0
2 0 0 0 0 1 0 0 1
1 1 1
2 1 1
1 1 1
UH
2 1 1
Example 3.6
Solution
00 00
01 01
10 11
11 10
59
Quantum Computing
Remembering that,
1
0
00 0 0
0
0
0
1
01 0 1
0
0
0
0
10 1 0
1
0
0
0
11 1 1
0
1
U CN 00 00 01 01 10 11 11 10
1 0 0 0
0 1 0 0
1 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0
0 0 1 0
0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
60
Quantum Computing
1 0 0 0
0 1 0 0
0 0 0 1
0 0 1 0
1 0 0 0
0 1 0 0
U CN
0 0 0 1
0 0 1 0
Example 3.7
Solution
00 00
01 10
10 01
11 11
U SW 00 00 01 10 10 01 11 11
1 0 0 0
0 1 0 0
0
1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1
0 1 0
0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
61
Quantum Computing
1 0 0 0
0 0 1 0
0 1 0 0
0 0 0 1
1 0 0 0
0 0 1 0
U SW
0 1 0 0
0 0 0 1
Example 3.8
Find the matrix representation of the following circuits and also show they are equivalent.
Z
Circuit 1 Circuit 2
Solution
For circuit 1:
Input Output
00 00
01 01
10 10
11 11
U 00 00 01 01 10 01 11 11
62
Quantum Computing
1 0 0 0
0 1 0 0
1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
0 0 1 0
0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
For circuit 2:
Input Output
00 00
01 01
10 10
11 11
Its truth table is the same as that of circuit 1 and hence its matrix representation is also identical
to circuit 1.
If we have a quantum circuit with several qubits and the matrix operations acting on each qubit
are known, then the overall matrix representation of the circuit is the tensor product of the
individual qubit matrices. This is better illustrated with several examples below.
63
Quantum Computing
Example 3.9
a)
x1 H
x2
Solution
For the first qubit, the matrix representation is simply the Hadamard gate matrix U H and for the
second qubit it is the identity matrix I 2 as it remains unaltered.
U1 U H I 2
1 1 1 1 0
2 1 1 0 1
1 0 1 0
1 0 1
1 0
2 1 0 1 0
0 1 0 1
b)
x1
x2 H
Solution
U2 H I2
64
Quantum Computing
1 1 0 1 1
2 0 1 1 1
1 0 1 0
0 1 0 1
1 0 1 0
0 1 0 1
Example 3.10
H H
H H
Circuit 1 Circuit 2
For circuit 1 :
U1 U H U H
U 2 U CNOT
U3 U H U H
1 1 1 1 1 1
U1 U 3 1 1
2 2 1 1
1 1 1 1
1 1 1 1 1
2 1 1 1 1
1 1 1 1
65
Quantum Computing
1 0 0 0
0 1 0 0
U2
0 0 0 1
0 0 1 0
1 1 1 1 1 0 0 0 1 1 1 1
0 1 1 1 1
1 1 1 1 1 0 1 0
U 3U 2U1
4 1 1 1 1 0 0 0 1 1 1 1 1
1 1 1 1 0 0 1 0 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
4 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
4 0 0 0
4
1 0 0 0
4 0 0 4 0
0 4 0 0
1 0 0 0
0 0 0 1
0 0 1 0
0 1 0 0
For circuit 2 :
This circuit involves controlled operation, so we have use the truth-table approach to construct
the matrix. The input-output relationship for this circuit is given as
Input Output
00 00
01 11
10 10
11 01
U 00 00 01 11 10 10 11 01
66
Quantum Computing
1 0 0 0
0 1 0 0
0
1 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0
0 1 0
0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
1 0 0 0
0 0 0 1
0 0 1 0
0 1 0 0
Since the matrix representation of both the circuits is identical, they are equivalent.
x H
xy
y
Figure 3.14 Quantum circuit to generate Bell states
00 11
00
2
67
Quantum Computing
01 10
01
2
00 11
10
2
01 10
11
2
Input Output
00 11
00 00
2
01 10
01 01
2
00 11
10 10
2
01 10
11 11
2
These are known as the Bell states after Bell or EPR states or EPR pairs after Einstein, Podolsky
and Rosen who first pointed out the strange properties of these states which we shall see in later
applications. These states are entangled and have the property that their state ab cannot be
decomposed as a b .
68
Quantum Computing
0, y 1 1, y
x
xy
2
Example 3.11
1
01 10 1 0 1 1 0 in the Hilbert space cannot be written as a product
2 2
state.
Solution
Assume that
1
c0 0 c1 1 d 0 0 d1 1
1
0 1 1 0 c0 , c1 , d0 , d1 C
2 2
where
c0 c1 1 and d0 d1 1.
2 2 2 2
c0 d 0 0
1
c0 d1
2
1
c1d 0
2
c1d1 0
This set of equations does not have a solution. Thus the EPR-state cannot be written as a product
state. The EPR-state is thus entangled.
69
Quantum Computing
Suppose we wish to copy a classical bit. Then this can be done using a classical CNOT gate as
shown in Figure 3.15.
x x x x
y x y x
0
Figure 3.15 Classical circuit to copy an unknown bit
We obtain an identical copy of the input. If we try to extend the same to copying a qubit, then let
us see what happens in Fig. 3.16.
a 0 b 1
a 00 b 11
1 2
Figure 3.16 Quantum circuit to copy an unknown qubit (Does not work)
We recall that a CNOT gate simply negates the second qubit when the first qubit is 1 else it
leaves the second qubit unchanged.
If the inputs to the CNOT gate are 0 and 0 respectively, then can represent the input as
1 00
The control qubit of the CNOT gate is 0, thus the output becomes
70
Quantum Computing
2 00
We have succeeded in copying the state 0 of the top qubit from the input side to the output
side.
If the inputs to the CNOT gate are 1 and 0 respectively, then we can represent the input
as
1 10
The control qubit of the CNOT gate is 1, so the target qubit is inverted. So the output is
2 11
We have succeeded in copying the state 1 of the top qubit from the input side to the output
side.
So in case of classical information, the CNOT gate can be used to copy classical information
encoded as a 0 or 1 .
However, if the inputs to the CNOT gate are a 0 b 1 and 0 respectively, then the input
state of the two qubits can be written as
1 a 00 b 10
Recalling the action of the CNOT gate, the output for this input state becomes
2 a 00 b 11 . . (3.17)
as the control qubit is 1 only in the second term and its target qubit gets flipped.
However, if we need an exact copy of the first qubit at the output side also, then our output
should have been
a 0 b 1 a 0 b 1
71
Quantum Computing
a 2 00 ab 01 ab 10 b2 11 . . (3.18)
The only case where Eqs. (3.17) and (3.18) are equal is when ab = 0. Unless ab = 0, the circuit
has failed in copying the qubit. Hence, it works only for classical information, i.e. the discrete
states 0 and 1, and not for the quantum superposition state a 0 b 1 .
This is also known as no-cloning theorem and is a very important difference between classical
information and quantum information.
The first is the principle of deferred measurement, which states that classically conditioned
operations can be replaced by quantum conditioned operations.
Measurements can always be moved from an intermediate stage of a quantum circuit to the end
of the circuit; if the measurement results are used at any stage of the circuit then the classically
controlled operations can be replaced by conditional quantum operations.
M1
H
M2
00
{ X M2 Z M1
0 1 2 3 4
72
Quantum Computing
H
00
{ X Z
Fig. 3.17 Quantum Teleportation circuit with measurements shifted to the end
Quantum measurements are often performed as an intermediate step in a quantum circuit and the
measurement results are used to conditionally control subsequent quantum gates. As an example,
the teleportation circuit of Fig 3.16 can be replaced by the circuit of Fig. 3.17 above. The
difference is that the measurements in the second circuit have been moved to the end of the
circuit. This has been done by replacing all the classical conditional operations by corresponding
quantum conditional operations. Of course, some of the interpretation of this circuit as a
‘teleportation circuit’ is lost since there is no classical information transfer in circuit B, a point
which will be better understood after going through Section 4.1.
Without loss of generality, any unterminated quantum wires qubits which are not measured) at
the end of a quantum circuit may be assumed to be measured.
In order to understand the meaning of this principle, imagine a quantum circuit containing just
two qubits and only the first qubit is measured at the end of the circuit. However, if the
measurement had also been performed on the second qubit, then it cannot change the statistics of
measurement on the first qubit. It should be appreciated that the role of measurements in
quantum circuits is it acts as an interface between the quantum and classical worlds.
Measurement is generally considered as an irreversible operation, destroying quantum
information and replacing it with classical information. However, in carefully designed cases like
teleportation, this is not true as the measurement result does not reveal any information about the
identity of the quantum state being measured. Indeed, this is a more general feature of
measurement – in order for a measurement to be reversible, it must reveal no information about
the quantum state being measured!
73
Quantum Computing
U U U
Figure 3.18 Three identical circuits with measurements commuted with controls
E
j 1
j I
where I is the identity operator. In other words, a partition of unity (identity) operator by
nonnegative operators is called a positive operator-valued measure (POVM). When a state is
subjected to such a POVM, outcome j occurs with probability
p( j ) E j
Example 3.12
E1 0 0
E2 1 1
1
0 1
2
Solution
74
Quantum Computing
0
1 1 0 1 1
1
0
0 1 1 0 0
1
0
1 0 1 0 0
1
p(1) E1
1
0 1 0 0 1 0 1
2 2
1
2
00 10 0 0 01
1
1 0 1 0
2
1
2
1
Thus p (1)
2
p(2) E2
1
0 11 1 1 0 1
2 2
1
2
0 1 11 1 0 11
1
0 1 0 1
2
1
2
75
Quantum Computing
1
Thus p (2)
2
Example 3.13
1 2 1 2
00 11 0 0 1 1
3 3 3 3
11 1 1
2
Find p , i.e. the probability of finding in the state .
Solution
1 2
11 00 11
3 3
Remembering that,
1
0
11 00 0 0 0 1 0
0
0
0
0
11 11 0 0 0 1 1
0
1
We get
2
3
Thus,
2 2
p
3
76
Quantum Computing
Example 3.14
1
01 10 1 0 1 1 0
2 2
and
0 I2
0 I 2 .
Solution
0 I 2
1
1
2
The first system is measured with probability 1/ 2 and the system collapses to the state 1
(partial measurement).
Example 3.15
1
01 10 1 0 1 1 0
2 2
Let
cos 0 sin 1
cos 0 sin 1
77
Quantum Computing
Solution
Since
0 0 1 1 1
01 1 0 0
It follows that
0 1 0 1 1
1 0 1 0 1
We find that
1
p , cos sin sin cos
2
or
1
p , sin 2
2
Thus p , 1/ 2 for all , since sin 2 1 for all R . For example, if , we have
p 0 . If / 4 we have p 1/ 2 .
It can be seen that the Table 3.15 contains truth tables for a three-qubit system and has eight
inputs and eight outputs, of which only four are needed in the half-adder. The rest of the four
states with C=1 for the half-adder operation and their outputs are not needed, but when included,
give complementary carry. Therefore, in effect, one obtains both the carry and their complement
in the half-adder using the complete three-bit truth table.
78
Quantum Computing
A B A+B Carry
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1
A A' A
B B' A B
C C ' C AB
79
Quantum Computing
3.7.2 Subtractor
The classical subtraction operation using two bits is also irreversible as shown in Table 3.16. It
can be made reversible using an ancillary bit as shown in the truth table in Table. The circuit of a
reversible subtractor is shown in Fig 3.20. Here the bit A in the input and bit B’ in the output are
redundant.
Similar to the half-adder the Table 3.17 contains truth tables for a three-qubit system and has
eight inputs and eight outputs, of which only four are needed for the subtractor operations. The
rest of the four states with A=1 for the subtractor operation and their outputs are not needed, but
when included give complementary borrow outputs. Therefore, in effect, one obtains both
borrow and its complement in subtractor operation using Table 3.17.
A B A-B Borrow
0 0 0 0
0 1 1 1
1 0 1 0
1 1 0 0
80
Quantum Computing
B B’=B
C
C ' B C
A A ' A BC C
81
Quantum Computing
CHAPTER 4
Quantum computing has some truly startling applications which range from communication to
factorization and searching to teleportation. This chapter presents quantum teleportation,
quantum parallelism, superdense coding and secure communication using quantum channels.
Chapter 5 is completely dedicated to factorization using Shor’s algorithm and Chapter 6 presents
Grover’s quantum search algorithm.
Suppose Alice and Bob are two friends who met a long time ago. Before they separated, the
generated an EPR pair and each one of them took one qubit of the EPR pair as they went
different ways. After several years, Alice wants to send a qubit to Bob. However, she can
send only classical information to Bob.
b) She can communicate only over a classical communication channel with Bob.
82
Quantum Computing
If Alice is familiar with quantum teleportation, her problem can be easily solved. The circuit that
is used for teleportation of a qubit is shown. In the circuit shown in Fig. 4.1, the two top lines
represent Alice’s system and the bottom line is Bob’s system. The only communication between
the two is through classical communication channel shown by double line.
M1
H
M2
00
{ X M2 Z M1
0 1 2 3 4
Step I
The state input to the circuit has the first qubit as and the second and third qubits are the
Bell states 00 . So the state input becomes
0 00
1
0 ( 00 11 ) 1 ( 00 11 )
2
Step II
Alice sends her qubits through a CNOT gate, which leaves the first term as it is but flips the
second qubit in the second term, obtaining
1
1 0 ( 00 11 ) 1 ( 10 01 )
2
Step III
Alice then sends the first qubit through a Hadamard gate, obtaining
83
Quantum Computing
1
2 ( 0 1 )( 00 11 ) ( 0 1 )( 10 01 )
2
or
1
2 000 011 100 111 010 001 110 101
2
This state may be re-written by regrouping terms as
1
2 00 ( 0 1 ) 01 ( 1 0 ) 10 ( 0 1 ) 11 ( 1 0 )
2
Step IV
Alice now performs a measurement and is equally likely to obtain the result 00, 01, 10 or 11 as
shown by the four terms in the last expression. This result is now communicated to Bob over a
classical communication channel. Bob must also be told what to do in case of each of the four
outcomes. There are four possibilities :
1. Alice measures 00
If we look at the first term 00 ( 0 1 ) , the first two qubits are Alice’s and are in the state
00 and the last one is Bob’s qubit and is in the state ( 0 1 ) which is the original state
. Hence Bob need not do anything further. He has obtained the qubit .
2. Alice measures 01
If Alice performs a measurement and obtains the result 01, then we need to look at the second
term in 2 . Bob’s qubit will be in the state ( 1 0 ) . However he needs to have the
original state 0 1 . This can be obtained by applying the Pauli X gate as
0 1
1 0
3. Alice measures 10
If Alice measures the result as 10, then a look at the third term tells that Bob’s qubit will be in
the state ( 0 1 ) . In order to obtain the original state 0 1 , he needs to use the
Pauli Z gate as
84
Quantum Computing
1 0
0 1
4. Alice measures 11
If Alice measures the result as 11, then the fourth term reveals that Bob’s qubit will be in the
state ( 1 0 ) . Thus Bob needs to first apply a Pauli X gate and then a Pauli Z gate.
0 1
1 0
1 0
0 1
Or in other words, Bob needs to apply the transformation Z M1 X M 2 . It is important to note that in
Fig. 4.1, the X gate is shown first, followed by the Z gate since in quantum circuits, time goes
from left to right in circuit diagrams. However, in matrices, the terms on the right happen first in
matrix products.
as
1 0 0 1
0 1 1 0
There are many interesting observations with regard to quantum teleportation viz.
Faster than light transfer of quantum information is not possible through teleportation as
the classical communication channel is involved in between, which prohibits speeds
faster than light.
It might appear at first glance that a copy of the quantum state has been teleported.
However, it is illusory since after teleportation only Bob has his qubit in the state
and the original date qubit ends up in one of the computation basis states 0 or 1 ,
depending on the result of the measurement.
It emphasizes the interchangeability of different resources in quantum mechanics,
showing that one shared EPR pair along with two bits of classical communication is a
resource that is at least equal to one qubit of communication.
85
Quantum Computing
Quantum Entanglement
This is a good juncture to realize a very important and puzzling concept in quantum computing
i.e. quantum entanglement. Qubits like those of Alice and Bob in the state 00 are in the state
of quantum entanglement.
00 11
00
2
Such as state has the remarkable property that there are no single qubit gates a and b such that
a b
The state of a composite system having the property that it cannot be written as a product of
states of its component systems is an entangled state. The reasons are not understood fully,
however entangled states play a crucial role in quantum computation and quantum information
as seen above and in later applications also. Fig. 4.2 shows a quantum entanglement setup used
to verify the presence of entangled photons in the system.
Figure 4.2 Quantum entanglement setup used to verify the presence of entangled
photons in the system (Courtesy : NASA)
86
Quantum Computing
Example 4.1
A H
B H
C H H
Here A is the input , B is the input 0 and C the input 0 . When 00 is fed into the
quantum circuit shown in Fig 4.3, the result can be easily computed using the matrix technique.
U1 I 2 U H I 2
U 2 I 2 U XOR
U 3 U XOR I 2
U4 U H I2 I2
U 5 I 2 U XOR
U6 I2 I2 U H
U 7 I 4 U NOT U NOT
U8 I2 I2 U H
U8U 7U 6U 5U 4U 3U 2U1 00
87
Quantum Computing
Let us apply the first four unitary matrices to the input state to obtain
U 4U 3U 2U1 00
a
2
000 100 011 111 010 110 001 101
b
2
U 4U 3U 2U1 00
1
0 1 a 0 0 1 1 1
0 1 b 0 1 1 0
2 2 2 2
U 8U 7U 6U 5U 4U 3U 2U1 00
a
2
000 100 010 110 011 111 001 101
b
2
1
0 1 1 0 1
2 2
It can be observed from the above that the state will be transferred to the lower output. This
example is an illustration of using matrices to compute the circuit output.
Suppose f ( x ) is a function with one-bit domain {0,1} and one-bit range {0,1} . Assume a 2 qubit
quantum computer which accepts the state x, y and transforms this into the state x, y f ( x)
where is modulo 2 addition. The first register is called the ‘data’ register and the second
register is called as the ‘target’ register. We use two qubits since we wish to leave the input x
register unchanged. The second qubit, y, acts as a result register. Let U f be the unitary transform
that impellents this as illustrated in Fig. 4.4. The transformation can be defined as :
x, y x, y f ( x)
and denoted as U f .
88
Quantum Computing
0 1
x x
2
Uf
0 y y f ( x)
If y 0 , then the final state of the second qubit is simply the function f ( x ) evaluated.
Now, if x 0 , then the second qubit has the output f (0) so that our output state is 0, f (0) . If
x 1 , then the second qubit has the output f (1) so that the output state is 1, f (1) .
Instead of applying 0 or 1 as the input x, we pass 0 through a Hadamard gate and obtain the state
1 1 1 1 1 1
2 1 1 0 2 1
0 1
i.e.
2
then in that case our quantum computer gives the output state as
0, f (0) 1, f (1)
2
This is indeed a very remarkable state as it has information about both f (0) and f (1) . We have
evaluated f ( x ) for two values of x simultaneously, thereby understanding the quantum
parallelism.
This is different from classical parallelism where multiple circuits are used to compute f ( x )
simultaneously. In quantum parallelism, a single f ( x ) circuit is used to evaluate the function for
multiple values of x simultaneously by exploiting the ability of a quantum computer to be in
superpositions of different states.
89
Quantum Computing
We have seen the procedure for quantum parallelism for two bits. This procedure can be easily
generalized for functions on any number of bits n by using a general operation known as the
Hadamard transform which is simply n Hadamard gates acting in parallel on n qubits.
For n=2 qubits, if we give both the qubits as 0 , then the output state becomes
0 1 0 1 00 01 10 11
2 2 2
The parallel action of two output gates can be written as H 2 where denotes tensor. In
general the result of performing the Hadamard transform on n qubits can be denoted as H n . If
all the qubits are in the 0 state, this can be written as
1
x
2n x
where the sum is over all possible values of x. So the Hadamard transform produces an equal
superposition of all computational basis states. It is done very efficiently in that the superposition
of 2 n states is produced using just n gates.
To answer this question classically we clearly need to query for both x 0 and x 1 , hence two
queries are required. The following discussion shows how the problem can be solved in just one
query.
The basic idea of Deutsch’s algorithm is that the superposition of quantum states creates
quantum parallelism or the ability to compute on many states simultaneously.
The states of the qubits at the various states are labelled in Fig.4.5.
90
Quantum Computing
0 H x x H
Uf
1 H y y f ( x)
0 1 2 3
0 01
It may appear strange to start out with a result register of 1 instead of 0, but we will understand
its reason in the discussion later. The Hadamard gate is applied to obtain the state
0 1 0 1
1
2 2
Suppose f ( x) 0 then
y f ( x) y 0
1
0 0 1 0 1 0 1
2 2
Suppose f ( x) 1 then
y f ( x) y 1
1
0 1 11 1 0 1
2 2
y f ( x) 1
f ( x) 1
0 1
2
91
Quantum Computing
Thus, U f transforms x
1
0 1 into 1
f ( x)
x
1
0 1
2 2
Or in other words
0 1 0 1 1
U f 1
f (0)
0 0 1 1
f (1)
1 0 1
2 2 2
1
2 1 0
f (0)
0 1 1
f (1)
1 0 1
1 0 0 1 1 0 1
1
f (0)
2
0 0 1 1 0 1
1
2
0 1 0 1
2 2
1
2
1
f (0)
0 0 1 1
f (1)
1 0 1
1
2 1 0
f (0)
0 1 1
f (1)
1 0 1
1
2
1 0
f (0)
0 1 1 0 1
1
0
2
0 1 1 0 1
92
Quantum Computing
0 1 0 1
2 2
0 1 0 1
if f (0) f (1)
2 2
2
0 1 0 1
if f (0) f (1)
2 2
Thus we get
0 1
0 if f (0) f (1)
2
3
0 1
1 if f (0) f (1)
2
0 1
3 f (0) f (1)
2
93
Quantum Computing
Deutsch’s algorithm answers a question about a global property of a solutions space like all
known quantum algorithms that provide exponential speedup over classical systems. It calculates
a solution to a problem faster than any classical computer ever can. However, the problem it
solves is rather not of much practical use.
The Deutsch-Jozsa algorithm circuit answers this question with just one query (Fig. 4.6).
n
0 H n x x H n
Uf
1 H y y f ( x)
0 1 2 3
We have
n
0 0 1
94
Quantum Computing
n
The notation 0 simply means n consecutive 0 qubits. We then apply the Hadamard gate to
each of the n qubits in parallel. This is represented as the H n transform.
1
i. j
H n
i j
j 2n
This notation states that given any arbitrary state vector, it will be composed of components
i .Each component of this state vector is transformed into a superposition of components j .
For example, let is examine a single qubit
a 0 b 1
Apply H 1 to get :
a 0 a 1 b 0 b 1
2 2 2 2
a b 0
a b 1
2 2
When we look at the actual transform using the usual notation, it can be seen that
1 1 1 a a b a b
1 1 b 0 1
2 2 2
1 H n 0 H 1
1 0 1
x
x0,1
n
2n 2
The notation 0,1 means all possible bit strings of size n. For example, if n 2 , this would be
n
95
Quantum Computing
(1) f ( x ) 0 1
2 x
x0,1
n
2n 2
(1) x. z f ( x ) 0 1
3 n n 2n z 2
z0,1 x0,1
n
The key to the Deutsch-Jozsa algorithm is to observe the probability amplitude of z 0 .
Case I
f ( x ) is constant
n
Hence for this case the probability amplitude of z 0 is expressed as
1
n 2
n
1
x0,1
Case II
f ( x ) is balanced
1 1
2 2
x1
n
x2
n
0
96
Quantum Computing
Hence we will never measure 0 when f ( x ) is balanced since the probability amplitudes
perfectly destructively interfere to produce a probability of zero for that quantity. In this case
anything except 0 will be measured.
Alice and Bob are two friends far apart and Alice wishes to transmit some classical information
to Bob. Alice is having two classical bits of information but can send only a single qubit to him.
Superdense coding helps solve her problem.
Initially, Alice and Bob share a pair of qubits in the entangled state
00 11
2
It is important to note that is a fixed state and there is no need for Alice to send any qubits
ahead of time. Instead, some third party may prepare the entangled state ahead of time, sending
one of the qubits to Alice and the other to Bob.
Depending on the combination Alice wants to send Bob, she does the following :
00
00 11
2
This is interpreted as 00 by Bob according to the protocol.
01
Alice applies the phase flip Z to her qubit. It leaves 0 unchanged and inverts the sign of 1 to
give - 1 .
97
Quantum Computing
00 11
2
10
Alice applies the quantum NOT gate, X to her qubit. It converts 0 into 1 and vice versa.
10 01
2
11
0 i 1 0
i
i 0 0 1
that is, 1 .
0 i 0 1
i
i 0 1 0
that is, 0 .
98
Quantum Computing
01 10
2
Even though two qubits are involved in the protocol, Alice never needs to interact with
the second qubit.
If Alice sends her qubit to Bob, giving Bob possession of both qubits, then by doing a
measurement in the Bell states, Bob can determine which bit sequence was sent.
The task accomplished by Alice would have been impossible if she had only transmitted
a single classical bit.
Quantum communications makes use of the fact that information can be encoded as the
polarisation of photons (i.e. the orientation of a photon's oscillation). An oscillation in one
direction can be thought of as 0 and in another as a 1. Two sets of polarisations are commonly
used, rectilinear and diagonal - Fig. 4.7).
99
Quantum Computing
The property that quantum communication exploits is that in order to receive the correct
information, photons have to be measured using the correct filter polarisation e.g. the same
polarisation that the information was transmitted with. If a receiver is in rectilinear polarisation,
and a diagonally polarised photon is sent, then a completely random result will appear at the
receiver. Using this, property information can be sent in such a way as to make it impossible for
an eavesdropper to listen undetected. The mechanism by which this works is as follows:
For example, say the sender named Alice wishes to transmit information to Bob without
eavesdropper Eve listening. They would follow the steps as described above. If Eve tries to
eavesdrop, she will have to measure the bits coming from Alice and then forward them to Bob
(she can't simply look at the information as doing so will alter it's content). She must use random
polarisations to do this, as she does not know which ones Alice used. The chances are that Eve
will correctly receive 50% of the information, the other 50% will consist of random values. The
fact that approximately half of the random values will be correct means that Eve can at best
forward 75% of the correct information to Bob.
Assuming that there is negligible noise on the communication line, Bob will be able to detect
that Eve has eavesdropped, as the information he received at the correct polarisation will contain
more than 25% errors. He checks for errors by comparing a random selection with Alice on a
public channel.
Another way that Eve could attempt to subvert communication between Bob and Alice is to
intercept the information and send her own instead. Eve will be thwarted by the fact that Alice
and Bob discuss a randomly selected group of values, giving away the fact that Eve changed the
information. It does not matter how subtly Eve intercepts the signal, Alice and Bob will always
be able to discover that she has been listening to the line. This system can only work if the noise
100
Quantum Computing
on the communication line is negligible, if the line had 25% noise for example it would be
impossible to distinguish an eavesdropper from the noise itself. British Telecom has managed to
implement a line with only 9% error over a distance of 10km, giving quantum communications a
promising future. Fig. 4.8 shows a quantum communication setup.
Example 4.2
As an example of the above, Alice selects a random sequence of bits as shown in Fig. 4.9. Out of
this sequence (Fig. 4.10), Alice and Bob will ultimately construct a common key.
Alice must encode these into polarized photons and send them to Bob along the quantum
channel.
Alice chooses to encode each bit in either the rectilinear polarization (+) form or the diagonal
polarization (x) form. Alice chooses to encode each bit in either the rectilinear polarization (+)
101
Quantum Computing
form or the diagonal polarization (x) form. The summary of polarization forms for both 1 and 0
are shown in Fig. 4.11(a) and (b) respectively.
Alice now sends the random bits with the following choice of polarization. She sends this
sequence of polarized photons to Bob (Fig. 4.12).
Bob must measure the direction of polarization of Alice’s photons to reconstruct the set of bits.
However, Bob does not know when Alice used rectilinear or diagonal polarization, so he ahs to
guess. If his guess s correct, then he will recover the correct bit. If his guess is wrong, he has
only a 50-50 chance of recovering the correct bit.
Bob receives Alice’s polarized photons. The decoding process is shown in Fig. 4.13. Alice’s
polarization choice is shown by the by the last line.
102
Quantum Computing
Alice tells Bob the polarizer orientation for a subset of the bits and Bob tells Alice the
orientations he used on the same subset.
For those cases where Alice and Bob agreed, Alice tells him what but values he should have
received. This is shown in Fig. 4.14. Thus, they agree there was no eavesdropping.
Since the channel is secure, Alice sends Bob the polarization orientation for another subset of the
buts. Bob compares the actual polarization with his guess. He only uses the bits for which the
two polarizations match (Fig. 4.15), and so does Alice.
Figure 4.15 The key is obtained by using bits for which the two polarizations match
103
Quantum Computing
After sending stream of bits in randomly chosen settings, Alice then telephones Bob and they
agree which are the good bits. The advantage of this is that suppose Eve is intercepting the bits
from Alice and re-sending them to Bob, then Eve has to guess which setting Alice used
(Horizontal-Vertical or Diagonal), so there is now a probability of ¼ for Alice and Bob to
disagree on the bit sent even when they use the same settings.
If Eve intercepts and measures the photons, she has to send her measured values on to Bob as
shown below in Fig. 4.16.
Bob is unaware of Eve’s presence decodes the photons as shown in Fig. 4.17.
He then sends the checks bits to Alice. Alice selects the check bits and sends polarization and bit
information, and if any eavesdropping is there, the error is immediately detected (Fig. 4.18).
104
CHAPTER 5
In this Chapter, we shall see one of the foremost and most useful algorithms of Quantum
Computing - Shor’s Algorithm. We start by first understanding the algorithm, and then seeing
how it works on a Quantum Computer which requires an understanding of the quantum Fourier
Transform.
The problem of factoring is that given a positive composite integer N, we have to find prime
numbers which when multiplied together will equal it. For example, multiplying 1234 by 3433 is
easy to work out, but calculating the factors of 4236322 is not so easy. The difficulty of
factorizing a number grows rapidly with additional digits. It took 8 months and 1600 Internet
users to crack RSA 129 (a number with 129 digits). RSA, named after the initials of its creators
Rivest, Shamir and Adleman is currently the most commonly used method for sending encrypted
data. It works by using two keys, one public and one private. The public key is used to encrypt
the data, while the private key is used to decrypt the data. The public key can be easily derived
from the private key but not vice versa. However, an eavesdropper who has acquired your public
key can in principle calculate the private key as they are mathematically related. In order to do so
it is necessary to factorize the public key, a task that is considered to be intractable.
Cryptographers thought that more digits could be added to the key to combat increasing
performance in computers (it would take longer than the age of the universe to calculate RSA
140). However, using a quantum computer, which is running Shor's algorithm, the number of
digits in the key has little effect on the difficulty of the problem. Cracking RSA 140 would take a
matter of seconds.
Section 5.1 explains the working of Shor’s algorithm through a simplified example in order to
bring forth the basic idea. In order to implement it on a quantum computer, the principle of
quantum Fourier Transform is presented in Section 5.2. Section 5.3 presents the implementation
of quantum Fourier transform using quantum gates. Section 5.4 presents the phase-estimation
problem and Section 5.5 presents Shor’s algorithm through phase estimation method. Section 5.6
presents the order-finding and factoring problem with the perspective of quantum Fourier
transform.
105
The purpose of this section is to illustrate the basic steps involved in Shor's Algorithm. In order
to keep the example relatively easy to follow we will consider the problem of finding the prime
factors of the number 15.
Stage 1
The first stage of the algorithm is to place a memory register into a coherent superposition of all
its possible states. The letter 'Q' will be used denote a qubit that is in the coherent state.
When a qubit is in the coherent state, it can be thought of as existing in two different universes.
In one universe it exists as a '1' and in the other it exists as a '0'. Extending this idea to the 3 bit
register we can imagine that the register exists in 8 different universes, one for each of the
classical states it could represent (i.e. 000, 001, 010, 011, 100, 101, 110, 111) as shown in Fig.
5.1. In order to hold the number 15, a four bit register is required (capable of representing the
numbers 0 to 15 simultaneously in the coherent state).
Stage 2
The second stage of the algorithm performs a calculation using the register. The details of which
are as follows:
106
X is raised to the power contained in the register (register A) and then divided by N
The remainder from this operation is placed in a second 4 bit register (register B).
After this operation has been performed, register B contains the superposition of each universes
results. This is best illustrated with an example, if we choose X to be 2, then the contents of
register B, for every possible value in register A are as shown in Table 5.1.
Register A Register B
0 1
1 2
2 4
3 8
4 1
5 2
6 4
7 8
8 1
9 2
10 4
11 8
12 1
13 2
14 4
15 8
Notice that the contents of register B follow a repeating sequence (1,2,4,8,1,2,4,8...), the
frequency at which this repeats can be named f. In this case the repeating sequence (1, 2, 4, 8)
has four values so f = 4.
Stage 3
The final stage is perhaps the most crucial and the frequency of repetition, r, can be found using
a quantum computer. This is done by performing a complex operation on register B and then
looking at its contents which causes the results from every universe to interfere with each other.
The resulting value for f is then used in the following equation to calculate a (possible) factor as
r
gcd ( X 2 1,N). The resulting number cannot be guaranteed to be a prime factor, but there is a
107
good chance that it is one. The interference that produces the value for f tends to favour the
correct answer as incorrect answers cancel each other out.
4
In our example the value f = 4 does give a correct answer of gcd ( 2 1 ,15) = gcd (3,15) = 3.
2
The fact that the answer cannot be guaranteed to be correct is of little consequence as it can be
easily checked with multiplication. If the answer is incorrect, there is a very strong chance that
repeating the calculation a few times with different values of X will produce the right answer.
Example 5.1
Suppose N = 21 and X = 2 :
r 0 1 2 3 4 5 6 7 8 9 10 11 12 13
r
X mod N 1 2 4 8 16 11 1 2 4 8 16 11 1 2
The order can be easily seen to be 6.
r 6
We can evaluate X 2 1 2 2 1 7 and gcd (7,21) = 7 is indeed a factor.
Example 5.2
Suppose N = 35 and X = 2 :
r 0 1 2 3 4 5 6 7 8 9 10 11 12 13
r
X mod N 1 2 4 8 16 32 29 23 11 22 9 18 1 2
r 14 15 16 17 18 19 20 21 22 23 24 25 26 27
r
X mod N 4 8 16 32 29 23 11 22 9 18 1 2 4 8
The order can be easily seen to be 12.
r 12
We can evaluate X 1 2 1 28 and gcd (28, 35) = 7 is a factor.
2 2
Example 5.3
Suppose N = 91 and X = 4 :
r 0 1 2 3 4 5 6 7 8 9 10 11 12 13
r
X mod N 1 4 16 64 74 23 1 4 16 64 74 23 1 4
The order can be easily seen to be 6.
r 6
We can evaluate X 1 2 1 7 and gcd (7,91) = 7 is a factor.
2 2
The order finding is done on a quantum computer using Quantum Fourier Transform which is
explained in the following section.
108
5.2 Quantum Fourier Transform
The Quantum Fourier Transform implements the analog of the classical Fourier transform. In the
classical domain, the Discrete Fourier transform takes as input a vector of complex numbers, x0 ,
x1 . . . xN 1 where the length N of the vector is a fixed parameter. The output is transformed data,
again a vector of complex numbers y0 , y1 . . . yN 1 , defined by
N 1
1
yk
N
x e
j 0
j
2 ijk / N
. . (5.1)
It can be viewed as a transform from 2 n numbers into a range of size 2 n containing the
frequency components from the domain.
The quantum Fourier transform is defined in exactly the same way, although the notation differs
slightly. It transforms a state space of size 2 n from the amplitude to the frequency domain.
N 1
1
j
N
x e
k 0
j
2 ijk / N
k . . (5.2)
We can take N 2n where n is some integer. We are working with an n qubit quantum
computer, therefore the computational basis is 0 , 1 . . . 2n 1 .
2n 1
1
j
2n
x e
k 0
j
2 ijk / 2n
k . . (5.3)
2n 1 2n 1 2n 1 2n 1
1
x
j 0
j j yk k
k 0 2n
x e
k 0 j 0
j
2 ijk / 2n
k . . (5.4)
Example 5.1
Solution
109
2n 1 2n 1
1
x e
2n k 0 j 0
j
2 ijk / 2n
k
1 2 1 2 1
3 3
2 3
x e
k 0 j 0
j
2 ijk / 2n
k
The inner summation has only one non-zero term i.e. x0 when j = 0.
23 1
1
j k
2 2 k 0
000 001 010 011 100 101 110 111
2 2
The vector with all qubits zero has got all the frequencies in with equal amplitude 1/ 2 2 .
It can be seen that the unitarity condition still holds that j 1 .
2
There is another representation of the quantum Fourier Transform which is also very useful. Its
mathematical basis is as follows :
2n 1
1
j
2n
e
k 0
2 ijk / 2n
k
n
j j1 2n1 j2 2n2 ... jn 20 ji 2ni
i 1
Similarly for k
n
k ki 2ni
i 0
110
n
1 2n 1 2 ij kl 2nl / 2n
n
e l 1
k
2 k 0
1 2n 1 2 ij kl 2 l
n
e l 1
k
2 k 0
2n 1
1
1 2 n
e2 ijk1 2 e2 ijk2 2 ... e2 ijkn 2 k
n
2 k 0
1 1 1
1
... e2 ijk1 2 e2 ijk2 2 ... e2 ijkn 2
1 2 n
k1k2 ...kn
2n k1 0 k2 0 kn 0
Now, the nth component can be written separately to get the transform in the form
1 1 1 1
1
... e e
n
2 ijk1 21 2
2 ijkn 2 n
e2 ijk2 2 ... e2 ijkn 2 k1k2 ...kn1 k
2n k1 0 k2 0 kn1 0 kn1 0
1
2 n
0 e 2 ijk1 21
1 0 e 2 ijk2 22
1 ... 0 e2 ijkn 2 1
n
Let us define a new notation :
jl jl 1 j
0. jl jl 1... jm 2 ... m ml 1
2 2 2
j is a binary number with the qubits j1 j2 ... jm .. jn . The weight of the mth qubit is 2nm .
k
So we can expand e2 ij 2 as
111
n
k
2 i 2 k jl 2nl k
j1 2n1 k
j2 2n2 k
e2 ij 2 e l 1
e2 i 2 e2 i 2 ...e2 i 2 j2 20
n1k n 2 k nnk
e 2 i 2 j1
e 2 i 2 j2
...e2 i 2 jn
n1k
Suppose that j1 0 , then e2 i 2 ji
1
Suppose that ji 1 and 2n1k 1, then the exponent is a multiple of 2 i , hence equal to 1.
1
0 e2 ij 2 1 0 e2 i 0. jn 1
For k=2
2
0 e2 ij 2 1 0 e2 i 0. jn1 jn 1
1
n
0 e 2 i 0. jn
1 0 e 2 i 0. jn1 . jn
1 ... 0 e2 i 0. j1 . j2... jn1 . jn 1 . . (5.5)
2
1
2
0 e2 i 0. jl ... jn 1
We take out the first component jl separately.
1
2
0 e2 i 0. jl e2 i 0. jl 1 ... jn / 2 1
112
1
2
0 e2 i 0. jl 1
1
2
0 e2 ijl / 2 1
1
2
0 (1) jl 1
0 1 0 1
This is just a Hadamard gate since it transforms a 0 to and 1 to .
2 2
1 0
Rk 2 i / 2 k
0 e
So we start from the least significant qubit in Eq. 5.5. We want to achieve
0 e 2 i 0. j1 . j2 ... jn
1
Step I
We start with
j1 j2 ... jn
Step II
1
2
0 e2 i 0. j1 1 j2 ... jn
Step IIIA
1
2
0 e 2 i 0. j1 j2 1 j2 ... jn
Step IIIB
113
1
2
0 e2 i 0. j1 j2 j3 1 j2 ... jn
Step IIIC
1
2
0 e2 i 0. j1 j2 ... jn 1 j2 ... jn
This is repeated for all the other bits j2 , j3 and so on till jn and the result is the quantum
Fourier transform as seen in the Fig. 5.3, but the qubits are in the reverse order. So we need swap
gates to get the qubits in the correct order.
. .
. .
. .
jn ... H 0 e2 i 0. jn 1
The first qubit goes through a Hadamard gate and ( n 1) conditional rotations, thereby requiring
n gates.
This is followed by a Hadamard gate and ( n 2) conditional rotations on the second qubit,
thereby requiring ( n 1) gates.
114
This continued till the last qubit where we require only a single Hadamard gate.
However, the qubits are now in the reverse order. In order to correct their order, at most n / 2
swaps are required. Therefore, the circuit provides a ( n 2 ) algorithm for evaluating the quantum
Fourier transform
The speedup obtained with quantum algorithms can be best understood by comparing this with
the best classical algorithms such as the Fast Fourier Transform (FFT) which compute the
discrete Fourier Transform using ( n 2n ) gates. Thus, it requires exponentially more operations
to compute the Fourier transform on a classical computer than it does to implement the quantum
Fourier transform on a quantum computer.
Example 5.4
The circuit for three qubit quantum Fourier transform is shown in Fig. 5.4.
H S T
H S
1 0
Rk 2 i / 2 k
0 e
1 0 1 0 1 0
3 T 0
2 i / 2 2 i / 8
0 e 0 e
where
115
e 2 i / 8 i
and
1 0 1 0 1 0 1 0
2 i / 2 2
2 i / 4
S 2
0 e 0 e 0 i 0
The controlled T gate has got the control qubit output same as control qubit input always. The
target qubit undergoes a matrix transformation only if the control qubit is 1 as follows :
i.e. 0 again.
1 0 0 0
0 1
i.e 1
The controlled S gate has got the control qubit output same as control qubit input always. The
target qubit undergoes a matrix transformation only if the control qubit is 1 as follows :
i.e. 0 again.
116
If the target qubit is 1 , then it is transformed to
1 0 0 0
0 2 1 2
i.e 2 1
The controlled S gate has got the control qubit output same as control qubit input and the target
bit undergoes a matrix transformation if the control qubit is 1.
Let us see the output of this circuit for two sample inputs 000 and 001 (Fig. 5.5).
H S T
H S
1 2 3 4 5 6 7 8
Figure 5.5 Circuit of Fig. 5.4 with the quantum states at each stage labelled
1 000
0 1
2 00
2
The control qubit of the S gate is 0 , so there is no change in the target qubit.
117
0 1
3 00
2
The control qubit of the T gate is 0 , so there is no change in the target qubit.
4 3
The control qubit of the S gate is 0 , so there is no change in the target qubit.
6 5
0 1 0 1 0 1
7
2 2 2
0 1 0 1 0 1
8
2 2 2
1 001
0 1
2 01
2
118
The control qubit of the S gate is 0 , so there is no change in the target qubit.
0 1
3 01
2
The control qubit of the T gate is 1 , so there is a transformation in the target qubit.
0 1
4 01
2
0 1 0 1
5 1
2 2
The control qubit of the S gate is 1 , so there is a transformation in the target qubit.
0 1 0 2 1
6 1
2 2
0 1 0 2 1 0 1
7
2 2 2
0 1 0 2 1 0 1
8
2 2 2
We can repeat the above steps for all the 8 possible input combinations. Using the matrix rule for
multiple qubit gates we can express the quantum Fourier transform explicitly as
119
1 1 1 1 1 1 1 1
1
2 3
4
5
6
7
1 2 4 6 1 2 4 6
1 1 3 6 1 4 7 2 5
8 1 4 1 4 1 4 1 4
1 5 2 7 4
1 6 3
1 6 4 2 1 6 4 2
1 7 6 5 4 3 2
or following the rules of matrix representation of multiple qubit gates more explicitly as
000 1 1 1 1 1 1 1 1 000
1
001 2 3 4 5 6 7 001
010 1 2 4 6 1 2 4 6 010
011 1 1 3 6 1 4 7 2 5 011
100 8 1 4 1 4 1 4 1 4 100
101 1 5 2 7 4 1 6 3 101
110 1 6 4 2 1 6 4 2 110
111 1 7 6 5 4 3 2 111
The left hand column vector denotes the amplitude of each combination in the output and the
right hand column vector denotes the amplitude of each combination in the input.
Our above 2 examples are simply the first and second columns of the complete 8 x 8 matrix since
1 1 1 1 1 1 1 1 1 1
1 7
2 3
4
5
6
0 1
1 2 4 6 1 2 4 0
6
1
1 1 3 6 1 4 7 2 5 0 1 1
for input 000
8 1 4 1 4 1 4 1 4 0 8 1
1 5 2 7 4
1 6 3 0 1
1 2 1
6 4 2 1 6 4 0
1 7 6 5 4 3 2 0 1
120
1 1 1 1 1 1 1 1 0 1
1 7
2 3
4
5
6
1
1 2 4 6 1 2 4 0
6
2
1 1 3 6 1 4 7 2 5 0 1 3
and for input 001 .
8 1 4 1 4 1 4 1 4 0 8
4
5
1 5 2 7 4
1 6 3 0
1 2 6
6 4 2 1 6 4 0
7
1 7 6 5 4 3 2 0
It implies
e2 i I U u 0
In general,
e2 i 2 I u U 2 u
t t
. . (5.6)
k
Looking at the Eq. (5.6), the basic approach of phase estimation is to apply the controlled U 2
0 1
operation with as the control for k {0,1,..., n} . Then apply inverse QFT to n qubits and
2
~
obtain , an estimate of .
The quantum phase estimation uses two registers, the first having t qubits in the state 0 . The
choice of t depends on the number of digits of accuracy needed in the phase estimate and the
probability for the phase estimation procedure to be successful. The second registers starts in the
state u and has as many qubits as are necessary.
121
t 1
0 ... 0 e2 i (2 )
1
H
First
register
0 e2 i (2 ) 1
2
0 ...
t qubits H
... 0 e2 i (2 ) 1
1
0
H
... 0 e2 i (2 ) 1
0
0
H
Second
0 1 2 ... t 1
u
register U2 U2 U2 U2 u
Step I
We start with
t
0 u
Step II
H t
122
Step III
k
Apply controlled U 2 operation for each of the k qubits of j
1
j u
2t j
Second Stage
Step IV
Apply inverse quantum Fourier Transform on the first register.
1
t
e 2 ij u
j u
2 j
u
Step V
~
The first register is measured to get .
0 H FT †
j u
u U
123
5.5 Shor’s Algorithm Using Phase Estimation
The basic approach employed in Shor’s algorithm using phase estimation is as follows :
U y xy(mod N )
Step II : Find us
Procedure :
r 1 s
2 i k
1
us
r
e
k 0
r
x k mod N
s
2 i
Suppose e r for 0 s r 1 are eigenvalues. Then
2 i
s r 1 s
2 i k
1
e r
r
e
k 0
r
x k mod N
r 1 s
2 i ( k 1)
1
r
e
k 0
r
x k mod N
r 1 s
2 i k
1
r
e
k 0
r
x k 1 mod N
r 1 s
2 i k
1
r
e
k 0
r
x k 1 mod N
Now, the question arises that how do we prepare us for Shor’s algorithm. We cannot prepare it
for a single eigenvalue, but we can do it for a superposition of them.
124
r 1
1
r
u
s 0
s
r 1 r 1 s
2 i k
1 1
r r
e
s 0 k 0
r
x k mod N
1 r 1 0 0 r
r s 0
e x mod N 00...1 00...1
r
r 1 r 1 s
2 i k
1 1
e
t t
0 r
x k mod N 0 00...1
r r s 0 k 0
r 1 r 1 s s
2 i k ( 2 i k )
1 1 1
t
j
r r
e r r
x k mod N
2 j s 0 k 0
r 1 r 1 s s
2 i k ( 2 i k )
1 1 1
t
j
r r
e r r
x k mod N
2 j s 0 k 0
r 1 s
2 i ( j k )
1 1
t
j
r
e r
x k mod N
2 j s 0
r 1 s
2 i ( j k )
1 1
t
r
e r
j x k mod N
2 j s 0
1 r 1 ~
r
s 0
s/r x k mod N
125
~
The first register is measured to obtain a particular s / r and then use continued fraction
expansion to find r.
For positive integers x and N, x N with no common factors, the order of x modulo N is defined
to be the least positive integer r, such that x r mod N 1 .
The order-finding problem is to determine the order for some specified x and N. Order-finding is
believed to be a hard problem on a classical computer, in the sense that no algorithm is known to
solve the problem using polynomial resources.
The quantum algorithm for order-finding is just the phase estimation algorithm applied to the
unitary operator :
U y xy(mod N )
Using the phase estimation procedure allows us to obtain, with high accuracy, the corresponding
s
2 i
eigenvalues e r , from which we can obtain the order r easily. Fig. 5.8 shows a quantum circuit
for the order-finding algorithm.
Register 1
0 H t FT
t qubits
Register 2
1 x j mod N
L qubits
126
Factoring
The factoring problem turns out to be equivalent to the order-finding problem in the sense that a
fast algorithm for order-finding can easily be turned into a fast algorithm for factoring. The
procedure is as follows :
All the steps in the algorithm can be performed efficiently on a classical computer except the
order-finding part, which is used by the algorithm. By repeating the procedure, we may find a
complete prime factorization of N.
3. Randomly choose x in the range 1 to N 1 . If gcd( x, N ) 1 then return the factor gcd( x, N ) .
5. If r is even and x r / 2 1(mod N ) then compute gcd( x r / 2 1, N ) and gcd( x r / 2 1, N ) , and test
to see of one of these is a non-trivial factor, returning that factor if so. Otherwise, the algorithm
fails.
Steps 1 and 2 of the algorithm either return a factor, or else ensure that N is an odd integer with
more than one prime factor. Step 3 either returns a factor, or produces a randomly chosen
element x between 0 and N-1. Step 4 calls the order-finding subroutine computing the order r of
x modulo N. Step 5 completes the algorithm.
The idea of the continued fraction algorithm is to describe real numbers in terms of intheegers
alone, using expressions of the form
1
a0 ,..., aM a0 1
a1
1
a2
1
...
aM
It involves decomposing a number as a continued fraction. The fractional part is inverted till it
13
can be written with a 1 in the numerator. As an example can be expressed as :
64
127
13 1 1 1 1
64 64 4 12 4 1 4 1
13 13 13 1
1
12 12
It is clear that the algorithm terminates after a finite number of ‘split and invert’ steps for any
rational number, since the numerators are decreasing.
Modular Exponentiation
j
Modular exponentiation involves computing the sequence of controlled U 2 operations used by
the phase estimation procedure as part of the order-finding algorithm. That is, we wish to
compute
t 1
z y z U zt 2 ...U z1 2 y
0
t 1
z x zt 2 ... x z1 2 y (mod N )
0
z x z y mod N
Therefore,
z y z x z y mod N
Z zt 2t 1 zt 1 2t 2 ... z1 20
t 1 t 2
x Z x zt 2 x zt1 2 ...x Z x z1 2
0
zt zt 1 z0
x2 x2 ... x 2
t 1 t 2 0
i
We can compute x 2 classically. It is to be noted that zi is binary, hence the above term is nearly
a sequence of conditional multiplies, except the mod part, but that distributes i.e.
zt zt 1 z0
x 2 mod N x 2 mod N ... x 2 mod N mod N
t 1 t 2 0
Note that this is only t conditional modular exponentiations.
128
CHAPTER 6
If we are given a map of several cities, and we wish to find the shortest route passing through all
the cities on the map, then a simple algorithm would be to find all possible routes through the
cities, while keeping a record of the shortest route so far. If there are N possible routes, then on a
classical computer it takes O( N ) operations to determine the shortest route using this method.
There is a quantum search algorithm, known as Grover’s algorithm which enables the search to
performed much faster in only O( N ) operations. The quantum search is general and can be
applied to any search problem and not just the route-finding problem.
In order to understand Grover’s algorithm, the concept of an oracle is needed, which is presented
in Section 6.1. Section 6.2 presents the steps in the Grover’s algorithm. The geometric
visualization of Grover’s algorithm provides a wonderful understanding of its working in Section
6.3 and helps to find its order in section 6.4 along with an example. Section 6.5 presents the
applicability of Grover’s algorithm for searching in an unstructured database and explains the
difficulties involved in the same.
The concept of an oracle can be better understood with the help of an example. Suppose we have
to find the prime factors p and q of a large number m, even though Grover’s algorithm is not
used for factoring. On a classical computer, the obvious method is to search all number from 2 to
m for the smaller of the two prime factors. We keep trying to successively divide m by each
number in this range and see if it is an exact divisor. In that case, if the remainder is 0, we have
found the smaller prime factor first. The other one can be found by dividing m by it. This search-
based method requires roughly m divisions to find a factor on a classical computer.
We need an oracle to tell us whether we have got an exact divisor or not. So we define a function
f ( x ) such that
f ( x) 1 if x divides m
f ( x) 0 otherwise
129
O
x q x q f ( x) . . (6.1)
where
So we can check whether x is a solution to our problem, in this case a factor, by preparing the
state x 0 and applying the above oracle. If the oracle qubit q has been flipped to 1 , then
we have found a solution.
It is important to realize that in no way is the oracle computing the answer. It only tells us that
the answer we have provided it with is correct or know. In this way, it only knows whether the
solution is correct or not but does not know it.
0 1
Application of oracle with qubit in state
2
In the quantum search algorithm, it is useful to apply the oracle with the qubit initially in the
0 1
state .
2
0 1
If x is not a solution to the problem, then applying the oracle to the state x will have no
2
change on the state of the qubit.
If x is a solution to the problem, in that case, both 0 and 1 will be flipped so that our final
0 1
state will be x .
2
0 1 O 0 1
(1)
f ( x)
x x . . (6.2)
2 2
130
0 1
The state of the oracle qubit remains unchanged always and so can be omitted from
2
further discussion of the algorithm.
O
x (1) f ( x ) x . . (6.3)
In a way, we can say that the oracle marks a solution to the problem by shifting the phase of the
solution.
O( N )
n 0
qubits H n measure
. . .
G G G
Oracle
Workspace
131
Phase :
0 0
n
H n
n
qubits H x x
oracle for x0
x (1) f ( x ) x
oracle
workspace
Step 0
n
The algorithm states with the computer in the state 0 . The Hadamard transform is used to put
the computer in the equal superposition state
N 1
1
N 1/ 2
x
x 0
So we apply H gates as
1 0 1
n
0 1 j
2n j 1
2
After this, the iterations of the Grover’s algorithm start. Let us look at the first iteration.
Step I
1 0 1
(1) f ( j)
j
1
2n j
1 0 1
j m
2n j m 1
2
132
1 0 1
j 2 m
2n j m 1
2
Step II
Apply H n
1 1 0 1
2 (1) m. j j
n
0
2n 2n j 1
2
2 2 0 1
(1)
n
1 n 0 m. j
j
2 2n j 0 1
2
Step III
2 2 0 1
(1)
n
1 n 0 m. j
j
2 2n j 0 1
2
2 n 4 2 0 1
n j n (1) m. j
j
2 j 2 j 1
2
Step IV
Applying H n
2 n 4 2 0 1
n j n m
2 2 1
2
It can be observed that the first term has a slightly lower probability and the correct answer m has
a slightly higher chance of being measured.
133
Further iterations
W R
n
j m
2 j 2n
Step I
Apply oracle :
W R
(1) f ( j)
j m
2n j 2n
W R
j m
2n j 2n
Step II
Apply H n
R 2W 1
W 0
n n
(1) j .m
j
2 2 j
Step III
R 2W R 2W 1
W 1
2
n 0 n (1) j .m
j
2 2
n
j 0
R 2W R 2W 1
W 2
2
n 0 (1) j .m
j
2n 2n j
Step IV
Apply H n
R 2W 1 R 2W
W 2
2
n n j
2n
m
2 j
134
Hence, for each iteration, the probability of obtaining a random answer W changes from
R 2W
Wi Wi 1 2 i 1 n i 1
2
Ri Ri 1 2Wi 1
1
Ri Ri 1 2 Wi 1 2 1
2
Hence 2 0 0 I becomes
1 0 1 0 1 0
2
0 0 0 1 0 1
1 0 1 1
0 1 0 0
which is again a 0 .
135
If the input is a 1 , we have
1 0 0 0
0 1 1 1
which is 1 .
Thus the combined effects of steps II, III and IV in the Grover’s iteration becomes
H n (2 0 0 I ) H n
But noting that is the equally weighted superposition of states defined above as
N 1
1
N 1/ 2
x
x 0
, we get
H n (2 0 0 I ) H n 2 I
The only thing that remains is the oracle which is applied before these. Thus, the complete
Grover iteration G may be written as
G (2 I )O
136
6.3 Geometric Visualization of Grover’s Iterations
G 3. Final State
1. Initial State
/2
/2
O 2. After Oracle
Let us now have a geometric understanding of what is done by the Grover iteration (Fig. 6.3).
indicate sum over all x to the (N-M) non-solutions to the search problem.
Let
x
1 x
N M
x
1 x
M
x
137
Noting that the total number of states is N, we can express the state , the equally weighted
N 1
1
superposition of states defined above as
N 1/ 2
x
x 0
to get
N M M
. . (6.4)
N N
Examine Fig. 6.3 in which and vectors are shown as perpendicular to each other. Both
are unit vectors but have been lengthened slightly to reduce clutter in the figure. In fact, all states
in the figure are unit vectors.
Effect of Oracle O
The oracle O performs a reflection about the vector in the plane defined by and .
That is
O( a b ) a b
So we go from the initial state 1 to the intermediate state 2 as shown in the Figure.
Effect of 2 I
We are applying both the oracle O and 2 I , both of which are reflections and the
product of two reflections is a rotation. Looking at Fig. 6.3 we can see that the net effect is that
the above two reflections which form one Grover iteration take to
3 3
G cos sin . . (6.5)
2 2
The net rotation in one Grover iteration of is from state 1 to state 3, i.e. an angle of .
Hence G is a rotation by an angle where
N M
cos using Eq. (6.4) . . (6.6)
2 N
138
and
M
sin using Eq. (6.4) . . (6.7)
2 N
3 3
G cos sin . . (6.8)
2 2
Using Eqs. (6.6) and (6.7) and noting that sin 2sin cos , we get
2 2
M N M 2
sin 2 M (N M )
N N N
Thus
cos sin
G
cos
. . (6.10)
sin
where
2
sin M (N M )
N
139
6.4 Order of Grover’s Algorithm
Now let us come to the question that how many Grover iterations are required to rotate near
, i.e. an angle of 90 . Coming back to Eq. (6.4), we have got in the state
2
N M M
N N
We have to rotate it by an angle 90 .
2
M
We have got cos 90 sin from Eq. (6.7).
2 2 N
M
Thus we gave to rotate by an angle cos 1 . Each iteration rotates us by an angle . Thus
N
number of iterations required R is
cos 1 M / N
R CI . . (6.11)
where CI(x) denotes the integer closest to the real number x, after rounding halves down, i.e.
CI (3.5) 3 .
From Eq. (6.11), we can see that R / 2 since our rotation angle is within / 2 . So a lower
bound on will give an upper bound on R.
M
sin
2 2 N
140
N
R . . (6.12)
4 M
That is, R O( N / M ) Grover iterations must be performed in order to obtain a solution to the
search problem.
Summarizing, for an N item search problem with M solutions, it turns out that we need to apply
the search oracle only O( N / M ) times in order to obtain a solution on a quantum computer.
This can be compared with the O ( N / M ) oracle calls required classically ad the quadratic
speedup obtained with Grocer’s algorithm can be appreciated!
Example 6.1
Grover’s algorithm can be understood concisely with the help of a two-bit quantum search
example (Fig. 6.5).
H H X X H
oracle
H H X H H X H
H H
1 2 3 4 5 6 7 8 9 10
141
x0 0 x0 1 x0 2 x0 3
Let us assume we select the oracle for the value x0 3 in Fig. 6.6. It represents the state 11 .
1 001
0 1 0 1 0 1
2
2 2 2
00 01 10 11 0 1
2 2
00 01 10 11 0 1
3
2 2
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
2 2 2 2 2 2 2 2 0 1
4
2
2
00 01 10 11 0 1
2 2
11 10 01 00 0 1
5
2 2
0 1 0 1 0 1 0 1
1 1 0 0
6
2 2 2 2 0 1
2 2
142
10 01 0 1
2 2
11 01 0 1
7
2 2
0 1 0 1
1 0
2 2 0 1
8
2 2
10 11 00 01 0 1
2 2
01 00 11 10 0 1
9
2 2
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
2 0 1
2 2 2 2 2 2 2
10
2 2
111
Thus after a single iteration of the Grover oracle, the top two qubits are obtained in the state
11 . In contrast, a classical computer or classical circuit trying to differentiate between the four
oracles would require on average 2.25 (i.e. (1 2 3 4) / 4 ) oracle queries since we may reach
the solution after 1, 2, 3 or 4 queries.
N-bit memory
CPU d1 d2 . . . d N 1 dN
LOAD
STORE
Figure 6.7 Classical database searching on a computer with CPU and memory
143
Having seen the above algorithm, the question naturally arises that can we use it to search a list
of names e.g. can we find ‘Dahlia’ in a list of 1000 flowers. Can our quantum search algorithm
help us in searching an unstructured database, i.e. a database which is not arranged in any
particular order.
Suppose, we have a database containing N 2n items each of length l bits. We label these items
as d1 , d 2 . . . d N . We want to determine whether a particular string s of l bits is in the database or
not.
1. It can LOAD data from memory into the CPU as shown in Figure.
2. It can STORE data from CPU to the memory as shown in Figure.
3. It can do manipulations of the data stored temporarily in the CPU.
The most efficient classical algorithm would create a running variable, also called as an index,
e.g. i which would start out at zero, and carry out the follow steps.
Of course, the CPU has to be large enough to store the n [log N ] bit index.
Let us attempt the same problem on a quantum computer. The quantum computer is assumed to
have the same two units, CPU and memory like a classical computer. The CPU has four
registers:
(1) A qubit register x which can store n bits and is used as the index register and is
initialized to 0 .
(2) A qubit register which can store l bits and is initialized to s and remains in that state for
the entire computation.
(3) A qubit register which can store l bits and is initialized to 0 and remains in that state for
the entire computation.
0 1
(4) A qubit register which can store l bits and is initialized to and remains in that
2
state for the entire computation.
Either we can have a quantum memory with N 2n cells of l qubits each, containing the
database entry d x , or we can have classical memory again with N 2n cells of l bits each.
144
However, the memory addressing of the classical memory is done through an index which can be
in a superposition of multiple values.
If the CPU’s index register is in the state x and the data register is in the state d , then the
contents d x of the memory cell are added to the data register, so
d d dx
The most important part of the quantum search algorithm is the quantum oracle which flips the
phase of the index when it locates s in the memory.
The quantum search algorithm steps for the computer are more or less the same as the classical
algorithm given above.
Step I
0 1
x s 0
2
Step II
Now a LOAD operation is applied. So it will load the contents of the memory addressed by x in
the third register. Thus the computer will now be in the state
0 1
x s dx
2
Step III
The second and third registers are now compared. If the are the same, then a bit flip is done to
register 4, otherwise nothing is changed. This operation can be summarized as
145
0 1
x s dx ififififififd x s
0 1 2
x s dx
2 x s d 0 1 ififififififd s
x
2
x
It can be seen that the oracle leaves register 2, 3 and 4 unchanged and unentangled with register
1. The overall effect is that register 1 is transformed from x to x if a match is there, i.e.
d x s and the register is left interchanged otherwise. So we can use the quantum search
algorithm to determine the location of s using O( N ) LOAD operations. This can be compared
with the N LOAD operations required by the classical algorithm.
How useful is the quantum search algorithm for searching classical databases
There are two points that need to be understood regarding application of quantum search
algorithm for searching classical databases :
1. Classical Databases are not ordinarily unstructured or unorganized. They are usually
arranged in some order, e.g. telephone directory is alphabetical and so on, so that we can use
binary search to locate an item in O (log N ) time for an N-element database. However, not all
databases have such structure and may have a much more complicated structure, thereby
rendering classical searches as essentially searching in an unstructured database.
In view of the above points, it seems that the main use of quantum search algorithm will not un
searching classical databases, but rather in searching for solutions to hard problems like
Hamiltonian cycle, traveling salesman and satisfiability problems.
146
CHAPTER 7
The physical realization of quantum computers is one of the fastest growing areas of research in
quantum physics and computer science and has proceeded from the research stage to actual
systems with qubits in single digits. As has been stated earlier, the current phase of quantum
computer physical realization is in the pioneering stage and any difficulties at this stage do not
dampen their potential.
This chapter presents several techniques for physical realization of quantum computers. Section
7.1 presents the basic requirements for quantum computation using any physical system. Section
7.2 outlines the harmonic oscillator quantum computer used as a basis for comparing other
realizations. Optical photon quantum computers are presented in Section 7.3 and cavity quantum
electrodynamics (QED) in Section 7.4. Section 7.5 outlines the ion trap approach to realization
of quantum computers and NMR quantum computing is presented in Section 7.6. Silicon
quantum computers, a promising prospect are presented in Section 7.7. The chapter ends with a
summary of the current state of physical realization of quantum computers.
Quantum computation relies on the transformation of quantum states and quantum bits are two-
level quantum systems. So for quantum computation, the set of accessible states should be finite.
For example, we can store an entire encyclopedia in the binary fraction x =
0.011000101000011…, but itwhat is unrealistic as that the presence of noise reduces the number
of distinguishable states to a finite number. So we must have a robust way of representing
quantum information. If the choice of representation is poor, it results in the problem of
decoherence.
Whatever technique is chosen for physical realization of quantum computers, we must be able to
perform a universal family of unitary transformations. In order to perform quantum computation,
we must be able to control the Hamiltonian to effect any arbitrary selection from the unitary
transformations since we want to manipulate single spin rotations. In this way, any unitary
transform can be composed from single spin operations and controlled-NOT gates
147
3. Prepare a fiducial initial state
We must be able to prepare the desired input state. In classical machines, this is very simple
since by setting some switches, we can set the input state in the desired state. However, in a
quantum system, this can be very difficult. Input state preparation can be a significant problem
for most physical systems. As an example, ions can be prepared in good input states by
physically cooling them into their ground state Similarly, in nuclear magnetic resonance, each
molecule can be thought of as a single quantum computer, but to obtain a measurable signal
strength, a large number of molecules is needed. Even though qubits can remain in arbitrary
superposition states for relatively long times, it is difficult to put all of the qubits in all of the
molecules into the same state.
We must be able to measure the result of the quantum computation. An important characteristic
of measurement process is that when a projective measurement is performed, we must be able to
get a useful answer with high probability. There are many practical difficulties associated with
measurement like inefficient photon counters and amplifier thermal noise reduce the information
about measured qubit states, projective measurements are difficult to implement and require
large and switchable coupling between quantum an classical systems. Measurements should not
happen when they are not desired, as that can lead to decoherence.
A good indicator of measurement capability is the signal to noise ration (SNR) which accounts
for measurement inefficiency as well as inherent signal strength available from coupling a
measurement apparatus to a quantum system.
A simple harmonic oscillator consists of a particle in a parabolic potential well obeying the
equation
V ( x) m 2 x 2
The first five solutions for the probability amplitudes that a particle in a harmonic oscillator will
be found at different positions within the potential are shown in Fig. 7.1.
148
n=4
n=3
n=2
n=1
n=0
Fig. 7.1 First five solutions for probability amplitudes in a simple harmonic oscillator
A harmonic oscillator quantum computer is used as the basis for studying other physical systems.
There are several examples of simple harmonic oscillator systems in the physical world, like a
mass on a spring, a resonant electrical circuit among others. In case of a spring—mass system,
the energy transfer is between potential energy of spring and kinetic energy of the mass. In case
of an electrical circuit, the energy exchange is between the capacitor and the inductor. In these
systems, the total energy of the system is a continuous parameter.
Drawbacks
1. We cannot always know the eigenvalue spectrum of the unitary operator for a certain quantum
computation. In fact in most problems solved by quantum algorithms, knowledge of the
eigenvalue is equivalent to a knowledge of the solution.
2. This technique does not allow one computation to be cascaded to another, as in general,
cascading two unitary transforms results in a new transform with unrelated eigenvalues.
3. The idea of a single harmonic oscillator to perform quantum computation is flawed since it
neglects the principle of digital representation of information. Quantum computations builds
upon digital computation, not analog computation.
149
4. Photons can in principle, be made to interact with each other using nonlinear optical
media which mediate interactions.
The energy in an electromagnetic cavity is quantized and each such quantum is called a photon.
It is possible for a cavity to have a superposition of zero or one photon, which can be expressed
as c0 0 c1 1 . Not let us consider two cavities and take the two states of a qubit as being
whether the photon is in the first cavity 01 or the other 10 . This state can be represented as
c0 01 c1 10 , referred to as dual-rail representation. We consider single photons traveling as a
wavepacket through free space. It can be pictured as a cavity moving along the wavepacket.
Each cavity in the above qubit state will this correspond to a different spatial mode.
One of the schemes for generating single photons in the laboratory is by attenuating the output of
a laser. The laser output is a state, called as coherent state , defined as follows
n
e
2
/2
n
n 0 n!
where n is an n-photon energy eigenstate which has several useful properties. The coherent
states are naturally radiated from driven oscillators such as a laser when pumped above its lasing
threshold. Upon attenuation, a coherent state just becomes a weaker coherent state which can be
made to have just photon, with high probability.
Drawbacks
The drawback in the optical photon quantum computer approach is that it is useful to interact
photons. The best non-linear optical media, Kerr media are very weak and cannot provide a cross
phase modulation of between single photon states. Approximately 50 photons must be
absorbed for each photon which experience a cross phase modulation. So the outlook for
building quantum computers from nonlinear optics components is slim.
However, like the classical world, where optical communication is the natural home of optics
due to lesser energy requirement than an electronic transmission line, it is quite possible that
optical qubits will find their natural use in the communication of quantum information, such as
quantum cryptography, rather than in computation. Fig. 7.2 shows a long distance phtotonic
quantum communication setup.
150
Figure 7.2 Long Distance Photonic Quantum Communication :
Photograph of the high-fidelity teleportation or entanglement-swapping experiment. In the
foreground one can see Victor’s polarization measurement, in the middle Alice’s Bell-state
analyser rests in an elevated box above the table. The contains the frequency doubled
Ti:Sapphire pump laser. (Courtesy : QuComm)
This approach improves upon the approach in the last section as in a way, it employs a better
nonlinear medium. Single photons can be good carriers of quantum information, but they require
some other medium in order to interact with each other. Because they are bulk materials,
traditional nonlinear optical Kerr media are unsatisfactory in satisfying this need. However, well
isolated single atoms might not necessarily suffer from the same decoherence effects, and
moreover, they could also provide cross phase modulation between photons. The two main
experimental components of a cavity QED system are the electromagnetic cavity (Fabry-Perot
cavity, Fig. 7.3) and the atom.
151
Fig. 7.3 Fabry-Perot cavity with two plane parallel mirrors
Drawbacks
1. The incident photons are absorbed with non-trivial probability when traversing the cavity and
atom and thus the true quantum operation performed is not unitary.
2. The above problem is aggravated if cascading of multiple gates is needed.
Spin is a strange and very real concept. When a particle has spin, it possesses a magnetic
moment as if it were a composite particle with some current running around in a loop. But
electrons are elementary particles, and the quarks which compose a nucleon are not known to
produce spin by orbital motion. Furthermore, the spin of a particle is only ever either integer or
half-integer.
Integer spin particles, known as bosons, include the photon. Being massless, it is somewhat
special and only has spin 1 (and non spin zero) components. These correspond to the two
familiar orthogonal polarization states. Half-integer spin particles, known as fermions,, include
the electron, proton and neutron. These are ‘spin-1/2’ particles, in that their spin component can
either by +1/2 (spin ‘up’) or -1/2 (spin ‘down’). When we say ‘spin’ what is usually referred to is
a spin-1/2 particle.
However, since the energy difference between different spin states is typically very small
compared with other energy scales (such as the kinetic energy of typical atoms at room
temperature), the spin states of an atom are usually difficult to observe and even more difficult to
152
control. In carefully controlled environments, exquisite control is possible. These environments
are created by isolating and trapping small numbers of charged atoms in electromagnetic traps,
then cooling the atoms until their kinetic energy is much lower than the spin energy contribution.
After this, incident monochromatic light can be tuned to selectively cause transitions which
change certain spin states depending on other spin states. This is the basic idea of how trapped
ions can be made to perform quantum computation.
Six ions confined in a linear rf trap. The Three trapped 112Cd+ ions exhibit four
four bright ions (#1,#3,#5,#6) are 113Cd , the modes of oscillation in an asymmetric rf
other two (#2, #4) are 111Cd. (Paul) ion trap.
Drawbacks
However, these technical limitations may someday be overcome and lifetimes can be extended
be extended by technological surprise. Maybe these trapped ions could be register of qubits in a
quantum computer someday.
153
7.6 Nuclear Magnetic Resonance
As seen above, the principal drawback of ion trap computers is the weakness of the phonon
mediated spin-spin coupling technique and its susceptibility to decoherence. A way around is to
trap molecules instead of single atoms since the magnetic dipole and electron mediated Fermi
contact interactions between neighbouring nuclei would provide strong natural couplings.
However, with several vibrational modes, single molecules have been difficult to trap and cool,
and this optical manipulation and detection of nuclear spins in trapped molecules has not been
feasible except in special circumstances.
However, direct manipulation and detection of nuclear spin states using radiofrequency
electromagnetic waves is a well-developed chemistry field known as nuclear magnetic resonance
(NMR). These techniques are widely known in chemistry and are used to measure properties of
solids, liquids and gases, determine their structure, imaging and applied even to biological or
medical applications. It has been tested for 7 qubits to find periodicity of Grover’s algorithm and
took less than 35 milliseconds. Figure 7.6 shows NMR molecular structures and equipment.
Application of NMR for quantum computation requires that a number of molecules (more than
108 ) must be present in order to produce a measurable signal and the output of an NMR
measurement is the average over all the molecule’s signals. Secondly, NMR is typically applied
to physical system in equilibrium at room temperature where the spin energy is less. So the
initial states of the spins is completely random. So the initial spins have to prepared in a pure
state by ‘distilling’ through temporal and spatial labeling.
Nuclear spins are nearly ideal qubits and single molecules would be nearly ideal quantum
computers if their spin states cold only be controlled and measured. Nuclear magnetic resonance
makes this possible using large ensembles of molecules at room temperature, but at the expense
of signal loss due to an inefficient preparation procedure.
Molecular "hard ware" of the first five- Nuclear magnetic resonance (NMR)
qubit NMR quantum computer spectrometer at the TU Münch
Figure 7.5 NMR Quantum Computing
154
Scientists at MIT and the Department of Energy's Los Alamos National Laboratory have made
yet another experimental leap forward in the quest for a functional quantum computer capable of
solving large mathematical problems or cracking secret codes faster than today's fastest
supercomputers.
Using nuclear magnetic resonance (NMR) techniques, researchers created a seven-qubit quantum
computer within a single drop of liquid. This latest advance could lead to computers that use
quantum bits, or qubits, for information processing.
Drawbacks
1. The preparation of the pure state reduces the signal exponentially in the number of qubits,
unless the initial polarization is sufficiently high.
2. The structure of the molecule plays the role of the architecture of the computer, determining
what pairs or groups of qubits interact with each others. All the qubits are not necessarily well
connected. However, solutions to this exist through cellular automata style architecture such as
one-dimensional chains.
Despite these drawbacks, NMR provides a testbed for quantum algorithms and illustrates basic
techniques which other realizations will have to implement to perform quantum computation.
The NMR idea is also a very rich idea of innovations, synergizing chemistry, physics,
engineering and mathematics and continued innovation between these fields will further this
technique.
The advantages of using Silicon are that we are familiar with it from years of building classical
computers. Donor nuclear spins are well-isolated from environment, it has low error rates and
long decoherence time
155
Figure 7.6 A Futuristic Scenario
.
The key challenges in producing efficient quantum circuits are to have a system with sufficiently
high number of operations within the characteristic coherence time of the qubits, to control the
coupling between qubits to form architectures, and to integrate the qubits with manipulation and
measurement circuitry. All operations (initialization, manipulation, and measurement) have been
achieved: using electrical gates for initialization and manipulation, and a single-electron
transistor for measurement.
The scheme gives a very long coherence time, (100 times longer than shown in other solid-state
implementations) and also provides flexibility in design, since the qubits may be combined in a
variety of two-dimensional circuits, as in conventional microprocessors. Thus it offers the
possibility of scaling-up from one device to a large quantum circuit - a necessary criterion for
making a useful quantum computer.
In conclusion, qubit operation of a silicon circuit has been successfully demonstrated, using
standard fabrication techniques and which is the first step towards making a silicon quantum
computer.
There is a worldwide race to build quantum computers right now, and show ways to scale the
quantum computer to bigger systems with more qubits—just like the microfabrication of
conventional chips have given us the impressive gains in conventional computing speed and
power.
The next step is to build the quantum computer bigger and bigger in number of qubits. There is
still a great deal of work to be done in order to learn how to control the qubits in each technique.
It won’t be nearly as easy as it was with conventional computer chips, but at least we know what
to do in principle. Table 7.1 summarizes the physical realization aspects of quantum computers.
156
Physical Qubit Unitary Initial state Readout
System representation evolution preparation
Energy levels
Harmonic 0 , 1 ,... Match eigenvalue
Oscillator 2 n
of a spectrums to that Not
Not considered
quantum given by considered
single quantum
computer Hamiltonian
oscillator gives
n qubits
Location of a
single photon
Phase shifters, Create single
Optical photon between tow
beamsplitters, photon states Detect single
quantum modes, 01 , nonlinear Kerr by photons
computer
10 or media attenuation
polarization
Location of
single photon Phase shifters, Create single Detect single
Optical cavity between two beamsplitters, photon states photons using
quantum modes 01 cavity QED by a
electrodynamics system coupled attenuating phtoomultiplier
and 10 or with optical field laser light tube
polarization
Cool the
Hyperfine atoms (by
(nuclear spin) trapping and
Laser pulses
state of an using optical
which externally Measure
atom, and pumping)
manipulate the population of
Ion traps lowest level into their
atomic state, hyperfine
vibrational motional
Shared phonon states
modes ground state,
state for qubits
(photons) of and
trapped atoms hyperfine
ground state
Magnetic field
Polarize Measure
pulses applied to
spins by voltage
Nuclear spins in a strong
Spin of an placing in induced by
Magnetic magnetic field,
atomic nucleus strong processing
Resonance couplings between
magnetic magnetic
spins provided by
field moment
chemical bonds
Silicon
Electrical Single-electron
Quantum Quantum-dots Electrical Gates
Gates transistor
Computer
157
CHAPTER 8
The gates available in the simulator can be seen in the example window viz.
1. Hadamard gate
2. Pauli X gate
3. Pauli Z gate
4. Swap gate
5. Controlled Not (CNOT gate)
6. Toffoli Gate
The gates can be pasted on the circuit by dragging and dropping it onto the relevant point in the
circuit. A gate can be erased by dragging ‘Erase Gate’ tab to it.
The number of qubits in the circuit can be increased by clicking on ‘Add Bit’ and removed by
clicking on the ‘Remove Bit’ tab. Similarly more gates can be added by clicking on the ‘Add
Gate’ tab and removed by the ‘Remove Gate’ tab.
Example 8.1
A simple circuit showing 2 Hadamard gates with inputs Q1 0 and Q2 1 is shown. Thus we
have the input state as Q1Q2 01 . The circuit is drawn in the Qudit simulator as described
above to get it in the form of Fig 8.1.
158
0 1 0 1 00 01 10 11
2 2 2
The output obtained above in x.y can be verified by clicking on the ‘Simulate Circuit’ tab which
shows the amplitudes of the various states at the bottom of the screen, i.e.
The output can be seen in the form of a vector by clicking on the ‘Show Output Vector’ tab as
Fig. 8.2.
159
The transfer matrix can be viewed by clicking on the ‘Show Transfer Matrix’ tab as in Fig. 8.3.
Example 8.2
The output of the two-bit quantum Grover search example 6.1 in Chapter 6 can be verified using
QCAD.
The circuit in Fig. 8.4 is drawn by dragging and dropping the appropriate gates.
160
The ‘Simulate Circuit’ tab is clicked to compute the output which is shown at the bottom of the
simulator screen as
.
Thus, it verifies the output manually computed in Example 6.1.
The output can be seen in the form of a vector by clicking on ‘Show Output Vector’ tab as Fig.
8.5.
The transfer matrix can be viewed by clicking on the ‘Show Transfer Matrix’ tab as Fig. 8.6.
161
Save transfer matrix
QUDIT has the option that the transfer matrix can be saved for further use. It has the advantage
that the matrix can be used by other software for further analysis. The transfer matrix is saved by
clicking on the ‘Save Transfer Matrix to Disk’ tab.
Circuit equivalence
QUDIT has the additional feature that it can be used to mathematically compare two circuits by
comparing their transfer matrices. This is done by simulating a circuit and clicking ‘Save
Transfer Matrix for Comparing’ tab. It asks for a choice, ‘Save to Matrix A or Matirx B?’ (Fig.
8.7).
Select either to save to one of the two matrices. The second circuit is now designed and
simulated. The second transfer matrix is saved to the second matrix. After this, the ‘Show
Equivalence Program’ tab is clicked to run the equivalence test followed by clicking on
‘Compare Matrices’ to compare the two matrices.
Other details of QCAD can be seen from its help file included in the CD-ROM and the website
http://www.phys.cs.is.nagoya-u.ac.jp/~watanabe/qcad.
The available quantum gates are shown in the QCAD toolbar. (Fig. 8.8). The options as they
appear in the toolbar are in the order :
1. Select
2. Eraser
162
3. Hadamard Gate
4. Not Gate
5. Controlled Not Gate
6. Toffoli (Controlled Controlled Not) Gate
7. Pauli X Gate
8. Pauli Y Gate
9. Pauli Z Gate
10. Swap Gate
11. Rotation Gate
12. Controlled Rotation Gate
13. Measurement Gate
On starting QCAD, a blank circuit appears as shown in Fig. 8.9. The various gates are pasted on
the qubits by clicking and dragging them on to the qubit.
The state of a qubit at start can be changed by clicking on it and selecting 0 or 1 . Extra qubits
can be disabled by removing the checkmark on ‘Enabled’ as shown in Fig. 8.10.
163
Figure 8.10 Enable / Disable qubit option in QCAD
Example 8.3
A simple circuit showing 2 Hadamard gates with inputs Q1 0 and Q2 1 is shown in Fig.
8.11. It is important to remember that in QCAD, the topmost qubit Q1 is referred as the
rightmost bit and the Q2 output is shown before that and so on. With the notation used so far, we
would have referred to it as Q1Q2 01 so far, but in QCAD output it is shown as Q2Q1 , i.e.
10 .
After application of the Hadamard gates, the output becomes using QCAD convention Q2Q1
0 1 0 1 00 01 10 11
2 2 2
This can be seen by clicking ‘Calc’ on the ‘Calc’ toolbar, or pressing the function key F5.
164
Figure 8.12 Standard View of result in QCAD
The ‘Standard View’ of the result shown in the ‘Qubits Status’ window is shown in Fig. 8.12.
The amplitude of each combination of qubits 00 , 01 , 10 and 11 listed. The value of 0.5
with the sign corresponds to that found above.
Example 8.4
In this example. the circuit of Example 8.3 has been extended to included measurement also (fig.
8.13). The measurement tab is selected from the QCAD toolbar and ‘Calc’ is executed by
pressing F5.
The measurement results can be seen by clicking on the ‘Measured’ tab in the ‘Qubits States’
window. The result contains indices, qubits’ status and the probability of the status to be
measured (Fig. 8.14).
165
It is important to note that this measurement does not achieve real measurement. The
measurement gates on QCAD only set the “measurement flags”. After the calculation, the
measurement is performed. For example the circuit in Fig. 8.13 will give exactly the same output
in QCAD as Fig. 8.15 and is equivalent to it in QCAD.
Example 8.6
The two-bit quantum Grover search example 6.1 in Chapter 6 can be tested using QCAD.
The circuit is drawn by selecting gates and dragging and dropping them on the qubits (Fig. 8.17).
166
For controlled gates, like controlled-NOT or Toffoli, gate, the control bits have to be specified as
shown in Fig. 8.18.
The output can be viewed in ‘Standard View’ by pressing F5. If ‘Only Non-zero’ is selected, the
output states with non-zero amplitudes are displayed as in Fig. 8.19, otherwise all the states are
displayed if ‘All’ is chosen, as in Fig 8.20.
Figure 8.19 Standard view output in QCAD with only non-zero amplitudes displayed
It can be verified that the output obtained through QCAD matches that found in Example 6.1 and
Example 8.2.
167
Example 8.7
The three qubit quantum Fourier transform circuit of Example 5.4 can be simulated using
QCAD. The circuit shown in Fig. 8.21 is constructed as described above.
In case of rotation gates, the phase has to be specified in degrees for each gate as shown in Fig
8.22.
The result of the circuit for input state 0 for all the three qubits, i.e. 000 is shown in Fig.
8.23.
168
Figure 8.23 QCAD output for Example 8.7
It can be verified that this corresponds to the first row of the matrix in Example 5.4 since the
1
amplitude of all the resulting states is 0.35355 as shown in Fig. 8.23.
2 2
The next input state has the first two qubits in the state 0 and the third qubit in the state 1 .
This is the state 100 in QCAD notation and is shown in Fig. 8.24.
The output of this circuit is shown in Fig. 8.25 and it can seen that it matches the second row of
the matrix in Example 5.4 after correcting the order of states between it and the QCAD notation
remembering that e2 i / 8 i . The small amplitude of 5.7118E-16 in some states can be
ignored.
169
Figure 8.25 QCAD output for circuit of Fig. 8.24
170
Quack Commands
The initialization commands are contained in the file quack.m which must be called before any
other commands. It contains definitions of all the matrices listed above as can be seen from the
MATLAB code of the file quack.m reproduced in Fig. 8.26.
function quack
clear all;
global PauliI;
global PauliX;
global PauliY;
global PauliZ;
global Hadamard;
global Phase;
global PiOnEight;
global record_history;
PauliI = [1 0 ; 0 1];
PauliX = [0 1 ; 1 0];
PauliY = [0 -i ; i 0];
PauliZ = [1 0 ; 0 -1];
record_history = true;
The full command reference of Quack is contained in the file Quack.pdf contained in the CD-
ROM enclosed. The commands used in examples below like H, X, toffoli etc. are defined in
the accompanying .m files.
We present below two examples, first of Grover’s search and the second of quantum
teleportation using Quack.
171
Example 8.8
This example presents Grover’s search algorithm for two qubits (Example 6.1) using Quack. It
evaluates the same circuit as in Fig 6.5 reproduced again as Fig. 8.27. The first two qubits are
prepared in the state 0 and the third qubit in the state 1 . This is followed by Hadamard
transforms on all the three qubits. Fig. 8.28 gives the MATLAB code for this example.
H H X X H
oracle
H H X H H X H
H H
After this, the gates shown in Fig. 8.27 are applied. The final outcomes of the qubits is displayed
in the end as
Measurement outcomes:
1
-1
quack
% Prepare the input state with first two qubits 0 and third 1
init_state(3);
prepare_one(3);
172
% Apply Hadamard transform
H(1)
H(2)
H(3)
% The circuit of Fig. is selected so first and second qubits are selected
% as such
if n == 3
toffoli(1,2,3)
end
173
% Measure the output state
disp('Measurement outcomes: ')
disp(Z_measure(1))
disp(Z_measure(2))
disp(Z_measure(3))
Example 8.9
The second example using Quack is the teleportation circuit of Fig 4.1 reproduced as Fig. 8.29.
The qubit to be teleported is the first one and the second and third qubits are prepared in the
00 11
entangled or Bell state 00 . A measurement is performed on the first two qubits and
2
based on the outcome of measurement, X or Z correction is applied as described in Section 4.1.
Fig. 8.30 shows the MATLAB output and Fig. 8.31 gives the MATLAB code for it.
M1
H
M2
00
{ X M2 Z M1
0 1 2 3 4
The third qubit now has the same state as the first qubit initially, so it has been teleported. The
output for measurement result 01 is shown in Fig. 8.30 wherein only X correction needed is
applied.
174
Single qubit teleportation example
Measurement result: 01
Applied X correction
Reduced density matrix of corrected output state:
0.5000 0.5000
0.5000 0.5000
Circuit history:
'|+>-<B|-'
'|B>-<B|-'
'|B>-----'
quack;
disp(' ');
disp('Single qubit teleportation example');
disp(' ');
init_state(3);
input_state = 1;
EPR_1 = 2;
EPR_2 = 3;
175
% Peform the Bell measurement on the first two qubits
outcome = bell_measure(input_state, EPR_1);
disp(['Measurement result: ' outcome]);
disp(' ');
% What does reduced density matrix of the uncorrected output state look like?
disp('Reduced density matrix of uncorrected output state:');
print_rdm(EPR_2);
global state;
state1 = state;
if outcome == '01'
disp('Applied X correction');
X(EPR_2);
end
if outcome == '10'
disp('Applied Z correction');
Z(EPR_2);
end
if outcome == '11'
disp('Applied XZ correction');
Z(EPR_2);
X(EPR_2);
end
% What does the reduced density matrix of the corrected output state look
like?
disp('Reduced density matrix of corrected output state:');
print_rdm(EPR_2);
176
8.4 Quantum Circuit Viewer (qasm2circ)
QASM is a simple text-format language for describing acyclic quantum circuits composed from
single qubit, multiply controlled single-qubit gates, multiple-qubit, and multiple-qubit controlled
multiple-qubit gates. qasm2circ is a package which converts a QASM file into a graphical
depiction of the quantum circuit, using standard quantum gate symbols (and other user-defined
symbols). This is done using latex (specifically, xypic), to produce high-quality output in epsf,
pdf, or png formats. It was developed at MIT and is available from the website
http://www.media.mit.edu/quanta/qasm2circ. The complete package with examples is available
on the accompanying CD-ROM.
Example 8.10
The first circuit drawn using qasm2circ is of EPR state creation using a Hadamard and CNOT
gate. The code in Fig. 8.32 defines the two qubits q0 and q1 and then the two gates are created
to give the resulting circuit as in Fig. 8.33.
#
# File: test1.qasm
# Date: 22-Mar-04
# Author: I. Chuang
#
# Sample qasm input file - EPR creation
#
qubit q0
qubit q1
177
Example 8.11
This example draws slightly modified form of the teleportation circuit of Fig. 4.1 in that the Bell
state preparation through Hadamard and CNOT gate is also shown. The three qubits q0, q1 and
q2 are defined, followed by the Hadamard and CNOT gates. This is followed by the
measurement and then the X or Z corrections are applied. The code is given in Fig. 8.34 and the
resulting circuit is shown in Fig. 8.35.
#
# File: test2.qasm
# Date: 29-Mar-04
# Author: I. Chuang
#
# Sample qasm input file - simple teleportation circuit
#
qubit q0
qubit q1
qubit q2
178