Quantum Computing Lecture Notes by Oskin
Quantum Computing Lecture Notes by Oskin
Mark Oskin
Department of Computer Science and Engineering
University of Washington
Abstract
The following lecture notes are based on the book Quantum Computation and Quantum In-
formation by Michael A. Nielsen and Isaac L. Chuang. They are for a math-based quantum
computing course that I teach here at the University of Washington to computer science grad-
uate students (with advanced undergraduates admitted upon request). These notes start with a
brief linear algebra review and proceed quickly to cover everything from quantum algorithms
to error correction techniques. The material takes approximately 16 hours of lecture time to
present. As a service to educators, the LATEXand Xfig source to these notes is available online
from my home page: http://www.cs.washington.edu/homes/oskin. In addition, under
the section “course material” from my web page, in the spring quarter/2002 590mo class you
will find a sequence of homework assignments geared to computer scientists. Please feel free to
adapt these notes and assignments to whatever classes your may be teaching. Corrections and
expanded material are welcome; please send them by email to [email protected].
1
Contents
3 Entanglement 9
4 Teleportation 11
5 Super-dense Coding 15
6 Deutsch’s Algorithm 16
7 Bloch Sphere 22
8.3 Swap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
2
9 Shor’s Algorithm 33
10 Grover’s Algorithm 43
11 Error Correction 46
3
1 Linear Algebra (short review)
The following linear algebra terms will be used throughout these notes.
Z - complex conjugate
if Z = a + b i then Z = a bi
jψi - vector,
2 “ket”
3 i.e.
c1
6 c2 7
6 7
4 ::: 5
cn
A - complex conjugate
of matrix
A.
if A =
1 6i
then A =
1 6i
3i 2 + 4i 3i 2 4i
AT - transposeof matrix A.
1 6i 1 3i
if A = then AT =
3i 2 + 4i 6i 2 + 4i
A† - Hermitian conjugate
(adjoint) of matrix A.
†
Note A = A T
1 6i † 1 3i
if A = then A =
3i 2 + 4i 6i 2 4i
4
k jψi k - norm ofpvector jψi
k jψi k= hψjψi
Important for normalization of jψi i.e. jψi= k jψi k
An important distinction needs to be made between quantum mechanics, quantum physics and
quantum computing. Quantum mechanics is a mathematical language, much like calculus. Just
as classical physics uses calculus to explain nature, quantum physics uses quantum mechanics to
explain nature. Just as classical computers can be thought of in boolean algebra terms, quantum
computers are reasoned about with quantum mechanics. There are four postulates to quantum
mechanics, which will form the basis of quantum computers:
“Associated to any isolated physical system is a complex vector space with inner prod-
uct (i.e. a Hilbert space) known as the state space of the system. The system is
completely described by its state vector, which is a unit vector in the system’s state
space.”
Consider a single qubit - a two-dimensional state space. Let jφ 0 i and jφ1 i be orthonormal basis
for the space. Then a qubit jψi = ajφ0i + bjφ1 i. In quantum computing we usually label the basis
with some boolean name but note carefully that this is only a name. For example, jφ 0 i = j0i and
jφ1i = j1i. Making this more concrete one might imagine that “j0i” is being represented by an
up-spin while “j1i” by a down-spin. The key is there is an abstraction between the technology
5
(spin state or other quantum phenomena) and the logical meaning. This same detachment occurs
classically where we traditionally call a high positive voltage “1” and a low ground potential “0”.
Note that jψi = aj0i + bj1i must be a unit vector. In other words, hψjψi = 1 or jaj 2 + jbj2 = 1. For
quantum computing fa; bg 2 C
This formalism for a quantum bit is a direct extension of one way to describe a classical computer.
That is, way may write that a classical bit jωi is in the state jωi = xj0i + yj1i. The only difference
is x and y are defined not over the complex numbers but rather from the set f0; 1g. That is fx; yg 2
f0; 1g. The same normalization condition applies jxj2 + jyj2 = 1. This normalization condition is
not a property of quantum mechanics but rather of probability theory.
The fact that U cannot depend on jψi and only on t 1 and t2 is a subtle and disappointing fact.
We will see later that if U could depend on jψi then quantum computers could easily solve NP
complete problems! Conceptually think of U as something you can apply to a quantum bit but you
cannot conditionally apply it. The transform occurs without any regard to the current state of jψi.
Example:
6
Important: U must be unitary, that is U †U =I
Example:
1 1 1 1
U = p1 then U † = p1
2 1 1
2 1 1
U †U = p1
2
p1 2
1
1
1
1
1
1
1
1
= 12
2 0
0 2
=I
Example:
7
Note that M0† M0 = M0 , hence
p(0) = hψjM0 jψi = [a ; b ]
1 0 a
=
0 0 b
= [a ; b ] jaj2
a
=
0
Hence the probability of measuring j0i is related to its probability amplitude a by way of jaj 2 .
It important to note that the state after measurement is related to the outcome of the measurement.
For example, suppose j0i was measured, then the state of the system after this measurement is
re-normalized as:
M0 jψi
jaj = jaj j0i
a
As a side note we are forced to wonder if Postulate 3 can be derived from Postulate 2. It seems
natural given that measurement in the physical world is just interacting a qubit with other qubits.
Thus it seems strange to have measurement be its own postulate. At this point though physicists
don’t know how derive the measurement postulate from the other three, so we shall just have to be
pragmatic and accept it.
“The state space of a composite physical system is the tensor product of the state
spaces of the component physical systems. [sic] e.g. suppose systems 1 through n
j i
and system i is in state ψi , then the joint state of the total system is ψ 1j i j i
ψ2
::: j i
ψn .”
Example:
Why the tensor product? This is not a proof, but one would expect some way to describe a com-
posite system. Tensor product works for classical systems (except the restricted definition of the
probability amplitudes makes it so that the result is a simple concatenation). For quantum systems
tensor product captures the essence of superposition, that is if system A is in state jAi and B in state
jBi then there should be some way to have a little of A and a little of B. Tensor product exposes
this.
8
3 Entanglement
Now take another qubit jψ2 i also in the zero j0i state. The joint state-space probability vector is
the tensor product of these two:
(As an exercise show that CNot is unitary), but for now lets just apply CNot to our two qubits:
2 3 2 1 3 2 p1 3
p
1 0 0 0 2
6 6 7 6 2 7
0 7
j (ψ01 ψ2 )00i = CNot jψ01ψ2i = 64 00 1
0
0
0
766
1 5 4 p1
7 6 0 7 p1
0
7=6
5 4 0 5
j i j i
7 = 2 ( 00 + 11 )
p1
2
0 0 1 0 0 2
The key to entanglement is the property that the state space cannot be decomposed into component
spaces. That is, for our example, there does not exists any jϕ 1 i and jϕ2 i such that jϕ1 i jϕ2 i =
p1 (j00i + j11i).
2
To illustrate why entanglement is so strange, lets consider performing a measurement just prior to
applying the CNot gate. The two measurement operators (for obtaining a j0i or a j1i) are:
9
2 3 2 3
1 0 0 0 0 0 0 0
6 0 0 0 0 7 6 0 1 0 0 7
M02 = 6
4 0
7 and M1 =6 7
0 1 0 5 2 4 0 0 0 0 5
0 0 0 0 0 0 0 1
Recall that just prior to the CNot the system is in the state jψ 01 ψ2 i = p1 j00i + 0j01i +
2
p1 j10i + 0j11i, hence the result of measuring the second qubit will clearly be j0i. Note that
2
M0†2 M02 = M02 . Therefore:
We can see that measurement had no effect on the first qubit. It remains in a superposition of j0i
and j1i. Now lets consider the same measurement but just after the CNot gate is applied. Here:
Hence, after the CNot gate is applied we have only a 1=2 chance of obtaining j0i. Of particular
interest to our discussion, however, is what happens to the state vector of the system:
10
2 3 2 p1 3
1 0 0 0 2
Mm jψi 6 0 0 0 0 76 7
After measurement: q = p11 2 6 7
4 0 0 1 0 56
6 0 7
7=
hψjMm† Mm jψi = 4 0 5
0 0 0 0 p1
2
2 1 3 2 3
p 1
2
6 0 7 6 7
p11 2 6
4
7 = 6 0 7 = 00 j i
= 0 5 4 0 5
0 0
This is the remarkable thing about entanglement. By measuring one qubit we can affect the prob-
ability amplitudes of the other qubits in a system! How to think about this process in an abstract
way is an open challenge in quantum computing. The difficulty is the lack of any classical analog.
One useful, but imprecise way to think about entanglement, superposition and measurement is that
superposition “is” quantum information. Entanglement links that information across quantum bits,
but does not create any more of it. Measurement “destroys” quantum information turning it into
classical. Thus think of an EPR pair as having as much “superposition” as an unentangled set of
qubits, one in a superposition between zero and one, and another in a pure state. The superposition
in the EPR pair is simply linked across qubits instead of being isolated in one.
This, admittedly fuzzy way of thinking about these concepts is useful when we examine telepor-
tation. There we insert an unknown quantum state (carrying a fixed amount of “quantum informa-
tion”) into a system of qubits. We mix them about with additional superposition and entanglement
and then measure out the superposition we just added. The net effect is the unknown quantum
state remains in the joint system of qubits, albeit migrated through entanglement to another physi-
cal qubit.
4 Teleportation
Contrary to its sci-fi counterpart, quantum teleportation is rather mundane. Quantum teleportation
is a means to replace the state of one qubit with that of another. It gets its out-of-this-world name
from the fact that the state is “transmitted” by setting up an entangled state-space of three qubits
and then removing two qubits from the entanglement (via measurement). Since the information
of the source qubit is preserved by these measurements that “information” (i.e. state) ends up in
the final third, destination qubit. This occurs, however, without the source (first) and destination
(third) qubit ever directly interacting. The interaction occurs via entanglement.
Suppose jψi = aj0i + bj1i and given an EPR pair p12 (j00i + j11i) the state of the entire system is:
11
Generate EPR pair and distribute to each end
Destination
in state A
Fixup
result
Source Transmit classical information
in state A
(destroyed in process)
Figure 1: Teleportation works by pre-transmitting an EPR pair to the source and destination. The
qubit containing the state to be “teleported” interacts with onehalf of this EPR pair creating a joint
state space. It is then measured and only classical information is transmitted to the destination.
This classical information is used to “fixup” the destination qubit
2 3
a
6 0 7
6 7
6 0 7
6 7
6 7
1
2
jij i j i jij i j i
p [a 0 ( 00 + 11 ) + b 1 ( 00 + 11 )] = p 6
1
26
a
b
7
7
6 7
6 0 7
6 7
4 0 5
b
Next we apply the H gate. However, as an aside, lets examine what happens when we apply the H
gate to j0i and to j1i. Recall
that:
1 1
H = p1
2 1 1
H j0i
1 1 1 1
= p = p
1 1
2 1 1 0 2 1
12
|y> H
|0>
|0> H X Z |y>
Figure 2: Quantum circuit depicting teleportation. Note that in this diagram single lines represent
quantum data while double lines represent classical information.
H j1i
1 1 0 1
= p = p1
1
2 1 1 1 2 1
13
1
2[j00iI jψi + j01iX jψi + j10iZ jψi + j11iiY jψi]
And of interest to us with teleportation:
P(10) = hϕjM10
†
M10 jϕi = hϕjM10 jϕi, since here M10
†
M10 . Thus:
2 3
0
6 0 7
6 7
6 0 7
6 7
6 7
ji16
M10 ϕ = 2 6
0
a
7
7
6 7
6 b 7
6 7
4 0 5
0
2 3
0
6 0 7
6 7
6 0 7
6 7
6 7 1
Therefor: hϕjM10 jϕi =
7 = [a a + b b ]
1 16 0
2 [a; b; b; a; a; b; b; a] 2 6
a 7 4
6 7
6 b 7
6 7
4 0 5
0
Recall that by definition of a qubit we know that a a + b b = 1, hence the probability of mea-
suring 01 is 1=4. The same is true for the other outcomes.
14
5 Super-dense Coding
Super dense coding is the less popular sibling of teleportation. It can actually be viewed as the
process in reverse. The idea is to send two classical bits of information by only sending one
quantum bit. The process starts out with an EPR pair that is shared between the receiver and
sender (the sender has one half and the receiver has the other).
b0b1
Interpret
Transmit
Figure 3: Super-dense coding works by first pre-communicating an EPR pair. To send two bits
of classical information one half of this EPR pair (a single qubit) is manipulated and sent to the
other side. The two qubits (the one pre-communicated and the one sent) are then interacted and
the resulting two bits of classical information is obtained.
01: apply Z
10: apply X
2 3
1
6 0 7
00:
1 0
0 1
p1
2
( j00i + j11i) ! p12 (j00i + j11i) = p1 6 7
24 0 5
1
2 3
1
6 0 7
01:
1
0
0
1
p1
2
j00i + j11i) ! p12 (j00i j11i) = p12 64
( 7
0 5
1
2 3
0
6 1 7
10:
0 1
1 0
p1
2
( j00i + j11i) ! p12 (j10i + j01i) = p1 6 7
24 1 5
0
15
2 3
0
6 1 7
11: i
0
i
i
0
p1
2
(j00i + j11i) ! p12 (j01i j10i) = p12 64 7
1 5
0
These states are known as bell basis states. They key to super-dense coding is that they are or-
thonormal from eachother and are hence distinguishable by a quantum measurement.
H bit 0
bit 1
Figure 4: To obtain the two bits of classical information a bell-basis measurement is performed.
6 Deutsch’s Algorithm
Deutsch’s algorithm is a perfect illustration of all that is miraculous, subtle, and disappointing
about quantum computers. It calculates a solution to a problem faster than any classical computer
16
ever can. It illustrates the subtle interaction of superposition, phase-kick back, and interference.
Finally, unfortunately, is solves a completely pointless problem.
Deutsch’s algorithm answers the following question: suppose f (x) is either constant or balanced,
which one is it? If f (x) were constant then for all x the result is either 0 or 1. However, if f (x)
were balanced then for one half of the inputs f (x) is 0 and for the other half it is 1 (which x’s
correspond to 0 or 1 is completely arbitrary). To answer this question classically, we clearly need
to query for both x = 0 and x = 1, hence two queries are required. Quantum mechanically though
we will illustrate how this can be solved in just one query.
x x
Uf
y y f(x)
p
Figure 5: Suppose U f implements f , x is input as (j0i + j1i) = 2 and y as j0i,pthen the remarkable
aspect of quantum computing is the output is equal to (j0; f (0)i + j1; f (1)i) = 2.
We begin by illustrating how superposition of quantum state creates quantum parallelism or the
ability to compute on many states simultaneously.
Given a function f (x) : f0; 1g ! f0; 1g using a quantum computer, use two qubits jx; yi and trans-
form them into jx; y f (x)i (where represents addition modular two). We use two qubits since
we wish to leave the input x or the query register, “un-changed”. The second qubit, y, acts as a
result register. Let U f be the unitary transform that implements this. This is illustrated in Figure 5.
Suppose we wish to calculate f (0), then we could input x as j0i, and y, our output register, as j0i
and apply the U f transform.
Suppose we wish to calculate f (1), then we could input x as j1i, and y, our output register, as j0i
and apply the U f transform.
But this is not a classical computer – we can actually querypthe results of 0 and 1 simultaneously
using quantum parallelism. For this, let x equal (j0i + j1i) = 2 and y equal 0.
17
The output jψ2 i =
j0 f (0)ip+j1 f (1)i
; ;
! Remarkable: U f is applied to j0i and j1i simultaneously! This is known as quantum paral-
lelism.
! Problem: sounds good, but measurement produces either j0; f (0)i or j1; f (1)i. Hence we
need to be clever about what type of question we ask, and how we go about extracting the answer.
|0> H x x H
Uf
|1> H y y f(x)
Figure 6: Deutsch’s Algorithm uses quantum parallelism and interference to extract information
about a global property of the solution space.
Key:
Deutsch’s algorithm, as all known quantum algorithms that provide exponential
speedup over classical systems do, answers a question about a global property of a
solution space. These are often called promise problems, whereby the structure of
the solution space is promised to be of some form and by carefully using superposi-
tion, entanglement and interference we can extract information about that structure.
The reason these problems obtain exponential improvement over all known clas-
sical algorithms is that classically one has to calculate every point in the solution
space in order to obtain full knowledge about this structure. Quantum mechan-
ically we calculate every point using quantum parallelism. Unfortunately this is
often not how most algorithms are phrased. Usually we work with problems that
are phrased of the form “what x gives a value of f (x) with the desired property?”
Thus far, quantum computers can only provide square-root improvement to such
query-based problems.
Let jψ0 i be the initial state vector and jψ1 i be the state of the system prior to applying U f . Let
jψ2i be the state of the system after applying U f and jψ3 i be the state of the system prior to
measurement.
It may seem strange to start out with a result register of 1 instead of 0, but ignore this for now, we
will return to it shortly. Apply the H gate to the query and result registers to obtain:
18
Suppose f (x) = 0 then y f (x) = y 0 = p12 (j0 0i j1 0i) = p12 (j0i j1i)
Suppose f (x) = 1 then y f (x) = y 1 = p1 (j0 1i j1 1i) = p12 ( j0i + j1i)
2
19
p1 j0i (j0i j1i) if f (0) = f (1)
jψ3i = p12 j1i (j0i j1i) if f (0) 6= f (1)
2
Since in our case f (0) f (1) = 0 , f (0) = f (1) we can write this as
h i
jψ3i = j f (0) f (1)i j0ip+j1i
2
Key:
Note that f (0) f (1) is a global property of f (x). Classically it would require
two evaluations of f (x) to find this answer. Using a quantum computer we are
able to evaluate both answers simultaneously and then interfere these answers to
combine them together. Another more subtle point is that the phase of the result
qubit transfers to the query qubit. This is a special case of phase kick back. In
effect, the query qubit acts as a control of whether or not to flip the result qubit.
While the result qubit is potentially flipped by the state of the query qubit, the
phase of the query qubit is altered by the phase of the result (or target) qubit! We
will explore this property in more detail later, since it is the key to Shor’s algorithm.
Suppose f (x) : f2n g ! f0; 1g and that f is either constant or balanced. The goal is determine which
one it is. Classically it is trivial to see that this would require (in worst case) querying just over
half the solution space, or 2n =2 + 1 queries. The Deutsch-Jozsa algorithm answers this question
with just one query!
n n
|00....0> H x x H
Uf
|1> H y y f(x)
20
We then apply the H n transform. This symbol means to apply the H gate to each of the n qubits
(in parallel, although this does not matter. The key is only that the H gate is applied once to each
qubit). One way to define this transform is:
i j
H n jii = ∑ j (
p1)n j ji
2
This notation is rather terse, but what it is saying is that given any arbitrary state vector, it will be
composed of components jii. Each component of this state vector is transformed into a superposi-
tion of components j ji. For example, lets examine a single qubit:
aj0i + bj1i
Apply H 1 to get:
00 01 10 11
a p2
( 1)
j0i + a (
p1) j1i + b ( p1) j0i + b ( p1) j1i = p1 (a + b) j0i + p1 (a b) j1i
2 2 2 2 2
When we look at the actual transform as we have been writing it in the past we find:
p1
2
1
1
1
1
a
b
=
ap
+b
2
j0i + ap2b j1i
Returning back to jψ0 i we transform it by:
j0i j1i
∑ p2n jxi p2
1
=
x2f0;1gn
The notation f0; 1gn means all possible bit strings of size n. For example, if n = 2, this would be
“00”, “01”, “10”, and “11”.
We then apply the transform U f that implements f (x) to obtain the state jψ 2 i:
jψ2i = ∑ (
f (x)
p1) n jxi j0ip j1i
x2f0;1gn 2 2
The key to the Deutsch-Jozsa algorithm is the rather subtle point: Observe the probability ampli-
21
tude of z = j0i n . Consider when f (x) is constant. Since z = j0i n , we know that ( 1)xz+ f (x) is
either 1 or +1 for all values of x (since z is equal to zero x z must be equal to zero. Further f (x)
was constant). Hence, if f (x) is constant the probability amplitude for z = j0i n is expressed as:
∑
1
2n
= 1
x2f0;1gn
Hence when you measure the query register you will obtain a zero. Since postulate one tells that
the probabilities must sum to 1, if f (x) is constant, then we must measure a zero.
On the other hand, lets consider if f (x) is balanced. Then ( 1)xz+ f (x) will be +1 for some x
and 1 for other x’s. This is where the balanced requirement comes into play. Since all x’s
are considered, and the function is perfectly balanced, the probability of obtaining z = j0i n is
expressed as:
+1 1
∑ 2n + ∑ 2n =0
x1 x2
Where x1 is the set of x’s such that f (x) is equal to 0 and x 2 are those x’s where f (x) is equal to
1. Hence you will not measure 0 when f (x) is balanced since the probability amplitudes perfectly
destructively interfere to produce a probability of zero for that quantity.
7 Bloch Sphere
The block sphere is a useful visualization tool for single quantum bits. Before discussing it, we
need to refresh our complex math a little.
x = rcos (θ)
y = rsin (θ)
Z = re iθ
22
Clearly eiγ cos θ2 is a fully general way of expressing all values of a that can still be normalized to
1. Lets examine jaj2 :
jbj2 = ei γ( +ϕ)
sin θ2 e i(γ+ϕ) sin θ =
2 sin2 θ2
|0>
y
x
|1>
Figure 8: The Bloch sphere is a useful visualization technique for single qubits and unitary trans-
form on them.
I refer you to Examples 4.8 and 4.9 from the book for rigorous mathematical proofs, but here note:
23
Any single qubit state is a point on the surface of the Bloch sphere.
Any unitary transform becomes a rotation on this sphere: U = e iγ Rn̂ (θ). This is a rotation
across some arbitrary angle n̂ and a global phase shift. More usefully this can be broken down into:
Rotations about the X , Y , and Z axis are related to the Pauli operators:
0 1 0 i 1 0
X = Y = Z=
1 0 i 0 0 1
Before discussing this precisely, lets build up to the R y rotation. Lets assume that:
cos θ2 sin θ2
Ry (θ) =
sin θ2 cos θ2
This e iθY =2 notation relates the Pauli operators back to rotations on the Bloch sphere:
cos θ2 0 0 i sin θ2 cos θ2 i sin θ2
i sin θ2 i sin θ2
=
0 cos θ2 0 cos θ2
24
Ry (θ) = e iθY =2 = cos θ2 I i sin θ2 Y =
cos θ2 0 0 i i sin θ2 cos θ2 sin θ2
i i sin θ2
=
0 cos θ2 0 sin θ2 cos θ2
Claim: Any single qubit unitary transform can be decomposed into the following:
Since U is unitary:
a c a b 1 0
U †U
b d
=I or =
c d 0 1
Which implies:
a a + c c = 1
b b + d d = 1
a b + c d = 0
b a + d c = 0
ia0 0 γ
Assuming an arbitrary form for a = e then a = eia cos 2 and
0 γ ia0
1 eia cos 2 e cos 2γ = c c
c c = 1 cos2 2γ
ic0 sin γ .
Which implies that c = e 2 We can then rewrite our unitary equations:
cos2 2γ + sin2 2γ = 1
b b + d d= 1
0 0
eia cos 2γ b + eic sin 2γ d = 0
0 0
b e ia cos 2γ + d e ic sin 2γ = 0
25
0 0 γ
From the last two equations it should be clear that b = e ib sin 2γ and d = e id cos 2 (it is
possible to invert where the negative sign is placed, but it is equivalent), which gives us:
cos2 2γ + sin2 2γ = 1
sin2 2γ + cos2 2γ = 1
0 0 γ ic0 γ id 0 cos γ =
eia cos 2γ e ib sin 2 + e sin 2 e 0
0 0 id 0
ic0 sin γ = 0
2
eib sin 2γ e ia cos γ γ
2 + e cos 2 e 2
Focusing on the last two equations we have:
0 0 γ γ i(c0 d 0 ) cos γ γ
ei(a b ) cos 2 sin 2 = e 2 sin 2
0 0 γ γ i(d 0 c0 ) cos γ γ
ei(b a ) cos 2 sin 2 =e 2 sin 2
Or quite simply: a0 b0 c0 = d0
There are many solutions with three free variables, but a clever one (for our purposes) is:
a = ( δ β) =2 α
b = (δ β) =2 α
c = ( δ + β) =2 α
d = (δ + β) =2 α
This makes:
iα e iδ=2 e iβ=2 cos (γ=2)
e e iα eiδ=2 e iβ=2 sin (γ=2)
U = iα e iδ=2 eiβ=2 sin (γ=2)
e e iα eiδ=2 eiβ=2 cos (γ=2)
iδ=2 e iβ=2 cos (γ=2)
iα e eiδ=2 e iβ=2 sin (γ=2)
=e iδ=2 eiβ=2 sin (γ=2)
e eiδ=2 eiβ=2 cos (γ=2)
iδ=2 cos (γ=2)
iα e iβ=2 0 e eiδ=2 sin (γ=2)
=e iδ=2 sin (γ=2)
0 eiβ=2 e eiδ=2 cos (γ=2)
β=2
δ=2
iα e 0 cos (γ=2) sin (γ=2) e 0
=e
0 eβ=2 sin (γ=2) cos (γ=2) 0 eδ=2
Claim: H
= Rz
π
2
Rx π
2
Rz π
2
Rz π2
=
e iπ=4 0
=e
iπ 4 =
e iπ=4 0
=
1
iπ
0
=2
=
1 0
0 eiπ=4 0 eiπ=4 0 e 0 i
26
cos (π=4) isin (π=4) 1 i
Rx π2 = p
1
=
isin (π=4) cos (π=4) 2 i 1
Rz π2
Rx π2
Rz π2
= p
1 1 0 1 i 1 0
2 0 i i 1 0 i
1 0 1 1 1 1
= p = p
1 1
2 0 i i i 2 1 1
Using our new canonical description of a qubit we can illustrate a fundamental aspect of quantum
computing, that is the notion that with controlled operations the target qubit is amplitude flipped
on the basis of the control qubit, but the control qubit is phase flipped by the target. This is a key
component of the Deutsch-Jozsa algorithm and as we will see shortly Shor’s algorithm as well.
27
h i h i
= cos θ j0i cos σj0i + eiλ sin σ j1i ei(φ+λ) sin θ j1i cos σ + π2 j0i e iλ sin σ + π2 j1i
h i h i
= cos θ j0i cos σj0i + eiλ sin σj1i + ei(φ+λ+π) sin θ j1i cos σ + π2 j0i + ei(π λ) sin σ + π2 j1i
Observe the phase shift that occurs on the first (control qubit). The phase of the target, λ, has now
become part of the phase of the control.
Observe that:
1 1 0 1 1 0
H = p1 = p1 + = Xp+Z
2 1 1 2 1 0 0 1 2
H X H Z
X +Z +Z + X
2 =
2Z
2 =Z
Conversely:
H Z H X
Claim: HZH = X
Xp
+Z Xp+Z
Z =
2 2
28
h ih i
Xp+Z ZXp+Z 2
=
2 2
h ih i
Xp+Z p+I
ZX
=
2 2
Z +XI +IX +Z
2 =
2X
2 = X
Quantum technologies will not be able to directly implement any quantum gate. Fortunately there
is a method to synthesize any arbitrary quantum gate from only a small minimal set. This universal
set is the quantum analog of the universal gate (NOR or NAND) for classical systems. A universal
set of operations are: H, X , T , and CNot. In this section we will show how any single qubit gate
can be implemented from H, X and T . For multiple qubit gates I refer you to pages 189-191 in
your book.
The T gate is sometimes referred to as the π=8 gate. It is a rotation about the Z axis by π=4:
T = π=8 =
1
iπ
0
=4
= eiπ=8
e iπ=8 0
= Rz (π =4)
0 e 0 eiπ=8
The essential idea with synthesizing single qubit gates is that any single qubit gate is going to take
a qubit which is a point on the Bloch sphere from one position to another. While an arbitrary single
qubit gate will do this with arbitrary precision, for computation purposes we can approximate the
single qubit gate. So long as we can approximate it to arbitrary precision from only a basic set of
gates, then in theory anyway we can synthesize the arbitrary gate. One can view this approximation
as dividing up the surface of the Bloch sphere into patches, circles each of which is ε small in size.
The intuition behind approximating an arbitrary rotation is we are going to form a rotation of an
irrational amount about some axis. The key is the irrationality of the amount (lets name it ∆). By
being irrational we are assured that k1 2π=∆ 6= k2 2π=∆ for all choices of k1 6= k2 . To understand
the significance of this, imagine a circle. Assuming we are somewhere on the circumference of
this circle, if we move ∆ amount in one direction we will never get back to where we started by
continuing to move ∆ increments in the same direction (the only way to get back is to move ∆).
Assuming we are at some point on this circle and we move ∆ distance around the circumference
then we will move be at some other unique point. Performing this operation again, we will be
at yet another unique point. Eventually these unique points cover within ε distance the entire
29
circumference. This covering holds for the surface of the Bloch sphere as well as a circle.
i π8 Z i π8 X
T HT H = e e
We are now back to our “canonical form” for a rotation, except we are rotating some amount
cos θ2 cos2 π8 . The key is θ is irrational.
This irrational rotation of amount θ along the vector n̂ we will denote as R n̂ (θ). We are close to fin-
ishing, the only thing left is the ability to move along an orthogonal vector m̂. This is accomplished
using something similar to HZH = X . Simply rotate along HR n̂ (θ) H.
π π
HRn̂ (θ) H = HT HT HH = HT HT = e i8Xe i8Z
= cos π
8 I i sin π
8 Z cos π
8 I i sin π
8 Z
Which we note is the same except for the sin2 π8 X Z, instead of ZX , hence iY instead of iY .
Hence, a new orthogonal rotation Rm̂ along the vector:
m̂ = cos π8 ; sin π8 ; cos π8
Hence, using our decomposition idea we can approximate any rotation to arbitrary precision:
30
8.1 More than two qubit controlled operations
Setup undo−Setup
|0> X X |0>
X
|0> X X |0>
Figure 11: Generalizations of the Toffoli gate are constructed by simply composing a “super con-
trol” and then de-composing it.
Claim: The control and target of a CNot gate can be swapped when surrounding the input and
output with H gates.
H H
H H
Figure 12: The control and target of a CNOT gate can be swapped when the inputs are surrounded
by H gates.
1
j i j1i) (j0i + j1i)] + ad [(j0i + j1i) (j0i j1i)]
2 [ac [( 0 +
j i j1i) (j0i + j1i)] + bd [(j0i j1i) (j0i j1i)]]
+bc [( 0
31
1
j i j i j i j i j00i j01i + j10i j11i]
= 2 [ac [ 00 + 01 + 10 + 11 ] + ad [
j i j i j i j i j i j01i j10i + j11i]]
+bc [ 00 + 01 10 11 ] bd [ 00
1
j i j01i + j11i + j10i] + ad [j00i j01i + j11i j10i]
2 [ac [ 00 +
j i j01i j11i j10i] bd [j00i j01i j11i + j10i]]
+bc [ 00 +
1
j i j i j i j i j00i j01i j10i + j11i]
= 2 [ac [ 00 + 01 + 10 + 11 ] + ad [
j i j i j i j i j i j01i + j10i j11i]]
+bc [ 00 + 01 10 11 ] bd [ 00
1
= 2 [ac [( j0i + j1i) (j0i + j1i)] + ad [(j0i j1i) (j0i j1i)]
+bc [( 0 j i j1i) (j0i + j1i)] + bd [(j0i + j1i) (j0i j1i)]]
Apply the H gates:
8.3 Swap
|y1> |y2>
|y2> |y1>
A Swap gate is three back to back CNot gates as shown in Figure 13.
32
Apply the second CNot:
9 Shor’s Algorithm
In this section we are going to begin by constructing a set of tools needed to actually implement
Shor’s algorithm. Then we put these tools together to actually factor. Our first tool is how factoring
is related to another problem: order finding.
For positive x, N such that x < N, the order of x modulo N is the least positive integer r such that
[xr (modN )] = 1
Suppose N = 77 and x = 10
r : 0 1 2 3 4 5 6 7 8 9 10 11 12 13
xr jN : 1 10 23 76 67 54 1 10 23 76 67 54 1 10
Suppose N = 15 and x = 2
r: 0 1 2 3 4 5 6 7 8 9
xr jN : 1 2 4 8 1 2 4 8 1 2
33
Suppose N = 15 and x = 4
r: 0 1 2 3 4 5 6 7 8 9
xr jN : 1 4 1 4 1 4 1 4 1 4
Suppose N = 15 and x = 11
r: 0 1 2 3 4 5 6 7 8 9
xr jN : 1 11 1 11 1 11 1 11 1 11
Observe that the period of repetition is one less than a factor of N! Shor’s algorithm can be
summarized in this way:
Interfere all of the xr ’s to obtain knowledge about a global property of the structure (i.e. the
period) of the solutions.
|0> 2t
2t j s/r
!QFT
H
yx^j mod N
t
|000....1> y yx^j mod N
The Quantum Fourier Transform (QFT) implements the analog of the classical Fourier Transform.
It transforms a state space of size 2n from the amplitude to the frequency domain (just as the
Fourier transform can be viewed as a transform from 2n numbers into a range of size 2n containing
the frequency components from the domain.
2
j=0
34
The QFT is similarly defined:
2n 1
j ji ! p1 n2 ∑ e2πi jk 2 jki =
n
k=0
2n 1 2n 1 2n 1 2n 1
∑ x j j ji ! ∑ yk jki = p1 n ∑ ∑ x j e2πi jk 2 jki =
n
2
j=0 k=0 k=0 j=0
Example:
i.e.:
0 8 16 24
is transformed to:
0 4 8 12 16 20 24 28
So how do we implement the QFT? This derivation is in the book at pages 216-219, but we will
expand many of the steps and deviate from it slightly for clarity:
k=0
Note that j is a binary number and can be decomposed into the form:
n
j = j 1 2n 1+ j 2 2n 2 + ::: + j n 20 = ∑ j i 2n i
i=1
Similarly for k
n
k = ∑ ki 2n i
i=1
35
Re-express the transform as
n
2n 1 2πi j ∑ kl 2n l
=2n
p1 n
2 ∑e l =1 jki
k=0
p1 n
2 ∑e l =1 jki
k=0
2n 1
p1 n ∑ e2πi jk12 e2πi jk2 2 e2πi jkn 2 jki
1 2 n
:::
2
k=0
1 1 1
p1 n ∑ ∑ ∑ e2πi jk1 2 e2πi jk2 2 e2πi jkn 2 jk1k2 kn i
1 2 n
::: ::: :::
2
k1 =0 k2 =0 kn =0
1 1 1 1
p1 n
2 ∑ ∑ ::: ∑ e2πi jk1 2
1
e2πi jk 2 e2πi jk 2 jk1 k2
2
2
:::
n
n
::: kn 1i ∑ e
2πi jk 2
n
jki
n
k1 =0 k2 =0 kn 1 =0 kn =0
(Suspend your skepticism on why we need this notation for a short while.) Note:
n
2πi2 k
∑ j l 2n l
e2πi j2
k
=e l =1 = e2πi2
kj
12
n 1
e2πi2 kj
22
n 2
::: e2πi2
kj
22
0
= e2πi2
n 1 kj
1 e2πi2 n 2 kj
2 ::: e2πi2
n n kj
n
36
n i k
Suppose that ji = 0 then e2πi2 ji = 1
Suppose that ji = 1 and 2n i k 1 then the exponent is a multiple of 2πi, hence equal to 1
Suppose that ji = 1 and 2n i k < 1, i.e., n i k < 0 then lets look at k = 1
For k = 2:
To see how to actually implement this, lets look at any one of the qubits and how it should be
transformed:
p1
2
j0i + e2π0 j : l ::: jn j1i
Pull off the first component:
p1
2
j0i + e2πi0 j e2π0 j: l : l 1 ::: jn =2 j1i
Looking at the first component only:
p1
2
j0i + e2πi0 j j1i : l = p1
2
j0i + e2πi j 2 j1i l= = p1
2
j0i + ( 1) jl j1i
Note we apply this rotation conditionally on whether or not j i is equal to 1. We do this by focusing
on the least significant digit first. We want to achieve:
j0i + e2πi0 j j : 1 2 ::: jn j1i
Start with j j1 ij j2: : : jn i
37
Apply H to obtain:
p1
2
j0i + e2πi0 j j1i j j2
: 1 ::: jn i
Apply controlled R3 :
p1
2
j0i + e2πi0 j j j j1i j j2
: 1 2 3 ::: jn i
And so on to obtain:
p1
2
j0i + e2πi0 j j
: 1 2 ::: jn j1i j j2 ::: jn i
This is done similarly for the other bits j 2 then j3 , etc, and that’s it. The result ends up with the
bits in reverse order, but simply swap them and you have the QFT!
H R2 R3 Rn
H R2 R n−1
Figure 15: The above circuit implements the Quantum Fourier Transform (QFT). Note the outputs
are reversed in their bit-significance.
A less rigorous, but more intuitive way to think of Shor’s algorithm is that you simply compute
the function yx j modN for all j. One wonders what value of y should be chosen, but an easy value,
and one that makes y disappear is to choose the number 1. Then, simply fourier transform the
solution space and measure the period, which is the number we are looking for. In some respects,
this is exactly how Shor’s algorithm works and we give that derivation here. However, a deeper
understanding of Shor’s algorithm comes from Phase estimation, which we’ll get to next. For now,
here is the straightforward description of Shor’s algorithm:
38
jψ1i = j0i t j00 ::: 1i
p
jψ4i = p2r t ∑ j jijxk modN i k 2 [0 r
; ; 1]
j2fk;k+r;k+r2;:::g
r 1
jψ5i = p1r ∑ js=rijxk modN i
s=0
2t |j>
|0> !QFT
H
|u> j |u>
U
Figure 16: Phase estimation estimates the phase of a particularly formed eigenvalue of the eign-
vector to a matrix (in the case depicted, U ).
This means:
2πiϕ
e I U jui = 0 from (λI A) x = 0
Or more generally
The idea with phase estimation is to apply the controlled U 2 operation with p12 (j0i + j1i) as the
k
control, for k = f0; 1; :::; ng. Then apply inverse QFT to n qubits and obtain j ϕ̃i, an estimate of ϕ.
In summary:
39
Start with: j0i t jui
Apply H t to get:
p1 t ∑ j jijui
2
j
k
Apply controlled-U 2 operation for each of the k qubits of j
jϕ̃ijui
r 1
jusi p1r ∑ e 2πi rs k
jxk modN i
k=0
r 1
e2πi r p1r
s
∑e 2πi sr k
jxk modN i
k=0
r 1
= p1r ∑ e 2πi sr (k 1)
jxk modN i
k=0
r 1
= p1r ∑ e 2πi sr k
jxk +1
modN i
k=0
40
= p1r ∑ e
r 1
2πi sr k
jxk modN i
k=0
r 1
U jusi = p1r ∑ e 2πi rs k
U jxk modN i
k=0
r 1
= p1
r ∑e 2πi sr k
jxk +1
modN i
k=0
= p1r ∑ e
r 1
2πi sr k
jxk modN i
k=0
So how to prepare jus i for Shor’s algorithm? We can’t for a single eigenvalue, but note, we can for
a superposition of them!
r 1
p1r ∑ jus i
s=0
r 1r 1
= p1r p1r ∑ ∑e 2πi rs k
jxk modN i
s=0 k=0
Look carefully at k = 0
r 1
1
r ∑ e0jx0 modN i = rr j00 ::: 1i = j00: : :1i
s=0
r 1r 1
j0i t p1 p1
r r ∑ ∑e 2πi sr k
jxk modN i = j0i t j00 1i :::
s=0 k=0
r 1r 1
p1 t ∑ j ji p1r p1r ∑ ∑e 2πi sr k
jxk modN i
2
j s=0 k=0
r 1r 1
p1 t ∑ j ji p1r p1r ∑ ∑e 2πi sr j+( 2πi rs k)
jxk modN i
2
j s=0 k=0
41
Measure the second register to obtain some k
r 1
p1 t ∑ j ji p1r ∑ e 2πi sr ( j+k)
jxk modN i
2
j s=0
r 1
∑ pr ∑ e j jijxk modN i
1
= p1 t
2πi sr ( j+k)
2
j s=0
r 1
= p1r ∑ jsf
=rijx modN i
k
s=0
r.
1
[a0 ; a1 ; : : : ; am ] = a0 + 1
a1 +
a2 + :::
1
Examples:
13 1 1 1 1
64 = 64 = 4+ 12 = 4+ 1 = 4+ 1 15
13 13 13 1
12 1+ 12
18 1 1 1 1 1
64 = 64 = 3+ 10 = 3+ 1 = 3+ 1 = 3+ 1 =
3+
1
1 27
18 18 18 8 1 1+ 10 1+ 10 1+ 1 2
10
8 1+ 8
jzijyi ! jzijxzymodN i
Note that:
Z = zt 2t 1+z
t 12
t 2 + : : : + z 20
1
xZ = xzt 2
t 1
xz t 12
t 2
xZ = xz 2
::: 1
0
42
h izt h izt h iz0
x2
t 1
x2
t 2 1
::: x2
0
i
Can compute x2 classically. Note that zi is binary, hence this is really a sequence of conditional
multiplies, almost. The tricky bit is mod, but that distributes, i.e.:
10 Grover’s Algorithm
sqrt{2^n} times
n n
|0> H
G G G
|1> H
n n n n
H x H |0> to |0> H
x
|x> to −|x>
f(x)
y (y + f(x)) mod 2
X X
X X
X X
X X
X H H X
Figure 19: A Grover operator taking j0i ! j0i and jxi ! jxi for x 6= 0. Note, this actually
does the reverse, but that is the same up to a global phase of 1, which isn’t observable.
43
Examine the first iteration of Grover’s algorithm:
Apply H gates:
j 2
Apply oracle:
! p12 ∑ ( 1) f ( j) j ji
(j0i j1i)
n p1
j 2
" #
= p1 n ∑ j ji jmi (j0ip12j1i)
j6=m
2
" #
j0i j1i)
= p1 n
2 ∑ j ji 2jmi
(
p1
2
j
Apply H n
" #
! j0i n p1 n p1 n 2∑ ( 1)m j j ji (j0ip1 j1i)
2 2
j 2
" #
j0i j1i)
= 1 2
2n j0i n 2
2n ∑( 1)m j j ji (
p1
j6=0 2
" #
j0i 1)m j j ji
j0i j1i)
=
2n
2n
4 n+ 2
2n ∑( (
p1
2
j
Apply H n
" #
=
2n
2n
4
∑ j ji + 22n jmi (j0ip12j1i)
j
So observe that the “other” part has a slightly lower probability, and the correct answer (m) has a
slightly more likely chance of being measured. Lets generalize this for an arbitrary iteration.
44
pW n ∑ j ji + pR n jmi
2 2
j
Apply oracle:
! pW2 ∑ ( n 1) f ( j) j ji pR n jmi
2
j
= pW n
2 ∑ j ji Rp
+2W
2n
jmi
j
Apply H n
! W j0i Rp
+2W p1 n ∑ ( 1) jm j ji
2n 2
j
R+2W
=W 2 2n j0i + Rp22W p12 ∑ (
+
n n 1) j m j j i
j
Apply H n
R+2W 1
!W 2 2n
p
2n ∑ j ji + R+22W
n jmi
j
Thus, for each iteration the probability of obtaining a random answer “W” changes from:
h i
Ri 1 +2Wi 1
Wi = Wi 1 2 2n
Ri = Ri 1 + 2Wi 1
p
(these probability amplitudes are all over 2n
Note that the sequence fW1 ; W2 ; : : : ; Wn g is non-increasing and the seqeuence fR1 ; R2 ; : : : ; Rn g is
non-decreasing. This (and the above equation) implies that the sequence fR 1 ; R2 R1 ; : : : ; Rn
Rn 1 g is non-increasing. We can use this fact to prove the correctness of Grover’s algorithm.
p
Suppose that Wi 1 1 =2 after 2n iterations. Then:
Ri Ri 1= 2 Wi 1 21 =2=1
45
p
Hence, Wp2n 2n , hence we must measure the correct answer, which is a direct contradiction to
p
Wi 1 1=2 ! Therefore after 2n iterations Wi 1 < 1=2. This means that probability of obtaining
p nis less than 1=4, which means with 75% chance we will measure the correct
the wrong answer
answer m after 2 iterations.
11 Error Correction
Let’s suppose there was no theory of error correction for quantum computers. Then a single quan-
tum bit de-coheres (randomizes) at the same rate as a classical bit: e λt , except for quantum
systems they tend to be so error prone that λ is quite large.
Given a system if n qubits the probability that there is no error in the entire system is the probability
of no-error on each qubit multiplied together. That is:
e λt e λt e :::
λt = e λt n
As an example of how faulty quantum systems are, lets compute the largest number of bits we can
factor using Shor’s algorithm without error correction.
Discounting the inverse QFT, Shor’s algorithm is roughly t = 65n 3 complexity, when factoring n
qubits. Suppose ε = 0:05 is the probability of failure that we want (this says that with 5% chance
we will fail, but that is acceptable since if we fail we will just measure random data, which we can
check and then re-run the algorithm anew). This implies that:
1 ε>e λt n
1 ε > e λ p(n)
An appropriate value of λ is 10 6 , this is far to aggressive for current demonstration systems (which
are more like 10 3 ), but is around what we expect future quantum systems to be. Furthermore, it
is above a critical threshold – more on this later. So for λ = 10 6 , how many bits can we factor
with Shor’s algorithm?
1 ε > e λ p(n)
log(1 ε) = λp(n)
46
14
!n= log(1 0:05)=10 6 =65 = [342] 4
1
4 qubits!
Clearly, this is not good. Fortunately, there are methods to apply essentially classical error correc-
tion techniques to quantum systems.
Create codes that allow for the measurement of error, without the measurement of the value.
I view this as information loss, we create codes whereby we can gain knowledge about the
error, but not the state, and thereby we “leak” the knowledge about the errors out of the
system.
Based on the ideas of classical codes (well almost). Classical codes such as TMR, i.e.,
0 = 000 and 1 = 111. Just repeat the classical bit and then take a majority vote.
Shor’s code for protecting against bit-flip errors is the most basic of quantum codes and is a direct
translation of TMR. That is, given a qubit:
|z1>
|z2>
|z3>
47
Error correction is based around the idea of using an ancilla set of qubit(s) that are entangled with
the code word. The ancilla is carefully entangled in such a way that it’s state is entangled with
the error on the qubits (if there is any) and not the state. To see how to do this, lets return to the
classical TMR codes again.
Suppose we have a classical code 010. Clearly majority voting would lead us to conclude that the
code should really be 000. However, lets arrive at this result using the restriction that we cannot
gain knowledge about the logical state of the code. That is, lets arrive not at the knowledge that the
code should be 000, but that only there is a bit-flip error on the 2nd qubit. Thus we won’t be able
to know whether it is 010 or 101. This knowledge, while incomplete, does tell us where the error
is and how to correct it. We can use it to know whether to apply a NOT gate to the 2nd’s qubit. To
gain this knowledge (and this knowledge only!), measure the following:
s1 = z1 z2 (that is s1 = z1 xor z2 )
s2 = z2 z3
code-word s1 s2
000 0 0
001 0 1
010 1 1
011 1 0
100 1 0
101 1 1
110 0 1
111 0 0
code-word s1 s2
010 1 1
101 1 1
There in lies the key: s1 and s2 do not tell us whether the code word should be 000 or 111, but they
do tell us that the 2nd bit has been flipped.
This is the key concept behind quantum error correction (one of two). We devise a measurement
that gives us partial knowledge, chiefly in this case, the xor. Here is how to do this in the quantum
world:
j i j
[a z1 z2 z3 + b z¯1 z¯2 z¯3 ] i j0i = ajz1z2 z3ij0i + bjz¯1z¯2 z¯3ij0i
Apply a CNot with the code-word bit 1 as the control and the ancilla the target.
Hence, the ancilla qubit above does not gain knowledge on whether z 1 or z2 is equal to 1 or 0, but
it does gain knowledge about the parity of z 1 and z2 . Doing the same for bits z2 and z3 we have:
This is understating the power of quantum error correction. Unlike classical bits, quantum bits
can be in a continuous range between 0 and 1. Furthermore, so are the errors! The true power of
quantum error correction is that it transform continuous errors to either no error at all, or a discrete
error. Here’s an example of how:
Suppose jψc i = aj000i + bj111i and some random rotation about the x-axis R x (θ) occurs on the
third qubit. This is expressed as:
! aj0ij0iRx(θ)j0i + bj1ij1iRx(θ)j1i
Recall that:
cos θ2 i sin θ2
Rx (θ) =
i sin θ2 cos θ2
Thus,
49
=a j0ij0i cos θ2 j0i i sin θ2 j1i +b j1ij1i i sin θ2 j0i + cos θ2 j1i
Now parity check the 2nd and 3rd qubits. First add the ancilla qubit:
aj0ij0i cos θ2 j0ij0i i sin θ2 j1ij0i +b j1ij1i i sin θ2 j0ij0i + cos θ2 j1ij0i
Similarly for 1:
2
p(1) = a2 sin2 θ2 + b2 sin2 θ2 = a + b2 sin2 θ2 = sin2 θ2
It doesn’t matter which one we pick, but lets choose 0, after measurement the qubits are re-
normalized to become:
a cos θ2 j000ij0i+b cos θ2 j111ij0i
q
cos2 θ2
= [a j000i + bj111i] j0i
Key:
The very fact of measuring a continuous error has made it discrete, and in this case
has made the error go away! Why did it go away? Think of it this way, the error
was some superposition / entanglement with the environment, and measurement has
clasped that entanglement and superposition. Alternatively, just think of the error
as additional “information” in the state vector and measurement has observed (and
made classical) that information. The fact that that information was not in a single
qubit, but in a joint system of the two qubits is subtle.
Quantum bits have a phase as well as an amplitude. This too must be protected. However, recall
that the phase flip Z surrounded by two H gates is a bit flip X. More generally, a phase rotation
surrounded by two H gates is an amplitude rotation. Thus a phase error is just a bit-flip error if the
code is setup to protect for bit flips but then the qubits of the code are passed through H gates prior
50
to use. Starting with the 3 bit Shor bit flip code we can derive the 3 bit Shor phase flip code in this
way. The encoder is shown in Figure 21
|y> H
|0> H
|0> H
Figure 21: Encoder that takes an arbitrary state jψi and encodes it in the 3 qubit Shor phase-flip
protecting code
However we need to correct for both phase and amplitude to be fully fault tolerant. For this, we
need an additional tool. The tool we use is concatenation. This is exactly like the classical use of
concatenation. For example, suppose we have the classical bit “1”, and we TMR encode this to be
“111”. This can protect for one of the bits being in error. However, suppose the error rate is so
high that it is possible for two bits to be in error. What we can do is take each bit of the “1-1-1”
and re-encode that with TMR to obtain: “111-111-111”. Then suppose we have the value “111-
001-111”. We first perform error correction on the lowest layer to obtain “111-000-111”. Next we
perform error correction on the upper layer (in logical space) to obtain “111-111-111”. This is not
the most efficient classical code, but it is easy to reason and work with. It can also be translated
directly into quantum codes.
To protect for both phase and amplitude on a qubit we first encode it with a bit-flip code, and pass
those qubits through H gates. This protects the upper layer for phase. We then re-encode each of
those qubits again with a bit flip code. This protects the lower layer for amplitude. All told, the
entire code (known as the Shor 9 qubit code, shown in Figure 22) protects for a single phase or
a single amplitude error on any of the 9 qubits and logically holds one 1 quantum bit. Figure 23
illustrates how to measure the error in a phase.
Now that we have the 9 qubit Shor code we can protect quantum state. But we also want compute
on it. To compute in a fault tolerant manner we cannot decode the code word (which we’ll call
the logical qubit) into a single qubit (which we’ll call a physical qubit), transform it, and then
re-encode it. The reason is the physical qubit is susceptible to errors, and if an error does occur
to it, in this unencoded state, then the computation is lost. The solution is to transform a basic set
of quantum operations that would ordinarily be applied to physical qubits such that they can be
applied to logical qubits in a fault tolerant manner.
Doing this for the Shor code is not easy. Logical X and Z operations can be performed simply
51
|y> H
|0>
|0>
|0> H
|0>
|0>
|0> H
|0>
|0>
Figure 22: Encoder that takes an arbitrary state jψi and encodes it in the 9 qubit Shor code.
(challenge: what are the logical implementations of these?), but logical H, CNOT, and T cannot. A
vast amount of quantum coding research is out there, but one of the easiest to transform codes is
the 7 qubit Steane code.
To introduce the 7 qubit Steane code we’ll take a brief detour into stabilizer codes. Stabilizer codes
and their associated stabilizers is a neat compact theory useful for describing quantum codes.
Then X1 X2 jψi = jψi and Z1 Z2 jψi = jψi. Thus we say that jψi is stabilized by X1 X2 and Z1 Z2 (here
X1 means the X gate applied to the first qubit). Note that X1 X2 is only a stabilizer for this particular
jψi, and does not generalize to arbitrary aj00i + bj11i.
Thus, the 3 qubit bit-flip Shor code is stabilized by Z 1 Z2 and Z2 Z3 . The 3 qubit phase-flip code
is stabilized by X1X2 and X2 X3 . What is nifty about the stabilizer formalism is that they indicate
precisely how to measure the error. To measure the error in a logical quantum bit one measures the
stabilizers.
52
Think about bit−flip error measure this way Implement it like this Formalize it like this:
H H Z
|0> H H
Figure 23: Recall that to measure the amplitude error we performed two CNOT operations on an
ancilla qubit initially in the j0i state. To implement this, however, we surrounded both the ancilla
and the code bits with H gates and inverted the direction of the CNOT gate. This was so that an
phase error on the ancilla did not pollute the qubits in the code word. To formalize this thinking
we thought of this as a controlled Z operation with the ancilla as the control. To measure the phase
error we just directly implement the formalism, which is to perform a controlled X (i.e. CNOT)
operation.
g1 I1 I2 I3 X4 X5 X6 X7
g2 I1 X2 X3 I4 I5 X6 X7
g3 X1 I2 X3 I4 X5 I6 X7
g4 I1 I2 I3 Z4 Z5 Z6 Z7
g5 I1 Z2 Z3 I4 I5 Z6 Z7
g6 Z1 I2 Z3 I4 Z5 I6 Z7
The Steane code is particularly nice because once we measure these stabilizers if any stabilizer
fg1; g2; g3g is non-zero then a phase error has occurred on the physical qubit that is part of the
logical qubit at position g 1 22 + g2 21 + g3 20 1 and if any stabilizer fg4 ; g5 ; g6 g is non-zero then a
bit-flip error has occurred on the physical qubit g4 22 + g5 21 + g6 20 1.
Figure 24 depicts how to (non-fault tolerantly) encode a physical qubit into the Steane code. This
figure is from John Preskill at Caltech and is not in your book.
The important part about the 7 qubit Steane code is that the H, X, Z, and CNOT gates can be applied
in logical form transversally. That is, bit-wise across the qubits of the code. Unfortunately, T
cannot. See pages 485-491 of the book for details on how to implement T.
How fault tolerant is the Steane code? For this lets perform a calculation. Assume the following:
53
bit 7 |0> H
|0> H
|0> H
|0>
|0>
|0>
bit 1 |y>
Figure 24: Non-fault tolerant encoder for the 7 Qubit Steane code. This figure is from John Preskill
at Caltech.
On average, no fixup is required (the likely case) after each logical operation and error cor-
rection step.
Failure occurs when two or more errors show up in a code word.
In general, error correction takes an error rate of p = 1 e λ to cp2 . The constant c is the
number of double-points of failure in the logical operation and error correction step (i.e. the
number of places that can both fail to produce two errors in a code word). It is about 21,942
for a straightforward implementation of stabilizer measurement for the 7 qubit Steane code.
1 ε < eλp(n)
into:
p(n)
1 ε< 1 cp2
ε
p(n) > cp2
Assuming we want a 95% chance of obtaining the correct answer and the same error rate as before
(λ = 10 6 ) we have that:
h i2
0:05 10 6
65n3 n
> 21; 942 1 e
54
|0> H H g1 |0> H H g6
b7 X H X H
b6 X H H
b5 X H X H
b4 X H H
b3 H X H
b2 H H
b1 H X H
Figure 25: Almost fault-tolerant measurement of the stabilizers g 1 and g6 . To make this circuit
fault tolerant, the ancilla must be a checked CAT state, and the measurement must be repeated at
least two times.
n 13 qubits
Clearly we have to do better, and for this we turn to recursive error correction. Similar to the
concatenation we used to combine the bit and phase flip codes we can concatenate a quantum code
with another quantum code. For our example, we are going to concatenate the 7 qubit Steane code
with itself. The idea is to take a qubit and encode it in the 7 qubit Steane code. Then take each
physical qubit that is part of that single logical qubit and re-encode it again in the 7 qubit Steane
code. Repeat this procedure until we have a sufficiently strong error correcting code.
Note that this repetition would seem to imply an exponential blowup in resources – and it does, but
it also creates an exponentially strong error correcting code. Thus the overhead is polynomial to
perform computation. As we will see, however, just being polynomial doesn’t make the overhead
insignificant.
Key:
Concatenating codes recursively works so long as the underlying decoherence rate
p = 1 e λ is less than 1=c, the unit of complexity of the error correction step. This
is the result of the threshold theorem which underpins fault tolerant computation.
The concept is straightforward: we have to be able to correct fast enough such that
any decoherence that occurs while we are correcting can be corrected away. If error
correction takes so long that it would do more harm than good, then arbitrarily long
quantum computation cannot be sustained.
55
Basic measurement is not fault tolerant:
Create CAT Check the CAT for errors use it un−create CAT
|0> H H
|0>
|0>
|0>
check check
Discard if check != 0
Figure 26: Making measurement of stabilizers fault-tolerant is an arduous task. First, a CAT state
must be used in order to prevent errors in one qubit of the code word from polluting other qubits
via the ancilla qubit. This CAT state must be checked to make sure it is reliable. Furthermore, the
whole process must be repeated at least twice for each stabilizer since the measurement must be
p2 reliable.
2k
(c ṗ) ε
<
c p(n)
Here, k 1 is the number of recursive levels of error correction. Note the 2k in the equation, this
is where the exponential improvement in tolerance to errors comes from.
Now we can factor large numbers. However, there is a down side. The overhead for each qubit
is 75 = 16; 807 physical qubits. Worse still 1 logical gate requires about 153 5 = 83; 841; 135; 993
physical gates. At 1Mhz operation 1 logical gate takes 23 hours to do (serially), so at k = 5,
factoring a 1024 bit number takes 200 million years!
56
g1, g2, g3, g4, g5, g6
H X Z
H X Z
H X Z
H X Z
H X Z
H X Z
H X Z
Figure 27: Fault tolerant computation proceeds by performing the coded operation, measuring
the stabilizers (syndrome measurement), and then possibly recovering from an error. For the
Steane code, the X, Z, H, and CNOT operations are easily applied in code-space, simply apply
them transversally. Note this is not the case for T.
Really only need k = 3 for 1024 bits, so only 343 qubits of overhead, and 3,581,577 ops/logical
op. This requires only 8000 years serially. Hence, still need quantum architecture.
k = 2, p = 10 8 , 51 years
57