Introduction To Quantum Computing: Wednesday, 17 January 2024 2:24 PM

Download as pdf or txt
Download as pdf or txt
You are on page 1of 265

#ClassNotes, #IQC

Introduction to Quantum Computing


Wednesday, 17 January 2024 2:24 PM
Review of
Matrices and Vectors

1/45
Vectors & Vector Spaces
Definition of Vector: A collection of complex or real numbers,
generally put in a column  v 
1 Transpose
 
 
v =  "  = [v1 ! v N ]T
 
 
v N 
 

Definition of Vector Addition: Add element-by-element

 a1   b1   a1 + b1 
a =  "  b =  "  a + b =  " 
a N  bN  a N + bN 

2/45
Definition of Scalar: A real or complex number.

If the vectors of interest are complex valued then the set of


scalars is taken to be complex numbers; if the vectors of
interest are real valued then the set of scalars is taken to be
real numbers.

Multiplying a Vector by a Scalar :

 a1   αa1 
a =  "  αa =  " 
a N  αa N 

Öchanges the vectorís length if |α| ≠ 1


Ö ìreversesî its direction if α < 0
3/45
Arithmetic Properties of Vectors: vector addition and
scalar multiplication exhibit the following properties pretty
much like the real numbers do
Let x, y, and z be vectors of the same dimension and let α
and β be scalars; then the following properties hold:
x+y=y+x
1. Commutativity
αx = xα

(x + y ) + z = y + (x + z )
2. Associativity α(βx) = (αβ)x

α ( x + y ) = αx + α y
3. Distributivity
(α + β)x = αx + βx

1x = x
4. Scalar Unity &
Scalar Zero 0x = 0, where 0 is the zero vector of all zeros
4/45
Definition of a Vector Space: A set V of N-dimensional vectors
(with a corresponding set of scalars) such that the set of vectors
is:
(i) ìclosedî under vector addition
(ii) ìclosedî under scalar multiplication

In other words:
ï addition of vectors ñ gives another vector in the set
ï multiplying a vector by a scalar ñ gives another vector in the set

Note: this means that ANY ìlinear combinationî of vectors in the


space results in a vector in the spaceÖ
If v1, v2, and v3 are all vectors in a given vector space V, then
3
v = α1v1 + α 2 v 2 + α 3 v 3 = ∑α i v i
i =1
is also in the vector space V.
5/45
Axioms of Vector Space: If V is a set of vectors satisfying the above
definition of a vector space then it satisfies the following axioms:
1. Commutativity (see above)
2. Associativity (see above)
3. Distributivity (see above)
4. Unity and Zero Scalar (see above)
5. Existence of an Additive Identity ñ any vector space V must
have a zero vector
6. Existence of Negative Vector: For every vector v in V its
negative must also be in V

SoÖ a vector space is nothing more than a set of vectors with


an ìarithmetic structureî
6/45
Def. of Subspace: Given a vector space V, a subset of vectors in V
that itself is closed under vector addition and scalar
multiplication (using the same set of scalars) is called a
subspace of V.

Examples:
1. The space R2 is a subspace of R3.
2. Any plane in R3 that passes through the origin is a subspace
3. Any line passing through the origin in R2 is a subspace of R2
4. The set R2 is NOT a subspace of C2 because R2 isnít closed
under complex scalars (a subspace must retain the original
spaceís set of scalars)

7/45
Geometric Structure of Vector Space
Length of a Vector (Vector Norm): For any vector v in CN
we define its length (or ìnormî) to be
N N
∑v 2
= ∑ vi
2
2
v 2
= i v
i =1 2
i =1

Properties of Vector Norm:


αv 2
=α v 2

α v1 + β v 2 2
≤ α v1 2
+ β v2 2 triangle inequality

v 2
< ∞ ∀v ∈ C N

v 2
= 0 iff v = 0
8/45
Distance Between Vectors: the distance between two
vectors in a vector space with the two norm is defined by:
d ( v1 , v 2 ) = v1 − v 2 2

Note that: d ( v 1 , v 2 ) = 0 iff v 1 = v 2

v1 v1 ñ v2

v2

9/45
Angle Between Vectors & Inner Product:
v
Motivate the idea in R :
2
 A cos θ 1
A v =  A sin θ  u= 
θ   0 

u
2
Note that: ∑u v
i =1
i i = 1 ⋅ A cos θ + 0 ⋅ A sin θ = A cos θ

Clearly we see thatÖ This gives a measure of the angle


between the vectors.
Now we generalize this idea!

10/45
Inner Product Between Vectors :
Define the inner product between two complex vectors in CN by:
N
< u, v >= ∑ u i vi*
i =1

Properties of Inner Products: < αu, v >= α < u, v >


1. Impact of Scalar Multiplication:
< u, βv >= β * < u, v >

< u, v + z >=< u, v > + < u, z >


2. Impact of Vector Addition:
< u + w, v >=< u, v > + < w, v >

2
3. Linking Inner Product to Norm: v 2
=< v, v >

4. Schwarz Inequality: < u, v > ≤ u 2


v 2

5. Inner Product and Angle: < u, v >


= cos(θ )
(Look back on previous page!) u2 v2
11/45
Inner Product, Angle, and Orthogonality :
< u, v >
= cos(θ )
u2 v2
(i) This lies between ñ1 and 1;
(ii) It measures directional alikeness of u and v
= +1 when u and v point in the same direction
= 0 when u and v are a ìright angleî
= ñ1 when u and v point in opposite directions

Two vectors u and v are said to be orthogonal when <u,v> = 0

If in addition, they each have unit length they are orthonormal

12/45
Building Vectors From Other Vectors
Can we find a set of ìprototypeî vectors {v1, v2, Ö, vM} from
which we can build all other vectors in some given vector space V
by using linear combinations of the vi?
M M
v = ∑α k v k u = ∑ βk vk
k =1 k =1
Same ìIngredientsîÖ just different amounts of them!!!

We want to be able to do is get any vector just by changing the


amountsÖ To do this requires that the set of ìprototypeî
vectors {v1, v2, Ö, vM} satisfy certain conditions.
Weíd also like to have the smallest number of members in the
set of ìprototypeî vectors.
13/45
Span of a Set of Vectors: A set of vectors {v1, v2, Ö, vM} is said to
span the vector space V if it is possible to write each vector v in V as
a linear combination of vectors from the set:
M
v = ∑αk vk
k =1

This property establishes if there are enough vectors in the


proposed prototype set to build all possible vectors in V.
It is clear that:
1. We need at least N vectors to
Examples in R2 span CN or RN but not just any N
vectors.
2. Any set of N mutually orthogonal
vectors spans CN or RN (a set of
vectors is mutually orthogonal if all
Does not Spans R2
pairs are orthogonal).
Span R2
14/45
Linear Independence: A set of vectors {v1, v2, Ö, vM} is said to
be linearly independent if none of the vectors in it can be written as
a linear combination of the others.
If a set of vectors is linearly dependent then there is ìredundancyî
in the setÖit has more vectors than needed to be a ìprototypeî set!
For example, say that we have a set of four vectors {v1, v2, v3, v4}
and lets say that we know that we can build v2 from v1 and v3Ö
then every vector we can build from {v1, v2, v3, v4} can also be built
from only {v1, v3, v4}.
It is clear that:
1. In CN or RN we can have no
Examples in R2 more than N linear independent
vectors.
2. Any set of mutually
orthogonal vectors is linear
independent (a set of vectors is
Linearly Not Linearly
mutually orthogonal if all pairs
Independent Independent
are orthogonal).
15/45
Basis of a Vector Space: A basis of a vector space is a set of
linear independent vectors that span the space.
ï ìSpanî says there are enough vectors to build everything
ï ìLinear Indepî says that there are not more than needed
Orthonormal (ON) Basis: If a basis of a vector space contains
vectors that are orthonormal to each other (all pairs of basis
vectors are orthogonal and each basis vector has unit norm).
Fact: Any set of N linearly independent vectors in CN (RN) is a
basis of CN (RN).
Dimension of a Vector Space: The number of vectors in any
basis for a vector space is said to be the dimension of the space.
Thus, CN and RN each have dimension of N.

16/45
Expansion and Transformation
Fact: For a given basis {v1, v2, Ö, vN}, the expansion of a vector v
in V is unique. That is, for each v there is only one, unique set of
N
coefficients {α1, α2, Ö , αN} such that v = α v
∑k =1
k k

In other words, this ìexpansionî or ìdecompositionî is unique.


Thus, for a given basis we can make a 1-to-1 correspondence
between vector v and the coefficients {α1, α2, Ö , αN}.
We can write the coefficients as a vector, too: α = [α1 ! α N ]T

 v1   α1  Expansion can be viewed as a mapping (or


    transformation) from vector v to vector α.
   
v= "  ←
→ α= "  We can view this transform as taking us
  1− to−1   from the original vector space into a new
    vector space made from the coefficient
v N  α N  vectors of all the original vectors.
   
17/45
Fact: For any given vector space there are an infinite number of
possible basis sets.
The coefficients with respect to any of them provides complete
information about a vectorÖ
some of them provide more insight into the vector and are therefore
more useful for certain signal processing tasks than others.

Often the key to solving a signal processing problem lies in finding


the correct basis to use for expandingÖ this is equivalent to finding
the right transform. See discussion coming next linking DFT to
these ideas!!!!

18/45
DFT from Basis Viewpoint:
If we have a discrete-time signal x[n] for n = 0, 1, Ö N-1
x = [x[0] x[1] ! x[ N − 1]]
T
Define vector:
Define a orthogonal basis from the exponentials used in the IDFT:

1  1   1   1 
1  e j 2 π1⋅1 / N   e j 2 π 2⋅1 / N   e j 2 π ( N −1)⋅1 / N 
d0 =  
"

d1 = 
 "


 j 2 π1( N −1) / N 
d2 = 
 "


 j 2 π 2( N −1) / N 
Ö d N −1 =
 "


 j 2 π( N −1)( N −1) / N 
1 e  e  e 

Then the IDFT equation can be viewed as an expansion of the


signal vector x in terms of this complex sinusoid basis:
N −1 T
1  X [ 0] X [1] X [ N − 1] 
x = ∑ X [k ] d k α= ! 
N
k =0 &
#%#
$  N N N 
αk

kth coefficient coefficient vector 19/45


Usefulness of an ON Basis
Whatís So Good About an ON Basis?: Given any basis
{v1, v2, Ö, vN} we can write any v in V as
N
v = ∑αk vk
k =1

Given the vector v how do we find the αís?


ï In general ñ hard! But for ON basis ñ easy!!
N 
If {v1, v2, Ö, vN} is an ON basis then v, v i = ∑ α j v j  , v i
 j =1 
N
= ∑α
j =1
j
&
v j , vi
#%# $
δ[ j − i ]

α i = v, v i = αi

ith coefficient = inner product with ith ON basis vector


20/45
Another Good Thing About an ON Basis: They preserve inner
products and normsÖ (called ìisometricî):
If {v1, v2, Ö, vN} is an ON basis and u and v are vectors
expanded as

N N
ThenÖ. v = ∑αk vk u = ∑ βk vk
k =1 k =1

1. < v ,u > = < α , β > (Preserves Inner Prod.)


2. ||v||2 = ||α||2 and ||u||2 = ||β||2 (Preserves Norms)

SoÖ using an ON basis provides:


ï Easy computation via inner products
ï Preservation of geometry (closeness, size, orientation, etc.

21/45
Example: DFT Coefficients as Inner Products:
Recall: N-pt. IDFT is an expansion of the signal vector in terms of
N Orthogonal vectors. Thus

X [k ] = x, d k

N −1
= ∑ x[ n ]d *
k [n ]
n =0

N −1
= ∑ x[n]e − j 2πkn / N
n =0

See ìreading notesî for some details about normalization issues in this case

22/45
Matrices
Matrix: Is an array of (real or complex) numbers organized in
rows and columns.  a11 a12 a13 a14 
 
Here is a 3x4 example:  
A = a 21 a 22 a 23 a 24 
 
 
a31 a32 a33 a34 

Weíll sometimes view a matrix as being built from its columns;


The 3x4 example above could be written as:

A = [a1 | a 2 | a 3 | a 4 ] a k = [a1k a2k a3k ]T

Weíll take two views of a matrix:


1. ìStorageî for a bunch of related numbers (e.g., Cov. Matrix)
2. A transform (or mapping, or operator) acting on a vector
(e.g., DFT, observation matrix, etcÖ. as weíll see)
23/45
Matrix as Transform: Our main view of matrices will be as
ìoperatorsî that transform one vector into another vector.
Consider the 3x4 example matrix above. We could use that matrix
to transform the 4-dimensional vector v into a 3-dimensional
vector u:
 v1 
 
 
v 2 
 
u = Av = [a1 | a 2 | a 3 | a 4 ]   = v1a1 + v2 a 2 + v3a 3 + v4 a 4
 v3 
 
 
v  Clearly u is built from the columns
 4
of matrix A; therefore, it must lie
in the span of the set of vectors that
make up the columns of A.
Note that the columns of A are
3-dimensional vectorsÖ so is u. 24/45
Transforming a Vector Space: If we apply A to all the vectors in
a vector space V we get a collection of vectors that are in a
new space called U.
In the 3x4 example matrix above we transformed a 4-dimensional
vector space V into a 3-dimensional vector space U
A 2x3 real matrix A would transform R3 into R2 :

Facts: If the mapping matrix A is square and its columns are


linearly independent then
(i) the space that vectors in V get mapped to (i.e., U) has the
same dimension as V (due to ìsquareî part)
(ii) this mapping is reversible (i.e., invertible); there is an inverse
matrix A-1 such that v = A-1u (due to ìsquareî & ìLIî part)
25/45
Transform = Matrix × Vector: a VERY useful viewpoint for all
sorts of signal processing scenarios. In general we can view many
linear transforms (e.g., DFT, etc.) in terms of some invertible
matrix A operating on a signal vector x to give another vector y:
y i = Axi x i = A −1y i

A, A −1

y2
x1 y1
x2

We can think of A and A-1 as


mapping back and forth
A, A −1 between two vector spaces
26/45
Matrix View & Basis View
Basis Matrix & Coefficient Vector:
Suppose we have a basis {v1, v2, Ö, vN} for a vector space V.
Then a vector v in space V can be written as: N
v = ∑αk vk
k =1

Another view of this:


 α1 
 
 
α2 
 
v = [v1 | v 2 | ! | v N ]  
&##%##$
NxN matrix  " 
v = Vα
 
 
α 
 N
The ìBasis Matrixî V transforms
the coefficient vector into the
original vector v
27/45
Three Views of Basis Matrix & Coefficient Vector:
View #1
Vector v is a linear combination of the columns of basis matrix V.
N
v = ∑αk vk
k =1
View #2
Matrix V maps vector α into vector v.
Now have
a way to go
v = Vα back-and-
View #3 forth
between
There is a matrix, V-1, that maps vector v into vector α. vector v
α = V −1v and its
coefficient
vector α

Aside: If a matrix A is square and has linearly independent columns, then A


is ìinvertibleî and A-1 exists such that A A-1 = A-1A = I where I is the identity
matrix having 1ís on the diagonal and zeros elsewhere.
28/45
Basis Matrix for ON Basis: We get a special structure!!!
Result: For an ON basis matrix VÖ V-1 = VH
(the superscript H denotes ìhermitian transposeî, which consists
of transposing the matrix and conjugating the elements)

To see this:
 < v1 , v1 > < v1 , v 2 > ! < v1 , v N > 
< v , v > < v , v > ! < v 2 , v N > 
VV H = 2 1 2 2

 " ' " 


 
< v N , v 1 > < v N , v 2 > ! < v N , v N >

1 0 ! 0
0 1 ! 0  Inner products are 0 or 1
= =I because this is an ON basis
" ' "
 
 0 0 ! 1 
29/45
Unitary and Orthogonal Matrices
A unitary matrix is a complex matrix A whose inverse is A-1 = AH
For the real-valued matrix caseÖ we get a special case of ìunitaryî
the idea of ìunitary matrixî becomes ìorthogonal matrixî
for which A-1 = AT
Two Properties of Unitary Matrices: Let U be a unitary matrix
and let y1 = Ux1 and y2 = Ux2
1. They preserve norms: ||yi|| = ||xi||.
2. They preserve inner products: < y1, y2 > = < x1, x2 >
That is the ìgeometryî of the old space is preserved by the unitary
matrix as it transforms into the new space.
(These are the same as the preservation properties of ON basis.)

30/45
DFT from Unitary Matrix Viewpoint:
Consider a discrete-time signal x[n] for n = 0, 1, Ö N-1.
N −1
Weíve already seen the DFT in a basis viewpoint: 1
x= ∑ N X [k ] d k
k =0 &
#%#
$
αk

Now we can view the DFT as a transform from the Unitary matrix
viewpoint:
1 1 1 ! 1 
 1 e j 2 π1⋅1 / N e j 2 π 2⋅1 / N ! e j 2 π ( N −1)⋅1 / N 
D = [d 0 | d1 | … | d N −1 ] = 
" " " " 
 j 2 π1( N −1) / N j 2 π ( N −1)( N −1) / N 
 1 e e j 2 π 2 ( N −1) / N ! e 
DFT IDFT
~
x = DH x 1 ~
x = Dx
N
(Acutally D is not unitary but N-1/2D is unitaryÖ see reading notes) 31/45
Geometry Preservation of Unitary Matrix Mappings
RecallÖ unitary matrices map in such a way that the sizes of
vectors and the orientation between vectors is not changed.

A, A −1

y2

x1
x2
y1

A, A −1
Unitary mappings just
ìrigidly rotateî the space.
32/45
Effect of Non-Unitary Matrix Mappings

A, A −1

y2

x1
x2
y1

A, A −1

33/45
More on Matrices as Transforms
Weíll limit ourselves here to real-valued vectors and matrices

y = Ax A maps any vector x in Rn


into some vector y in Rm
m×1 m×n n×1
Mostly interested in two cases:
1. ìTall Matrixî m>n
2. ìSquare Matrixî m = n

Rn Rm
A y
x

Range(A): ìRange Space of Aî =


vector y = weighted sum of columns of A set of all vectors in Rm that can be
⇒ may only be able to reach certain yís reached by mapping
34/45
Range of a ìTall Matrixî (m > n) The range(A) ⊂ Rm
Rn Rm

x A y

ìProofî: Since y is ìbuiltî from the n columns of A there are


not enough to form a basis for Rm (they donít span Rm)

Range of a ìSquare Matrixî (m = n)

If the columns of A are linearly indepÖ.The range(A) = Rm


Öbecause the columns form a basis for Rm

OtherwiseÖ.The range(A) ⊂ Rm
Öbecause the columns donít span Rm
35/45
Rank of a Matrix: rank(A) = largest # of linearly independent
columns (or rows) of matrix A
For an m×n matrix we have that rank(A) ≤ min(m,n)
An m×n matrix A has ìfull rankî when rank(A) = min(m,n)
Example: This matrix has rank of 3 because the 4th column cam be
written as a combination of the first 3 columns
1 0 0 1
 
 
0 1 0 2
 
 
A = 0 0 1 1
 
 
0 0 0 0
 
 
0 0 0 0

36/45
Characterizing ìTall Matrixî Mappings
We are interested in answering: Given a vector y, what vector x
mapped into it via matrix A?
ìTall Matrixî (m > n) Case
If y does not lie in range(A), then there is No Solution
If y lies in range(A), then there is a solution (but not
necessarily just one unique solution)

y = Ax
y∉range(A) y∈range(A)

No Solution A full A not


rank full rank

One Solution Many Solutions 37/45


Full-Rank ìTall Matrixî (m > n) Case y = Ax
A
Rn Rm
y
x
Range(A)

For a given y∈range(A)Ö


there is only one x that maps to it.

This is because the columns of A are linearly independent


and we know from our studies of vector spaces that the
coefficient vector of y is uniqueÖ x is that coefficient
vector

By looking at y we can determine which x gave rise to it


38/45
NonFull-Rank ìTall Matrixî (m > n) Case y = Ax
A
Range(A)
Rn Rm
y
x1
x2 A

For a given y∈range(A) there is more than one x that maps


to it

This is because the columns of A are linearly dependent


and that redundancy provides several ways to combine
them to create y

By looking at y we can not determine which x gave rise to it

39/45
Characterizing ìSquare Matrixî Mappings

Q: Given any y∈Rn can we find an x∈Rn that maps to it?


A: Not always!!!
y = Ax Careful!!! This is quite a
different flow diagram here!!!
A full A not
rank full rank

One Solution
y∉range(A) y∈range(A)

No Solution Many Solutions

When a square A is full rank then its range covers the


complete new spaceÖ then, y must be in range(A) and
because the columns of A are a basis there is a way to
build y 40/45
A Full-Rank Square Matrix is Invertible
A square matrix that has full rank is said to beÖ.
ìnonsingularî, ìinvertibleî
Then we can find the x that mapped to y using x = A-1y

Several ways to check if n×n A is invertible:


1. A is invertible if and only if (iff) its columns (or rows) are
linearly independent (i.e., if it is full rank)
2. A is invertible iff det(A) ≠ 0
3. A is invertible if (but not only if) it is ìpositive definiteî (see
later)
4. A is invertible if (but not only if) all its eigenvalues are
nonzero

Pos. Def. Invertible


Matrices Matrices

41/45
Eigenvalues and Eigenvectors of Square Matrices
If matrix A is n×n, then A maps Rn → Rn
Q: For a given n×n matrix A, which vectors get mapped into
being almost themselves???
More preciselyÖ Which vectors get mapped to a scalar multiple
of themselves???
Even more preciselyÖ which vectors v satisfy the following:
Av = λv
Input Output
These vectors are ìspecialî and are called the eigenvectors of A.
The scalar λ is that e-vectorís corresponding eigenvalue.
v Av

42/45
ìEigen-Facts for Symmetric Matricesî
ï If n×n real matrix A is symmetric, then
ñ e-vectors corresponding to distinct e-values are orthonormal
ñ e-values are real valued
ñ can decompose A as A = VΛ V T
V = [v1 v2 ! vn ] VV T = I

Λ = diag{λ1 , λ2 ,…, λn }
ï If, further, A is pos. def. (semi-def.), then
ñ e-values are positive (non-negative)
ñ rank(A) = # of non-zero e-values
ï Pos. Def. ⇒ Full Rank (and therefore invertible)
ï Pos. Semi-Def. ⇒ Not Full Rank (and therefore not invertible)
ñ When A is P. D., then we can write
A −1 = VΛ −1 V T
{ }
For P.D. A, A-1 has
the same e-vectors and Λ −1 = diag 1 λ , 1 λ ,…, 1 λ
1 2 n
has reciprocal e-values 43/45
Other Matrix Issues
Weíll limit our discussion to real-valued matrices and vectors
Quadratic Forms and Positive-(Semi)Definite Matrices
Quadratic Form = Matrix form for a 2nd-order multivariate
polynomial
 x1   a11 a12 
Example: x =   A =  

 x2  a 21 a 22 

variable fixed
The quadratic form of matrix A is:

QA ( x1 , x2 ) = x T Ax (1 × 2) ⋅ ( 2 × 2) ⋅ ( 2 × 1) = (1 × 1) scalar

2 2
scalar = ∑∑ ij i j 11 1 22 2 + (a12 + a21 ) x1 x2
a x x = a x 2
+ a x 2

i =1 j =1 44/45
ï Values of the elements of matrix A determine the characteristics
of the quadratic form QA(x)
ñ If QA(x) ≥ 0 ∀x ≠ 0Ö then say that QA(x) is ìpositive semi-definiteî
ñ If QA(x) > 0 ∀x ≠ 0Ö then say that QA(x) is ìpositive definiteî
ñ Otherwise say that QA(x) is ìnon-definiteî
ï These terms carry over to the matrix that defines the Quad Form
ñ If QA(x) ≥ 0 ∀x ≠ 0Ö then say that A is ìpositive semi-definiteî
ñ If QA(x) > 0 ∀x ≠ 0Ö then say that A is ìpositive definiteî

45/45
Foundations and Trends® in Signal Processing
arXiv:2205.09510v4 [quant-ph] 11 Jun 2022

An Introduction to Quantum
Machine Learning for Engineers
Suggested Citation: Osvaldo Simeone (2022), “An Introduction to Quantum Machine
Learning for Engineers”, Foundations and Trends® in Signal Processing: Vol. xx, No. xx,
pp 1–18. DOI: 10.1561/XXXXXXXXX.

This article may be used only for the purpose of research, teaching,
and/or private study. Commercial use or systematic downloading
(by robots or other automatic processes) is prohibited without ex-
plicit Publisher approval.
Boston — Delft
Contents

1 Classical Bit (Cbit) and Quantum Bit (Qubit) 8


1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.2 Random Classical Bit . . . . . . . . . . . . . . . . . . . . 8
1.3 Qubit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.4 Single-Qubit Quantum Gates . . . . . . . . . . . . . . . . 18
1.5 Amplitude Diagrams . . . . . . . . . . . . . . . . . . . . . 29
1.6 Interference . . . . . . . . . . . . . . . . . . . . . . . . . 30
1.7 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . 33
1.8 Recommended Resources . . . . . . . . . . . . . . . . . . 33
1.9 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

2 Classical Bits (Cbits) and Quantum Bits (Qubits) 35


2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 35
2.2 Multiple Random Classical Bits . . . . . . . . . . . . . . . 35
2.3 Multiple Qubits . . . . . . . . . . . . . . . . . . . . . . . 42
2.4 Quantum Circuits and Local Operations . . . . . . . . . . 46
2.5 Entanglement . . . . . . . . . . . . . . . . . . . . . . . . 50
2.6 Multi-Qubit Quantum Gates . . . . . . . . . . . . . . . . 55
2.7 Creating Entanglement . . . . . . . . . . . . . . . . . . . 64
2.8 Amplitude Diagrams . . . . . . . . . . . . . . . . . . . . . 65
2.9 Superdense Coding . . . . . . . . . . . . . . . . . . . . . 66
2.10 Trading Quantum and Classical Resources . . . . . . . . . 70
2.11 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . 71
2.12 Recommended Resources . . . . . . . . . . . . . . . . . . 72
2.13 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . 72

3 Generalizing Quantum Measurements (Part I) 75


3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 75
3.2 Measurements in an Arbitrary Orthonormal Basis . . . . . 75
3.3 Partial Measurements . . . . . . . . . . . . . . . . . . . . 82
3.4 Non-Selective Partial Measurements and Decoherence . . . 89
3.5 Density Matrices . . . . . . . . . . . . . . . . . . . . . . . 91
3.6 Partial Trace . . . . . . . . . . . . . . . . . . . . . . . . . 97
3.7 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . 101
3.8 Recommended Resources . . . . . . . . . . . . . . . . . . 102
3.9 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

4 Quantum Computing 111


4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 111
4.2 Gate-Based Model of Quantum Computation . . . . . . . 111
4.3 Computing Binary Functions and Quantum RAM . . . . . 113
4.4 Deutsch’s Problem and Quantum Parallelism . . . . . . . 119
4.5 Phase Kick-Back . . . . . . . . . . . . . . . . . . . . . . . 122
4.6 Validity of Deutsch’s Algorithm . . . . . . . . . . . . . . . 124
4.7 No Cloning Theorem . . . . . . . . . . . . . . . . . . . . 126
4.8 Classical Cloning: Basis-Copying Gate . . . . . . . . . . . 128
4.9 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . 129
4.10 Recommended Resources . . . . . . . . . . . . . . . . . . 130
4.11 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . 130

5 Generalizing Quantum Measurements (Part II) 131


5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 131
5.2 Projective Measurements . . . . . . . . . . . . . . . . . . 131
5.3 Observables . . . . . . . . . . . . . . . . . . . . . . . . . 139
5.4 Implementing Projective Measurements . . . . . . . . . . 146
5.5 Quantum Error Correction . . . . . . . . . . . . . . . . . 149
5.6 Implementing Projective Measurements with Ancillas . . . 155
5.7 Positive Operator-Valued Measurements . . . . . . . . . . 159
5.8 Quantum Channels . . . . . . . . . . . . . . . . . . . . . 164
5.9 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . 168
5.10 Recommended Resources . . . . . . . . . . . . . . . . . . 169
5.11 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . 169

6 Quantum Machine Learning 171


6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 171
6.2 What is Quantum Machine Learning? . . . . . . . . . . . 172
6.3 A Taxonomy of Quantum Machine Learning . . . . . . . . 174
6.4 Ansatz and Parametrized Quantum Circuits . . . . . . . . 177
6.5 Cost Functions for Quantum Machine Learning . . . . . . 185
6.6 Variational Quantum Eigensolver . . . . . . . . . . . . . . 192
6.7 Unsupervised Learning for Generative Models . . . . . . . 197
6.8 Supervised Learning . . . . . . . . . . . . . . . . . . . . . 204
6.9 Beyond Generic Ansatzes . . . . . . . . . . . . . . . . . . 213
6.10 Beyond Angle Encoding . . . . . . . . . . . . . . . . . . . 215
6.11 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . 217
6.12 Recommended Resources . . . . . . . . . . . . . . . . . . 218
6.13 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . 218

Acknowledgements 223

References 224
An Introduction to Quantum
Machine Learning for Engineers
Osvaldo Simeone1
1 King’s College London

ABSTRACT
In the current noisy intermediate-scale quantum (NISQ)
era, quantum machine learning is emerging as a dominant
paradigm to program gate-based quantum computers. In
quantum machine learning, the gates of a quantum circuit
are parametrized, and the parameters are tuned via clas-
sical optimization based on data and on measurements of
the outputs of the circuit. Parametrized quantum circuits
(PQCs) can efficiently address combinatorial optimization
problems, implement probabilistic generative models, and
carry out inference (classification and regression). This mono-
graph provides a self-contained introduction to quantum
machine learning for an audience of engineers with a back-
ground in probability and linear algebra. It first describes
the necessary background, concepts, and tools necessary to
describe quantum operations and measurements. Then, it
covers parametrized quantum circuits, the variational quan-
tum eigensolver, as well as unsupervised and supervised
quantum machine learning formulations.

Osvaldo Simeone (2022), “An Introduction to Quantum Machine Learning for


Engineers”, Foundations and Trends® in Signal Processing: Vol. xx, No. xx, pp 1–18.
DOI: 10.1561/XXXXXXXXX.
©2022 ...
Preface

Motivation

As many engineers, I have developed an early fascination for quantum


theory – for its history, its counterintuitive predictions, its central role in
the development of many existing technologies (semiconductors, lasers,
MRI, atomic clocks) and, perhaps above all, its promise to unlock future,
revolutionary, paradigms in materials, chemical, industrial, computer,
and communication engineering.
At first, the topic is inviting for an engineer with my background on
electrical and information engineering: The mathematical formalism is
familiar, based as it is on linear algebra and probability; and concepts
with wide-ranging and intriguing implications, such as superposition
and entanglement, can be easily described on paper. Spend more time
with it, however, and the field reveals its complexity, becoming for many,
the former me included, too abstruse to invite further study. Particu-
larly unfamiliar are ideas and architectures underlying key quantum
algorithms, such as Shor’s factorization method. As if that was not
enough, the impressions that most algorithmic breakthroughs are by
now textbook material, and that all the “action” is currently focused
on scaling hardware implementations, have kept me from engaging with
the state of the art on quantum computing.
This monograph is motivated by a number of recent developments

2
3

that appear to define a possible new role for researchers with an engineer-
ing profile similar to mine. First, there are now several software libraries
– such as IBM’s Qiskit, Google’s Cirq, and Xanadu’s PennyLane – that
make programming quantum algorithms more accessible, while also
providing cloud-based access to actual quantum computers. Second, a
new framework is emerging for programming quantum algorithms to be
run on current quantum hardware: quantum machine learning.

Quantum Machine Learning

Quantum computing algorithms have been traditionally designed by


hand assuming the availability of fault-tolerant quantum proces-
sors that can reliably support a large number of qubits and quantum
operations, also known as quantum gates. A qubit is the basic unit
of quantum information and computing, playing the role of a bit in
classical computers. In practice, current quantum computers imple-
ment a few tens of qubits, with quantum gates that are inherently
imperfect and noisy. Quantum machine learning refers to an emerg-
ing, alternative design paradigm that is tailored for current noisy
intermediate-scale quantum (NISQ) computers. The approach fol-
lows a two-step methodology akin to classical machine learning. In it,
one first fixes a priori a, possibly generic, parametrized architecture
for the quantum gates defining a quantum algorithm, and then uses
classical optimization to tune the parameters of the gates.
In more detail, as sketched in Fig. 1, in quantum machine learning,
the quantum algorithm is defined by a quantum circuit – denoted
as U (◊) in the figure – whose constituent quantum gates implement
operations that depend on a vector ◊ of free parameters. Measurements
of the quantum state produced by the quantum circuit produce classical
information that is fed to a classical processor, along with data. The
classical optimizer produces updates to the vector ◊ with the goal of
minimizing some designer-specified cost function.
The quantum machine learning architecture of Fig. 1 has a number
of potential advantages over the traditional approach of handcrafting
quantum algorithms assuming fault-tolerant quantum computers:
4

classical
optimizer

average

Figure 1: Illustration of the quantum machine learning design methodology: A


parametrized quantum circuit with a pre-specified architecture is optimized via its
vector of parameters, ◊, by a classical optimizer based on data and measurements
of its outputs. As we will see in this monograph, the operation of a parametrized
quantum circuit is defined by a unitary matrix U (◊) dependent on vector ◊. The
block marked with a gauge sign represents quantum measurements, which convert
quantum information produced by the quantum circuit into classical information. This
conversion is inherently random, and measurement outputs are typically averaged
before being fed to the classical optimizer.

• By keeping the quantum computer in the loop, the classical opti-


mizer can directly account for the non-idealities and limitations
of quantum operations via measurements of the output of the
quantum computer.

• If the parametrized quantum algorithm is sufficiently flexible and


the classical optimizer sufficiently effective, the approach may
automatically design well-performing quantum algorithms that
would have been hard to optimize by hand via traditional formal
methods.

Quantum machine learning, intended as the study of applications


of parametrized quantum circuits, is distinct from the related topic of
quantum-aided classical machine learning. The aim of this older line of
work is to speed up classical machine learning methods by leveraging
traditional quantum computing subroutines. This monograph will focus
solely on quantum machine learning as illustrated in Fig. 1.
Important open research questions in the field of quantum machine
learning are discussed at the end of this text. It is my hope that
5

researchers who may not have otherwise contributed to these research


directions would be motivated to do so upon reading these pages.

Goal and Organization

The main goal of this monograph is to present a self-contained introduc-


tion to quantum information processing and quantum machine learning
for a readership of engineers with a background in linear algebra and
probability. My ambition in presenting this text is to offer a resource
that may allow more researchers with no prior exposure to quantum
theory to contribute to the field of quantum machine learning with new
ideas and methods.
The monograph is written as a textbook, with no references except
for end-of-chapter sections. References are kept to a minimum, and
are mostly limited to books that the reader may peruse for additional
information on different topics introduced in these pages. I have also
included problems at the end of each chapter with the main aims of
reviewing some key ideas described in the text and of inviting the reader
to explore topics beyond this monograph.
It may be worth emphasizing that the text is meant to be read
sequentially, as I have attempted to introduce notations and concepts
progressively from the first page to the last page.
The monograph does not include discussions about specific appli-
cations and use cases. There are several reasons for this. First, many
applications are domain specific, pertaining fields like quantum chem-
istry, and are deemed to be outside the scope of this text, which focuses
on concepts and tools. Second, many existing generic tasks and data
sets currently used in the quantum machine learning literature are quite
simplistic, and they arguably yield little insight into the potential of
the technology. The reader is referred to research papers, appearing on
a daily basis on repositories like arXiv, for up-to-date results, including
new benchmarks and experiments.
The rest of the text is organized in the following chapters.
Chapter 1. Classical bit (cbit) and quantum bit (qubit):
This chapter introduces the concept of qubit through an algebraic
generalization of random classical bits (cbits). A qubit can evolve in
6

quantum systems via reversible linear (unitary) transformations – also


known as quantum gates – or via measurements. The mathematical
formalism underlying the description of both quantum gates and mea-
surements is also covered in the chapter. Finally, the chapter illustrates
a key difference in the behavior of random cbits and qubits, namely the
phenomenon of interference.
Chapter 2. Classical bits (cbits) and quantum bits (qubits):
This chapter extends the concepts introduced in the previous chapter,
including quantum gates and measurements, to systems comprising
multiple qubits. The new phenomenon of entanglement – a form of
correlation between quantum systems with no classical counterpart –
is introduced, and superdense coding is presented as an application of
entanglement.
Chapter 3. Generalizing quantum measurements (Part I):
The third chapter presents two important generalizations of quantum
measurements, namely measurements in an arbitrary basis and non-
selective measurements. Decoherence, density matrices, and partial trace
are also presented as concepts arising naturally from the introduction
non-selective measurements.
Chapter 4. Quantum computing: Chapter 4 presents a brief
introduction to the traditional approach for the design of quantum
algorithms in gate-based quantum computers. This presentation culmi-
nates in the description of Deutsch’s algorithm, the first example of a
quantum solution that can provably improve over classical algorithms.
The chapter also describes the no cloning theorem, which sets important
constraints on the design of quantum computing algorithms.
Chapter 5. Generalizing quantum measurements (Part II):
This chapter presents two further extensions of quantum measurements:
projective measurements and positive operator-valued measurements
(POVMs). POVMs represent the most general form of quantum mea-
surement. As an example of the application of projective measurements,
the problem of quantum error correction is briefly introduced; while un-
ambiguous state detection is presented as technique enabled by POVMs.
Observables are covered, and the chapter ends with a description of
quantum channels as non-selective quantum measurements.
Chapter 6. Quantum machine learning: The final chapter pro-
7

vides an introduction to quantum machine learning that builds on


the material covered in the previous chapters. After a description of
the taxonomy of quantum machine learning methods, the concepts of
parametrized quantum circuits and ansatz are introduced, along with
the definition of cost functions used in quantum machine learning. These
are leveraged to describe the variational quantum eigensolver (VQE),
as well as unsupervised and supervised learning strategies for settings
in which data are classical and processing is quantum. An outlook is
also provided pointing to more advanced techniques and directions for
research.
1
Classical Bit (Cbit) and Quantum Bit (Qubit)

1.1 Introduction

This chapter introduces the qubit as the basic unit of quantum infor-
mation and computing. To this end, we start by reviewing classical bits
(cbits) and random cbits. Then, we present the qubit as an algebraic
“extension” of the two-dimensional probability distribution of a random
cbit to a complex, normalized, two-dimensional vector. The chapter will
also present the two main ways in which a qubit can evolve over time:
unitary operations, also known as quantum gates, and measurements.
While quantum gates describe the evolution of a qubit in a closed system,
measurements convert quantum information to classical information by
coupling the qubit with a measurement instrument.

1.2 Random Classical Bit

We start by introducing some basic notation and key ideas used in


quantum theory by considering the reference case of a classical bit.

8
1.2. Random Classical Bit 9

cbit amplitude vector


5 6
1
0 |0Í =
0
5 6
0
1 |1Í =
1

Table 1.1: A cbit can be represented as a binary digit or as a two-dimensional


one-hot vector, with the latter being described using Dirac’s ket notation.

1.2.1 A Classical Bit as a One-Hot Vector


A classical bit (cbit) is a system that can be in two unambiguously
distinguishable, or orthogonal, levels. Examples include on-off switches
and up-down magnets. Mathematically, the state of a cbit is represented
by a logical binary digit taking value 0 or 1.
Alternatively, the state of a cbit can be described by a two-dimensional
“one-hot” amplitude vector. As illustrated in Table 1.1, the one-hot
amplitude vector contains a single “1” digit, whose position indicates
whether the cbit takes value 0 or 1. Specifically, a cbit taking value 0 is
encoded by a one-hot vector with a “1” digit in the first position, while
a cbit taking value 1 is encoded by one-hot vector with a “1” digit in
the second position.

1.2.2 Dirac’s Ket and Bra Notations


Dirac’s ket notation is conventionally used in quantum theory to identify
column vectors. Accordingly, a column vector is represented as |aÍ, where
a is an identifier for the vector. For a single cbit, as illustrated in Table
1.1, the ket vector representing the cbit value 0, which serves as identifier,
is the one-hot amplitude vector
C D
1
|0Í = , (1.1)
0

while the ket vector representing the cbit value 1 is


C D
0
|1Í = . (1.2)
1
10 Classical Bit (Cbit) and Quantum Bit (Qubit)

Dirac’s bra notation is used to identify row vectors. Given a ket


|aÍ, the bra Èa| is defined as the Hermitian transpose of the ket vector
|aÍ, i.e.,
Èa| = |a͆ , (1.3)
where † represents the Hermitian transpose operation. The Hermitian
transpose is given by the cascade of a transposition operation, denoted
as (·)T , and of an element-wise complex conjugation, denoted as (·)ú ,
i.e., (·)† = ((·)T )ú . For example, the bra vector corresponding to the bit
value 1 is
È1| = [ 0 1 ]. (1.4)
We will see later in this chapter that quantum states involve complex
numbers, making it important to use a Hermitian transpose, rather
than a standard transpose, operation to define the bra in (1.3).
The inner product between two kets |aÍ and |bÍ is defined as

|a͆ |bÍ = Èa||bÍ = Èa|bÍ, (1.5)

where the last expression is known as Dirac’s bra-ket notation for the
inner product. (The pun is intended.) Note that we have the equality

Èb|aÍ = Èa|bÍú , (1.6)

where we recall that (·)ú represents the complex conjugate operation.


The squared ¸2 norm of a ket |aÍ is accordingly defined as

|||aÍ||22 = Èa|aÍ. (1.7)

Note that the subscript in || · ||2 identifies the type of norm. In this
monograph, we will only use the ¸2 norm, and hence we will use the
term norm for the operation || · ||2 .
The kets |0Í and |1Í define an orthonormal basis for the linear
space of two-dimensional vectors. In fact, the two vectors are orthogonal,
i.e.,
È0|1Í = È1|0Í = 0, (1.8)
and they have unitary norm, i.e.,

È0|0Í = È1|1Í = 1. (1.9)


1.2. Random Classical Bit 11

Throughout this monograph, for reasons that will be made clear


later in this chapter, we will take all bra and ket vectors (not only
|0Í and |1Í) to have unitary norm. The assumption of unitary norm
vectors amounts to the condition

|||aÍ||22 = ||Èa|||22 = Èa|aÍ = 1 (1.10)

for all kets |aÍ.

1.2.3 A Random Cbit as a Probability Vector

The amplitude, one-hot, vector representation of a cbit is clearly less


efficient than the direct specification in terms of a single logical bit. In
fact, the one-hot vector requires two binary digits to describe a single
cbit. Despite this shortcoming, amplitude vectors are routinely used in
machine learning when dealing with discrete random variables.
The probability distribution, or probability mass function,
of a random cbit is given by the two-dimensional vector
C D
p0
p= , (1.11)
p1

where px Ø 0 represents the probability of the random cbit taking value


x œ {0, 1}, and we have the condition

p0 + p1 = 1. (1.12)

Note that the norm of a probability vector is generally different from 1.


Hence, following the convention described in the previous subsection,
the ket notation is not used for vector p.
By the definition (1.11), the probability of observing value x œ {0, 1}
can be computed via the inner product

|x͆ p = Èx|p = px , (1.13)

where we recall that |xÍ is the one-hot amplitude vector representing


cbit value x œ {0, 1} (see Table 1.1). Geometrically, the inner product
(1.13) can be interpreted as the projection of the probability vector p
into the direction defined by vector |xÍ.
12 Classical Bit (Cbit) and Quantum Bit (Qubit)

Being two dimensional, the probability vector (1.11) for a single


random cbit can be written as a linear combination of the orthonormal
basis vectors {|0Í, |1Í} as
C D
p0
p= = p0 |0Í + p1 |1Í. (1.14)
p1

In words, the probability vector (1.11) can be viewed as the “superposi-


tion” of the two orthogonal vectors |0Í and |1Í, each representing one of
the two possible states of the system. The weights of this superposition
are given by the corresponding probabilities p0 and p1 .

1.2.4 Measuring a Random Cbit

A random cbit seems to “contain more information” than a deterministic


one, since its state is defined by the probability vector p. This is in the
sense that, in order to specify the state of a random cbit, one needs to
describe the probability p0 or p1 (since p0 + p1 = 1), while the state of
a deterministic cbit is clearly described by a single binary digit. But
how much information can be actually extracted from the observation
of a deterministic cbit or a random cbit?
Suppose first that you are handed a deterministic cbit, e.g., a coin
resting on one of its two faces. Evidently, a single glance at the coin
would reveal its binary value.
Consider now being given a random cbit – say a slot machine with
a single arm producing either digit 0 or 1 with probabilities p0 and p1 ,
respectively. In order to extract the state of the random cbit, that is, its
probability vector p, a single “glance” is not sufficient. Rather, one needs
to carry out multiple measurements of the random cbit, producing a
number of independent realizations of the random cbit, each drawn from
probability distribution p. From the obtained measurement outputs,
one can estimate the probability px , for x œ {0, 1}, by evaluating the
fraction of realizations of the random cbit with value x.
In the example of the slot machine, obtaining multiple measurements
entails playing the arm of the slot machine several times. Importantly,
each independent measurement requires that the system be reset to the
original state so as to generate a new realization of the same random
1.3. Qubit 13

cbit. Quantitatively, using the outlined fraction-based estimator, by


Chebyshev’s inequality, one needs O(1/‘2 ) independent measurements
of the random cbits in order to produce an estimate with precision
‘ > 0.

1.3 Qubit

In this section, building on the basic background material presented so


far in this chapter, we introduce the notion of a qubit.

1.3.1 A Qubit as a Complex Amplitude Vector


A quantum bit (qubit) is a two-level quantum system, such as the
up-down spin of an electron or the vertical-horizontal polarization of
a photon. In a manner somewhat analogous to a random cbit, whose
state is defined by a probability vector p as in (1.14), the state of a
qubit is described by a two-dimensional amplitude vector
C D
–0
|ÂÍ = = –0 |0Í + –1 |1Í. (1.15)
–1

There are two key differences between the state |ÂÍ in (1.15) of a
quantum qubit and the state p of a random cbit:

• Unlike a probability vector p, the amplitude vector has complex


entries –0 and –1 . (Note that complex entries include real-valued
entries as a special case.)

• The qubit state vector (1.15) has the defining property of having
unitary norm, i.e.,

|||ÂÍ||22 = ÈÂ|ÂÍ = |–0 |2 + |–1 |2 = 1. (1.16)

This condition is different from the property (1.12) satisfied by


probability vectors, which stipulates that the sum of the entries
of p – and not the norm of the vector – equals 1. We observe that
property (1.16) is consistent with the convention introduced in
the previous section of considering all kets (and bras) to have
unitary norm.
14 Classical Bit (Cbit) and Quantum Bit (Qubit)

Figure 1.1: (left) An illustration of the two-dimensional Hilbert space with the
computational basis {|0Í, |1Í} and a given qubit state |ÂÍ in (1.15); (right) An
illustration of computational and diagonal bases.

While being distinct from the state of a random cbit, the qubit
state (1.15) recovers as special cases the two possible states, expressed
as one-hot amplitude vectors, of a deterministic cbit. In fact, setting
the amplitudes as –0 = 1 (and hence –1 = 0), or –1 = 1 (and hence
–0 = 0), recovers the deterministic cbit states |0Í and |1Í, respectively.
Therefore, a qubit that can only assume states |0Í and |1Í is equivalent
to a deterministic cbit.
By (1.15), we say that the qubit is in a superposition of states
|0Í and |1Í, with respective complex amplitudes –0 and –1 . Mathemat-
ically, this implies that the state of a qubit is a vector that lies in a
two-dimensional complex linear vector space, referred to as the Hilbert
space of dimension two. The states |0Í and |1Í form the so-called com-
putational basis of the Hilbert space. A geometric interpretation of a
quantum state, simplified by representing real amplitudes, is provided
by the left part of Fig. 1.1.
Being a two-dimensional vector, the state of the qubit can be equiv-
alently expressed as a superposition of any two orthonormal vectors
forming a basis of the Hilbert space. An important example is given by
the so-called diagonal basis, which consists of the two vectors
C D
1 1 1
|+Í = Ô (|0Í + |1ÍÍ = Ô (1.17)
2 2 1
and C D
1 1 1
|≠Í = Ô (|0Í ≠ |1Í) = Ô . (1.18)
2 2 ≠1
1.3. Qubit 15
x
|ÂÍ = –0 |0Í + –1 |1Í |xÍ w.p. |–x |2

Figure 1.2: A von Neumann measurement in the computational basis, also known
as a standard measurement, for a single qubit. (The abbreviation “w.p.” stands for
“with probability”.)
It can be directly checked that vectors |+Í and |≠Í are orthogonal and
that they have unitary norm. They are illustrated in the right part of
Fig. 1.1. The qubit state (1.15) can be expressed as a superposition of
diagonal states as
C D
–0 1 1
|ÂÍ = = Ô (–0 + –1 )|+Í + Ô (–0 ≠ –1 )|≠Í. (1.19)
–1 2 2
Therefore,
Ô the amplitude of the basis vector |+Í is given by the scaled
sum 1/ 2(–0 + –1 ), while the
Ô amplitude of the basis vector |≠Í is given
by the scaled difference 1/ 2(–0 ≠ –1 ).

1.3.2 Measuring a Qubit: von Neumann Measurements


In a manner somewhat similar to a random cbit (see Sec. 1.2.4), the state
of a qubit is only accessible through measurements of the qubit. Note
that we will henceforth refer to a qubit and to its state interchangeably.
A measurement takes as input a qubit in an arbitrary state |ÂÍ, as in
(1.15), and produces a cbit as the measurement’s output, while leaving
the qubit in a generally different state from the original state |ÂÍ.
The most basic type of measurement is known as von Neumann
measurement in the computational basis, or standard measure-
ment for short. Given an input qubit state |ÂÍ = –0 |0Í + –1 |1Í, a stan-
dard measurement is defined by the following two properties illustrated
in Fig. 1.2:

• Born’s rule: The probability of observing cbit x œ {0, 1} is

Pr[measurement output equals x œ {0, 1}] = |–x |2 ; (1.20)

• “Collapse” of the state: If the measured cbit is x œ {0, 1}, the


post-measurement state of the qubit is |xÍ.

Measurements are typically depicted as shown in Fig. 1.2. Accord-


ingly, a measurement is denoted via a gauge block, with the output
16 Classical Bit (Cbit) and Quantum Bit (Qubit)

cbit x œ {0, 1} indicated on top of the block and the post-measurement


state shown as the output to the right of the block.
By the Born rule (1.20), the absolute value squared |–x |2 of the
quantum amplitude –x defines the probability of a measurement out-
come x œ {0, 1}. Geometrically, this probability corresponds to the
magnitude squared of the projection of the input state |ÂÍ into the
computational-basis vector |xÍ (see Fig. 1.1). Note that the quadratic
dependence of the measurement probabilities on the amplitudes in the
qubit state vector explains the difference between the conditions (1.12)
and (1.16) satisfied by probability vectors and amplitude vectors. One
possible way to think of the absolute value squared of the amplitude
that appears in Born’s rule (1.20) is as a measure of intensity, e.g., of a
photon beam.
The Born rule can be equivalently expressed using the bra-ket
notation by noting that the x-th amplitude of qubit state |ÂÍ can be
obtained as
–x = |x͆ |ÂÍ = Èx|ÂÍ, (1.21)
which implies

|–x |2 = |Èx|ÂÍ|2 . (1.22)

It is also useful to note that, by (1.22), the probability |–x |2 can be


expressed as

|–x |2 = Èx|ÂÍÈx|ÂÍú = Èx|ÂÍÈÂ|xÍ = Èx|fl|xÍ, (1.23)

where fl = |ÂÍÈÂ| is the so-called density matrix associated with state


|ÂÍ, which will be formally introduced in Chapter 3.
By the “collapse”-of-the-state property, while the input state |ÂÍ is
generally unknown (that is why one measures it), the post-measurement
state is fully determined by the output of the measurement. In fact, the
measurement “collapses” the input qubit state |ÂÍ to the computational-
basis vector |xÍ corresponding to the measurement’s output cbit x œ
{0, 1}.
As we have discussed in the previous subsection, a qubit that can
only take states |0Í and |1Í behaves like a standard deterministic cbit.
As a sanity check, one can directly verify that, by Born’s rule, measuring
1.3. Qubit 17

a qubit in state |xÍ, for x œ {0, 1}, returns output x with probability 1,
while leaving the qubit state unchanged.
To conclude this section, it should be mentioned that the interpreta-
tion of the “collapse”-of-the-state property is much debated in physics
and philosophy (and in movies, where the “many-world” interpretation
provides an easy excuse for a plot twist).
We will see in Chapter 3, and then again in Chapter 5, that there
are different types of measurements; until then, we will always assume
standard measurements.

1.3.3 Random Cbit vs. Qubit

By Born’s rule, if the amplitudes {–x }1x=0 are real and non-negative,
we can write the state (1.15) of a qubit as
C Ô D
p0
|ÂÍ = Ô , (1.24)
p1

where px is the probability (1.20) that a measurement of the qubit


returns the cbit x. Accordingly, there may be a temptation to think
of a qubit state as the square root of a probability vector. Even more
treacherously, this perspective may lead one to treat a qubit as merely
being a random cbit defined by a probability vector p = [|–0 |2 , |–1 |2 ]T .
Accordingly, one would model a qubit in the superposition state (1.15)
as having a true, but unknown, classical state |xÍ, with x œ {0, 1}, which
is only revealed upon measurement. This temptation should be resisted!
By Born’s rule (1.20), the viewpoint described in the previous
paragraph provides the correct description of the output of the standard
measurement of a qubit. However, a qubit in state (1.24) behaves very
differently from a random cbit state defined by the probability vector
p = [|–0 |2 , |–1 |2 ]T in terms of how it evolves over time and of how it
interacts with other qubits. Specifically, as we will detail in Sec. 1.6,
the two amplitudes –0 and –1 defining the superposition state |ÂÍ can
combine over time in ways that produce subsequent measurements that
cannot be described by the evolution of a random cbit. (So, Schrodinger’s
cat is actually neither dead nor alive, but it behaves according to a
superposition of the two states.)
18 Classical Bit (Cbit) and Quantum Bit (Qubit)

1.4 Single-Qubit Quantum Gates

In this section, we describe how the state of a qubit evolves in a closed


quantum system, introducing the key concept of a quantum gate.

1.4.1 Closed Quantum Systems and Unitary Transformations


Consider a closed quantum system consisting of a single qubit that
is not subject to measurement. Note that implementing a measurement
would require the presence of an instrument connecting the qubit to
the outside world of an “observer”. In a closed system, by the laws of
quantum physics, the state of a qubit evolves according to linear and
reversible transformations. Linearity may come as a surprise, as
one may expect that nature could produce more complex behavior, but
it is a model that has stood the test of time through a large number of
experimental validations. Reversibility is a consequence of the principle
that a closed system should conserve information.
To elaborate on this last point, irreversible operations imply a loss of
information, and deleting information requires energy. By Landauer’s
principle, it specifically requires kB T ln(2) joule per bit, where kB is
the Boltzmann constant and T is the temperature of the heat sink in
kelvins. Therefore, a closed system consisting of a single qubit cannot
delete information, as this would entail the injection of energy from the
outside. It follows that transformations in a closed system should be
reversible. In contrast, measurements correspond to interactions with
external instruments, and are not reversible.
The only non-trivial linear reversible operation mapping a determin-
istic cbit state to a deterministic cbit state is the NOT, or bit flip,
operation. The NOT operation is defined by the logical mapping
0 ‘æ 0̄ = 1, (1.25)
and
1 ‘æ 1̄ = 0, (1.26)
where the bar notation indicates logical negation. The NOT operation
can be hence summarized as
x ‘æ x̄ = x ü 1, (1.27)
1.4. Single-Qubit Quantum Gates 19
|ÂÍ U |ÂÍ
U
input qubit state output qubit state

Figure 1.3: The state of a qubit evolves in a closed system according to the product
of the input state |ÂÍ by a unitary matrix U , also known as a single-qubit quantum
gate.

where ü indicates the XOR operation.


The NOT mapping defined by (1.27) can be expressed in terms of
the one-hot representation of the state of a cbit by introducing the 2 ◊ 2
Pauli X matrix C D
0 1
X= . (1.28)
1 0
In fact, given the input state |xÍ of a cbit with x œ {0, 1} (see Table
1.1), the state of the cbit at the output of a NOT operation (1.25)-(1.26)
is given by the one-hot amplitude vector
X|xÍ = |x̄Í = |x ü 1Í. (1.29)
The Pauli X matrix (1.28), describing a NOT operation, has the
following property
XX † = X † X = I, (1.30)
where I denotes the 2 ◊ 2 identity matrix
C D
1 0
I= . (1.31)
0 1
The equalities in (1.30) are the defining properties of the class of unitary
matrices.
More broadly, any reversible linear transformations mapping a qubit
state into a qubit state is described by a 2 ◊ 2 unitary matrix U ; and,
conversely, any unitary matrix U defines a linear reversible transforma-
tion between quantum states. Generalizing (1.30), a unitary matrix U
satisfies the equalities
U U † = U † U = I. (1.32)
Hence, the inverse of a unitary matrix equals its Hermitian transpose,
i.e., we have U ≠1 = U † . A unitary matrix maps a qubit state into a
qubit state, since it conserves the norm of the input vector, i.e.,
||U |ÂÍ||22 = ÈÂ|U † U |ÂÍ = |||ÂÍ||22 = 1, (1.33)
20 Classical Bit (Cbit) and Quantum Bit (Qubit)

|ÂÍ X X |ÂÍ

|ÂÍ X |ÂÍ

Figure 1.4: Two equivalent representations of a Pauli X, or NOT, gate.

where we have used (1.32).


To summarize, as illustrated in Fig. 1.3, in a closed system, a qubit
in state |ÂÍ evolves to the state

|Â Õ Í = U |ÂÍ (1.34)

for some unitary matrix U . This transformation is linear and reversible.


In fact, by (1.32), one can return the qubit to the initial state |ÂÍ by
applying the transformation U † (also unitary by (1.32)), i.e.,

|ÂÍ = U † |Â Õ Í. (1.35)

An example of a unitary transformation is given by the NOT, or Pauli


X, matrix (1.28), which is typically depicted in one of the two ways
shown in Fig. 1.4.

1.4.2 Quantum Gates


By the discussion so far in this subsection, any unitary matrix U is
in principle physically realizable as the evolution of a closed quantum
system. A unitary matrix operating on a single qubit is referred to as a
single-qubit quantum gate in the context of quantum computing.
In practice, as illustrated in Fig. 1.5, a transformation U of a qubit
in a quantum computer is typically implemented via a cascade of basic
single-qubit quantum gates selected from a library of transformations
available in the given quantum system. This cascade can be expressed
mathematically as the product

U = UK · UK≠1 · · · U1 , (1.36)

where the 2 ◊ 2 unitary matrices Uk with k œ {1, 2, ..., K} represent


the operation of basic quantum gates. Note that the product of unitary
matrices is also unitary (as it can be checked by using (1.32)).
1.4. Single-Qubit Quantum Gates 21

name operator
C D
1 0
identity I=
0 1
C D
0 1
Pauli X X=
1 0
C D
1 0
Pauli Z Z=
0 ≠1
C D
0 ≠i
Pauli Y Y = iXZ =
i 0
C D
1 1
Hadamard H= Ô1 = Ô1 (X + Z)
2 1 ≠1 2
C D
cos(◊/2) ≠ sin(◊/2)
Pauli Y -rotation RY (◊) =
sin(◊/2) cos(◊/2)

Table 1.2: Examples of notable single qubit-quantum gates.

Accordingly, as in Fig. 1.5, the evolution of a qubit in a closed


quantum system can be generally described by a quantum circuit
in which a wire represents a qubit, and multiple quantum gates are
applied in the order from left to right. Note that the order in which the
quantum gates are applied to the input state is the inverse of the order
in which the corresponding matrices appear in the product (1.36) when
read from left to right.
Examples of basic single-qubit quantum gates implemented in stan-
dard quantum computers are given in Table 1.2. These include the four
Pauli matrices, or Pauli operators, namely I (the identity matrix),
X, Y , and Z; the Hadamard gate H; and the Pauli Y -rotation
RY (◊). The Pauli matrices X, Y , and Z are related by the cyclic
product properties XY = iZ, Y Z = iX, and ZX = iY , where i is
the complex unit. They are also anti-commuting in the sense that we
have the products P1 P2 = ≠P2 P1 with P1 , P2 œ {X, Y, Z} and P1 ”= P2 .
In the next two subsections, we describe three useful characteriza-
22 Classical Bit (Cbit) and Quantum Bit (Qubit)

|ÂÍ U1 U2 ··· UK UK · · · U2 U1 |ÂÍ

Figure 1.5: Example of quantum circuit describing the evolution of the state of a
qubit in a closed system as a cascade of single-qubit quantum gates implementing
unitary matrices U1 , U2 ,..., and UK .
tions of unitary matrices and hence of quantum gates.

1.4.3 Quantum Gates as Change-of-Basis Transformations


Any unitary matrix operating on a qubit can be expressed as

U = |v0 ÍÈu0 | + |v1 ÍÈu1 |, (1.37)

where {|v0 Í, |v1 Í} and {|u0 Í, |u1 Í} are two orthonormal bases of the
two-dimensional Hilbert space. By (1.37), we can interpret a unitary
operator as mapping each vector |ux Í from one orthonormal basis to
a vector |vx Í in another orthonormal basis for x œ {0, 1}. In fact, by
(1.37), we have the mapping

U |ux Í = (|v0 ÍÈu0 | + |v1 ÍÈu1 |)|ux Í


= |v0 ÍÈu0 |ux Í + |v1 ÍÈu1 |ux Í
= |vx Í (1.38)

for x œ {0, 1}. Therefore, a unitary matrix (1.37) applies a change of


basis from basis {|u0 Í, |u1 Í} to basis {|v0 Í, |v1 Í}. A geometric interpre-
tation is provided in Fig. 1.6.
By linearity, once one specifies the operation of a unitary matrix on
the two vectors of an orthonormal basis {|u0 Í, |u1 Í}, as in (1.37), the
output of the matrix-vector multiplication U |ÂÍ is defined for any qubit
state |ÂÍ. In fact, as discussed in Sec. 1.3.1, any qubit state |ÂÍ can be
expressed as the superposition |ÂÍ = –0 |u0 Í + –1 |u1 Í of the two vectors
|u0 Í and |u1 Í. Therefore, we have the equality

U |ÂÍ = –0 U |u0 Í + –1 U |v1 Í


= –0 |v0 Í + –1 |v1 Í. (1.39)

Table 1.3 reports some examples of single-qubit quantum gates


expressed in the form (1.37), which are detailed next.
1.4. Single-Qubit Quantum Gates 23

• Identity gate: The identity “gate” maps any quantum state to


itself. Therefore, the form (1.37) applies with any orthonormal basis
{|ux Í = |vx Í}1x=0 , i.e., we have

I = |v0 ÍÈv0 | + |v1 ÍÈv1 |. (1.40)

Condition (1.40) is also known as a resolution of the identity.


• Pauli X, or NOT, gate: The Pauli X, or NOT, gate acts as a bit
flip, mapping state |0Í to |1Í, and state |1Í to |0Í. By (1.29), the Pauli
X gate can be also thought of as a shift operator, as it maps each
vector |xÍ, with x œ {0, 1}, to the “shifted” version |x ü 1Í with “shift”
given by 1. Given a qubit state in the superposition (1.15), the effect of
the Pauli X gate is to assign amplitude –0 to the basis vector |1Í and
the amplitude –1 to the basis vector |0Í, i.e.,

X(–0 |0Í + –1 |1Í) = –0 |1Í + –1 |0Í. (1.41)

• Pauli Z gate: While the Pauli X operator swaps the amplitudes of


the computational basis vectors, the Pauli Z gate swaps the amplitudes
of the vectors in the diagonal basis {|+Í, |≠Í} – an operation known as
phase flip. The name is a consequence of the fact that the Z operator
flips the phase of the amplitude of the |1Í vector for an arbitrary input
state (1.15), in the sense that we have

Z(–0 |0Í + –1 |1Í) = –0 |0Í ≠ –1 |1Í. (1.42)

• Hadamard gate: The Hadamard gate transforms the computational


basis into the diagonal basis and back, in the sense we have the equalities

H|0Í = |+Í and H|1Í = |≠Í, (1.43)


as well as
H|+Í = |0Í and H|≠Í = |1Í. (1.44)
The Hadamard gate can be thought of as performing a two-dimensional
discrete Fourier transform, as well as the corresponding inverse discrete
Fourier transform. In this interpretation, the vector |+Í represents
the zero-frequency (i.e., constant) signal, and the vector |≠Í is the
maximum-frequency signal.
24 Classical Bit (Cbit) and Quantum Bit (Qubit)

Figure 1.6: A geometric illustration of the operation of a unitary matrix as the


change-of-basis transformation (1.37).

name operator
C D
1 0
identity I= = |v0 ÍÈv0 | + |v1 ÍÈv1 | for any orth. basis {|vx Í}1x=0
0 1
C D
0 1
Pauli X X= = |0ÍÈ1| + |1ÍÈ0|
1 0
C D
1 0
Pauli Z Z= = |+ÍÈ≠| + |≠ÍÈ+|
0 ≠1
C D
1 1
Hadamard H= Ô1 = |0ÍÈ+| + |1ÍÈ≠| = |+ÍÈ0| + |≠ÍÈ1|
2 1 ≠1

Table 1.3: Examples of single-qubit quantum gates as change-of-basis transforma-


tions defined by the decomposition (1.37).
1.4. Single-Qubit Quantum Gates 25

1.4.4 Quantum Gates as Transformations with Unitary-Magnitude


Eigenvalues

To introduce an alternative interpretation of quantum gates, we will


need to review first the spectral theorem, which applies to normal
matrices. A normal matrix A is a square N ◊ N matrix that satisfies
the condition
AA† = A† A. (1.45)
By the spectral theorem, any normal matrix can be expressed in
terms of its eigendecomposition
N
ÿ ≠1
A= ⁄x |vx ÍÈvx |, (1.46)
x=0

where {|vx Í}N


x=0 are the eigenvectors, which form an orthonormal basis
≠1

of the N -dimensional Hilbert space, and {⁄x }Nx=0 are the corresponding
≠1

eigenvalues, which are generally complex.


Using the eigendecomposition (1.46), given a normal matrix A and
a scalar function f (·), we define the matrix function
N
ÿ ≠1
f (A) = f (⁄x )|vx ÍÈvx |. (1.47)
x=0

That is, function f (A) is evaluated by applying the scalar function f (·)
separately to each eigenvalue of matrix A.
A unitary matrix U is a normal matrix, since it satisfies the condition
(1.32) and hence also the equality (1.45). Therefore, a 2 ◊ 2 unitary
matrix can be expressed in terms of its eigendecomposition (1.46) with
N = 2 eigenvectors and eigenvalues, i.e., as

U = ⁄0 |v0 ÍÈv0 | + ⁄1 |v1 ÍÈv1 |, (1.48)

where {|vx Í}1x=0 is the orthonormal basis of eigenvectors. Furthermore,


all the eigenvalues of unitary matrices have absolute value equal to
1, i.e., |⁄x | = 1 for x œ {0, 1}. To see this, note that, by (1.48), the
condition (1.32) is equivalent to the equality

|⁄0 |2 |v0 ÍÈv0 | + |⁄1 |2 |v1 ÍÈv1 | = I, (1.49)


26 Classical Bit (Cbit) and Quantum Bit (Qubit)

and we have the resolution-of-identity condition (1.40).


The change-of-basis representation (1.37) describes a unitary matrix
as a map from a state in one basis to a state in another basis. In
contrast, the eigendecomposition (1.48) identifies states – the eigenvec-
tors {|vx Í}1x=0 – that are left unchanged by the operator except for a
scaling by a complex number with a unitary absolute value, namely
the eigenvalue ⁄x for state |vx Í. This is in the sense that we have the
equalities
U |vx Í = ⁄x |vx Í (1.50)
for x œ {0, 1}.
Some examples of single-qubit gates expressed in terms of their
eigendecompositions can be found in Table 1.4, where we have defined
the so-called circular orthonormal basis
1
| + iÍ = Ô (|0Í + i|1Í) (1.51)
2
1
| ≠ iÍ = Ô (|0Í ≠ i|1Í). (1.52)
2
Note that the identity has all eigenvalues equal to 1, while all other
Pauli gates – X, Y , and Z – have one eigenvalue equal to 1 and the
other equal to ≠1. Given the eigendecompositions in Table 1.4, the
orthonormal bases {|+Í, |≠Í}, {| + iÍ, | ≠ iÍ}, and {|0Í, |1Í} are also
known as X, Y , and Z bases, respectively.

1.4.5 Quantum Gates from Hermitian Generators


As we discuss in this subsection, a unitary matrix – and hence also a
quantum gate – can be expressed as an exponential transformation of a
generator matrix. In order to explain this characterization of a unitary
matrix, we need to introduce the definition of Hermitian matrices.
A 2 ◊ 2 matrix A is Hermitian if it satisfies the property
A† = A. (1.53)
Since the equality (1.53) implies (1.45), a Hermitian matrix is normal.
Therefore, as a result of the spectral theorem, it has an eigendecom-
position (1.46). Furthermore, it can be shown using (1.53) that all
eigenvalues of a Hermitian matrix are real.
Lecture 3.26. Hermitian, unitary and normal
matrices
A. Eremenko
March 10, 2023

In the previous lecture we considered matrices with non-negative entries.


They frequently appear in applications to probability, statistics and social
sciences, as it is demonstrated by examples in the previous lecture and section
5.3 of the textbook.
Now we consider important classes of matrices which are relevant to
physics and engineering. I recall them.
We consider operators in a complex vector space with an Hermitian prod-
uct. For example, Cn with the standard Hermitian product

(x, y) = x⇤ y = x1 y1 + . . . + xn yn .

I recall that “Hermitian transpose” of A is denoted by A⇤ and is obtained


by transposing A and complex conjugating all entries. So for a real matrix
A⇤ = AT .
A matrix A is called Hermitian if

A⇤ = A.

Real Hermitian is the same as symmetric. A matrix U is called unitary if

U ⇤ U = I.

So a real unitary matrix is the same as orthogonal. Examples:


! !
2 1+i a b
A= , B= .
1 i 1 b a

Matrix A is Hermitian, while B is unitary if and only if |a|2 + |b|2 = 1.

1
For these types of matrices we have the following important theorems.
Spectral theorem for Hermitian matrices. For an Hermitian matrix,
(i) all eigenvalues are real,
(ii) eigenvectors corresponding to distinct eigenvalues are orthogonal,
(iii) there is an orthonormal basis consisting of eigenvectors.
Spectral theorem for unitary matrices. For a unitary matrix,
(i) all eigenvalues have absolute value 1,
(ii) eigenvectors corresponding to distinct eigenvalues are orthogonal,
(iii) there is an orthonormal basis consisting of eigenvectors.
So Hermitian and unitary matrices are always diagonalizable (though
some eigenvalues can be equal). For example, the unit matrix is both Her-
mitian and unitary. I recall that eigenvectors of any matrix corresponding
to distinct eigenvalues are linearly independent. For Hermitian and unitary
matrices we have a stronger property (ii).
Let me prove statements (i) of both theorems.
Suppose A is Hermitian, that is A⇤ = A. Let be an eigenvalue. This
means that there exists a vector v 6= 0 such that

Av = v.

Multiply this on v from the left. We obtain

v⇤ Av = v⇤ v = v⇤ v = kvk2 .

Now apply operation to this equality:

v⇤ A⇤ v = kvk2 .

The left hand sides are equal since A⇤ = A, so the right hand sides have to
be equal. But kvk2 6= 0 (since eigenvector is not 0 by definition), so =
that is is real.
Now suppose that A is unitary, that is A⇤ A = I. Let be an eigenvalue.
This means that there exists v 6= 0 such that

Av = v.

Then also
v ⇤ A⇤ = v ⇤

2
Let us multiply these equalities:

v⇤ A⇤ Av = v⇤ v = | |2 kvk2 .

But since A⇤ A = I, the left hand side is kvk2 . Since kvk2 6= 0, we must have
| | = 1.
So we proved (i) of both theorems. Since statements (ii) and (iii) are
the same, it is reasonable to find a bigger class of matrices for which these
two statements are true, and which contains both Hermitian and unitary
matrices. This class consists of normal matrices.
A matrix is called normal if it satisfies

A⇤ A = AA⇤ .

Evidently Hermitian and unitary matrices are normal.


Exercise: give an example of a matrix which is normal but neither Her-
mitian nor unitary. Hint: an appropriate diagonal matrix will do the job.

Spectral theorem for normal matrices. A matrix is normal is and only


if there is an orthogonal basis of Cn consisting of eigenvectors.
So normal matrices is the largest class for which statements (ii) and (iii)
are true.
You can read the proof of this theorem in the handout “Spectral theorems
for Hermitian and unitary matrices”.
Let us see what our theorems imply for real matrices. Suppose that A
is real and symmetric. Then it is also Hermitian, so all eigenvalues are real.
Then eigenvectors can be also chosen real, since they are solutions of linear
equations with real coefficients, therefore

A = B⇤B 1 ,

where ⇤ is a real diagonal matrix and B is orthogonal (a real unitary matrix


is orthogonal).
Now suppose that we have an orthogonal matrix Q. The eigenvalues are
no longer guaranteed to be real, so in general, one cannot diagonalize Q using
only real matrices.
Connection with exponentials.

3
Hermitian or real symmetric matrices are easy to understand: both classes
are real vector spaces (a linear combination of Hermitian matrices with real
coefficients is Hermitian, and same for real symmetric matrices).
Unitary (or orthogonal) matrices are more difficult.
Example: describe all 2 ⇥ 2 unitary matrices with determinant 1.
Let our matrix be !
a b
A= ,
c d
where a, b, c, d are complex numbers. Let us try to write conditions on a, b, c, d
which ensure that A is unitary. By definition this means that AA⇤ = I. Since
det A = 1, !
d b
A 1= ,
c a
so we must have a = d, c = b, so
!
a b
A= , |a|2 + |b|2 = 1, a, b 2 C.
b a

This is a general form of a 2 ⇥ 2 unitary matrix with determinant 1.


In particular, when a, b are real, we obtain the general form of a 2 ⇥ 2
orthogonal matrix with determinant 1.
!
a b
A= , |a|2 + |b|2 = 1, a, b 2 R.
b a

With matrices of larger size, it is more difficult to describe all unitary (or
orthogonal) matrices.
Let H be a Hermitian matrix, that is H ⇤ = H. I claim that the exponen-
tial of U = exp(iH) is unitary. Indeed,

U ⇤ = exp( iH ⇤ ) = exp( iH) = U 1


.

Conversely, every unitary matrix U is an exponential of iH for some Hermi-


tian H.
Indeed by the spectral theorem, for a unitary matrix U one can find a
unitary matrix B such that

U = B⇤B 1 , ⇤ = diag( 1 , . . . , n ),

4
where | j | = 1 for all j. Therefore we can write j = exp(i✓j ) with some real
✓j , and thus
1
U = Bei⇥ B 1
= eiB⇥B , where ⇥ = diag(✓1 , . . . , ✓n ).
1
Now the matrix H = B⇥B is unitary, because

H ⇤ = (B⇥B 1 )⇤ = (B 1 )⇤ ⇥B ⇤ = B⇥B 1
= H,

since ⇥ is real and B ⇤ = B 1 .


Thus unitary matrices are exactly of the form eiA , where A is Hermitian.

Now we discuss a similar representation for orthogonal matrices. Let A


be a real skew-symmetric matrix, that is AT = A⇤ = A. Then iA is
Hermitian:
( iA)⇤ = iA⇤ = iAT = iA.
So eA = ei( iA) is unitary, and since A is real, eA is also real, thus eA is
orthogonal.
However we will not obtain all orthogonal matrices in this way. Indeed,
for a skew symmetric matrix A, all main diagonal elements are zeros, so the
trace is zero, and
det eA = etr A = e0 = 1.
One can show that the formula

eA , where A is skew symmetric

actually represents all orthogonal matrices with determinant 1, and we will


prove this for the important case when n = 3 in one of the following lectures.
I recall that orthogonal matrices with determinant 1 represent rotations. This
explains the importance of having a formula for all of them.

5
Introduction References

Introduction to quantum computing

Pushpendra Singh, Ph.D. (IIT Delhi)


[email protected]

SOE, JNU Delhi

February 2024

P. Singh SOE, JNU Delhi


Introduction to quantum computing 1 / 26
Introduction References

1 Introduction

2 References

P. Singh SOE, JNU Delhi


Introduction to quantum computing 2 / 26
Introduction References

1 Introduction

2 References

P. Singh SOE, JNU Delhi


Introduction to quantum computing 3 / 26
Introduction References

• Bra–ket hi notation:
• In quantum mechanics ket notation is used to denote quantum
states, and |v i is pronounced as “ket-v ”
• Mathematically |v i denotes a column vector in an abstract com-
plex vector space V , and physically it represents a quantum
state of some quantum system.
• A hf | is pronounced as “bra-f ”. Mathematically it denotes a
linear form (or linear functional) f : V ! C such that hf |v i 2 C
for v 2 V and f 2 V 0 , where V 0 is a dual space of V
• The linear form hv | 2 V 0 is a covector to |v i 2 V and obtained
by Hermitian conjugation, i.e., hv | = |v i† . This is however not
correct in a technical sense, since the ket represents a vector in
a complex Hilbert-space H, and the bra is a linear functional
on vectors in H. In other words |v i is just a vector, while hv |
is the combination of a vector and an inner product.
P. Singh SOE, JNU Delhi
Introduction to quantum computing 4 / 26
Introduction References

• Inner product and bra–ket identification on Hilbert space —


The inner product on Hilbert space (with the first argument
anti linear as preferred by physicists) is fully equivalent to an
(anti-linear) identification between the space of kets and that of
bras in the bra-ket notation: for a vector | i define a functional
f = h | by f ( ) = (| i, | i) = h | i
• Bras and kets are considered as row and column vectors
• Linear operators are ubiquitous in the theory of quantum me-
chanics. For example, observable physical quantities are rep-
resented by self-adjoint operators (A = A† ), such as energy or
momentum

P. Singh SOE, JNU Delhi


Introduction to quantum computing 5 / 26
Introduction References

• Hermitian conjugate operator:


| i = A | i if and only if h | = h | A†
If A is expressed as an N ⇥ N matrix, then A† is its conjugate
transpose. Self-adjoint operators, where A = A† , play an im-
portant role in quantum mechanics; for example, an observable
is always described by a self-adjoint operator. If A is a self-
adjoint operator, then h |A| i is always a real number. This
implies that expectation values of observables are real.
• A bra h | and a ket | i (i.e. a functional and a vector), can
be combined to an operator of rank one with outer product
| ih |: |⇠i 7! | ih |⇠i .
• Projection operators: A projection operator P has the property
P 2 = P. Consider a complete orthonormal basis {| 1 i , · · · , | n i}
and a state in an n-dimensional vector space (Hilbert space) as
| i = ↵1 | 1 i + · · · + ↵n | n i where ↵i = h i | i

P. Singh SOE, JNU Delhi


Introduction to quantum computing 6 / 26
Introduction References

1 The projection operator: P 1 = | 1 i h 1 | projects the state onto


the subspace defined by | 1 i:
P 1 | i = | 1 i h 1 | | i = | 1 i h 1 | i = ↵1 | 1 i. This operator
leaves ↵1 | 1 i invariant, and it annihilates all vectors orthogonal
to | 1 i.
2 The projection operator: P 1 2 = | 1 i h 1 | + | 2 i h 2 | projects
the state onto the subspace defined by | 1 i and | 2 i:
P 1 2 | i = ↵1 | 1 i + ↵2 | 2 i
3 The identity operator: P 1 ··· n = | 1 i h 1 | + · · · + | n i h n | = I
projects out the entire state: P 1 ··· n | i = I | i = | i
• In quantum mechanics, a projection operator is a type of oper-
ator that maps a quantum state onto a subspace of the original
Hilbert space. Let’s denote a projection operator by P, and the
subspace onto which it projects by S. The projection operator
P has the following properties:

P. Singh SOE, JNU Delhi


Introduction to quantum computing 7 / 26
Introduction References

1. Hermitian Operator: The projection operator P is Hermitian,


meaning P † = P, where P † is the adjoint (conjugate transpose)
of P.
2. Idempotent: The projection operator is idempotent, mean-
ing P 2 = P. This property implies that applying the projection
operator twice is the same as applying it once.
3. Eigenvalues: The eigenvalues of a projection operator are
either 0 or 1. If P projects onto a subspace S, then P applied
to any vector in S yields the same vector, and its eigenvalue is
1. If P applied to any vector orthogonal to S yields the zero
vector, and its eigenvalue is 0.
4. Orthogonality: The range (image) of the projection operator
P is orthogonal to the null space (kernel) of P.
5. Complementarity: The projection operator P and its com-
plementary projection operator I P (where I is the identity
operator) are complementary projectors. If P projects onto a
P. Singh SOE, JNU Delhi
Introduction to quantum computing 8 / 26
Introduction References

subspace S, then I P projects onto the orthogonal comple-


ment of S.
6. Trace: The trace of a projection operator is equal to the
dimension of the subspace onto which it projects.
• The transformative processes are represented by unitary linear
operators such as rotation or the progression of time
• Mathematically, for a quantum circuit U with no entanglement
and an n-qubit product state | i = | 1 i ⌦ · · · ⌦ | n i, we can
write: U | i = U1 | 1 i ⌦ · · · ⌦ Un | n i, where Ui are 2 ⇥ 2
complex unitary matrices such that U1 ⌦ · · · ⌦ Un = U. Such
computation can be done in polynomial time on a classical
computer because we just need to do n-matrix multiplications.
Moreover, it can be done in parallel, and it will take constant
time in n.

P. Singh SOE, JNU Delhi


Introduction to quantum computing 9 / 26
Introduction References

• Now, even more peculiarly, certain quantum computation can


be efficiently simulated classically even in the presence of en-
tanglement. This is due to the Gottesman–Knill theorem. The
theorem states that some highly entangled circuits can be sim-
ulated efficiently on a classical computer.
• Gottesman–Knill theorem: A quantum circuit using only the
following elements can be simulated efficiently on a classical
computer:
(i) Preparation of qubits in computational basis states,
(ii) Clifford gates (Hadamard gates, controlled NOT gates,
phase gate S), and
(iii) Measurements in the computational basis.

P. Singh SOE, JNU Delhi


Introduction to quantum computing 10 / 26
Introduction References

• The theorem proves that, for all quantum algorithms with a


speed up that relies on entanglement which can be achieved
with a CNOT and a Hadamard gate to produce entangled
states, this kind of entanglement alone does not give any com-
puting advantage.
• The adjoint operator, also known as the adjoint transformation
or conjugate transpose, has several key properties. Let’s con-
sider an operator A and its adjoint A† :
1. Definition: - The adjoint A† is defined by taking the conju-
gate transpose of the operator A.
2. Hermitian Operators: - If A = A† , then A is a Hermitian
operator. Hermitian operators have real eigenvalues, and their
eigenvectors corresponding to distinct eigenvalues are orthogo-
nal.
3. Unitary Operators: - If A† A = AA† = I , where I is the iden-
tity operator, then A is a unitary operator. Unitary operators
P. Singh SOE, JNU Delhi
Introduction to quantum computing 11 / 26
Introduction References

preserve inner products and are often associated with transfor-


mations that preserve the norm of vectors.
4. Properties of Adjoint with Scalars: - (cA)† = cA† , where c
is a scalar.
5. Adjoint of a Sum: - (A + B)† = A† + B † .
6. Adjoint of a Product: - (AB)† = B † A† .
7. Adjoint of an Inverse: - (A 1 )† = (A† ) 1 , if A is invertible.
8. Double Adjoint: - (A† )† = A.
These properties are essential in various areas of mathematics
and physics, particularly in quantum mechanics, where opera-
tors and their adjoints play a central role in describing physical
systems and their evolution.

P. Singh SOE, JNU Delhi


Introduction to quantum computing 12 / 26
Introduction References

• In functional analysis and linear algebra, the adjoint of a linear


operator between Hilbert spaces is also known as the Hermitian
adjoint or conjugate transpose. It is denoted as A† . For a linear
operator A on a Hilbert space, the adjoint satisfies the property
hAx, y i = hx, A† y i for all vectors x and y in the Hilbert space,
where hAx, y i = hx, A† y i =) (Ax)† y = x † A† y . This concept
is particularly important in quantum mechanics and other areas
of physics.
• Let’s consider a complex matrix for the example of a linear op-
erator on a finite-dimensional vector space and find its adjoint.
Suppose we have a linear operator T : C3 ! C3 defined by the
complex matrix:
2 3
1 + i 2i 3
[T ] = 4 0 1 4i 5
0 0 1

P. Singh SOE, JNU Delhi


Introduction to quantum computing 13 / 26
Introduction References

This operator acts on vectors in C3 by matrix multiplication:


T (v) = [T ] · v.
Now, let’s find the adjoint operator T † . The adjoint satisfies:

hT v, wi = hv, T † wi
for all vectors v, w 2 C3 , where h·, ·i is the standard inner
product.
In matrix notation, the inner products can be written as:

hT v, wi = vH [T ]H w

hv, T † wi = vH [T † ]w
Here, H denotes the conjugate transpose (Hermitian transpose)
of a matrix.

P. Singh SOE, JNU Delhi


Introduction to quantum computing 14 / 26
Introduction References

The adjoint T † turns out to be the conjugate transpose of the


matrix [T ]:
2 3
1 i 0 0
[T † ] = [T ]H = 4 2i 1 05
3 4i 1

This means that the adjoint operator T † is associated with the


conjugate transpose of the original complex matrix T . The
adjoint has similar properties to those in the real case, making
it important in applications involving complex vector spaces and
linear transformations.

P. Singh SOE, JNU Delhi


Introduction to quantum computing 15 / 26
Introduction References

• Let’s define the example with a linear operator in the context


of quantum computing, considering a Hilbert space associated
with quantum states.
Suppose we have a quantum operator U acting on quantum
states in a Hilbert space, denoted as | i. The linear operator
U is defined as:

U:H!H

U| i = ↵| i
Here, | i represents a quantum state, and U| i is obtained by
multiplying the state by a complex scalar ↵.
Now, let’s find the adjoint operator U † . The adjoint satisfies:

hU| i, | ii = h| i, U † | ii
P. Singh SOE, JNU Delhi
Introduction to quantum computing 16 / 26
Introduction References

for all quantum states | i, | i in the Hilbert space, where h·, ·i


is the quantum inner product.
Calculating the inner products:

hU| i, | ii = h↵| i, | ii = h |↵| i

h| i, U † | ii = h |U † | i
The adjoint U † turns out to be the operator defined by:

U † | i = ↵| i
This means that the adjoint operator U † of the original quan-
tum operator U is obtained by multiplying the quantum state
| i by the complex conjugate of ↵.
In the language of quantum computing, this example illustrates
a quantum operator U and its adjoint U † acting on quantum
P. Singh SOE, JNU Delhi
Introduction to quantum computing 17 / 26
Introduction References

states in a Hilbert space. The adjoint operation is linear in


the second argument, which is a common feature in quantum
computing contexts.
• Let’s consider an example of a linear operator on a Hilbert space
and its adjoint.
Suppose we are working in the space L2 ([0, 1]), which consists
of square-integrable complex-valued functions defined on the
interval [0, 1]. Let the linear operator A be defined by:

A : L2 ([0, 1]) ! L2 ([0, 1])

(Af )(x) = x · f (x)


Here, f (x) is a function in L2 ([0, 1]), and Af is obtained by
multiplying f (x) by the variable x.
Now, let’s find the adjoint operator A† . The adjoint satisfies:
P. Singh SOE, JNU Delhi
Introduction to quantum computing 18 / 26
Introduction References

hAf , g i = hf , A† g i
for all f , g 2 L2 ([0, 1]), where h·, ·i is the inner product.
Let’s calculate the inner products:
Z 1
hAf , g i = x · f (x) · g (x) dx
0
Z 1

hf , A g i = f (x) · A† g (x) dx
0

The adjoint A† turns out to be the operator defined by:

(A† g )(x) = x · g (x)

P. Singh SOE, JNU Delhi


Introduction to quantum computing 19 / 26
Introduction References

This means that the adjoint operator A† of the original operator


A is obtained by multiplying the function g (x) by the complex
conjugate of x.
In summary, the adjoint operator A† for the given example is
such that:

(A† g )(x) = x · g (x)


This is just one illustrative example, and the specific form of
the adjoint depends on the particular linear operator and inner
product space under consideration.

P. Singh SOE, JNU Delhi


Introduction to quantum computing 20 / 26
Introduction References

1 Introduction

2 References

P. Singh SOE, JNU Delhi


Introduction to quantum computing 21 / 26
Introduction References

References I

[1] https://en.wikipedia.org/wiki/Bra%E2%80%93ket_
notation
[2] S. Haykin, M. Moher, Introduction to Analog and Digital Com-
munications, 2nd ed. Hoboken, NJ: John Wiley & Sons, Inc.,
2007.
[3] B.P. Lathi, Signal Processing and Linear Systems, Carmichael,
CA: Berkeley-Cambridge Press, 1998.
[4] P. Singh, S. D. Joshi, R. K. Patney, K. Saha, “The Fourier
decomposition method for nonlinear and non-stationary time
series analysis,” Proc. R. Soc. A, vol. 473 (2199), no. 20160871,
2017.

P. Singh SOE, JNU Delhi


Introduction to quantum computing 22 / 26
Introduction References

References II

[5] J.C.R. Hunt, J. C. Vassilicos, “Kolmogorov’s contributions to


the physical and geometrical understanding of small-scale tur-
bulence and recent developments,” Proc. R. Soc. Lond. A, vol.
434, pp. 183–210, 1991.
[6] Q. Chen, X. Lang, L. Xie, H. Su, “Multivariate intrinsic chirp
mode decomposition,” Signal Processing, vol. 183, no. 108009,
2021.
[7] J.S. Walker, Fourier series, Encyclopedia of Physical Science
and Technology, 3rd ed. San Diego: Academic Press, 2002.
[8] L. Carleson, “On convergence and growth of partial sums of
Fourier series,” Acta Math, vol. 116, pp. 137–157, 1966.

P. Singh SOE, JNU Delhi


Introduction to quantum computing 23 / 26
Introduction References

References III

[9] R.A. Hunt, “On the convergence of Fourier series, Orthogonal


Expansions and their Continuous Analogues,” Proc. Conf., Ed-
wardsville, Ill., 1967, Southern Illinois Univ. Press, Carbondale,
Ill., pp. 235–255, 1968.
[10] A.N. Kolmogorov, “Une série de Fourier–Lebesgue divergente
presque partout,” Fundamenta Mathematicae, vol. 4, pp. 324–
328, 1923.
[11] C. Candan, “Proper Definition and Handling of Dirac Delta
Functions [Lecture Notes],” IEEE Signal Processing Magazine,
vol. 38, no. 3, pp. 186–203, May 2021.
[12] P. Singh, Novel Generalized Fourier Representations and Phase
Transforms, Digital Signal Processing, 102830, 2020. https:
//www.ncbi.nlm.nih.gov/pmc/articles/PMC7416779/
P. Singh SOE, JNU Delhi
Introduction to quantum computing 24 / 26
Introduction References

References IV

[13] F.W King, Hilbert Transforms, Vol. 1, Cambridge University


Press, Cambridge, UK (2009).
[14] Singh P. 2018 Novel Fourier quadrature transforms and analytic
signal representations for nonlinear and non-stationary time-
series analysis. R. Soc. open sci. 5: 181131. http://dx.doi.
org/10.1098/rsos.181131
[15] N. Ahmed, T. Natarajan, K.R. Rao, Discrete Cosine Transform,
IEEE Trans. Computers, 90–93, (1974).
[16] P. Singh, A. Gupta, SD Joshi, General Parameterized Fourier
Transform: A Unified Framework for the Fourier, Laplace,
Mellin and Z Transforms,” IEEE Transactions on Signal Pro-
cessing, vol. 70, pp. 1295–1309, 2022,

P. Singh SOE, JNU Delhi


Introduction to quantum computing 25 / 26
Introduction References

Thank you for your attention!

P. Singh SOE, JNU Delhi


Introduction to quantum computing 26 / 26
1.4. Single-Qubit Quantum Gates 27

name operator
C D
1 0
identity I= = |v0 ÍÈv0 | + |v1 ÍÈv1 | for any orth. basis {|vx Í}1x=0
0 1
C D
0 1
Pauli X X= = |+ÍÈ+| ≠ |≠ÍÈ≠|
1 0
C D
1 0
Pauli Z Z= = |0ÍÈ0| ≠ |1ÍÈ1|
0 ≠1
C D
0 ≠i
Pauli Y Y = = | + iÍÈ+i| ≠ | ≠ iÍÈ≠i|
i 0

Table 1.4: Examples of single-qubit quantum gates expressed in terms of their


eigendecompositions (1.48) with unitary-magnitude eigenvalues.

Any unitary matrix U can be expressed in terms of a Hermitian


matrix G as
U = exp(≠iG). (1.54)
The Hermitian matrix G is known as the generator – or, in physics,
as the Hamiltonian – of the unitary U . Recall that a function of a
normal matrix is defined as in (1.47).
It can be easily checked that a matrix in the form (1.54) is indeed
unitary. In fact, the defining property (1.32) of unitary matrices is
verified as
U † U = exp(iG† ) exp(≠iG) = exp(iG† ≠ iG) = I = U U † , (1.55)
where we have used the property (1.53), i.e., the equality G† = G.
As an example of the characterization (1.54), the Pauli Y -rotation
matrix RY (◊) in Table 1.2 can be expressed as a function of the Pauli
Y matrix as 3 4

RY (◊) = exp ≠i Y , (1.56)
2
so that the generator matrix is given by the Hermitian matrix G =
(◊/2)Y . One can similarly define the Pauli X-rotation matrix
3 4

RX (◊) = exp ≠i X , (1.57)
2
Thomas G. Wong

Introduction to Classical and


Quantum Computing
Chapter 2
One Quantum Bit

By drawing parallels to classical computing from the previous chapter, we can in-
troduce quantum information and computation in a natural way. Since we have not
yet defined “quantum,” just take it to mean a different set of rules, which we will
bring up as they become relevant.

2.1 Qubit Touchdown: A Quantum Computing Board Game

Quantum physics has a reputation for being difficult and confusing, exacerbated by
(incorrect) references to quantum mechanics in movies to justify their sci-fi plot ele-
ments. To help reduce this intimidation factor and ease the introduction of quantum
computing, I made a board game called Qubit Touchdown. It is shown in Fig. 2.1,
and it is available print-on-demand from The Game Crafter.1
Qubit Touchdown is a two player game. It consists of a game board, shown in
Fig. 2.2a, an orange football token, a die with only zeros and ones on it, and fifty-
two action cards, shown in Fig. 2.2b. To start the game, one player “kicks off” by
rolling the binary die, and the football token starts at zero or one, depending on
the outcome of the roll. Beginning with the other player, players take turns playing
action cards, which move the football according to the lines and arrows
p on the game
board. For example, at position 0, H moves the ball to position +; X moves the
ball to i; X and Y move the ball to 1; and Z, I, and S keep the ball at position 0.
For the measurement card, if the football is at 0 or 1, nothing happens. Otherwise,
one kicks off again by rolling the binary die. When a player scores a touchdown by
moving the ball into their opponent’s endzone, they roll the die to kick off again,
and play continues with the other player. Whoever scores the most touchdowns, by
the time all the action cards have been used, wins.
All of these game mechanics come from quantum computing.

1 https://www.thegamecrafter.com/games/qubit-touchdown

73
74 2 One Quantum Bit

Fig. 2.1: The complete Qubit Touchdown board game.

It is not necessary to play Qubit Touchdown in order to continue with this text-
book.
Exercise 2.1. In Qubit Touchdown,psay the ball is at position 0. Where would it move if you played
(a) X, (b) Y , (c) Z, (d) H, (e) S, (f) X, (g) I, (h) measurement?

Exercise 2.2. In Qubit Touchdown,psay the ball is at position i. Where would it move if you played
(a) X, (b) Y , (c) Z, (d) H, (e) S, (f) X, (g) I, (h) measurement?

2.2 Superposition

2.2.1 Zero or One

A quantum bit, or qubit, is both similar to and different from a classical bit in some
important ways. First, like a classical bit, a qubit can take two values, 0 or 1. Using
bra-ket notation or Dirac notation from quantum physics, we write 0 and 1 enclosed
between a vertical bar and an angle bracket called a ket:

|0i, |1i.

Although it may seem strange to write a quantum 0 and a quantum 1 like this, it will
be very useful later.
We can visualize these distinct states, |0i and |1i, as the north and south poles of
a sphere of radius 1 called the Bloch sphere:
2.2 Superposition 75

(a) (b)

Fig. 2.2: The Qubit Touchdown (a) game board and (b) action cards.
76 2 One Quantum Bit

z
|0i

y
x

|1i

Following the standard physics convention, the x-axis comes out of the page, the
y-axis points to the side, and z-axis is oriented up. Then, since the Bloch sphere
has radius 1, |0i corresponds to the (x, y, z) point (0, 0, 1), and |1i corresponds to
(0, 0, 1).

2.2.2 Superposition

If we had a classical bit, |0i and |1i would be the only two states. But, the laws of
quantum mechanics allow the state of a qubit to be a combination of |0i and |1i,
called a superposition of |0i and |1i. For example, here is a state that is equal parts
|0i and |1i:
1
p (|0i + |1i) .
2
p p
In this state, the coefficient of |0i is 1/ 2, and the coefficient of |1i is also 1/ 2.
So, it is equal parts |0i and |1i. Given this, it should be on the equator of the Bloch
sphere, which is halfway between the north and south poles:
z

y
x

This state is at the (x, y, z) point (1, 0, 0), where the Bloch sphere intersects the x-
axis. Later, we will learn how to calculate these coordinates, but for now, we will
focus on building geometric intuition.
2.2 Superposition 77

There are many other states on the equator of the Bloch sphere, all of which are
equal parts |0i and |1i. We can reach them by changing the relative phase of |0i and
|1i. For example, if we instead use a negative sign, we get
z

1
p (|0i |1i)
2 y
x

This state is at the point ( 1,p


0, 0), on the x-axis. To reach the y-axis at (0, 1, 0),
we instead use a phase of i = 1:
z

1
p (|0i + i|1i)
2 y
x

We see that imaginary and complex numbers are used in quantum computing. In
case it has been a while since you have used them, in the next section, we will
review complex numbers in detail. Continuing, to reach the y-axis at (0, 1, 0),
we use a phase of i:
z

1
p (|0i i|1i)
2 y
x
78 2 One Quantum Bit

These states appear frequently enough that they have names: “plus,” “minus,” “i,”
and “minus i”:
1
|+i = p (|0i + |1i) ,
2
1
| i = p (|0i |1i) ,
2
(2.1)
1
|ii = p (|0i + i|1i) ,
2
1
| ii = p (|0i i|1i) .
2
Drawing them together with |0i and |1i on the Bloch sphere, we get the following,
which also appears on the back of every action card in Qubit Touchdown:

z
|0i

| i
| ii
|ii
|+i y
x

|1i

In Qubit Touchdown, these six states correspond to the six positions on the game
board in Fig. 2.2a. The football token corresponds to a qubit, so the ball moving
around the game board corresponds to a qubit changing between these states (more
on this later).
Of course, there are many other points on the equator of the Bloch sphere. We
can reach them using other complex phases, such as
2.2 Superposition 79

1 ⇣ ⌘
p |0i + ei⇡/6 |1i
2 y
x

Superpositions are not restricted to the equator, either. They can favor |0i or |1i by
being in the northern or southern hemisphere, such as
p
3 1 2 1 2i
|0i + |1i |0i + |1i
2 2 3 3
z z

y y
x x

In fact,

A qubit can be any point on the Bloch sphere.

Again, we will later see how to calculate where a quantum state is on the Bloch
sphere. Before we do that, however, we need to review complex numbers and discuss
measuring qubits.
Exercise 2.3. Draw a Bloch sphere and label the following locations:
(a) Where a qubit is exactly |0i.
(b) Where a qubit is exactly |1i.
(c) Where a qubit is half |0i and half |1i.
(d) Where a qubit is more |0i than |1i.
(e) Where a qubit is more |1i than |0i.
80 2 One Quantum Bit

2.2.3 Review of Complex Numbers

A complex number z is a number with a real part x plus i times an imaginary part y:

z = x + iy.
p
For example, 1 + i 3 is a complex number. The parts are called components. We
denote the real component of z as ¬(z), and it just equals x:

¬(z) = x.

Similarly, we denote the imaginary component as ¡(z), and it just equals y:

¡(z) = y.
p p p
For example, ¬(1 + i 3) = 1 and ¡(1 + i 3) = 3. Real numbers are complex
numbers; their imaginary parts are just zero. Similarly, imaginary numbers are com-
plex numbers; their real parts are just zero.
The above form x + iy is called the Cartesian form or rectangular form of a com-
plex number. In quantum computing, it is often useful to write a complex number
as its length r times its complex phase eiq :

z = reiq .

This is called the polar form of a complex number, and any complex number can be
written this way. To convert from the Cartesian form x + iy to the polar form reiq ,
we use the following equations, which we will prove in a moment:
p
r = x2 + y2 , (2.2)
⇣y⌘
q = tan 1 . (2.3)
x
To convert from the polar form reiq to the Cartesian form x+iy, we use the following
equations, which we will also prove in a moment:

x = r cos q (2.4)
y = r sin q . (2.5)

These relationships can be proved a couple different ways:


• Geometrically, complex number is a point on the complex plane, which has the
real component as its x-axis and the imaginary component as its y-axis:
2.2 Superposition 81

Im
x + iy

r y

x Re

Its length is r, and the angle it makes counter-clockwise from the real axis is
q . Since x and y are the legs of a right triangle, and r is the hypotenuse, the
Pythagorean theorem 2 2 2
p says that x + y = r . Taking the square root of each
2 2
side, we get r = x + y , which proves Eq. (2.2).
Next, from the drawing, q is an angle in a right triangle, and y is opposite of
q , x is adjacent, and r is the hypotenuse. We can relate these quantities using
the trigonometric functions sine, cosine, and tangent.2 First, using sine, we get
sin q = y/r. Multiplying both sides by r, we get y = r sin q , which is Eq. (2.5).
Next using cosine, we get cos q = x/r. Multiplying both sides by r, we get
x = r cos q , which is Eq. (2.4). Finally, using tangent, we get tan q = y/x. Taking
the inverse tangent of both sides, we get q = tan 1 (y/x), which is Eq. (2.3).
• Algebraically, we can write a complex phase in Cartesian form using Euler’s
formula, which says says that

eiq = cos q + i sin q . (2.6)

If you have taken more advanced math than is required for this textbook, you
may be familiar with Euler’s formula and its proof. (It is typically seen during
the second semester of calculus.) If not, no worries. You do not need to know
where it comes from. It is simple enough to memorize now, which you should
do, since it will show up again.
Now using Euler’s formula, we can write the polar form of a complex number
as
z = reiq = r (cos q + i sin q ) = r| cos
{z q} +i r| sin
{z q} .
x y

Thus, the real part of z is x = r cos q , which is Eq. (2.4), and the imaginary part
is y = r sin q , which is Eq. (2.5). If we take the sum of the squares of these
components, we get

x2 + y2 = r2 cos2 q + r2 sin2 q = r2 (cos2 q + sin2 q ) = r2 .


| {z }
1

2 Many people remember the trigonometric functions using the mnemonic SOH-CAH-TOA, where
sine is opposite over hypotenuse (SOH), cosine is adjacent over hypotenuse (CAH), and tangent is
opposite over adjacent (TOA).
82 2 One Quantum Bit

In the last equality, we used the Pythagorean identity sin2 q +p cos2 q = 1 from
trigonometry. Taking the square root of both sides, we get r = x2 + y2 , which
proves Eq. (2.2). Next, if we divide y = r sin q by x = r cos q , we get

y sin q
= = tan q .
x cos q
Taking the inverse tangent of both sides, we get Eq. (2.3).
p
For example, say we have a complex number in Cartesian
q form, z = 1+i 3. To con-
p 2 p p
vert this to polar form, we calculate its length r = 12 + 3 = 1 + 3 = 4 = 2
p
and angle q = tan 1 ( 3/1) = p/3 radians or 60 . The convention is to use radians,
so putting these together, the polar form is z = 2eip/3 .
There are a few more aspects of complex numbers that come up frequently in
quantum computing, so let us review them now:
• The complex conjugate (or just conjugate) of a complex number is the complex
number obtained by negating its imaginary part. That is, we replace i with i.
We denote the complex conjugate of z as z⇤ , so if z = x + iy = reiq , then

z⇤ = x iy = re iq .
p ⇤ p ⇤
From the previous example, 1 + i 3 = 1 i 3 and 2eip/3 = 2e ip/3 .
• The norm of a complex number z, which we denote |z|, is simply its length r:

|z| = r.
p
Then from the previous example, |1 + i 3| = 2, since its length r is 2.
• The norm-square of a complex number z, which we denote |z|2 , is simply the
square of its norm, so it is r2 :
|z|2 = r2 .
p
From the previous example, |1 + i 3|2 = 4. One way to calculate the norm-
square is multiplying a complex number by its conjugate:

|z|2 = z⇤ z = zz⇤ . (2.7)

We can prove that this works using either the Cartesian or polar form. In Carte-
sian form,

zz⇤ = (x + iy)(x iy) = x2 ixy + ixy i2 y2 = x2 + y2 = r2 = |z|2 ,


p 2
where in the third step, we used i2 = 1 = 1. In polar form,

zz⇤ = reiq re iq
= r2 eiq iq
= r2 e0 = r2 = |z|2 .

Finally, Eq. (2.7) gives us another way to find the norm of z, by taking the square
root of z times its conjugate z⇤ :
2.3 Measurement 83
q p p
|z| = |z|2 = z⇤ z = zz⇤ .

Exercise 2.4. Consider the complex number z = 1 + 2i.


(a) Find ¬(z).
(b) Find ¡(z).
(c) Plot z as a point in the complex plane.
(d) Write z in polar form reiq .
(e) Find z⇤ .
(f) Find |z|.
(g) Find |z|2 .

Exercise 2.5. Consider the complex number z = 3 i.


(a) Find ¬(z).
(b) Find ¡(z).
(c) Plot z as a point in the complex plane.
(d) Write z in polar form reiq . Hint: The angle should be between p and 3p/2 (i.e., 180 and
270 ).
(e) Find z⇤ .
(f) Find |z|.
(g) Find |z|2 .

2.3 Measurement

2.3.1 Measurement in the Z-Basis

In a previous section, we had the following qubit, which was on the equator of the
Bloch sphere:
z

1 ⇣ ⌘
p |0i + ei⇡/6 |1i
2 y
x

Although the laws of quantum mechanics permit this superposition of |0i and |1i,
it also demands that if we measure the qubit, such as at the end of a computation
in order to read the result, we get a single, definite value. That is, we get |0i or
|1i, each with some probability, not a superposition of |0i and |1i. Geometrically,
this particular qubit lies on the equator, halfway between the north and south poles,
so if we measure it, we get |0i with probability 1/2 or |1i with probability 1/2. To
84 2 One Quantum Bit

calculate these probabilities, we take the norm-square of the coefficient of |0i or |1i.
That is, the probability of getting |0i is
2
1 1
p = ,
2 2

and the probability of getting |1i is


2
eip/6 eip/6 e ip/6 e0 1
p = p p = = .
2 2 2 2 2

The coefficients are called amplitudes, so:

The probability is given by the norm-square of the amplitude.

Let us look at another example, which we also saw earlier:


z

2 1 2i
|0i + |1i y
3 3
x

Geometrically, since the qubit is closer to the south pole, we expect that the prob-
ability of getting |1i is greater than the probability of getting |0i. To get the exact
probabilities, we calculate the norm-square of each amplitude:
2
2 4
= ,
3 9

and
2
1 2i 1 2i 1 + 2i 1 + 2i 2i 4i2 5
= = = .
3 3 3 9 9
So, if we measure the qubit, the probability of getting |0i is 4/9, and the probability
of getting |1i is 5/9. As expected, the probability of getting |1i is greater than the
probability of getting |0i, and also note that the total probability is 4/9 + 5/9 = 1,
as it must.
Exercise 2.6. A qubit is in the state
2.3 Measurement 85
p
1+i 3 2 i
|0i + |1i.
3 3
If you measure the qubit, what is the probability of getting
(a) |0i?
(b) |1i?

Say a qubit is superposition of |0i and |1i. Say we measure it, and the outcome
is |0i. Now for something new: The qubit is no longer in a superposition of |0i and
|1i. It is now simply |0i, and we know because we measured it. Measuring the qubit
changed it. It forced it to take a stand. We say the state has collapsed to |0i. If we
measure the qubit again, we get |0i with probability 1. This aspect of measurement
is important enough to box:

Measurement collapses the qubit.

In Qubit Touchdown, playing the measurement action card, or kicking off after a
touchdown, corresponds to measuring the qubit. For the measurement action card,
if the ball is at position 0 or 1, then nothing happens, just like measuring a qubit in
state |0i or |1i returns the same state with probability 1. If the ball is at position i or
i, then the binary die is rolled, and the ball is moved to 0 or 1 with 50% probability
each, just like measuring a qubit in the |ii or | ii states collapses the state to |0i or
|1i with 50% probability. Finally, after scoring a touchdown, the ball is either at the
+ or positions in the endzones. Then, the binary die is rolled, moving the ball
to 0 or 1 with 50% probability each. In the same way, when a qubit is in the |+i
or | i state, measuring it yields |0i or |1i with 50% probability each, and the state
collapses to whichever state was measured.
Exercise 2.7. A qubit is in the state

2 1 + 2i
|0i + |1i.
3 3
Say you measure the qubit and get |0i. If you measure the qubit a second time, what is the proba-
bility of getting
(a) |0i?
(b) |1i?

2.3.2 Normalization

We say a quantum state is normalized if its total probability is 1, as it should be.


Sometimes, we must find an overall normalization constant to make this true. For
example, a qubit is in the state
⇣p ⌘
A 2|0i + i|1i .
86 2 One Quantum Bit

We normalize this state by finding the normalization constant A that ensures that the
total probability is 1. So,
p p
1 = (A 2)(A 2)⇤ + (Ai)(Ai)⇤
= 2|A|2 + |A|2
= 3|A|2
1
|A|2 = .
3
As we will prove later, the overall phase does not matter, so we might as well pick
A to be real. Thus,
1
A= p ,
3
and the normalized state is
1 ⇣p ⌘
p 2|0i + i|1i .
3

Exercise 2.8. A qubit is in the state


eip/8
p |0i + b |1i.
5
What is a possible value of b ?

Exercise 2.9. A qubit is in the state


⇣ ⌘
A 2eip/6 |0i 3|1i .

(a) Normalize the state (i.e., find A).


(b) If you measure the qubit, what is the probability that you get |0i?
(c) If you measure the qubit, what is the probability that you get |1i?

2.3.3 Measurement in Other Bases

Even though we introduced |0i and |1i as the north and south poles, respectively, of
the Bloch sphere, the Bloch sphere is not a planet, and it is not spinning. Then, any
two opposite points could be taken as the north and south poles. For example, |+i
and | i could be the north and south poles, or |ii and | ii, or any opposite points.
A set of distinct measurement outcomes is called a basis, and {|0i, |1i} is called the
Z-basis because they lie on the z-axis of the Bloch sphere. Similarly, {|+i, | i} is
called the X-basis because they lie on the x-axis of the Bloch sphere, and {|ii, | ii}
is called the Y -basis because they lie on the y-axis of the Bloch sphere. We can
measure with respect to any of these bases, or with respect to any two states on
opposite sides of the Bloch sphere.
For example, consider a qubit in the state
2.3 Measurement 87
p
3 1
|0i + |1i,
2 2
which appears on the Bloch sphere at an angle of 30 above the x-axis, as shown
below:
z
p
3 1 |0i
|0i + |1i
2 2
| i
| ii •
|ii
|+i y
x

|1i

Let us measure this with respect to four different bases: the Z-basis {|0i, |1i}, the
X-basis {|+i, | i}, the Y -basis {|ii, | ii}, and a fourth basis (below).
1. If we measure the qubit in the Z-basis {|0i, |1i}, then we get |0i with probability
3/4 or |1i with probability 1/4.
2. What if we measure in the X-basis {|+i, | i} instead? Geometrically, the prob-
ability of getting |+i should be much higher than the probability of getting | i
because the state is so much closer to |+i on the Bloch sphere. To calculate the
probabilities precisely, we need to express the state in terms of |+i and | i so
that we can identify the amplitudes and then find their norm-squares. From the
definitions of |+i and | i in Eq. (2.1), we have

1 1
|0i = p (|+i + | i) , |1i = p (|+i | i) .
2 2
Substituting into the state of our qubit,
p p
3 1 3 1 1 1
|0i + |1i = p (|+i + | i) + p (|+i | i)
2 2 2 2 2 2
p p
3+1 3 1
= p |+i + p | i.
2 2 2 2
Now the amplitudes are easy to identify, and we can find the probabilities by
taking their norm-squares. The probability of measuring |+i is
p 2 p
3+1 3+2
p = ⇡ 0.93,
2 2 4

and the probability of measuring | i is


88 2 One Quantum Bit
p 2 p
3 1 3+2
p = ⇡ 0.07.
2 2 4

This is consistent with the Bloch sphere, since the state is much closer to |+i
than it is to | i.
3. Now what if we measure in the {|ii, | ii} basis? Geometrically, the Bloch
sphere reveals that the state is halfway between |ii and | ii, so we get one
or the other with probability 1/2 each. We can also calculate this by rewrit-
ing the state in terms of |ii and | ii and then finding the norm-square of the
amplitudes. From the definitions of |ii and | ii in Eq. (2.1),

1 i
|0i = p (|ii + | ii) , |1i = p (|ii | ii) .
2 2
Substituting,
p p
3 1 3 1 1 i
|0i + |1i = p (|ii + | ii) + p (|ii | ii)
2 2 2 2 2 2
p p
3 i 3+i
= p |ii + p | ii.
2 2 2 2
So, the probability of getting |ii is
p 2
3 i 3+1 1
p = = ,
2 2 8 2

and the probability of getting | ii is


p 2
3+i 3+1 1
p = = ,
2 2 8 2

as expected.
4. Consider the following two states, which we will call |ai and |bi:
p
3 i
|ai = |0i + |1i,
2 p 2
i 3
|bi = |0i + |1i.
2 2
Here they are on the Bloch sphere:
2.3 Measurement 89

z
p p
3 1 3 i
|0i + |1i |0i + |1i
2 2 2 2


y
x
p
i 3
|0i + |1i
2 2

|ai is located 30 above the y-axis, and |bi is located 30 below the y-axis.
(You will prove this in Exercise 2.16.) Since they are located on opposite points
of the Bloch sphere, they are a basis. Let us measure in this {|ai, |bi} basis.
Geometrically, the qubit is closer to |ai, so we expect a higher probability of
getting |ai than |bi. To calculate the precise numbers, we first write |0i and |1i
in terms of |ai and |bi:
p p
3 i i 3
|0i = |ai |bi, |1i = |ai + |bi.
2 2 2 2
Substituting, the state of our qubit is
p p p ! p !
3 1 3 3 i 1 i 3
|0i + |1i = |ai |bi + |ai + |bi
2 2 2 2 2 2 2 2
p
3 i 3(1 i)
= |ai + |bi.
4 4
Taking the norm-square of each amplitude, the probability of getting |ai is
2
3 i 9+1 5
= = ,
4 16 8

and the probability of getting |bi is


p 2
3(1 i) 3
= .
4 8

Later, when we describe qubits in the mathematics of linear algebra, we will see
another way to convert between bases.
Exercise 2.10. A qubit is in the state
p
1 3
|0i |1i.
2 2
90 2 One Quantum Bit

(a) If you measure it in the Z-basis {|0i, |1i}, what states can you get and with what probabilities?
(b) Write the qubit’s state in terms of |+i and | i.
(c) If you measure it in the basis {|+i, | i}, what states can you get and with what probabilities?

Exercise 2.11. The following two states are opposite points on the Bloch sphere:
p
3 i
|ai = |0i + |1i,
2 2
p
i 3
|bi = |0i + |1i.
2 2
So, we can measure relative to them. Now consider a qubit in the state
p
1 3
|0i |1i.
2 2
(a) Write the qubit’s state in terms of |ai and |bi.
(b) If you measure the qubit in the basis {|ai, |bi}, what states can you get and with what proba-
bilities?

2.3.4 Consecutive Measurements

We have already seen that measuring a qubit collapses the state to whatever was
measured. This can lead to interesting statistics, even more so if we change the
measurement basis. For example, consider the following three measurements:
1. Say we first measure the qubit in the Z-basis {|0i, |1i}. Then, the qubit collapses
to |0i or |1i.
2. Next, if we measure in the X-basis {|+i, | i}, then since both |0i and |1i are
halfway between |+i and | i, the qubit collapses to |+i or | i, each with
probability 1/2.
3. If we then measure in the Z-basis {|0i, |1i}, then since |+i and | i are halfway
between |0i and |1i, the probability of each is 1/2. We can continue alternating
between these two measurement bases, each time having a 50:50 chance of
getting each outcome.

Exercise 2.12. A qubit is in the state |0i. If you measure it in the X-basis {|+i, | i} and then
measure it again in the Z-basis {|0i, |1i}, what is the probability of getting
(a) |0i?
(b) |1i?

2.4 Bloch Sphere Mapping

We know that a qubit can be visualized as a point on the Bloch sphere. Now, let us
explain how to determine where the point should be.
2.4 Bloch Sphere Mapping 91

2.4.1 Global and Relative Phases

Say the qubit from the last section is multiplied by an overall, global phase:
p !
iq 3 1
e |0i + |1i ,
2 2

for some angle q . If we measure this in the Z-basis, {|0i, |1i} the probability of
getting |0i is
p 2
iq 3 3
e = ,
2 4

and the probability of getting |1i is


2
1 1
eiq = ,
2 4

as they were without the global phase. So, the phase does not change anything.
If we instead measure in the X-basis {|+i, | i}, then we can rewrite the state as
p p !
iq 3+1 3 1
e p |+i + p | i .
2 2 2 2

Then, the probability of getting |+i is


p 2 p
3+1 3+2
eiq p = ⇡ 0.93,
2 2 4

and the probability of measuring | i is


p 2 p
iq 3 1 3+2
e p = ⇡ 0.07,
2 2 4

as they were before without the global phase. So again, the phase does not change
anything.
This is true no matter what measurement basis we use, and it leads to the follow-
ing result:

Global phases are physically irrelevant.

As such, global phases can be dropped/ignored. States that differ by a global phase
are actually the same state; they correspond to the same point on the Bloch sphere.
Note that a relative phase is physically significant, such as
92 2 One Quantum Bit

1
|+i = p (|0i + |1i)
2
vs
1 1 ⇣ ⌘
|ii = p (|0i + i|1i) = p |0i + eip/2 |1i .
2 2
These correspond to different points on the Bloch sphere, and they can be distin-
guished by measurements in appropriate bases. Although measuring |+i and |ii in
the Z-basis yields the same statistics, i.e., |0i with probability 1/2 or |1i with prob-
ability 1/2, measuring in the X-basis {|+i, | i}yields different results. Measuring
|+i in the X-basis always yields |+i, but measuring |ii in the X-basis yields |+i or
| i with a 50:50 probability.
Exercise 2.13. Is there a measurement that can distinguish the following pairs of states? If yes,
give a measurement. If no, explain your reasoning.
1 eip/8
(a) |+i = p (|0i + |1i) and eip/8 |+i = p (|0i + |1i).
2 2
1 1
(b) |+i = p (|0i + |1i) and | i = p (|0i |1i).
2 2
(c) |0i and eip/4 |0i.

2.4.2 Spherical Coordinates

A generic quantum state is typically called y (the Greek letter “psi,” which is pro-
nounced “sigh”), and since it is quantum, we write it as a ket |yi. Now say we have
a generic qubit |yi with some amplitudes a and b :

|yi = a|0i + b |1i,

where |a|2 + |b |2 = 1 for normalization. Since the global phase does not matter, we
can assume that a is real and positive, and b may be complex. To determine the
location of this qubit on the Bloch sphere, we first parameterize, or write in terms
of other parameters, a and b in terms of two angles q and f :
✓ ◆ ✓ ◆
q q
a = cos , b = eif sin .
2 2

With 0  q  p and 0  f < 2p, this captures all the properties we need: a is
real and positive, b is complex, and the state is normalized. Substituting, we have
rewritten the qubit’s state as
✓ ◆ ✓ ◆
q q
|yi = cos |0i + eif sin |1i. (2.8)
2 2

Let us work through an example. Say a qubit is in the state


2.4 Bloch Sphere Mapping 93
p
3+i 3 1
|0i |1i.
4 2
We see that the amplitude of |0i is complex, but in Eq. (2.8),
p it needs
p to be real. To
make it real, we first convert it to polar form. Since (3 + i 3)/4 = ( 3/2)eip/6 , the
state is p
3 ip/6 1
e |0i |1i.
2 2
Factoring, this becomes
p ! p
ip/6 3 ip/6 1 3 1
e |0i e |1i ⌘ |0i e ip/6 |1i,
2 2 2 2

where ⌘ denotes “equivalent to,” and the states are equivalent because the global
phase does not matter and can be dropped. Comparing this to the Bloch sphere
parameterization in Eq. (2.8), we still need to change the minus sign to a plus sign.
We can do this using eip = 1. Then, the state is
p p
3 ip ip/6 1 3 1
|0i + e e |1i = |0i + ei5p/6 |1i.
2 2 2 2
Now it takes the form of Eq. (2.8), and we identify
✓ ◆ p ✓ ◆
q 3 q 1
cos = , eif = ei5p/6 , sin = .
2 2 2 2

Solving the first or last equation for q using the inverse cosine or inverse sine, and
solving the second equation for f , we get

p 5p
q= , f= .
3 6
Thus, plugging into Eq. (2.8), the state of the qubit is equivalent to
✓ ◆ ✓ ◆
p/3 p/3
cos |0i + ei5p/6 sin |1i.
2 2

Next, to map this qubit to a location on the Bloch sphere, we identify q and f as
the following angles:
94 2 One Quantum Bit
z


y

So, q measures the angle down from the north pole, called the polar angle, and
f measures the angle across from the x-axis in the xy plane, called the azimuthal
angle. If you have taken more advanced mathematics than is required for this book,
these are precisely spherical coordinates with a radius of 1. Spherical coordinates
are typically covered in the third semester of calculus, but everything you need for
this textbook will be explained here.
Returning to our example, we had q = p/3 and f = 5p/6, so the state is located
on the Bloch sphere at an angle of p/3 or 60 from the north pole, and 5p/6 or 150
rotated to the side:
z

p
3+i 3 1
|0i |1i y
4 2
x

Exercise 2.14. A qubit is in the state

1
|ii = p (|0i + i|1i) .
2
(a) Where on the Bloch sphere is this state? Give your answer in (q , f ) coordinates.
(b) Sketch the point on the Bloch sphere.

Exercise 2.15. A qubit is in the state


p
1 i 3
p |0i + |1i.
2 2 2

(a) Where on the Bloch sphere is this state? Give your answer in (q , f ) coordinates.
2.4 Bloch Sphere Mapping 95

(b) Sketch the point on the Bloch sphere.

Exercise 2.16. Consider the following two states from Exercise 2.11:
p
3 i
|ai = |0i + |1i,
2 2
p
i 3
|bi = |0i + |1i.
2 2
Prove these are opposite points of the Bloch sphere by finding their points in spherical coordinates
(qa , fa ) and (qb , fb ). Verify that qb = p qa and fb = fa + p, which means they lie on opposite
points of the Bloch sphere.

2.4.3 Cartesian Coordinates

We can also determine the (x, y, z) coordinates, called Cartesian coordinates, of a


point on the Bloch sphere. To see how to determine these from the spherical coordi-
nates (q , f ), let us first zoom in and focus on the polar angle q :
z z

sin

cos ✓

✓ zoom
! 1
y

y

x
In this picture, we drew a dashed line from the point to the z-axis, perpendicular to
it. This creates a right triangle, which we shaded gray. Since the radius of the Bloch
sphere is 1, the hypotenuse of the gray triangle is 1, which we labeled in the picture.
Then, since sin q is opposite over hypotenuse, and the hypotenuse is 1, we get that
sin q is the opposite side, which we labeled in the picture. Similarly, since cos q is
adjacent over hypotenuse, and the hypotenuse is 1, we get that cos q is the adjacent
side, which we also labeled in the picture. This adjacent side gives the z-coordinate
(height) of the point, i.e., z = cos q .
To get the x and y coordinates, we look at the projection onto the xy-plane:
96 2 One Quantum Bit
z

sin

cos ✓
1

os y
✓c
sin

sin

sin ✓ sin
x

First, we copied sin q from the top dashed line to below, since they are opposite sides
of a rectangle. This is the hypotenuse of the bottom gray triangle. Then, since sin f
is opposite over hypotenuse, we get that the opposite side is equal to the hypotenuse
times sin f , or sin q sin f , which we labeled in the drawing. This corresponds to
the y-coordinate (distance to the right) of the point, i.e., y = sin q sin f . Similarly,
since cos f is adjacent over hypotenuse, we get that the adjacent side is equal to
the hypotenuse times cos f , or sin q cos f . This is labeled as the left side of the
gray triangle in the drawing, and it corresponds to the x-coordinate (distance out of
the page), i.e., x = sin q cos f . Combining these results with the z-coordinate, we
can convert from spherical coordinates to Cartesian coordinates using the following
formulas:

x = sin q cos f ,
y = sin q sin f ,
z = cos q .

Continuing the previous example, we had q = p/3 and f = 5p/6, so the (x, y, z)
coordinates are of the qubit are
⇣p ⌘ ✓ ◆ p p
5p 3 3 3
x = sin cos = · = ,
3 6 2 2 4
⇣ p ⌘ ✓ 5p ◆ p p
3 1 3
y = sin sin = · = ,
3 6 2 2 4
⇣p ⌘ 1
z = cos = .
3 2
p
So, the qubit corresponds to point ( 3/4, 3/4, 1/2) on the Bloch sphere.
Exercise 2.17. In Cartesian (x, y, z), coordinates, where on the Bloch sphere is the state from
(a) Exercise 2.14?
(b) Exercise 2.15?
2.5 Physical Qubits 97

2.5 Physical Qubits

Physically, any quantum system with two distinct states can be used as a qubit.
While one is not expected to be familiar with quantum physics, some examples
include:
• Photons, or quantum particles of light, have a property called polarization. A
photon’s polarization can be vertical or horizontal, or a superposition of both,
and we can use this as a qubit.
• Trapped ions. An ion is an atom that has an overall charge (instead of being
neutral) because it has gained or lost one or more electrons. Individual ions can
be trapped in space using electric fields. Two energy levels of an ion can be used
as a qubit.
• Cold atoms. Neutral atoms can be trapped at low temperatures using a magneto-
optical trap, which uses magnetic fields and lasers to cool and trap the atoms.
Another approach is using an optical lattice constructed by laser beams. Once
trapped, two energy levels of an atom can be used as a qubit.
• Nuclear magnetic resonance. The nuclei of atoms and molecules have a quan-
tum property called spin, which can be used as a qubit. Spins can be identified
by their frequency of precession when subject to a strong magnetic field.
• Quantum dots. An electron can be bound to a small semiconductor device, sim-
ilar to an electron bound to the nucleus of an atom. In these “artificial atoms,”
the spin of an electron, which can be “spin up” or “spin down,” can be used as
a qubit.
• Defect qubits. A diamond crystal may have a missing carbon atom, and if we
replace a carbon atom next to this vacancy with a nitrogen atom, we get a
“spin triplet” that can be used for quantum computing. This is called a nitrogen-
vacancy center in diamond.
• Superconductors. In a superconducting circuit, charge flows with zero resis-
tance. The magnetic flux across an inductor and the charge on a capacitor
cause a harmonic potential energy with equally spaced, discrete energy levels.
A Josephson junction is a thin insulating layer that is added, and it changes the
potential energy so that the energy levels become unequally spaced. Then, the
energy levels can be distinguished, and two of them can be used as a qubit.
Informationally, these systems contain the same amount of information: two distinct
quantum states. So we simply use |0i and |1i for the rest of the discussion.
Exercise 2.18. A review of various ways to build a quantum computer is the article “Quantum
Computers” by Ladd et al. (2010). The published version in Nature 464, 45–53 is available at
https://dx.doi.org/10.1038/nature08812, but it may require a subscription. Search
through the text and fill in the blanks:
(a) Photons: “Realizing a qubit as the state of a photon is appealing because
photons are relatively free of the that plagues other quantum systems.”
(b) Trapped ions: “Individual atomic ions can be confined in free space with nanometre precision
using appropriate from nearby electrodes.”
(c) Cold atoms: “An array of cold neutral atoms may be confined in free space by a pattern of
crossed , forming an optical lattice.”
98 2 One Quantum Bit

(d) Nuclear magnetic resonance: “In a , nuclear Larmor frequencies vary


from atom to atom [...] Irradiating the nuclei with resonant pulses allows
manipulation of nuclei of a distinct frequency, giving generic gates.”
(e) Quantum dots: “These ‘artificial atoms’ occur when a small semiconductor nanostructure, im-
purity or impurity complex binds one or more electrons or holes (empty valence-band states)
into a localized potential with ,
which is analogous to an electron bound to an .”
(f) Doped solids: “ may then be stored in either the
donor electron, or in the state of the single 31 P nuclear spin, accessed via the electron-nuclear
coupling.”
(g) Nitrogen-vacancy centers: “The state of a nitrogen-vacancy centre may
then be coherently manipulated with resonant fields, and then detected
in a few milliseconds via spin-dependent fluorescence in an micro-
scope.”
(h) Superconductors: “There are three basic types of superconducting qubits— ,
and .”

Exercise 2.19. Visit https://en.wikipedia.org/wiki/List_of_companies_invo


lved_in_quantum_computing_or_communication for a list of companies involved in
quantum computing. For each of the following types of qubits, name a company that is using them.
(a) Photons
(b) Trapped ions
(c) Cold atoms
(d) Nuclear magnetic resonance (NMR)
(e) Quantum dots
(f) Defect qubits
(g) Superconductors

Exercise 2.20. Visit https://qubitzoo.org and pick your favorite qubit.


(a) What is the name of your qubit? (e.g., exchange-only qubit, not Steve.)
(b) What type of technology is your qubit?
(c) What is some motivation for building a qubit this way?

Exercise 2.21. Visit https://en.wikipedia.org/wiki/Qubit#Physical_impleme


ntations and pick a qubit.
(a) What is the physical system or technology used for your qubit (physical support)?
(b) What is the name of your type of qubit?
(c) What physical property is used to store information (information support)?
(d) What state is typically used for |0i?
(e) What state is typically used for |1i?

2.6 Quantum Gates

2.6.1 Linear Maps

Quantum gates act on qubits, like logic gates act on bits. In this section, we will
explore what quantum gates are.
A quantum gate transforms the state of a qubit into other states. As we will
see later, we often use the capital letter U to denote a quantum gate. For example,
consider a quantum gate that performs the following map:
2.6 Quantum Gates 99
p
2 i 1
U|0i = |0i |1i,
2 p 2
1 2+i
U|1i = |0i + |1i.
2 2
A quantum gate must be linear, meaning we can distribute it across superpositions:

U(a|0i + b |1i) = aU|0i + bU|1i


p ! p !
2 i 1 1 2+i
=a |0i |1i + b |0i + |1i
2 2 2 2
p ! p !
2 i 1 1 2+i
= a +b |0i + a +b |1i.
2 2 2 2

For this to be a valid quantum gate, the total probability must remain 1. Assuming
the original state was normalized, i.e., |a|2 + |b |2 = 1, we can calculate the total
probability by summing the norm-square of each amplitude to see if it is still 1:
p 2 p 2
2 i 1 1 2+i
a +b + a +b
2 2 2 2
p ! p !
2 i 1 ⇤ 2+i ⇤1
= a +b a +b
2 2 2 2
p ! p !
1 2+i 1 2 i
+ a +b a⇤ + b ⇤
2 2 2 2
p p p p
2 ( 2 i)( 2 + i) ⇤ 2 i ⇤ 2+i 1
= |a| + ab +ba + |b |2
4 p p4 p4 p 4
21 ⇤ 2 i ⇤ 2+i 2 ( 2 + i)( 2 i)
+ |a| ab ba + |b |
4 4 4 4
3 1 1 3
= |a|2 + |b |2 + |a|2 + |b |2
4 4 4 4
= |a|2 + |b |2
= 1.

So, U is a valid quantum gate. Then,

Quantum gates are linear maps that keep the total probability equal to 1.

In the next chapter, when we introduce linear algebra, we will learn that operators
correspond to tables of numbers called matrices, and a valid quantum gate is a type
of matrix called a unitary matrix. That is why quantum gates are often labeled U,
for unitary.
100 2 One Quantum Bit

Exercise 2.22. Consider a map U that transforms the Z-basis states as follows:

U|0i = |0i + |1i,


U|1i = |0i |1i.

Say |yi = a|0i + b |1i is a normalized quantum state, i.e., |a|2 + |b |2 = 1.


(a) Calculate U|yi.
(b) From your answer to (a), is U a valid quantum gate? Explain your reasoning.

Exercise 2.23. Consider a map U that transforms the Z-basis states as follows:
p p
3 3+i
U|0i = |0i + |1i,
2 4
p p
3+i 3 + 3i
U|1i = |0i |1i.
4 4
Say |yi = a|0i + b |1i is a normalized quantum state, i.e., |a|2 + |b |2 = 1.
(a) Calculate U|yi.
(b) From your answer to (a), is U a valid quantum gate? Explain your reasoning.

2.6.2 Classical Reversible Gates

Recall from Section 1.5 that a classical logic gate is reversible if its outputs are
unique. For example, a gate with input A and output B with the following truth table
is reversible, since it is always possible to determine the input from the output:
AB
0 1
1 0
Thus, the gate does the following to a bit:

0 ! 1,
1 ! 0.

How would this gate act on a qubit? It would map the following:

Gate|0i = |1i,
Gate|1i = |0i.

Then, acting on a superposition a|0i + b |1i, where |a|2 + |b |2 = 1, it would do the


following:
Gate (a|0i + b |1i) = a|1i + b |0i = b |0i + a|1i.
We see that a and b simply got swapped. So, the final state is normalized, since

|b |2 + |a|2 = |a|2 + |b |2 = 1.
2.6 Quantum Gates 101

Thus, this classical reversible logic gate is also a valid quantum gate.
This is true in general. Any classical reversible logic gate simply permutes (shuf-
fles) the amplitudes around. This chapter is just on a single qubit, but jumping ahead
to Chapter 4 on multiple qubits, if there were more than two amplitudes, a classical
reversible logic gate would just permute them, so the state stays normalized. Thus,

Classical reversible logic gates are valid quantum gates.

In contrast, irreversible gates are not valid quantum gates. For example, consider
the irreversible gate with the following truth table:
AB
0 0
1 0
This would act on the basis states of a qubit as:

Gate|0i = |0i,
Gate|1i = |0i.

Then, acting on a superposition,

Gate (a|0i + b |1i) = a|0i + b |0i = (a + b )|0i.

Now, the amplitudes are not permuted. Instead, they are combined. The total prob-
ability of this is

|a + b |2 = |a|2 + |b |2 + a ⇤ b + ab ⇤ = 1 + a ⇤ b + ab ⇤ 6= 1,

so this is not a valid quantum gate.


Exercise 2.24. Consider each of the following classical logic gates with input A, output B, and
truth table shown below. Is each gate a valid quantum gate? Why?
(a) (b)
AB AB
0 0 0 1
1 1 1 1

Exercise 2.25. Consider each of the following classical logic gates with inputs A and B, outputs C
and D, and truth table shown below. Is each gate a valid quantum gate? Why?
(a) (b)
ABCD ABCD
0 0 0 1 0 0 0 0
0 1 1 1 0 1 0 0
1 0 0 0 1 0 1 0
1 1 1 0 1 1 1 1
102 2 One Quantum Bit

2.6.3 Common One-Qubit Quantum Gates

Although any probability-preserving linear map is a valid quantum gate, let us list
some important one-qubit gates that frequently appear in quantum computing:
• The identity gate turns |0i into |0i and |1i into |1i, hence doing nothing:

I|0i = |0i,
I|1i = |1i.

This is a classical reversible gate (the identity gate), so it keeps states normal-
ized and is a valid quantum gate.
In Qubit Touchdown, this corresponds to the Identity Gate action card, which
does nothing to the football’s position.
• The Pauli X gate, or NOT gate, turns |0i into |1i, and |1i into |0i:

X|0i = |1i,
X|1i = |0i.

This is a classical reversible gate (the NOT gate), so it keeps states normalized
and is a valid quantum gate.
On the Bloch sphere, it can be shown that X is a rotation about the x-axis by
180 :
z

y
x

With this rotation in mind, we geometrically see that X causes |0i (the north
pole) to rotate to |1i (the south pole), and vice versa. We also see that |ii and
| ii rotate to each other, whereas |+i and | i are unchanged. Note, however,
that mathematically X| i = | i ⌘ | i since the global phase does not matter.
If we apply the X gate twice, we rotate around the x-axis of the Bloch sphere
by 360 , which does nothing. Then, X 2 = I. We can use this fact to simplify
consecutive applications of X. For example,
500
X 1001 = X 1000 X = X 2 X = I 500 X = X.

In Qubit Touchdown, the Pauli X Gate action card corresponds to the X gate.
2.6 Quantum Gates 103

• The Pauli Y gate turns |0i into i|1i, and |1i into i|0i:

Y |0i = i|1i,
Y |1i = i|0i.

This is not a classical gate at all because of the i and i. Let us prove that it is
a valid quantum gate by acting on a general superposition:

Y (a|0i + b |1i) = a Y |0i +b Y |1i = ia|1i ib |0i = ib |0i + ia|1i.


|{z} |{z}
i|1i i|0i

The total probability of this is

| ib |2 + |ia|2 = ( ib )(ib ⇤ ) + (ia)( ia ⇤ ) = |b |2 + |a|2 = 1,

so it is a valid quantum gate.


On the Bloch sphere, it can be shown that Y is a rotation about the y-axis by
180 :
z

y
x

So, if we apply the Y gate twice, we rotate around the y-axis of the Bloch sphere
by 360 , which does nothing. Then, Y 2 = I. In Qubit Touchdown, the Pauli Y
Gate action card corresponds to the Y gate.
• The Pauli Z gate keeps |0i as |0i and turns |1i into |1i:

Z|0i = |0i,
Z|1i = |1i.

This is not a classical gate at all. In Exercise 2.28, you will show that this is a
valid quantum gate.
On the Bloch sphere, it can be shown that Z is a rotation about the z-axis by
180 :
104 2 One Quantum Bit

y
x

As before, Z 2 = I. In Qubit Touchdown, the Pauli Z Gate action card is the Z


gate.
Exercise 2.26. Calculate Z 217 X 101Y 50 (a|0i + b |1i).

Exercise 2.27. Prove that


(a) XZXZ(a|0i + b |1i) = (a|0i + b |1i).
(b) ZXZX(a|0i + b |1i) = (a|0i + b |1i).
This will be used later in the textbook when we discuss Grover’s algorithm.

• Phase gate, which is the square root of the Z gate (i.e., S2 = Z):

S|0i = |0i,
S|1i = i|1i.

In Exercise 2.28, you will show that this is a valid quantum gate.
On the Bloch sphere, it can be shown that S is a rotation about the z-axis by 90 :
z

90

y
x

Now, S2 rotates by 90 twice, so it is equivalent to rotating by 180 . Then,


S2 = Z. We would need to apply S four times in order to return to the same point
on the Bloch sphere, so S4 = I. In Qubit Touchdown, the Phase Gate action card
is the S gate.
2.6 Quantum Gates 105

• T gate (also called p/8 gate), which is the square root the S gate (i.e., T 2 = S),
or fourth root of the Z gate:

T |0i = |0i,
T |1i = eip/4 |1i.

In Exercise 2.28, you will show that this is a valid quantum gate.
On the Bloch sphere, T is a rotation about the z-axis by 45 :
z

45

y
x

Then, it is obvious that T 2 = S and T 4 = Z, since rotating by 45 twice is


equivalent to rotating by 90 , and rotating by 45 four times is equivalent to
rotating by 180 .

Exercise 2.28. Consider the gate Rz (q ), which rotates about the z-axis by angle q :

Rz (q )|0i = |0i,
Rz (q )|1i = eiq |1i.

The Z gate, S gate, and T gate are all specific instances of the Rz gate, with Z = Rz (p), S = Rz (p/2),
and T = Rz (p/4). Say |yi = a|0i + b |1i is a normalized quantum state, i.e., |a|2 + |b |2 = 1.
(a) Calculate Rz (q )|yi.
(b) Show that the total probability of Rz (q )|yi is 1, so Rz (q ) is a valid quantum gate, and hence,
Z, S, and T are all valid quantum gates.

• The Hadamard gate turns |0i into |+i, and |1i into | i:

1
H|0i = p (|0i + |1i) = |+i,
2
1
H|1i = p (|0i |1i) = | i.
2
In Exercise 2.29, you will show that this is a valid quantum gate.
On the Bloch sphere, it can be shown that H is a rotation about the x + z-axis by
180 :
106 2 One Quantum Bit

x+z

y
x

Then, H maps between |0i and |+i, between |1i and | i, and between |ii and
| ii. Let us also prove these algebraically. From the definition of the Hadamard
gate, we already have H|0i = |+i and H|1i = | i. Going in the other direction,

1
H|+i = H p (|0i + |1i)
2
1
= p (H|0i + H|1i)
2

1 1 1
= p p (|0i + |1i) + p (|0i |1i)
2 2 2
= |0i,

and similarly (Exercise 2.30),

H| i = |1i.

We also have
1
H|ii = H p (|0i + i|1i)
2
1
= p (H|0i + iH|1i)
2

1 1 i
= p p (|0i + |1i) + p (|0i |1i)
2 2 2
✓ ◆
1 1+i 1 i
=p p |0i + p |1i
2 2 2
1 ⇣ ip/4 ⌘
= p e |0i + e ip/4 |1i
2
1 ⇣ ⌘
= eip/4 p |0i + e ip/2 |1i
2
ip/4 1
=e p (|0i i|1i)
2
2.6 Quantum Gates 107

= eip/4 | ii
⌘ | ii.

Similarly (Exercise 2.30),


ip/4
H| ii = e |ii ⌘ |ii.

If we apply the H gate twice, we rotates by 360 , which does nothing. So,
H 2 = I.
In Qubit Touchdown, the Hadamard Gate action card is the Hadamard gate,
which is why it moves the football between 0 and +, between 1 and , and
between i and i.
Exercise 2.29. Say |yi = a|0i + b |1i is a normalized quantum state, i.e., |a|2 + |b |2 = 1.
(a) Calculate H|yi.
(b) Show that the total probability of H|yi is 1, so H is a valid quantum gate.
Exercise 2.30. Work out the math to show that
(a) H| i = |1i.
(b) H| ii = e ip/4 |ii ⌘ |ii.

We can combine these quantum gates to create all sorts of states. For example,
1
HST H|0i = HST p (|0i + |1i)
2
1 ⇣ ⌘
= HS p |0i + eip/4 |1i
2
1 ⇣ ⌘
= H p |0i + ei3p/4 |1i
2

1 1 1
= p p (|0i + |1i) + ei3p/4 p (|0i |1i)
2 2 2
1 h⇣ ⌘ ⇣ ⌘ i
= 1 + ei3p/4 |0i + 1 ei3p/4 |1i , (2.9)
2

where in the third line, we used ieip/4 = eip/2 eip/4 = ei3p/4 . On the Bloch sphere,
this state is in the southern hemisphere:
z

y
x
108 2 One Quantum Bit

If we measure this qubit in the Z-basis {|0i, |1i}, the probability of getting |0i is

1⇣ ⌘ 2 1⇣ ⌘1⇣ ⌘
1 + ei3p/4 = 1 + ei3p/4 1 + e i3p/4
2 2 2
1⇣ ⌘
= 1 + e i3p/4 + ei3p/4 + e0
4✓ ◆
1 3p
= 2 + 2 cos
4 4
p !
1 2
= 1
2 2
⇡ 0.146,

where to go from the second to the third line, we used Euler’s formula Eq. (2.6) so
that eiq + e iq = 2 cos q . Similarly, the probability of getting |1i is
⌘ 2 1✓ ◆ p !
1⇣ i3p/4 3p 1 2
1 e = 2 2 cos = 1+ ⇡ 0.854.
2 4 4 2 2

As expected, since the state is in the southern hemisphere, there is a greater proba-
bility of getting |1i when measuring the qubit.
Exercise 2.31. Calculate Y 51 H 99 T 36 Z 25 |0i.

Exercise 2.32. Prove that HXH = Z by showing that HXH|0i and Z|0i result in the same state,
and HXH|1i and Z|1i result in the same state. Such an equation is called a circuit identity.

Exercise 2.33. Answer the following:


(a) Calculate HT HT H|0i.
(b) If you measure this in the Z-basis {|0i, |1i}, what is the probability that you get |0i and the
probability that you get |1i?

2.6.4 General One-Qubit Gates

You may have noticed that all the quantum gates from the last section were rotations
by some angle around some axis. This is true in general:

One-qubit quantum gates are rotations on the Bloch sphere.

This is because rotations on the Bloch sphere satisfy the two properties that we
require of quantum gates: they are linear maps, and they keep the total probability
equal to 1. Proving that rotations are linear requires some math, which we sketch
below. Rotations keep the total probability equal to 1 because a qubit is a point on
the Bloch sphere, so if we rotate it, it remains a point on the Bloch sphere.
2.6 Quantum Gates 109

Mathematically, say we rotate by angle q about some axis of rotation, which we


can specify in terms of the x-, y-, and z-axes. We denote the direction of the x-axis
by x̂, the direction of the y-axis by ŷ, and the direction of the z-axis by ẑ. Then, we
can denote the axis of rotation by n̂, and

n̂ = nx x̂ + ny ŷ + nz ẑ.

Note n̂ is a unit vector, meaning it must has length 1, i.e., n2x + n2y + n2z = 1.
For example, the Hadamard gate is a rotation by q = 180 = p radians about the
axis halfway between the x- and z-axes, and we can express this axis by
1 1
n̂ = p x̂ + p ẑ,
2 2

Note n2x + n2y + n2z = 1/2 + 0 + 1/2 = 1, as expected.


Now, we state as a fact (without proof) that a rotation by angle q about axis
n̂ = (nx , ny , nz ) can be written in terms of I, X, Y , and Z:
 ✓ ◆ ✓ ◆
q q
U = eig cos I i sin (nx X + nyY + nz Z) , (2.10)
2 2

where g is a global phase that we can set to anything (or drop), since it does not have
any physical relevance. p
pReturning to our example of the Hadamard gate, with q = p and n̂ = (1/ 2, 0,
1/ 2), we have
 ⇣ ⌘ ⇣p ⌘✓ 1 ◆
p 1
U = eig cos I i sin p X + 0Y + p Z
2 2 2 2
1
= ieig p (X + Z) .
2
To show that U is the Hadamard gate, let us see how it acts on |0i and |1i:

1 1
U|0i = ieig p (X + Z) |0i = ieig p (X|0i + Z|0i)
2 2
1
= ieig p (|1i + |0i) = ieig |+i,
2
1 1
U|1i = ieig p (X + Z) |1i = ieig p (X|1i + Z|1i)
2 2
ig 1
= ie p (|0i |1i) = ieig | i.
2

We can drop the global phase of ieig , so U|0i = |+i and U|1i = | i, which is the
Hadamard gate. Alternatively, we can choose g = p/2, and then since i = ei3p/2 ,
the global phase is ieig = ei3p/2 eip/2 = ei2p = 1.
110 2 One Quantum Bit

We can also use Eq. (2.10) to prove that rotations are linear. Note U is a sum of I,
X, Y , and Z with numbers as coefficients; we call this a linear combination of I, X,
Y , and Z. Since each of these gates distribute over superpositions, U also distributes
over superpositions, and so it is linear:
 ✓ ◆ ✓ ◆
q q
U(a|0i + b |1i) = eig cos I i sin (nx X + nyY + nz Z) (a|0i + b |1i)
2 2
 ✓ ◆ ✓ ◆
q q
= aeig cos I i sin (nx X + nyY + nz Z) |0i
2 2
 ✓ ◆ ✓ ◆
q q
+ b eig cos I i sin (nx X + nyY + nz Z) |1i
2 2
= aU|0i + bU|1i.

Exercise 2.34. Consider a rotation by 45 about the z-axis.


(a) What is n̂?
(b) Use Eq. (2.10) to express the rotation U is terms of I, X, Y , and Z.
(c) Find U|0i.
(d) Find U|1i.
(e) Show that U is the T gate, up to a global phase.

Exercise 2.35. Consider a rotation by 180 around the axis equidistant from the x-, y-, and z-axes.
Below, the first picture shows the axis on the Bloch sphere. It may be a little difficult to visualize,
however, so another description of it using a cube is shown below in the second picture. The cube
has a corner at the origin and edges of length s along the x-, y-, and z-axes. Then, the axis of rotation
goes through the origin and the point (s, s, s), and the axis of rotation is drawn as a thicker line.
z
z

x+y+z
s
(s, s, s)
y
s
x y
s
x

(a) Draw the Bloch sphere and show where |0i goes after applying the rotation. Do this without
any calculations by visualizing the rotation on the Bloch sphere.
(b) Draw the Bloch sphere and show where |1i goes after applying the rotation. Do this without
any calculations by visualizing the rotation on the Bloch sphere.
(c) What is n̂? Hint: It should have equal components in the x-, y-, and z-axes, and it should be a
unit vector.
(d) Use Eq. (2.10) to express the rotation U is terms of I, X, Y , and Z.
(e) Find U|0i.
(f) Find U|1i.
2.7 Quantum Circuits 111

2.7 Quantum Circuits

2.7.1 Circuit Diagrams

Just like we can draw a classical circuit diagram consisting of bits and logic gates,
we can draw quantum circuit diagrams consisting of qubits and quantum gates. For
example, HST H|0i is
|0i H T S H

The circuit is read left-to-right, just like a classical circuit diagram. So, we start with
a single qubit in the |0i state and apply a Hadamard gate H to it, followed by a T
gate, then a phase gate S, and finally another H gate. It is implied that we measure
the qubit at the end of the circuit. We can also explicitly draw the measurement as a
meter:
|0i H T S H

2.7.2 Quirk

A great web-based tool for simulating quantum circuits is Quirk at https://alga


ssert.com/quirk:

There are a variety of quantum gates that users can drag and drop onto the circuit,
and users can also make custom gates. Each qubit is initially a |0i, as shown below:
112 2 One Quantum Bit

The state of each qubit is visualized a couple ways. First, the probability that a
measurement of the qubit yields |1i is zero, and this is labeled as “Off.” Second,
the Bloch sphere representation of the qubit is shown, and the state is a point at the
north pole, as expected.
Now if we apply the X gate, Quirk shows the following:

Note Quirk uses to denote a single X gate, whereas we use X (later, we will
also use when the X gate is controlled by another qubit). Since X|0i = |1i, the
probability of measuring |1i is 1. This is labeled as “On,” and the Bloch sphere now
shows the state at the south pole, as expected.
Now consider H|0i = |+i:

In Quirk, it shows a 50% chance of being |1i when measured in the Z-basis, and it
lies on the x-axis of the Bloch sphere, as expected.
Finally, let us simulate HST H|0i, which we earlier computed by hand to have a
0.146 probability of being |0i and a 0.854 probability of being |1i. Simulating it in
Quirk,

Quirk displays that the probability of measuring |1i is 85.4% = 0.854, in agreement
with our previous calculations from Eq. (2.9).
Exercise 2.36. Answer the following about HY T HX|0i.
(a) Draw HY T HX|0i as a quantum circuit.
(b) Using Quirk, sketch where HY T HX|0i appears on the Bloch sphere.
(c) Using Quirk, if you measure HY T HX|0i in the Z-basis, what is the probability that you get
|0i and the probability that you get |1i?

2.8 Summary

The smallest unit of quantum information is the qubit. Besides having two orthog-
onal states |0i and |1i, a qubit can be a superposition of them with complex am-
plitudes. The norm-square of the amplitudes gives the probability of measuring the
qubit as a 0 or 1, and depending on the outcome, the qubit collapses to |0i or |1i.
Qubits can also be measured in other bases. A qubit can be visualized on the Bloch
2.8 Summary 113

sphere. Qubits are operated on by quantum gates, which are linear maps that keep
the total probability equal to 1. A single-qubit gate is a rotation on the Bloch sphere.
A quantum circuit is a drawing to depict what quantum gates act on a qubit, and an
online simulator for quantum circuits is Quirk.
Chapter 3
Linear Algebra

So far, we have done quantum computing using elementary algebra and using the
fact that quantum gates are linear, so they distribute across superpositions. This can
be tedious, however, such as when calculating HY T HX(a|0i + b |1i). Fortunately,
there is an easier way to do the math of quantum computing using linear algebra,
where numbers are arranged in columns, rows, and tables (called matrices). Ulti-
mately, linear algebra is a tool. Learning how to use a new tool may be difficult at
first, but ultimately, it makes the job easier. We will show how linear algebra can be
used for many of the calculations from the previous chapter.
We had a similar progression with classical computing. In Chapter 1, we could
do all of classical computing using truth tables, including to show that ABC +ABC +
ABC + ABC = A + B + AC. Boolean algebra makes such calculations easier, but it
requires becoming proficient enough with the tool. Linear algebra is to quantum
computing as boolean algebra is to classical computing.

3.1 Quantum States

3.1.1 Column Vectors

We write |0i and |1i as column vectors, which are vertical lists of numbers:
✓ ◆ ✓ ◆
1 0
|0i = , |1i = .
0 1

Our notation is to write vectors in large parenthesis, but some people use square
brackets instead. These are called column vectors because they have a single col-
umn, and they have length 2 because they have two entries. Writing |0i and |1i, this
way, it is easy to write superpositions of them. A generic qubit with amplitudes a
and b would be

115
116 3 Linear Algebra
✓ ◆ ✓ ◆ ✓ ◆ ✓ ◆
1 0 a 0
|yi = a|0i + b |1i = a +b = +
0 1 0 b
✓ ◆
a
= .
b

For example, |ii can be written as a column vector:


✓ ◆ ✓ ◆ ✓ p ◆ ✓ ◆
1 i 1 1 i 0 1/ 2 0
p
|ii = p |0i + p |1i = p +p = +
2 2 2 0 2 1 0 i/ 2
✓ p ◆ ✓ ◆
1/p 2 1 1
= =p .
i/ 2 2 i

Exercise 3.1. A qubit is in the following state:


p
1 3
|0i |1i.
2 2
Write this state as a column vector.

Exercise 3.2. A qubit is in the following state:


✓p ◆
3/2
.
1/2

If you measure this qubit in the Z-basis {|0i, |1i}, what states can you get and with what probabil-
ities?

3.1.2 Row Vectors

Next, the transpose of a column vector is obtained by rewriting it as a row vector,


and it is denoted by | (a superscript letter T). So,
✓ ◆|
a
= ab .
b

In quantum computing, we typically use the conjugate transpose, which is obtained


by taking the complex conjugate of each component of the transpose. It is denoted
by † (a dagger):
✓ ◆†
a
= a⇤ b ⇤ .
b
This is used so frequently in quantum mechanics that bra-ket notation has a special
way of writing it: with an angle bracket and a vertical bar, called a bra:

hy| = a ⇤ b ⇤ .
3.1 Quantum States 117

Then, a bra is the conjugate transpose of a ket, and conversely, a ket is the conjugate
transpose of a bra. Flipping between kets and bras is called “taking the dual”, and the
dual of a ket is its✓brapversion,
◆ and the dual of a bra is its ket version. For example,
1/p 2
the dual of |ii = is
i/ 2
p p
hi| = 1/ 2 i/ 2 .
✓ ◆ ✓ ◆
1 0
We can also take the conjugate transpose of |0i = and |1i = to get the
0 1
Z-basis vectors as bras:

h0| = 1 0 , h1| = 0 1 .

Then, hy| can be written as

hy| = a ⇤ b ⇤ = a ⇤ 0 + 0 b ⇤ = a ⇤ 1 0 + b ⇤ 0 1
= a ⇤ h0| + b ⇤ h1|.

Notice this has amplitudes a ⇤ and b ⇤ , so when we go from |yi to hy|, we need
to take the complex conjugate of the amplitudes. For example, taking the dual of
|ii = p12 |0i + pi2 |1i, we get

1 i
hi| = p h0| p h1|.
2 2
To summarize, to go between kets and bras,
✓ ◆
a
|yi = () hy| = a ⇤ b ⇤ ,
b
|yi = a|0i + b |1i () hy| = a ⇤ h0| + b ⇤ h1|.

Exercise 3.3. Consider the following two states |ai and |bi:
p
3 1 2 1 2i
|ai = |0i + |1i, |bi = |0i + |1i.
2 2 3 3
Answer the following questions:
(a) What is ha| in terms of h0| and h1|?
(b) What is ha| as a row vector?
(c) What is hb| in terms of h0| and h1|?
(d) What is hb| as a row vector?
118 3 Linear Algebra

3.2 Inner Products

3.2.1 Inner Products Are Scalars

Say we have two states,


✓ ◆ ✓ ◆
a g
|yi = , and |f i = .
b d

One way to multiply |yi and |f i is by taking their inner product, and it is defined
as hy| times |f i: ✓ ◆
g
hy||f i = a ⇤ b ⇤ .
d
Typically, we combine the two vertical bars into one and write the inner product as
✓ ◆
g
hy|f i = a ⇤ b ⇤ .
d

We call hy|f i a bra-ket or bracket, and the word bracket is the origin of the terms
bra and ket. To evaluate the inner product, from linear algebra, we multiply a row
vector and a column vector by multiplying the first entry of each vector together,
multiplying the second entry of each vector together, and adding them (i.e., taking
their dot product):
hy|f i = a ⇤ g + b ⇤ d .
Note the result is just a number, or scalar. So, an inner product is also called a scalar
product.
The inner product of |f i and |yi is just the complex conjugate of the inner prod-
uct of |yi and |f i:
hf |yi = hy|f i⇤ .
To prove this, we can just do a simple calculation:
✓ ◆
a
hf |yi = g d⇤ ⇤
= g ⇤ a + d ⇤ b = (ga ⇤ + d b ⇤ )⇤ = (a ⇤ g + b ⇤ d )⇤
b
= hy|f i⇤ .

Inner products have several uses, which we will see next and throughout this
chapter.
Exercise 3.4. Consider
p
3+i 3 1
|ai = |0i + |1i,
4 2
p
1 15
|bi = |0i + |1i.
4 4
(a) Find ha|bi.
3.2 Inner Products 119

(b) Find hb|ai.


(c) What is the relationship between your answers to parts (a) and (b)?

3.2.2 Orthonormality

Several properties can be expressed using the inner product:


• First, let us take the inner product of |yi = a|0i + b |1i with itself:
✓ ◆
a
hy|yi = a b ⇤ ⇤
= |a|2 + |b |2 = 1.
b

So, hy|yi is just the total probability, and if hy|yi = 1, the state |yi is normal-
ized.
• Consider the inner product of the Z-basis states |0i and |1i:
✓ ◆
0
h0|1i = 1 0 = 1 · 0 + 0 · 1 = 0 + 0 = 0.
1

Next, consider the inner product of the X-basis states |+i and | i:
✓ ◆ ✓ ◆
1 1 1 1 1 1
h+| i = p 1 1 p = 11 = (1 1) = 0.
2 2 1 2 1 2

Finally, consider the inner product of the Y -basis states |ii and | ii:
✓ ◆ ✓ ◆
1 1 1 1 1 1
hi| ii = p 1 i p = 1 i = 1 + i2 = 0,
2 2 i 2 i 2
p
where we used i2 = ( 1)2 = 1.
In all of these, the outcome was zero. In fact, any two states on opposite sides of
the Bloch sphere have zero inner product (Exercise 3.8). We say that states with
zero inner product are orthogonal. Thus, orthogonal states are distinct measure-
ment outcomes.
• These two properties, normalized and orthogonal, can be combined into a sin-
gle word, orthonormal. So |0i and |1i are orthonormal because each state is
individually normalized, and they are orthogonal to each other. Similarly, |+i
and | i are orthonormal, and |ii and | ii are orthonormal.

Exercise 3.5. Consider a qubit in the following state

|yi = A (2|0i + 3i|1i) .

(a) Calculate hy|yi.


(b) Find a value of A that normalizes |yi.

Exercise 3.6. Determine if each pair of states is orthogonal or not.


120 3 Linear Algebra

(a) |+i and | i.


(b) |0i and
p |+i. p p p
1 + 3i 2 i 2+i 1 + 3i
(c) |0i + |1i and |0i + |1i.
4 2 2 4

Exercise 3.7. Consider


p
3+i 3 1
|ai = |0i + |1i,
4 2
1
|bi = |0i + x|1i.
4
(a) Find x so that |ai and |bi are orthogonal.
(b) Find x so that |bi is normalized.
(c) For what values of x (if any) are |ai and |bi orthonormal?

Exercise 3.8. Say we have two qubits |ai and |bi. We can parameterize them in spherical coordi-
nates (q , f ) on the Bloch sphere:
✓ ◆ ✓ ◆
qa qa
|ai = cos |0i + eifa sin |1i,
2 2
✓ ◆ ✓ ◆
qb qb
|bi = cos |0i + eifb sin |1i.
2 2

Now say |ai and |bi lie on opposite points of the Bloch sphere. This means qb = p qa and
fb = fa + p. Show that ha|bi = 0, i.e., they are orthogonal. Possibly useful trigonometric identities:

sin(u ± v) = sin(u) cos(v) ± cos(u) sin(v),


cos(u ± v) = cos(u) cos(v) ⌥ sin(u) sin(v).

3.2.3 Projection, Measurement, and Change of Basis

Next, inner products can be used to find the amplitudes of quantum states, which
can be norm-squared to yield measurement probabilities. The amplitudes can also
be used to change the basis. As an example, consider a qubit in the following state:
p
3 1
|yi = |0i + |1i.
2 2
It appears on the Bloch sphere as shown below:
3.2 Inner Products 121

z
p
3 1 |0i
|0i + |1i
2 2
| i
| ii •
|ii
|+i y
x

|1i

In Section 2.3.3, we measured this qubit in the Z-basis, X-basis, Y -basis, and a
fourth basis. Let us see how to reproduce the results using inner products.
First, we want to find the possible measurement outcomes and their probabili-
ties if we measure |yi in the {|0i, |1i} basis. Although we can just “read off” the
amplitudes of |yi with respect to |0i and |1i and take the norm-square of each to
find the probabilities, we can also find the amplitudes using inner products and the
orthonormality of {|0i, |1i}. For example, the amplitude of |0i is
p ! p p
3 1 3 1 3
h0|yi = h0| |0i + |1i = h0|0i + h0|1i = .
2 2 2 | {z } 2 | {z } 2
1 0

When calculating this, the amplitude from |1i vanishes because |0i and |1i are or-
thogonal (i.e., h0|1i = 0). We get just the amplitude from |0i because |0i is normal-
ized (i.e., h0|0i = 1). Similarly, the amplitude of |1i is
p ! p
3 1 3 1 1
h1|yi = h1| |0i + |1i = h1|0i + h1|1i = .
2 2 2 | {z } 2 | {z } 2
0 1

Taking the norm-square of each of these, the possible measurement outcomes are
|0i with probability 3/4 and |1i with probability 1/4. Since h0|yi and h1|yi are the
amplitudes of |0i and |1i, respectively, we can write the state of the qubit as

|yi = h0|yi|0i + h1|yi|1i.

This technique is far more useful when we cannot just read off the amplitudes,
such as when measuring in other bases. Let us measure in the X-basis {|+i, | i}
now. The amplitude of |+i is
p !
1 3 1
h+|yi = p (h0| + h1|) |0i + |1i
2 2 2
122 3 Linear Algebra
p p !
1 3 1 3 1
=p h0|0i + h0|1i + h1|0i + h1|1i
2 2 | {z } 2 | {z } 2 | {z } 2 | {z }
1 0 0 1
p !
1 3 1
=p +
2 2 2
p
3+1
= p .
2 2
This agrees with our calculation in Section 2.3.3. Similarly, the amplitude of | i is
h |yi, but now let us calculate it using linear algebra:
✓p ◆ p ! p
1 3/2 1 3 1 3 1
h |yi = p 1 1 =p = p .
2 1/2 2 2 2 2 2

Again, this agrees with Section 2.3.3. This approach is especially convenient be-
cause we can do the calculations using a computer algebra system that supports
linear algebra, like Mathematica or SageMath:
• In Mathematica,
psi={{Sqrt[3]/2},{1/2}};
minus={{1/Sqrt[2]},{-1/Sqrt[2]}};
ConjugateTranspose[minus].psi

The first line defines a column vector named psi (for |yi), and the second line
defines a column vector named minus (for | i). To take their inner product,
we take the conjugate transpose of minus (which is h |) and perform a vector
multiplication (denoted by the period) with psi. The result of this is
p
3 1
p ,
2 2
as expected.
• In SageMath,
sage: psi = vector([sqrt(3)/2,1/2])
sage: minus = vector([1/sqrt(2),-1/sqrt(2)])
sage: minus.conjugate()*psi
1/4*sqrt(3)*sqrt(2) - 1/4*sqrt(2)

The first line defines a vector psi (for |yi), and the second line defines a vector
minus (for | i). Note we do not need to specify whether it is a column vector
or row vector in SageMath. It will automatically transpose the vector to what-
ever shape is needed. In the third line, we calculate minus.conjugate() (for
h |) and multiply it onto psi using an asterisks, yielding the fourth line as the
answer. Let us simplify it:
p p p p
p p p 3 2 2 3 1
(1/4) 3 2 (1/4) 2 = = p .
4 4 2 2
3.2 Inner Products 123

This matches what we expected.


Since h+|yi and h |yi are the amplitudes of |+i and | i, respectively, we can
write the state of the qubit in the {|+i, | i} basis as

|yi = h+|yi|+i + h |yi| i.

In Section 2.3.3, we also measured |yi in the Y -basis and in a fourth basis. These
will be left as Exercise 3.9.
In general,

For an orthonormal basis {|ai, |bi}, the state of a qubit can be written as

|yi = a|ai + b |bi,

where a = ha|yi and b = hb|yi.

Finally, we end with some terminology. We have been saying that ha|yi is the
amplitude of |yi in |ai. We can also say that ha|yi is the amount of |yi that is in
|ai. Or, ha|yi is the amount that |yi and |ai overlap. In mathematical language,
ha|yi is the projection of |yi onto |ai.
Exercise 3.9. Consider a qubit in the following state
p
3 1
|yi = |0i + |1i.
2 2
Consider measuring this qubit in the Y -basis {|ii, | ii} and the orthonormal basis {|ai, |bi}, where
p
3 i
|ai = |0i + |1i,
2 2
p
i 3
|bi = |0i + |1i.
2 2
(a) Calculate hi|yi.
(b) Calculate h i|yi.
(c) If you measure the qubit in the Y -basis, what states can you get and with what probabilities?
(d) Calculate ha|yi.
(e) Calculate hb|yi.
(f)If you measure the qubit in the {|ai, |bi} basis, what states can you get and with what proba-
bilities?
Hint: Your answers should agree with Section 2.3.3.

Exercise 3.10. Consider a qubit in the following state


p
3+i 3 1
|yi = |0i |1i,
4 2
which lies on the Bloch sphere at (q , f ) = (p/3, 5p/6).
(a) If you measure it in the Z-basis {|0i, |1i}, what states can you get and with what probabilities?
124 3 Linear Algebra

(b) If you measure it in the X-basis {|+i, | i}, what states can you get and with what probabili-
ties?
(c) If you measure it in the Y -basis {|ii, | ii}, what states can you get and with what probabili-
ties?

Exercise 3.11. A qubit is in the state


✓ ◆
1 1 2i
|yi = p .
6 1

(a) Express this state in the {|+i, | i} basis.


(b) Express this state in the {|ii, | ii} basis.

3.3 Quantum Gates

3.3.1 Gates as Matrices

Recall a quantum gate U generally turns |0i and |1i into superpositions of |0i and
|1i:
✓ ◆
a
U|0i = a|0i + b|1i = ,
b
✓ ◆
c
U|1i = c|0i + d|1i = .
d

We can arrange the resulting amplitudes side-by-side, resulting in a matrix, which


is a rectangular array/table of numbers:
✓✓ ◆ ✓ ◆◆ ✓ ◆
a c ac
U= = .
b d bd

This is a 2⇥2 matrix because it has two rows and two columns. Plugging this matrix
into U|0i and U|1i, we get
✓ ◆✓ ◆ ✓ ◆
ac 1 a
U|0i = = ,
bd 0 b
✓ ◆✓ ◆ ✓ ◆
ac 0 c
U|1i = = .
bd 1 d

These correctly suggest that we can multiply a matrix and a vector in the following
manner: To get the first (second) entry, we take the first (second) row of the matrix
and multiply it component-by-component with the vector, then add the results:
3.3 Quantum Gates 125
✓ ◆✓ ◆ ✓ ◆ ✓ ◆
ac 1 a·1+c·0 a
= = ,
bd 0 b·1+d ·0 b
✓ ◆✓ ◆ ✓ ◆ ✓ ◆
ac 0 a·0+c·1 c
= = .
bd 1 b·0+d ·1 d

This is exactly the way matrices and vectors multiply in linear algebra.
Of course, U can also act on superpositions. If a qubit is in the state
✓ ◆
a
|yi = a|0i + b |1i = ,
b

then applying U transforms this to

U|yi = a(a|0i + b|1i) + b (c|0i + d|1i)


= (aa + cb )|0i + (ba + db )|1i
✓ ◆
aa + cb
= .
ba + db

Let us show that the matrix representation of this yields the expected result:
✓ ◆✓ ◆ ✓ ◆
ac a aa + cb
U|yi = = .
bd b ba + db

This is exactly what we expect.


In the language of linear algebra, quantum gates are matrices. Of course, the
matrix must ensure that the total probability remains 1, so in the previous example,
we must have |aa + cb |2 + |ba + db |2 = 1. This yields the following point:

Quantum gates are matrices that keep the total probability equal to 1.

For example, we previously showed in Section 2.6.1 that the following is a valid
quantum gate because it keeps the total probability equal to 1:
p p !
2 i 1 2 i
U|0i = |0i |1i = 2
1 ,
2 2 2
p !
1
1 2+i 2
U|1i = |0i + |1i = p2+i .
2 2 2

Then, as a matrix, p !
2 i 1
U= 2 p 2 .
1 2+i
2 2
126 3 Linear Algebra

In Quirk, we can create this quantum gate by clicking the “Make Gate” button at
the top of the page. A dialog box will pop up with different options, and we want to
create a gate from a matrix:

We enter the matrix, give it a name, and then click “Create Matrix Gate.” Then, it
will appear in the bottom-right toolbar under “Custom Gates:”

We can drag this onto the main circuit like any other gate. Here it is, along with a T
and H gate:

From this, we see that HTU|0i has a 57.3% chance of collapsing to |1i, and hence
a 42.7% chance of collapsing to a |0i.
Exercise 3.12. Consider an operator U performs the following mapping on the Z-basis states:
✓ ◆ ✓ ◆
1 1 1 i
U|0i = p , U|1i = p .
2 i 2 1
(a) What is U ✓as a◆matrix?
a
(b) What is U ?
b
(c) From your answer to (b), is U a valid quantum gate? Explain your reasoning.
3.3 Quantum Gates 127

Exercise 3.13. A quantum gate U performs the following mapping on the Z-basis states:

1
U|0i = p [(3 + i)|0i (1 + i)|1i] ,
2 3
1
U|1i = p [(1 i)|0i + (3 i)|1i] .
2 3
(a) What is U as a matrix?
(b) Create U as a custom gate in Quirk. Using Quirk, if you measure HUH|0i, what are the
possible outcomes, and with what probabilities?

3.3.2 Common One-Qubit Gates as Matrices

Previously, we introduced several common one-qubit gates, including the identity


gate I, Pauli X, Y , and Z gates, the phase gate S, the T gate, and the Hadamard gate
H. Now, each of these can be represented as a matrix:

Gate Action on Computational Basis Matrix Representation


✓ ◆
I|0i = |0i 10
Identity I=
I|1i = |1i 01
✓ ◆
X|0i = |1i 01
Pauli X X=
X|1i = |0i 10
✓ ◆
Y |0i = i|1i 0 i
Pauli Y Y=
Y |1i = i|0i i 0
✓ ◆
Z|0i = |0i 1 0
Pauli Z Z=
Z|1i = |1i 0 1
✓ ◆
S|0i = |0i 10
Phase S S=
S|1i = i|1i 0 i
✓ ◆
T |0i = |0i 1 0
T T=
T |1i = eip/4 |1i 0 eip/4
✓ ◆
H|0i = p1 (|0i + |1i) 1 1 1
Hadamard H 2 H= 2 p
H|1i = p1 (|0i |1i) 1 1
2

Of particular note is ✓ ◆
10
I= .
01
This is called the 2 ⇥ 2 identity matrix. When it acts on a vector, it does nothing. For
example, ✓ ◆✓ ◆ ✓ ◆ ✓ ◆
10 a 1a + 0b a
= = .
01 b 0a + 1b b
128 3 Linear Algebra

The same is true of large matrices. An N ⇥ N matrix with 1’s on the diagonal and
0’s everywhere else is called the N ⇥ N identity matrix.
Exercise 3.14. Recall from Eq. (2.10) than a single-qubit gate is a rotation by some angle q about
some axis n̂ = (nx , ny , nz ). Consider a quantum gate that rotates by 90 about the y-axis. Using
Eq. (2.10) with g = 0, what is this gate as a matrix?

3.3.3 Sequential Quantum Gates

Using linear algebra, we can compute the effect of a sequence of quantum gates. For
example, we had previously shown in Eq. (2.9) that
1 h⇣ ⌘ ⇣ ⌘ i
HST H|0i = 1 + ei3p/4 |0i + 1 ei3p/4 |1i .
2
Now, we can perform this same calculation using linear algebra by multiply each
matrix onto the vector:
✓ ◆✓ ◆✓ ◆ ✓ ◆✓ ◆
1 1 1 10 1 0 1 1 1 1
HST H|0i = p ip/4 p
2 1 1 0 i 0 e 2 1 1 0
✓ ◆✓ ◆✓ ◆✓ ◆
1 1 1 10 1 0 1
= ip/4
2 1 1 0 i 0 e 1
✓ ◆✓ ◆✓ ◆
1 1 1 10 1
= ip/4
2 1 1 0 i e
✓ ◆✓ ◆
1 1 1 1
=
2 1 1 ei3p/4
✓ ◆
1 1 + ei3p/4
= .
2 1 ei3p/4

We can also compute this using any computing system that supports linear algebra,
such as Mathematica or SageMath:
• In Mathematica,
zero = {{1}, {0}};
H = 1/Sqrt[2] {{1, 1}, {1, -1}};
S = {{1, 0}, {0, I}};
T = {{1, 0}, {0, Eˆ(I Pi/4)}};
H.S.T.H.zero
The first line defines a column vector named zero, and the second, third, and
fourth lines define the quantum gates as matrices. The fifth line multiplies them
together. Note a period (.) must be used for matrix multiplication; an asterisk
(*) denotes element-by-element multiplication. The output of this code is
⇢⇢ ⇢
1 1 ip 1 1 ip
+ ie 4 , ie 4 ,
2 2 2 2
3.3 Quantum Gates 129

which is precisely what we calculated by hand since i = eip/2 , and so ieip/4 =


eip/2 eip/4 = ei(p/2+p/4) = ei3p/4 .
• In SageMath,
sage: zero = vector([1,0]).column()
sage: H = 1/sqrt(2) * Matrix([[1,1],[1,-1]])
sage: S = Matrix([[1,0],[0,i]])
sage: T = Matrix([[1,0],[0,eˆ(i*pi/4)]])
sage: H*S*T*H*zero
[ (1/4*I - 1/4)*sqrt(2) + 1/2]
[-(1/4*I - 1/4)*sqrt(2) + 1/2]

The first line defines a column vector named zero, and the next three lines define
the quantum gates as matrices. The fifth line multiplies them together, and the
final two lines are the output, which is a column vector:
✓ i 1 p ◆
4 4 p2 + 12
i 1 .
4 4 2 + 12
p p p
Since (i/4 1/4) 2 = (i 1)/(2 2) and (i 1)/ 2 = ei3p/4 , this becomes
✓ ◆
1 1 + ei3p/4
,
2 1 ei3p/4

which is exactly what we had before.

Exercise 3.15. In Section 3.3.1, we simulated the following circuit in Quirk:

where p !
2 i 1
U= 2 p2 .
1 2+i
2 2
Calculate HTU|0i.

3.3.4 Circuit Identities

In Exercise 2.32, we proved the circuit identity HXH = Z by showing that HXH|0i
and Z|0i result in the same state, and HXH|1i and Z|1i result in the same state. We
can prove HXH = Z another way using linear algebra:
✓ ◆✓ ◆ ✓ ◆
1 1 1 01 1 1 1
HXH = p p
2 1 1 10 2 1 1
✓ ◆✓ ◆✓ ◆
1 1 1 01 1 1
= .
2 1 1 10 1 1
130 3 Linear Algebra

To continue this calculation, let us multiply the two matrices on the right (X and H).
The procedure is very similar to multiplying a matrix onto a column vector, except
we now have two column vectors. So, we distribute the middle matrix across the
two column vectors of the rightmost matrix.
✓ ◆ ✓ ◆✓ ◆ ✓ ◆✓ ◆!
1 1 1 01 1 01 1
HXH =
2 1 1 10 1 10 1
✓ ◆ ✓ ◆ ✓ ◆!
1 1 1 1 1
=
2 1 1 1 1
✓ ◆✓ ◆
1 1 1 1 1
= .
2 1 1 1 1

Now, we can multiply these two matrices by again distributing the left matrix so that
it multiples both columns of the right vector:
✓ ◆✓ ◆ ✓ ◆✓ ◆!
1 1 1 1 1 1 1
HXH =
2 1 1 1 1 1 1
✓ ◆ ✓ ◆! ✓ ◆ ✓ ◆
1 2 0 1 2 0 1 0
= = =
2 0 2 2 0 2 0 1
= Z.

So, we have proved HXH = Z. We can also perform these calculations using a
computer algebra system that supports linear algebra, such as Mathematica or Sage-
Math:
• In Mathematica,
H = 1/Sqrt[2] {{1, 1}, {1, -1}};
X = {{0, 1}, {1, 0}};
H.X.H

This defines the H and X gates as matrices and then multiplies them together,
and the output is
{{1,0},{0,-1}}.

This is precisely Z as a matrix.


• In SageMath,
sage: H = 1/sqrt(2) * Matrix([[1,1],[1,-1]])
sage: X = Matrix([[0,1],[1,0]])
sage: H*X*H
[ 1 0]
[ 0 -1]

This defines the H and X gates as matrices and then multiplies them together,
and the output is a 2 ⇥ 2 matrix, which is precisely Z.
3.3 Quantum Gates 131

Exercise 3.16. Prove that XY = iZ two different ways:


(a) Show that XY |0i = iZ|0i and XY |1i = iZ|1i.
(b) Multiply XY as matrices and show that it equals iZ.

3.3.5 Unitarity

Recall from Section 3.3.1 that if a quantum gate U transforms |0i and |1i as follows
✓ ◆
a
U|0i = a|0i + b|1i = ,
b
✓ ◆
c
U|1i = c|0i + d|1i = ,
d

then U can be written as a 2 ⇥ 2 matrix:




ac
U= .
bd

If we apply it to a state |yi = a|0i + b |1i, we get


✓ ◆✓ ◆ ✓ ◆
ac a aa + cb
U|yi = = .
bd b ba + db

We see that U|yi is a column vector, so we can also write it as a ket |Uyi:

U|yi = |Uyi.

Now, consider the conjugate transpose of |Uyi:


✓ ⇤ ⇤◆
a b
hUy| = a⇤ a ⇤ + c⇤ b ⇤ b⇤ a ⇤ + d ⇤ b ⇤ = a ⇤ b ⇤
c⇤ d ⇤
✓ ◆†
ac
= a⇤ b⇤ = hy|U † ,
bd

where the second equality comes from the convention for multiplying a row vector
and a matrix, where the first column of the matrix is multiplied by the row vector
according to the usual rule to yield the first entry, and the second column of the
matrix is multiplied by the row vector according to the usual rule to yield the second
entry. As another proof, a property of the (conjugate) transpose is that (AB)† = B† A† ,
and since |yi† = hy|, we have

hUy| = (|Uyi)† = (U|yi)† = |yi†U † = hy|U † .

To summarize,
132 3 Linear Algebra

|Uyi = U|yi,
(3.1)
hUy| = hy|U † .
Using this, we can come up with an easy way to determine whether a matrix
keeps the total probability equal to 1. Consider a quantum gate (matrix) U. If it acts
on |yi, we have
U|yi = |Uyi.
For U to be a quantum gate, this must be normalized. That is, the inner product of
|Uyi with itself must equal 1:

hUy|Uyi = 1
hy|U †U|yi = hy|yi
U †U = I.

A matrix that satisfies this property U †U = I (and UU † = I) is called unitary. Thus,

Quantum gates are unitary matrices, and unitary matrices are quantum gates.

This is why we typically use U to denote a quantum gate. It stands for unitary.
As an example application of this, is the following matrix a quantum gate?
✓ ◆
1 1 i
U=p
2 i1

We can just check whether it is unitary, so whether U †U = I or not.


✓ ◆ ✓ ◆ ✓ ◆
† 1 1 i 1 1 i 1 i
U U= p p = 6= I.
2 i1 2 i1 i1

So no, it is not a quantum gate.


Exercise 3.17. Is ✓ ◆
1 1 i
U=p
2 i 1
a quantum gate? If so, what is U|0i, and what is U|1i?

Exercise 3.18. Is ✓ ◆
1 1 1
U=p
2 i i
a quantum gate? If so, what is U|0i, and what is U|1i?

3.3.6 Reversibility

A matrix M is reversible or invertible if there exists a matrix denoted M 1 such that


3.4 Outer Products 133

1 1
M M = MM = I.

So, if we multiply a vector by both a matrix and its inverse, nothing happens to the
vector because this is equivalent to multiplying it by the identity matrix.
Now, since a quantum gate U must be unitary, it satisfies

U †U = UU † = I.

Then, the inverse of U is simply U † , i.e., U 1 = U † . So, a quantum gate is always


reversible, and its inverse is its conjugate transpose:

A quantum gate U is always reversible, and its inverse is U † .

If we have a qubit and we applied a quantum gate U, we can undo the gate by
applying U † :
U †U|yi = I|yi = |yi.

Exercise 3.19. Consider the following quantum gate, written as a 2 ⇥ 2 matrix:


p p p p !
1+p 3
2 p2
+ i 12p63 12p63 + i 12p63
U= 1+
p p p
p 3 + i 1 p 3 1+p 3 + i 1+p 3
2 6 2 6 2 2 2 6

(a) What is the inverse of U, written as a 2 ⇥ 2 matrix?


(b) A qubit is in the state p
3 1
|yi = |0i + |1i.
2 2

What is U U|yi? Hint: You can answer this without any messy calculations.

3.4 Outer Products

3.4.1 Outer Products Are Matrices

Consider two states

|yi = a|0i + b |1i, |f i = g|0i + d |1i.

Instead of multiplying |yi and |f i as an inner product hy|f i, where the bra is on
the left and the ket is on the right, another way to multiply them is by having the ket
on the left and the bra on the right, which is called an outer product:
✓ ◆
a
|yihf | = g⇤ d ⇤ .
b
134 3 Linear Algebra

To multiply these vectors according to the rules of linear algebra, we multiply each
row of |yi by each column of |f i, resulting in
✓✓ ◆ ✓ ◆ ◆ ✓✓ ⇤ ◆ ✓ ⇤ ◆◆ ✓ ⇤ ◆
a ⇤ a ag ad ag ad ⇤
|yihf | = g d ⇤ = = .
b b b g⇤ bd⇤ b g⇤ b d ⇤

The result is a 2 ⇥ 2 matrix. So, whereas inner products result in scalars, outer prod-
ucts result in matrices, and we can add outer products together to construct various
quantum gates.
For example, consider
U = |1ih0| + |0ih1|.
Let us find how this acts on |yi = a|0i + b |1i and show that it is a valid quantum
gate.

U|yi = (|1ih0| + |0ih1|) (a|0i + b |1i)


= a|1i h0|0i +b |1i h0|1i +a|0i h1|0i +b |0i h1|1i
| {z } | {z } | {z } | {z }
1 0 0 1
= a|1i + b |0i
= b |0i + a|1i.

The total probability of this is |b |2 + |a|2 = 1, so this is a valid quantum gate.


Applying U swapped |0i and |1i, so it is just the X gate. As another approach, we
can find U as a matrix:
✓ ◆ ✓ ◆ ✓ ◆ ✓ ◆ ✓ ◆
0 1 00 01 01
U = |1ih0| + |0ih1| = 10 + 01 = + = .
1 0 10 00 10

This is precisely the matrix for the X gate. To confirm that it is a valid quantum gate,
we simply show that it is unitary, i.e., if U †U = I:
✓ ◆✓ ◆ ✓ ◆
† 01 01 10
U U= = = I.
10 10 01

The outer product of |f i and |yi is just the conjugate transpose of the outer
product of |yi and |f i:
|f ihy| = |yihf |† .
We can prove this through a simple calculation:
✓ ◆ ✓ ⇤ ◆ ✓ ⇤ ◆†
g ga gb ⇤ ag ad ⇤
|f ihy| = a⇤ b ⇤ = = = |yihf |† .
d d a⇤ d b ⇤ b g⇤ b d ⇤

In the above equtaion, one may use parenthesis to clarify that the entire outer product
is conjugated and transposed, not just the bra, i.e., |f ihy| = (|yihf |)† .
Exercise 3.20. Consider the following outer product
3.4 Outer Products 135

|iih |.

(a) What is it as a matrix?


(b) Is this a valid quantum gate?

Exercise 3.21. Consider the following sum of outer products:

1 1 1 1
p |0ih0| + p |0ih1| + p |1ih0| p |1ih1|.
2 2 2 2
(a) What is it as a matrix?
(b) Is this a valid quantum gate?

3.4.2 Completeness Relation

Recall from Section 3.2.3 that for any orthonormal basis {|ai, |bi}, the state of a
qubit can be written as
|yi = a|ai + b |bi,
where a = ha|yi and b = hb|yi. Substituting these values,

|yi = ha|yi |ai + hb|yi |bi.


| {z } | {z }
scalar scalar

As indicated above, the inner products are just scalars/numbers, so instead of multi-
ply them onto the vectors |ai and |bi on the left, we can equivalently multiply them
on the right:
|yi = |ai ha|yi +|bi hb|yi .
| {z } | {z }
scalar scalar

Both of these terms are a ket times a bra times a ket. To make this more clear, we
can write them as
|yi = |aiha||yi + |bihb||yi.
Now, notice we have two outer products, |aiha| and |bihb|. Since they are both
multiplying |yi, we can factor to get

|yi = |aiha| + |bihb| |yi.

For this to be true for all |yi, we must have

|aiha| + |bihb| = I.

This is called the completeness relation, and it indicates the state of any qubit can be
expressed in terms of |ai and |bi, a property we call completeness. We say {|ai, |bi}
forms a complete orthonormal basis. All the bases we have discussed (any two states
on opposite sides on the Bloch sphere) are complete.
Let us box this:
136 3 Linear Algebra

A complete orthonormal basis {|ai, |bi} satisfies the completeness relation

|aiha| + |bihb| = I.

Exercise 3.22. Verify that {|+i, | i} is a complete orthonormal basis by showing that

|+ih+| + | ih | = I.

Exercise 3.23. Verify that {|0i, |+i} is a not a complete orthonormal basis by showing that

|0ih0| + |+ih+| 6= I.

3.5 Summary

The mathematical language of quantum computing is linear algebra. Quantum states


are represented by column vectors called kets, and the conjugate transpose of a ket
is a bra. Multiplying a bra and a ket is an inner product that yields the projection or
amplitude of the states onto each other. A state whose inner product with itself is
1 is normalized, and states with zero inner product are orthogonal. Quantum gates
are unitary matrices, which satisfy U †U = I. Unitary matrices are always reversible
with U 1 = U † . Multiplying a ket and a bra is an outer product, which is a matrix.
A complete orthonormal basis satisfies the completeness relation, meaning the sum
of the outer products of each basis vector with itself equals the identity matrix.
Chapter 4
Multiple Quantum Bits

In Chapter 2, we explored the qubit, what happens when it is measured, and how
quantum gates act on it. In Chapter 3, we upgraded our tools for working with a
qubit by introducing linear algebra. Now, we are positioned to explore systems con-
sisting of multiple qubits. Sometimes, these qubits are disjoint, but other times, the
qubits are intertwined together. We will learn how quantum gates acting on multi-
qubit systems can be used to perform computations, namely adding binary numbers.
This same addition problem was explored in Chapter 1 using classical computers,
providing a comparison. Then, we will explore sets of universal quantum gates and
how to correct for errors in quantum computers.

4.1 Entanglion: A Quantum Computing Board Game

4.1.1 Mechanics

IBM Research released an open-source board game called Entanglion to teach the
fundamental ideas and mechanics of quantum computing. It is available at https:
//entanglion.github.io, and anyone can download and print the game board
and pieces. The complete rules are available on the website, but let us summarize
the most important parts here, since they reflect the rules of quantum computing.
Entanglion is a two-player collaborative game, and the goal is to collect, as
a team, eight components to build a quantum computer that are scattered across
different planets, while avoiding detection by the planetary defenses. There are
three galaxies in the Entanglion universe: Centarious, Superious, and Entanglion,
as shown in Fig. 4.1. Centarious has two planets, Zero and One, and Superious also
has two planets, Plus and Minus. On the other hand, Entanglion has eight planets,
each holding one of the components to build a quantum computer.
Each player has one spaceship, and one is red while the other is blue. Players
determine the starting locations of their spaceships by rolling a die that only has 0

137
138 4 Multiple Quantum Bits

Fig. 4.1: The universe for the Entanglion board game. It consists of three galaxies:
Centarious, Superious, and Entanglion. The two players’ spaceships (red and blue)
move across the board from planet to planet according to the labeled paths. Dashed
paths correspond to the red player, and solid paths correspond to the blue player.
Inside the Entanglion galaxy, both spaceships move together.

and 1 as the outcomes. This is called the Centarious die because the outcomes of 0
and 1 correspond to the planets Zero and One, both in the galaxy Centarious.
The players take turns moving their spaceships to different planets by playing en-
gine cards H, X, CNOT, and SWAP. As shown in Fig. 4.1, different engine cards are
used for transitions between different planets. In Centarious and Superious, play-
ers’ spaceships can be on different planets. To move into the Entanglion galaxy, one
player must be in Centarious, and the other player must be in Superious. Then the
player in Centarious uses a CNOT engine card, and both spaceships move to the
same planet in the Entanglion galaxy. This planet is where a horizontal line from
4.1 Entanglion: A Quantum Computing Board Game 139

the Centarious planet intersects with the vertical line from the Superious planet, as
shown by the lines . pppppppppp / in Fig. 4.1. For example, if the red player is at One,
and the blue player is at Plus, and the red player uses a CNOT engine card, then
the red player moves horizontally from One to Psi Plus, and the blue player moves
vertically from Plus to Psi Plus. Inside the Entanglion galaxy, the spaceships always
move together as a pair, so they are always at the same planet.
Anytime the spaceships move to a planet in the Entanglion galaxy, or when a
player attempts to retrieve a component to build a quantum computer, there is a
chance they will be detected by the planetary defenses. The roll of an eight-sized die
determines this, and if the spaceships are detected, both of them move to a random
planet in Centarious determining by rolling the Centarious die.
The game also contains a shuffled deck of event cards, which are played when-
ever the spaceships are detected by planetary defenses, or after six engine cards
have been played. The cards are named after important scientists who contributed to
quantum physics and quantum computing, or after quantum effects. The mechanics
of these cards do not precisely correlate with actual quantum computing, so we limit
our discussion of them here.
Exercise 4.1. Refer to the Entanglion game board in Fig. 4.1.
(a) When can a player use CNOT to move between planets Zero and One?
(b) If the red player is at planet Zero and the blue player is at planet Minus, and the red player
uses a CNOT engine card, where do the players move?
(c) How can the players move between planets Psi Plus and Omega Three?

4.1.2 Connection to Quantum Computing

The rules of Entanglion reflect how quantum computers work. We will explore these
connections in detail throughout this chapter, but here is a quick summary:
• The red and blue spaceships are qubits.
• The planets are various states that qubits can be in. Centarious contains the
classical states |0i and |1i, Superious contains the two superposition states |+i
and | i, and Entanglion contains eight entangled states, where the states of the
two qubits are intertwined, so the spaceships move together.
• The engine cards H, X, CNOT, and SWAP are quantum gates that are applied to
the qubits. This transforms the qubits to different states, or moves the spaceships
to different planets.
• Detection by planetary defenses corresponds to a measurement. Measuring a
qubit yields a classical 0 or 1 with some probability, so the spaceships move to
planet Zero or One according to a roll of the Centarious die.

Exercise 4.2. Read https://medium.com/qiskit/designing-a-quantum-computi


ng-board-game-de4a450cad8c and answer the following questions:
(a) How many major iterations of the board game were there?
(b) The emphasis of the game was on mastery.
140 4 Multiple Quantum Bits

(c) What win rates for AI players corresponded to an adequate level of challenge for human
players?
(d) Entanglion is a play on what word?

4.2 States and Measurement

4.2.1 Tensor Product

When we have multiple qubits, we write their states as a tensor product ⌦. For
example, two qubits, both in the |0i state, are written

|0i ⌦ |0i,

and this is pronounced “zero tensor zero.” Often, we compress the notation and leave
out the tensor product in both writing and speech:

|0i|0i.

We frequently compress the notation further still:

|00i.

With two qubits, the Z-basis is {|00i, |01i, |10i, |11i}. A general state is a super-
position of these basis states:

c0 |00i + c1 |01i + c2 |10i + c3 |11i.

If we measure these two qubits in the Z-basis, we get |00i with probability |c0 |2 ,
|01i with probability |c1 |2 , |10i with probability |c2 |2 , or |11i with probability |c3 |2 .
Thus, the total probability is |c0 |2 + |c1 |2 + |c2 |2 + |c3 |2 , and it should equal 1.
With three qubits, there are eight Z-basis states |000i, |001i, |010i, |011i, |100i,
|101i, |110i, and |111i. Sometimes, these binary strings are written as decimal num-
bers |0i, |1i, . . . , |7i. Inspired by this, let us call the right qubit the zeroth qubit, the
middle qubit the first qubit, and the left qubit the second qubit, so a Z-basis state
takes the form
|b2 b1 b0 i.
Then, the decimal representation of this is

22 b2 + 21 b1 + 20 b0 .

In other words, we label qubits right-to-left, starting with zero. This convention,
where the rightmost qubit is the zeroth qubit, is called little endian. Quirk and many
quantum programming languages, including those in Chapter 5, also use little en-
dian. In contrast, the opposite convention, where the leftmost qubit is the zeroth
4.2 States and Measurement 141

qubit, is called big endian. Of note, Nielsen and Chuang’s standard advanced text-
book uses the big endian convention. Disputes over which convention is “better”
has raged classical computing for decades, and the same debates carry into quantum
computing. The reality is that you should be able to use both, but for consistency,
we use little endian throughout this textbook. Next, the general state of three qubits
is a superposition of these basis vectors:
7
 c j | ji = c0 |0i + c1 |1i + · · · + c7 |7i,
j=0

and the probability of getting | ji when measuring in the Z-basis is |c j |2 , so  j |c j |2 =


1.
With n qubits, there are N = 2n Z-basis states, which we can label as n-bit strings
or by the decimal numbers 0 through N 1. As an n-bit string,

|bN 1 . . . b1 b0 i = 2N 1 bN 1 + · · · + 21 b1 + 20 b0 .

Of course, the general state of n-qubits is a superposition of these Z-basis states:


N 1
 c j | ji = c0 |0i + c1 |1i + · · · + cN 1 |N 1i.
j=0

This has N amplitudes c0 through cN 1 . Thus, if we have just n = 300 qubits, then
we must keep track of N = 2300 ⇡ 2.04 ⇥ 1090 amplitudes, which is more than the
number of atoms in the visible universe (1078 to 1082 ). This is evidence, but not a
proof, that it is difficult for classical computers to simulate quantum computers. It
is evidence because classical computers cannot keep track of this many amplitudes,
but it is not a proof because it is unknown whether quantum computers need all these
amplitudes. That is, if quantum computers can function with much fewer amplitudes
(a polynomial number instead of an exponential number in n), a classical computer
would be able to keep track of all of them. In terms of complexity classes, the
exponential number of amplitudes in a general entangled state is evidence that P 6=
BQP.
We can also use powers to simplify the notation. If we have n qubits, each in the
state |0i, we can write the state as

|0i⌦n = |0i ⌦ |0i ⌦ · · · ⌦ |0i = |0i|0i . . . |0i = | 00 . . . 0}i = |0n i.


| {z
| {z } | {z }
n n n

With a single qubit, we could parameterize a state as

q q
cos |0i + eif sin |1i,
2 2
with the coordinates (q , f ) interpreted as a point on the Bloch sphere. With two
qubits, however, we have four complex amplitudes c0 , c1 , c2 , c3 (although one can
142 4 Multiple Quantum Bits

be made real by factoring out an global phase), and unfortunately, this is too many
parameters to represent in three-dimensions. There is no Bloch sphere representa-
tion for a general multi-qubit state.
The tensor product also works for bras, so

h0| ⌦ h0| = h0|h0| = h00|.

Then, the inner product of, say h01| and |00i, is obtained by matching up qubits. For
example,
h01|00i = h0|0i · h1|0i = 0.
| {z } | {z }
1 0

So |01i and |00i are orthogonal.


Exercise 4.3. Calculate the following inner products:
(a) h10|11i.
(b) h+ |01i.
(c) h1 + 0|1 0i.

4.2.2 Kronecker Product

In linear algebra, the tensor product is simply the Kronecker product, which is ob-
tained by multiplying each term of the first matrix/vector by the entire second ma-
trix/vector. For example, with two qubits,
0 ✓ ◆1 0 1
✓ ◆ ✓ ◆ 1 1
1 1 B1 0 C B0C
|00i = |0i|0i = |0i ⌦ |0i = ⌦ =B ✓ ◆C B C
@ 1 A = @0A .
0 0
0
0 0
0 ✓ ◆1 0 1
✓ ◆ ✓ ◆ 0 0
1 0 B1 1 C B1C
|01i = |0i|1i = |0i ⌦ |1i = ⌦ =B ✓ ◆C B C
@ 0 A = @0A .
0 1
0
1 0
0 ✓ ◆1 0 1
✓ ◆ ✓ ◆ 1 0
0 1 B0 0 C B0C
|10i = |1i|0i = |1i ⌦ |0i = ⌦ =B ✓ ◆C B C
@ 1 A = @1A .
1 0
1
0 0
0 ✓ ◆1 0 1
✓ ◆ ✓ ◆ 0 0
0 0 B0 1 C B0C
|11i = |1i|1i = |1i ⌦ |1i = ⌦ =B ✓ ◆C B C
@ 0 A = @0A .
1 1
1
1 1
Then,
4.2 States and Measurement 143
0 1
c0
Bc1 C
c0 |00i + c1 |01i + c2 |10i + c3 |11i = B C
@c2 A .
c3
Similarly, with three qubits, its state can be written as a column vector with eight
elements: 0 1
c0
7 Bc1 C
B C
 c j | ji = c0 |0i + c1 |1i + · · · + c7 |7i = B . C.
@ .. A
j=0
c7
With n qubits, the vector has N = 2n elements:
0 1
c0
N 1 B c1 C
B C
|yi = Â c j | ji = c0 |0i + c1 |1i + · · · + cN 1 |N 1i = B
@
..
.
C.
A
j=0
cN 1

With bras, the Kronecker product is still the tensor product. For example,

h00| = h0| ⌦ h0| = 1 0 ⌦ 1 0 = 1 1 0 0 1 0 = 1000 .

So, a general quantum state of n qubits, written as a bra, is


N 1
hy| = Â c⇤j h j| = c⇤0 h0| + c⇤1 h1| + · · · + c⇤N 1 hN 1| = c⇤0 c⇤1 · · · c⇤N 1 .
j=0

Exercise 4.4. Verify that


0 1
0
B0C
B C
B0C
B C
B0C
|1i ⌦ |1i ⌦ |0i = B C .
B0C
B0C
B C
@1A
0

Exercise 4.5. Consider a two-qubit state


p
1 i 3+i
|yi = |00i + p |10i + |11i.
2 2 4

(a) What is |yi as a (column) vector?


(a) What is hy| as a (row) vector?

Exercise 4.6. Show that {|00i, |01i, |10i, |11i} is a complete orthonormal basis for the state of two
qubits by showing that it satisfies the completeness relation

|00ih00| + |01ih01| + |10ih10| + |11ih11| = I,


144 4 Multiple Quantum Bits

where I is the 4 ⇥ 4 identity matrix:


0 1
1 0 0 0
B0 1 0 0C
B
I=@ C.
0 0 1 0A
0 0 0 1

4.2.3 Measuring Individual Qubits

Say we have two qubits in the state


p
1 1 3 1
p |00i + |01i + |10i + |11i.
2 2 4 4

If we measure both qubits, we would get |00i with probability 1/2, |01i with prob-
ability 1/4, |10i with probability 3/16, or |11i with probability 1/16.
Now, instead of measuring both qubits, let us only measure the left qubit. This
yields |0i or |1i with some probabilities, and the state collapses to some state, so the
outcomes are

|0i with some probability, and the state collapses to something,


|1i with some probability, and the state collapses to something.

The probability of getting |0i when measuring the left qubit is given by the sum of
the norm-squares of the amplitudes of |00i and |01i, since those both have the left
qubit as |0i. That is, the probability of getting |0i is
2 2
1 1 3
p + = .
2 2 4

Similarly, if the outcome is |1i, then from the |10i and |11i states, the probability is
p 2 2
3 1 1
+ = .
4 4 4

Then, the results of the measurement are:


3
|0i with probability , and the state collapses to something,
4
1
|1i with probability , and the state collapses to something.
4
Now for the states after measurement, if the outcome is |0i, then the state collapses
to the parts where the left qubit is |0i, so it becomes
4.2 States and Measurement 145
✓ ◆
1 1
A p |00i + |01i ,
2 2

where A is a normalization constant. Similarly, if the outcome is |1i, then the state
collapses to the terms where the left qubit is |1i, so it becomes
p !
3 1
B |10i + |11i .
4 4
p
where B is a normalization constant. Normalizing these, we get A = 2/ 3 and B =
2, so measuring the left qubit yields
r
3 2 1
|0i with probability , and the state collapses to |00i + p |01i,
4 3 3
p
1 3 1
|1i with probability , and the state collapses to |10i + |11i.
4 2 2
We can apply these ideas to any number of qubits. For example, if we have three
qubits in the state

c0 |000i + c1 |001i + c2 |010i + c3 |011i + c4 |100i + c5 |101i + c6 |110i + c7 |111i,

and we measure the left and middle qubits, the possible outcomes are

c0 |000i + c1 |001i
|00i with probability |c0 |2 + |c1 |2 , collapses to p ,
|c0 |2 + |c1 |2
c2 |010i + c3 |011i
|01i with probability |c2 |2 + |c3 |2 , collapses to p ,
|c2 |2 + |c3 |2
c4 |100i + c5 |101i
|10i with probability |c4 |2 + |c5 |2 , collapses to p ,
|c4 |2 + |c5 |2
c6 |110i + c7 |111i
|11i with probability |c6 |2 + |c7 |2 , collapses to p .
|c6 |2 + |c7 |2

Exercise 4.7. Two qubits are in the state


p
i 1 2i eip/100 3
p |00i + p |01i + p |10i + p |11i.
10 10 10 10
If we measure the qubits in the Z-basis {|00i, |01i, |10i, |11i}, what are the possible outcomes and
with what probabilities?

Exercise 4.8. Normalize the following quantum state:


✓ ◆
1 p
A |00i + i|01i + 2|10i |11i .
2
146 4 Multiple Quantum Bits

4.2.4 Sequential Single-Qubit Measurements

We have answered the question of what happens when we measure just a single qubit
or a subset of qubits. Now, let us take this a step further and consider what happens
if we measure the qubits, one after another. For example, in the last section, we
started with two qubits in the state
p
1 1 3 1
p |00i + |01i + |10i + |11i.
2 2 4 4

If we first measure the left qubit, we get


r
3 2 1
|0i with probability , and the state collapses to |00i + p |01i,
4 3 3
p
1 3 1
|1i with probability , and the state collapses to |10i + |11i.
4 2 2
Now if we measure the right qubit after this, the possible outcomes for the sequence
of measurements are |00i, |01i, |10i, and |11i. The probability of getting |00i is the
probability of first getting |0i for the left qubit, which was 3/4, times the probability
of getting |0i for the right qubit, which is 2/3 because the state collapsed after the
first measurement. Multiplying these, the probability of getting |00i is (3/4)(2/3) =
2/4 = 1/2. We can perform this calculation for every possible outcome:

32 1
Prob(|00i) = Prob(first left |0i) Prob(then right |0i) = = ,
43 2
31 1
Prob(|01i) = Prob(first left |0i) Prob(then right |1i) = = ,
43 4
13 3
Prob(|10i) = Prob(first left |1i) Prob(then right |0i) = = ,
4 4 16
11 1
Prob(|11i) = Prob(first left |1i) Prob(then right |1i) = = .
4 4 16
Notice these outcomes and probabilities are exactly the same as if we had measured
both qubits at the same time, as they should be. Measuring both qubits is the same
as measuring one after another, assuming the state was not modified between the
two measurements.
Exercise 4.9. Consider the two-qubit state
p
1 1 1 3
|00i + |01i + p |10i + |11i.
4 2 2 4

If you measure only the left qubit, what are the resulting states, and with what probabilities?

Exercise 4.10. Consider the three-qubit state

1 1 1 1 1 1 1 1
|000i + p |001i + p |010i + |011i + |100i + |101i + |110i + p |111i.
6 3 2 6 2 6 3 6 3
4.3 Entanglement 147

If you measure only the left and right qubits, but not the middle qubit, what are the resulting states,
and with what probabilities?

4.3 Entanglement

4.3.1 Product States

Some quantum states can be factored into (the tensor product of) individual qubit
states. For example,
1 1 1
(|00i |01i + |10i |11i) = p (|0i + |1i) ⌦ p (|0i |1i)
2 2 2
| {z } | {z }
|+i | i

= |+i ⌦ | i
= |+i| i.

To confirm this to yourself, work it out in reverse order by multiplying out the states
and showing that you get the original state. Such factorizable states are called prod-
uct states or simply separable states. Each single-qubit state can be visualized on
the Bloch sphere, so |+i| i would be two Bloch spheres, with the first at the x-axis,
and the other at the x-axis:
z z

y y
x x

Let us work through an example of how to factor a state. Say two qubits are in
the state
1 ⇣p p ⌘
p 3|00i 3|01i + |10i |11i .
2 2
We want to write this as the product of two single-qubit states,

|y1 i|y0 i,

where
|y1 i = a1 |0i + b1 |1i, |y0 i = a0 |0i + b0 |1i.
Then,
148 4 Multiple Quantum Bits

|y1 i|y0 i = (a1 |0i + b1 |1i) (a0 |0i + b0 |1i)


= a1 a0 |00i + a1 b0 |01i + b1 a0 |10i + b1 b0 |11i.

Matching up the coefficients with our original state,


p p
3 3 1 1
a1 a0 = p , a1 b0 = p , b1 a0 = p , b1 b0 = p .
2 2 2 2 2 2 2 2
Using these equations, let us solve for the variables in terms of one of them. Starting
with the first equation, we can solve for a1 in terms of a0 :
p
3
a1 = p .
2 2a0

Plugging this into the second equation, we can solve for b0 in terms of a0 :

b0 = a0 .

For the third equation, we can solve for b1 in terms of a0 :


1
b1 = p .
2 2a0
p
Finally, plugging in b1 = 1/2 2a0 and b0 = a0 into the fourth equation, we get

1 1
p = p ,
2 2 2 2
which is a true statement, so it is satisfied, although it does not tell us anything new.
So, we have solved for a1 , b1 , and b0 in terms of a0 , and this is actually sufficient.
Plugging into the product state,

|y1 i|y0 i = (a1 |0i + b1 |1i) (a0 |0i + b0 |1i)


p !
3 1 1
= p |0i + p |1i (a0 |0i a0 |1i) .
2 2a0 2 2 a0

We see that a0 cancels, yielding


p !
3 1
|y1 i|y0 i = p |0i + p |1i (|0i |1i) .
2 2 2 2
p
Moving the factor of 1/ 2 to the right qubit so that both qubits are normalized,
p !✓ ◆
3 1 1 1
|y1 i|y0 i = |0i + |1i p |0i p |1i .
2 2 2 2
4.3 Entanglement 149
p
3 1
Thus, the left qubit is in the state2 |0i + 2 |1i, and the right qubit is in the state | i.
In general, a product state of n qubits can be written

(an 1 |0i + bn 1 |1i) ⌦ · · · ⌦ (a1 |0i + b1 |1i) ⌦ (a0 |0i + b0 |1i) .

This only has 2n amplitudes, so a classical computer can efficiently store the ampli-
tudes of product states. If quantum computers only used product states, they would
be efficiently simulated by classical computers.

4.3.2 Entangled States

There exist quantum states that cannot be factored into product states. These are
called entangled states. For example, with two qubits,
↵ 1
F + = p (|00i + |11i)
2
cannot be written as |y1 i|y0 i. As a proof, let us try writing it as a product state
using the procedure from the last section:

|y1 i|y0 i = (a1 |0i + b1 |1i) (a0 |0i + b0 |1i)


= a1 a0 |00i + a1 b0 |01i + b1 a0 |10i + b1 b0 |11i.

Matching the coefficients, we get


1 1
a1 a0 = p , a1 b0 = 0, b1 a0 = 0, b1 b0 = p .
2 2
The second equation
p requires a1 = 0 or b0 = 0. If a1 = 0, then the first equation
p
gives 0 = 1/ 2, which is false. If b0 = 0, then the fourth equation gives 0 = 1/ 2.
Thus, there is no solution to these four equations, so |F + i cannot be written as a
product state. It is an entangled state. This property that the state of the qubits are
intertwined is called entanglement.
Since an entangled state cannot be factored, a general entangled state of n qubits
would have N = 2n amplitudes c0 through cN 1 :
0 1
c0
N 1 B c1 C
B C
|yi = Â c j | ji = c0 |0i + c1 |1i + · · · + cN 1 |N 1i = B . C .
j=0 @ .. A
cN 1

In the Entanglion board game, the planets within the Entanglion galaxy corre-
spond to two-qubit states that are entangled. Planet Phi Plus is precisely |F + i.
We will discuss entanglement in more detail in Chapter 6.
150 4 Multiple Quantum Bits

Exercise 4.11. Are each of the following states a product state or entangled state? If it is a product
state, give the factorization.
1
(a) p (|01i + |10i).
2
1
(b) p (|10i + i|11i).
2

Exercise 4.12. Are each of the following states a product state or entangled state? If it is a product
state, give the factorization.
1⇣ p p ⌘
(a) 3|00i 3|01i + 3|10i |11i .
4 r
1 2
(b) p |0i|+i + |1i| i.
3 3

4.4 Quantum Gates

4.4.1 One-Qubit Quantum Gates

Say we have multiple qubits, and we want to apply a single-qubit gate (like I, X,
Y , Z, S, T , or H) to just a single qubit. For example, say we have two qubits in the
|00i = |0i ⌦ |0i state, and we want to apply the Hadamard gate to the left qubit,
but leave the right qubit alone (i.e., apply the identity gate to it). We write the gates
using a tensor product, so we write

(H ⌦ I)(|0i ⌦ |0i) = H|0i ⌦ I|0i


= |+i ⌦ |0i
1
= p (|0i + |1i) ⌦ |0i
2
1
= p (|0i ⌦ |0i + |1i ⌦ |0i) .
2
Compressing the notation and also writing the result as a column vector,
0 1
1
1 1 B 0C
(H ⌦ I)|00i = p (|00i + |10i) = p B C.
2 2 1A
@
0

To draw as a quantum circuit, we use the convention that the rightmost qubit corre-
sponds to the top row of the quantum circuit, and the leftmost qubit corresponds to
the bottom row of the quantum circuit:
|0i I |0i
or
|0i H |0i H
4.4 Quantum Gates 151

We follow this convention so that it matches Quirk, and in Chapter 5 the IBM Quan-
tum Composer. Nielsen and Chuang follows the opposite convention, where the
leftmost qubit corresponds to the top row of the quantum circuit.
We can find H ⌦ I as a matrix a couple different ways. First, we can find how
H ⌦ I acts on each of the basis states |00i, |01i, |10i, |11i. We already found how it
acts on |00i above. Continuing with the rest,
0 1
0
1 1 B 1C
(H ⌦ I)|01i = p (|01i + |11i) = p B C,
2 2 0A
@
1
0 1
1
1 1 B 0C
(H ⌦ I)|10i = p (|00i |10i) = p B @
C,
2 2 1A
0
0 1
0
1 1 B 1C
(H ⌦ I)|11i = p (|01i |11i) = p B C.
2 2 0A
@
1

As in Section 3.3.1, we can write H ⌦ I as a matrix by combining the column vectors


for (H ⌦ I)|00i, . . . , (H ⌦ I)|11i as a 4 ⇥ 4 grid:
0 1
10 1 0
1 B0 1 0 1 C
H ⌦I = p B C.
2 @1 0 1 0 A
01 0 1

The second way to find this matrix is by taking the Kronecker product of H and I:
0 ✓ ◆ ✓ ◆1
✓ ◆ ✓ ◆ 10 10
1· 1·
1 1 1 10 1 B 0 1 C
✓0 1 ◆C
H ⌦I = p ⌦ =p B @
✓ ◆
A
2 1 1 0 1 2 1· 1 0 1 0

01 01
0 1
10 1 0
1 B0 1 0 1 C
=p B C.
2 @1 0 1 0 A
01 0 1

This matches what we previously obtained. We can also find the Kronecker product
using Mathematica or SageMath:
• In Mathematica,
H=1/Sqrt[2]*{{1,1},{1,-1}};
eye={{1,0},{0,1}};
KroneckerProduct[H,eye]
152 4 Multiple Quantum Bits

• In SageMath,
sage: H = 1/sqrt(2) * Matrix([[1,1],[1,-1]])
sage: eye = Matrix([[1,0],[0,1]])
sage: H.tensor_product(eye)

As another example, to act on the left qubit with H and the right qubit with X,
we would write H ⌦ X, so
1
(H ⌦ X)|0i|0i = |+i|1i = p (|01i + |11i) .
2
As a quantum circuit, we would draw this as
|0i X
|0i H

Simulating this in Quirk, we get

This is consistent with the state |+i|1i. Since the right/top qubit is |1i, Quirk cor-
rectly shows that the probability of getting |1i when measuring it is 100% (On),
and it correctly draws the state at the south pole of the Bloch sphere. Similarly, the
left/bottom qubit is |+i, and Quirk correctly shows that the probability of measuring
it to be |1i is 50%, and it correctly draws the state at the x-axis of the Bloch sphere.
In additional, Quirk also depicts the amplitudes on the real-imaginary plane, labeled
“Final amplitudes.” There are four boxes, and the top-left box depicts the amplitude
of p|00i, which is zero, and the top-right box depicts the amplitude of |01i, which is
1/ 2. Since this is real, it corresponds to a vector pointing along the real axis of the
real-imaginary
p plane. The background is also half filled, indicating a probability of
|1/ 2|2 = 1/2. Mousing over, we get

p
and the amplitude is also explicitly given as 0.70711 = 1/ 2, which has a phase
or angle of 0 on the real-imaginary plane since it is purely real, and a norm-square
magnitude of 50%. The bottom-left box depicts the amplitude of |10i, which pis zero,
and finally the bottom-right box depicts the amplitude of |11i, which is 1/ 2.
4.4 Quantum Gates 153

As a third example, if we have n qubits, and we want to apply H to all n qubits,


we can write H ⌦ H ⌦ · · · ⌦ H as H ⌦n . For example,

H ⌦n |0i⌦n = |+i⌦n .

Note one-qubit gates are unable to create entangled states because each qubit
evolves independently of the others. To create entanglement, we need quantum gates
that operate on multiple qubits at a time.
Exercise 4.13. In this problem, you will prove some of the game mechanics of Entanglion. Please
refer to Fig. 4.1 for the game board. If the players are on planet Psi Plus, and either player uses an
X engine card, they both move to planet Phi Plus, and vice versa. Similarly, if the players are on
planet Psi Minus, and either player uses an X engine card, they both move to planet Phi Minus,
and vice versa. These planets correspond to the following states:
↵ 1
F + = p (|00i + |11i) ,
2
↵ 1
F = p (|00i |11i) ,
2
↵ 1
Y + = p (|01i + |10i) ,
2
↵ 1
Y = p (|01i |10i) .
2

(a) Show that when the X gate is applied to either qubit of |Y + i, the result is |F + i, up to a global
phase.
(b) Show that when the X gate is applied to either qubit of |F + i, the result is |Y + i, up to a global
phase.
(c) Show that when the X gate is applied to either qubit of |Y i, the result is |F i, up to a global
phase.
(d) Show that when the X gate is applied to either qubit of |F i, the result is |Y i, up to a global
phase.

Exercise 4.14. Answer the following questions.


(a) What is H ⌦ X as a 4 ⇥ 4 matrix?
(b) Consider p
1 1 1 3
|yi = |00i + |01i + p |10i + |11i.
4 2 2 4
What is (H ⌦ X)|yi? Hint: You may use a computer.

4.4.2 Two-Qubit Quantum Gates

Quantum gates can also operate on two qubits at the same time. Some important
examples include:
• The CNOT gate or controlled-NOT gate inverts the right qubit if the left qubit
is 1:
154 4 Multiple Quantum Bits

CNOT|00i = |00i,
CNOT|01i = |01i,
CNOT|10i = |11i,
CNOT|11i = |10i.

The left qubit is called the control qubit, and the right qubit is called the target
qubit. Note the control qubit is unchanged by CNOT, whereas the target qubit
becomes the XOR (exclusive OR) of the inputs:

CNOT|ai|bi = |ai|a bi.

Thus, CNOT is a quantum XOR gate. Also, since the X gate is the NOT gate,
the CNOT gate is also called the CX gate or controlled-X gate.
In Entanglion (see Fig. 4.1), the player who uses the CNOT engine card is the
target qubit, and the other player is the control qubit. So, you can move between
planets Zero and One by playing a CNOT engine card when the other player is
at One.
Acting on a superposition,

CNOT (c0 |00i + c1 |01i + c2 |10i + c3 |11i)


= c0 CNOT|00i + c1 CNOT|01i + c2 CNOT|10i + c3 CNOT|11i
= c0 |00i + c1 |01i + c2 |11i + c3 |10i
= c0 |00i + c1 |01i + c3 |10i + c2 |11i.

So, the amplitudes of |10i and |11i are swapped.


As a matrix, the columns correspond to CNOT acting on |00i, |01i, |10i, and
|11i: 0 1
1000
B0 1 0 0C
CNOT = B C
@0 0 0 1A .
0010
For example, acting on a general superposition,
0 10 1 0 1
1 0 0 0 c0 c0
B0 1 0 0C Bc1 C Bc1 C
CNOT (c0 |00i + c1 |01i + c2 |10i + c3 |11i) = B
@0
CB C = B C.
0 0 1A @c2 A @c3 A
0 0 1 0 c3 c2

So, the amplitudes of |10i and |11i are swapped, as expected.


As a quantum circuit, CNOT spans two qubits or two lines:


4.4 Quantum Gates 155

The solid dot indicates control, and the denotes the target, which is the XOR
of the control and the target. Simulating this in Quirk, we drag an X gate onto the
top line and a “Control” solid dot, which is in the top Toolbox under “Probes,”
onto the bottom line:

We also clicked on the initial state of the control qubit to change it to |1i (alter-
natively, we could leave the initial state as |0i and apply X to it, resulting in |1i).
This triggers the CNOT, changing the target from |0i to |1i. The result is that
both qubits are “On” with 100% probability. They are both at the south poles of
their Bloch spheres, and the amplitude of |11i is 1.
To further clarify the control and target qubits, we may write CNOT with sub-
scripts:

CNOTi j = CNOT with qubit i as the control and qubit j as the target.

Since we label the qubits from right-to-left starting with 0, we have been using

CNOT = CNOT10 .

If we instead want the control and target to be flipped, it would be CNOT01 , and
we would draw the circuit as

To simulate this in Quirk, we just put the control on the zeroth qubit and the X
gate on the first qubit:

We set the control qubit to |1i, and so the CNOT gate flipped the target to |1i.
Another way to flip the control and target qubits is to apply Hadamard gates to
both sides of the CNOT:
H H •
=
H • H

In other words,
(H ⌦ H)CNOT(H ⌦ H) = CNOT01
156 4 Multiple Quantum Bits

We can prove this circuit identity using either elementary algebra or linear alge-
bra. First, using elementary algebra, the right-hand-side of equation yields the
following when applied to a superposition of the Z-basis states:

CNOT01 (c0 |00i + c1 |01i + c2 |10i + c3 |11i)


= c0 |00i + c1 |11i + c2 |10i + c3 |01i
= (c0 |00i + c3 |01i + c2 |10i + c1 |11i) .

Let us show that the left-hand-side yields the same state:

c0 |00i + c1 |01i + c2 |10i + c3 |11i


H⌦H
! c0 |++i + c1 |+ i + c2 | +i + c3 | i
c0 c1
= (|00i + |01i + |10i + |11i) + (|00i |01i + |10i |11i)
2 2
c2 c3
+ (|00i + |01i |10i |11i) + (|00i |01i |10i + |11i)
2 2
1 1
= (c0 + c1 + c2 + c3 ) |00i + (c0 c1 + c2 c3 ) |01i
2 2
1 1
+ (c0 + c1 c2 c3 ) |10i + (c0 c1 c2 + c3 ) |11i
2 2
CNOT 1 1
! (c0 + c1 + c2 + c3 ) |00i + (c0 c1 + c2 c3 ) |01i
2 2
1 1
+ (c0 + c1 c2 c3 ) |11i + (c0 c1 c2 + c3 ) |10i
2 2
1 1
= (c0 + c1 + c2 + c3 ) |00i + (c0 c1 + c2 c3 ) |01i
2 2
1 1
+ (c0 c1 c2 + c3 ) |10i + (c0 + c1 c2 c3 ) |11i
2 2
H⌦H 1 1
! (c0 + c1 + c2 + c3 ) |++i + (c0 c1 + c2 c3 ) |+ i
4 4
1 1
+ (c0 c1 c2 + c3 ) | +i + (c0 + c1 c2 c3 ) | i
4 4
1
= (c0 + c1 + c2 + c3 ) (|00i + |01i + |10i + |11i)
4
1
+ (c0 c1 + c2 c3 ) (|00i |01i + |10i |11i)
4
1
+ (c0 c1 c2 + c3 ) (|00i + |01i |10i |11i)
4
1
+ (c0 + c1 c2 c3 ) (|00i |01i |10i + |11i)
4
= c0 |00i + c3 |01i + c2 |10i + c1 |11i.

This is the same state, and so we have proved the circuit identity. It was rather
tedious, however. Proving the circuit identity using linear algebra is easier. First,
4.4 Quantum Gates 157

note that 0 1
1 0 0 0
B0 0 0 1C
CNOT01 = B
@0
C,
0 1 0A
0 1 0 0
since its columns show that |00i stays |00i, |01i becomes |11i, |10i stays |10i,
and |11i becomes |01i. Now, let us show that (H ⌦ H)CNOT(H ⌦ H) corre-
sponds to the same matrix. First,
0 1
✓ ◆ ✓ ◆ 1 1 1 1
1 1 1 1 1 1 1 B1 1 1 1C
H ⌦H = p ⌦p = B C.
2 1 1 2 1 1 2 @1 1 1 1A
1 1 1 1

Then,

(H ⌦ H)CNOT(H ⌦ H)
0 10 1 0 1
1 1 1 1 1 0 0 0 1 1 1 1
1BB1 1 1 1C B
C B0 1 0 0C B
C 1 B1 1 1 1C
C
= @
2 1 1 1 1A @0 0 0 1 2 1 1 1 1A
A @
1 1 1 1 0 0 1 0 1 1 1 1
0 10 1
1 1 1 1 1 1 1 1
1B 1 1 1 1C B1 1 1 1C
= B @
CB C
4 1 1 1 1A @1 1 1 1A
1 1 1 1 1 1 1 1
0 1
4000
1 B0 0 0 4C
= B C
4 @0 0 4 0A
0400
0 1
1000
B0 0 0 1C
=B C
@0 0 1 0A .
0100

This is precisely CNOT01 , and so we have proved the circuit identity using
linear algebra. We also could have computed it using Mathematica or SageMath.
Simulating the identity in Quirk,
158 4 Multiple Quantum Bits

Since the top qubit is initially |1i, and it is now the control qubit, the bottom
qubit gets flipped to |1i. So, both qubits are “On.”
The CNOT gate is important because it can produce entanglement. For example,
1 1 ↵
CNOT|+i|0i = CNOT p (|00i + |10i) = p (|00i + |11i) = F+ ,
2 2
1 1 ↵
CNOT| i|0i = CNOT p (|00i |10i) = p (|00i |11i) = F ,
2 2
1 1 ↵
CNOT|+i|1i = CNOT p (|01i + |11i) = p (|01i + |10i) = Y+ ,
2 2
1 1 ↵
CNOT| i|1i = CNOT p (|01i |11i) = p (|01i |10i) = Y .
2 2

In Section 4.3.2, we proved that |F + i is entangled. It can be shown that the


other three states, |F i, |Y + i, and |Y i, are also entangled. So, in each of the
above four calculations, we started with product states and ended up with en-
tangled states. This demonstrates that CNOT can create entanglement. The four
states, |F + i, |F i, |Y + i, and |Y i, are known as the Bell states or EPR states
or EPR pairs (for Einstein, Podolsky, and Rosen). They form an orthonormal
basis called the Bell basis (see Exercise 4.19), and they will be important in
Chapter 6.
In Entanglion (see Fig. 4.1), the player who uses the CNOT engine card is the
target qubit, and the other player is the control qubit. So, playing a CNOT engine
card while at planet Zero, while your teammate is at planet Plus, causes both of
you to move to planet Phi Plus. Similarly, the spaceships go from planets Zero
and Minus to Phi Minus, One and Plus to Psi Plus, and One and Minus to Psi
Minus.

Exercise 4.15. Prove the following circuit identities, such as by finding the matrix representation
of each circuit.
(a) CNOT(X ⌦ I) = (X ⌦ X)CNOT.

X
=
X • • X
(b) CNOT(I ⌦ X) = (I ⌦ X)CNOT.

X X
=
• •
(c) CNOT(Z ⌦ I) = (Z ⌦ I)CNOT.

=
Z • • Z
(d) CNOT(I ⌦ Z) = (Z ⌦ Z)CNOT.
4.4 Quantum Gates 159

Z Z
=
• • Z
Exercise 4.16. Consider the following circuit, which consists of two CNOTs.
A • A0
B • B0
C C0
(a) What is the truth table for this circuit?
(b) How does it compare to the reversible circuit for XOR in Exercise 1.43?
Exercise 4.17. Recall CNOT flips the right qubit if the left qubit is 1. The anti-controlled-NOT
gate flips the right qubit if the left qubit is 0. As a quantum circuit, the anti-control is drawn as an
open dot instead of a solid dot. Prove that it can be obtained from an ordinary CNOT by applying
an X gate to each side of the control:

=
X • X
Exercise 4.18. If we apply CNOT in the Z-basis {|00i, |01i, |10i, |11i}, the left qubit acts as the
control and the right qubit acts as the target. In this problem, we will prove that in the X-basis
{|++i, |+ i, | +i, | i, if the right qubit is | i, the left qubit gets flipped between |+i and | i,
so the control and target are reversed. That is,

CNOT|+i|+i = |+i|+i,
CNOT|+i| i = | i| i,
CNOT| i|+i = | i|+i,
CNOT| i| i = |+i| i.

To prove these four equations, we start with the circuit identity from the main text:

(H ⌦ H)CNOT(H ⌦ H) = CNOT01 .

Then, we multiply on the left and on the right by H ⌦ H:

(H ⌦ H)(H ⌦ H)CNOT(H ⌦ H)(H ⌦ H) = (H ⌦ H)CNOT01 (H ⌦ H).

Since H 2 = I, this becomes

(I ⌦ I)CNOT(I ⌦ I) = (H ⌦ H)CNOT01 (H ⌦ H).

Dropping the identity matrices,

CNOT = (H ⌦ H)CNOT01 (H ⌦ H).

Now it is straightforward to prove how CNOT acts in the X-basis. Beginning with |++i,

CNOT|+i|+i = (H ⌦ H)CNOT01 (H ⌦ H)|+i|+i


= (H ⌦ H)CNOT01 |0i|0i
= (H ⌦ H)|0i|0i
= |+i|+i.

Work out how CNOT acts on the remaining three basis states |+ i, | +i, and | i.
160 4 Multiple Quantum Bits

Exercise 4.19. Prove that the Bell basis satisfies the completeness relation:
↵⌦ ↵⌦ ↵⌦ ↵⌦
F+ F+ + F F + Y+ Y+ + Y Y = I,

where I is the 4 ⇥ 4 identity matrix.

• Just like CNOT, the controlled-U gate applies some quantum gate U to the right
qubit if the left qubit is 1:

CU|00i = |00i,
CU|01i = |01i,
CU|10i = |1i ⌦U|0i,
CU|11i = |1i ⌦U|1i.

To get the matrix representation of CU, first say U acts on a single qubit as

U|0i = a|0i + b|1i,


U|1i = c|0i + d|1i.

So, U as a 2 ⇥ 2 matrix is ✓ ◆
ac
U= .
bd
Then,

CU|00i = |00i,
CU|01i = |01i,
CU|10i = |1i ⌦ (a|0i + b|1i) = a|10i + b|11i,
CU|11i = |1i ⌦ (c|0i + d|1i) = c|10i + d|11i.

Representing each of these as column vectors and putting them together, CU as


a 4 ⇥ 4 matrix is 0 1
1000
B0 1 0 0 C
CU = B C
@0 0 a c A .
00bd
This agrees with 0 1
1 0 0 0
B0 1 0 0C
CNOT = CX = B
@0
C.
0 0 1A
0 0 1 0
Some examples are controlled-Z and controlled-phase:
Z S
• •
4.4 Quantum Gates 161

Exercise 4.20. What is the controlled-Z gate as a matrix?

• The SWAP gate simply swaps the two qubits:

SWAP|00i = |00i,
SWAP|01i = |10i,
SWAP|10i = |01i,
SWAP|11i = |11i.

In other words,
SWAP|ai|bi = |bi|ai.
This gate cannot produce entanglement because, if the qubits are in a product
state, swapping the factors results in a product state. Acting on a superposition,

SWAP (c0 |00i + c1 |01i + c2 |10i + c3 |11i)


= c0 SWAP|00i + c1 SWAP|01i + c2 SWAP|10i + c3 SWAP|11i
= c0 |00i + c1 |10i + c2 |01i + c3 |11i
= c0 |00i + c2 |01i + c1 |10i + c3 |11i.

So, the amplitudes of |01i and |10i are swapped.


As a matrix, the columns correspond to SWAP acting on |00i, |01i, |10i, and
|11i: 0 1
1000
B0 0 1 0C
SWAP = B C
@0 1 0 0A .
0001
For example, acting on a general superposition,
0 10 1 0 1
1 0 0 0 c0 c0
B0 0 1 0C Bc1 C Bc2 C
SWAP (c0 |00i + c1 |01i + c2 |10i + c3 |11i) = B
@0
CB C = B C.
1 0 0A @c2 A @c1 A
0 0 0 1 c3 c3

So, the amplitudes of |01i and |10i are swapped, as expected.


As a quantum circuit, we can draw a SWAP gate using a vertical line with ⇥’s
at each end, or by literally swapping the wires:

|ai ⇥ |bi |ai |bi


or
|bi ⇥ |ai |bi |ai

In Quirk, “Swap” is located in the top Toolbox under “Half Turns”:


162 4 Multiple Quantum Bits

We also included an X gate so that the top qubit is a |1i. This swaps with the
bottom qubit, which then swaps with the middle qubit, so the result is that the
middle qubit is |1i.
A SWAP gate can also be created using three CNOT gates:
⇥ •
=
⇥ • •
Or as an equation,

SWAP = (CNOT)(CNOT01 )(CNOT).

As a proof, we can work through what each CNOT does and show that the result
is a SWAP:
CNOT CNOT01
|ai|bi ! |ai|a bi ! |a a bi|a bi = |(a a) bi|a bi
CNOT
= |0 bi|a bi = |bi|a bi ! |bi|a b bi = |bi|ai.

As another proof, we can multiply the three CNOTs as matrices and show that
we get the matrix of a SWAP:
0 10 10 1 0 1
1000 1000 1000 1000
B0 1 0 0C B0 0 0 1C B0 1 0 0C B0 0 1 0C
B CB CB C B C
@0 0 0 1A @0 0 1 0A @0 0 0 1A = @0 1 0 0A = SWAP.
0010 0100 0010 0001

Exercise 4.21. Entanglion contains four yellow planets besides the Bell States. Please see the game
board at Fig. 4.1. They are labeled Omega Zero through Omega Three. These are not standard
names, but they correspond to the quantum states

1
|w0 i = (|00i |01i + |10i + |11i) ,
2
1
|w1 i = ( |00i + |01i + |10i + |11i) ,
2
1
|w2 i = (|00i + |01i + |10i |11i) ,
2
1
|w3 i = (|00i + |01i |10i + |11i) .
2
The blue player corresponds to the left qubit, and the red player corresponds to the right qubit.
(a) Show that when the SWAP gate is applied to |w0 i, we get |w3 i.
4.4 Quantum Gates 163

(b) Show that when X is applied to the left qubit of |w1 i, we get |w3 i.
(c) Show that when CNOT01 is applied to |w2 i, we get |w0 i.
(d) Show that when CNOT = CNOT10 is applied to |w3 i, we get |w2 i.

Exercise 4.22. The Mølmer-Sørensen (MS) gate is a two-qubit gate that can be naturally imple-
mented on trapped ion quantum computers. It transforms Z-basis states by

1
|00i ! p (|00i + i|11i) ,
2
1
|01i ! p (|01i i|10i) ,
2
1
|10i ! p (|10i i|01i) ,
2
1
|11i ! p (|11i + i|00i) .
2
(a) What is the MS gate as a matrix?
(b) Show that MS8 = I. (You may use a computer.)

4.4.3 Toffoli Gate

A three-qubit gate that often appears in quantum computing is the Toffoli gate, or
controlled-controlled-NOT gate, that we discussed in Section 1.5.3. Since it is re-
versible, it is a quantum gate, and it flips the right qubit if the left and middle qubits
are 1:

Toffoli|000i = |000i,
Toffoli|001i = |001i,
Toffoli|010i = |010i,
Toffoli|011i = |011i,
Toffoli|100i = |100i,
Toffoli|101i = |101i,
Toffoli|110i = |111i,
Toffoli|111i = |110i.

Or
Toffoli|ai|bi|ci = |ai|bi|ab ci.
Recall from Section 1.5.3 that the Toffoli gate is universal for classical comput-
ing, and any efficient classical algorithm can be converted into an efficient algorithm
only utilizing Toffoli gates. Since the Toffoli gate is a quantum gate, quantum com-
puters can efficiently do everything a classical computer can efficiently do. In terms
of complexity classes, P is contained within BQP.
As a matrix, the columns correspond to Toffoli acting on |000i, |001i, . . . , |111i:
164 4 Multiple Quantum Bits
0 1
1 0 0 0 0 0 0 0
B0 1 0 0 0 0 0 0C
B C
B0 0 1 0 0 0 0 0C
B C
B0 0 0 1 0 0 0 0C
Toffoli = B
B0
C.
B 0 0 0 1 0 0 0CC
B0 0 0 0 0 1 0 0C
B C
@0 0 0 0 0 0 0 1A
0 0 0 0 0 0 1 0

In Section 1.5.3, we drew the Toffoli gate as a box. In quantum computing, we


typically draw the Toffoli gate similarly to the CNOT gate, with solid dots indicating
the control qubits and indicating the target:



In Quirk, we simply drag two control dots onto the circuit, along with the X gate:

We made the bottom two qubits both in the |1i state, so the Toffoli gate flips the top
qubit to |1i.
Exercise 4.23. Show that the Toffoli gate can be constructed from the one-qubit gates Hadamard
H, phase S, T , and T † , plus the two-qubit CNOT gate:

H T† T T† T H
• = • • T† T† S
• • • • • T
Just do the matrix multiplications on the computer.
Exercise 4.24. Consider the anti-Toffoli gate, which was introduced in Exercise 1.41. In quan-
tum computing, it is typically drawn like the anti-CNOT gate from Exercise 4.17, with open dots
indicating the anti-controls:

(a) How does the anti-Toffoli gate act on each basis state?
(b) What is the anti-Toffoli gate as a matrix?
4.4 Quantum Gates 165

4.4.4 No-Cloning Theorem

Classically, it is easy to copy or clone information by reading each bit and writing
it somewhere. In quantum computing, cloning qubits is more complicated. Say we
have a qubit in some superposition state. If we measure it in the Z-basis, we get |0i
or |1i with some probability. So, we do not learn the original superposition state.
Furthermore, the measurement collapses the state to |0i or |1i, meaning we lost
whatever superposition state we originally had.
To investigate this in greater detail, say we have a qubit in a known quantum
state, such as |+i. Since we know its state, we can produce additional copies of it:
I⌦H
|+i|0i ! |+i|+i.

We went from having one copy to two. So, copying a known quantum state is no
problem.
The issue is copying an unknown quantum state. Say we have a qubit in an un-
known quantum state |yi = a|0i + b |1i, and we would like to make a copy of it:

|yi|0i ! |yi|yi.

Is there a quantum gate U that allows us to copy or clone a general unknown qubit?
U would need to satisfy
U|yi|0i = |yi|yi.
Expressing this using linear algebra, we require
0 1
U11 U12 U13 U14 ✓ ◆ ✓ ◆ ✓ ◆ ✓ ◆
BU21 U22 U23 U24 C a 1 a a
B C
@U31 U32 U33 U34 A b ⌦ 0 = b ⌦ b
U41 U42 U43 U44
0 10 1 0 2 1
U11 U12 U13 U14 a a
BU21 U22 U23 U24 C B 0 C Bab C
B CB C B C
@U31 U32 U33 U34 A @b A = @ab A
U41 U42 U43 U44 0 b2
0 1 0 21
U11 a +U13 b a
BU21 a +U23 b C Bab C
B C B C
@U31 a +U33 b A = @ab A
U41 a +U43 b b2

There are many possible solutions, such as

U11 = a, U13 = 0, U21 = 0, U23 = a,


U31 = 0, U33 = a, U41 = 0, U43 = b ,
166 4 Multiple Quantum Bits

but this requires knowing a and b , which we do not know. Any general solution
requires knowing a and b , so there is no operator U that allows us to copy a general,
unknown quantum state.
As another “proof,” U|yi|0i = |yi|yi is akin to going from y to y 2 , and this is
quadratic, not linear. The mathematics we are using is called linear algebra because
matrices are linear. Vectors are transformed by linear transformations.
This result is called the no-cloning theorem. While classical information can be
cloned, quantum information can not generally be cloned.
Using this theorem, some scientists have proposed quantum software that cannot
be copied or pirated, and quantum money that cannot be copied or counterfeited,
but that is beyond the scope of this textbook.
Exercise 4.25. Say there is a unitary U that is able to clone qubits in two known states |yi and
|f i. That is,

U|yi|0i = |yi|yi,
U|f i|0i = |f i|f i.

For example, an operator that can clone both |0i and |1i is CNOT, since CNOT|00i = |00i and
CNOT|10i = |11i. Taking the inner product of the previous two equations,

hy|h0|U †U|f i|0i = (hy|hy|) (|f i|f i)


(hy|h0|) (|f i|0i) = (hy|hy|) (|f i|f i)
hy|f ih0|0i = hy|f ihy|f i
hy|f i = (hy|f i)2 .

For hy|f i to be equal to its square, it must equal 0 or 1. Thus, |yi = |f i, or |yi and |f i are
orthogonal. Thus, an operator can only clone states that are orthogonal.
Does there exist a quantum operator U that can clone both
(a) |+i and | i?
(b) |ii and | ii?
(c) |0i and |+i?

4.5 Quantum Adders

In Section 1.3, after defining classical bits and logic gates, we demonstrated how
to compute something: the sum of two binary numbers, each of length n. Now that
we have defined qubits and quantum gates, let us also construct quantum circuits
that add binary numbers. Before we do that, however, let us review the classical
ripple-carry adder.

4.5.1 Classical Adder

First, to review, we can add two binary numbers as follows:


4.5 Quantum Adders 167

(carry) 1 1 1 0 0
1011
“+” 1110
(sum) 11001

Or, in terms of variables,

(carry) c4 c3 c2 c1 c0
a3 a2 a1 a0
“+” b3 b2 b1 b0
(sum) s4 s3 s2 s1 s0

where the initial carry in is c0 = 0. In general, if the binary numbers have length n,
then the output has length n + 1.
Classically, we can add binary numbers using the ripple-carry adder from Sec-
tion 1.3.5:
C0 = 0 S0
A0 FA
B0 S1
A1 FA
B1 S2
A2 FA
B2 S3
A3 FA
B3 C 4 = S4

where FA denotes a full adder:


Cin S
A FA
B Cout

Each full adder has three inputs: a carry in Cin and two bits A and B. From these, it
computes the sum S = A B Cin and the carry out is Cout = AB +Cin (A B).
168 4 Multiple Quantum Bits

4.5.2 Making the Classical Adder a Quantum Gate

This full adder is not reversible, since it does not have enough outputs to uniquely
determine the inputs. So, it is not a quantum gate. There are several ways, however,
to convert it to a quantum gate.
1. From Exercise 1.45, we can turn the full adder into a reversible circuit by taking
the XOR of each of its outputs with and extra bit:
Cin Cin
A A
B B
S

FA
Cout
S D
D

Cout E
E

This entire circuit can be drawn as a single gate with five inputs and five outputs:

Cin Cin
A A
B FA B
Rev
D S D
E Cout E

This gate is reversible, so it is a quantum gate. As we will discuss later in Sec-


tion 4.6, it is always possible to break up a large quantum gate like this into the
smaller gates we are familiar with, but it could take many smaller gates, and the
best way to do this is an open area of research.
2. From Section 1.3.3, a full adder can be made from two XOR gates, two AND
gates, and one OR gate:
4.5 Quantum Adders 169

Cin
S

A
B Cout

One approach is to replace all five of these logic gates with (more than five)
NAND gates. Then, we can implement each NAND gate using a Toffoli gate,
which is reversible and a quantum gate. While this works in principle, the pro-
cedure can be wasteful, leading to extra gates and qubits.
3. Adapting the previous method, instead of converting all the logic gates into
NAND gates and then Toffoli gates, we convert each logic gate into a re-
versible/quantum gate more directly. The basic logic gates are NOT, AND, OR,
XOR, NAND, and NOR. From Section 2.6.3, the X gate is simply the NOT
gate. From Section 1.5.3, the Toffoli gate can implement AND and NAND by
setting its third bit to 0 or 1, respectively. From Exercise 1.41, the anti-Toffoli
gate can implement NOR and OR by setting its third bit to 0 or 1, respectively.
From Exercise 4.16, two CNOT gates can be used to implement XOR. These
results are summarized in the following table:
170 4 Multiple Quantum Bits

Classical Reversible/Quantum

NOT A A X-Gate A X A

A A • A
AND AB Toffoli B • B
B 0 AB
A A
A
OR A+B anti-Toffoli B B
B
1 A+B
A • A
A
XOR A B CNOTs B • B
B
0 A B
A A • A
NAND AB Toffoli B • B
B 1 AB
A A
A
NOR A+B anti-Toffoli B B
B
0 A+B
Replacing each gate in the full adder, we get the following circuit:
Cin • • Cin
A • • A
B • • B
A B
0 • • A B
A B Cin
0 S
AB
0 AB
Cin (A B)
0 Cin (A B)
0 X Cout

The first two CNOTs implement an XOR gate (A B), and the next two CNOTs
also implement an XOR gate, computing A B Cin = S. Next, the Toffoli gate
implements an AND gate (AB), and another Toffoli gate implements another
AND gate [Cin (A B)]. Finally, an X gate turns an extra bit from a 0 to a 1,
and together with an anti-Toffoli gate, they implement an OR gate, yielding
AB + Cin (A B) = Cout . Since these are all reversible gates, it is a quantum
circuit.
4.5 Quantum Adders 171

Notice this method uses several extra bits. Besides the inputs (Cin , A, and B) and
the outputs (S and Cout ), three extra bits were used for intermediate calculations:
A B, AB, and Cin (A B). These extra bits are called ancilla bits or ancillary
bits, and in quantum circuits, they should be cleaned up by turning them back
into zeros. This is so they can be reused in later parts of a circuit and so that they
do not cause unintended entanglement. One method for cleaning up ancillary
bits is called uncomputation, where we apply in reverse order the inverses of
the gates that were used to calculate the ancillas. Since the Toffoli and CNOT
gates are their own inverses, the full adder becomes
Cin • • • Cin
A • • • • A
B • • • • B
0 • • • 0
0 S
0 0
0 0
0 X Cout

Simulating in Quirk (see https://bit.ly/34BY6AD), we get

We see that with all three inputs Cin , A, and B set to 1, both the sum S and carry-
out Cout are 1, as expected, and each of the three ancilla qubits correctly start
and end in |0i.
4. We can come up with a more clever implementation that uses fewer gates and
bits. Let us do this over the next several sections.
172 4 Multiple Quantum Bits

4.5.3 Quantum Setup

Quantumly, we can encode the binary numbers in two quantum registers |ai and |bi.
One way to add them reversibly is to replace |bi with the sum:

|ai|bi ! |ai|si,

where s = a + b. For example, using the quantum adder, 1011 + 1110 = 11001,
would be
|1011i|01110i ! |1011i|11001i.
By adding this way, it is always possible to determine the inputs: a is the left register,
and b can be obtained by subtracting a from s. Since the sum can have length n + 1,
this means our second register needs an extra qubit |bn i that is initially |0i:

|ai = |an 1 i . . . |a1 i|a0 i,


|bi = |bn = 0i|bn 1 i . . . |b1 i|b0 i.

where s = a + b.
In the intermediate steps of the computation, the quantum adder also needs to
keep track of carry bits, so we also have a quantum register of length n for the carry
bits:
|ci = |cn 1 i . . . |c1 i|c0 i.
Initially, this ancillary carry register contains all zeros, and at the end of our com-
putation, we should restore them to all zeros. Putting these together, we want our
quantum adder to map
|ai|bi|ci ! |ai|si|ci.

4.5.4 Quantum Sum

Since CNOT|ai|bi = |ai|a bi, we can implement the sum using two CNOTs:
|ci i
|ci i • |ci i
|ai i
|ai i • |ai i
|ai bi i
|bi i |ai bi ci i = |si i

In the above circuit, the first CNOT turns |bi i into |ai bi i, and the second turns it
into |ai bi ci i, which is |si i: We can combine this into a single quantum gate:
4.5 Quantum Adders 173

|ci i |ci i
|ai i S |ai i
|bi i |ai bi ci i = |si i

There are also several ways to create custom gates in Quirk. One way is to first
create the sum by dragging and dropping controls and X gates:

Next, we can click on the “Make Gate” button at the top of the page. A dialog box
will pop up with different options, and we want to create a gate from the circuit we
just drew:

We can either turn the whole circuit into a gate, or we can just select the first two
columns (1:2). Let us also name the gate “S.” If we click “Create Circuit Gate,” we
return to the main screen, and now our gate appears at the bottom right toolbar under
“Custom Gates:”
174 4 Multiple Quantum Bits

We can drag this onto the main circuit like any other gate:

By changing the initial state of the qubits to |1i, we can also test the circuit to verify
that it adds correctly.

4.5.5 Quantum Carry

Recall from Exercise 1.30) that the OR gate that is used to calculate Cout can be
replaced by an XOR gate. That is,

Cout = AB Cin (A B).

To implement this, recall the Toffoli gate is

Toffoli|ai|bi|ci = |ai|bi|ab ci.

This allows us to create the AND of A and B, XORed with C. Then, a quantum carry
circuit is
|ci i |ci i
|ci i • |ci i
|ai i |ai i
|ai i • • |ai i
|bi i |ai bi i
|bi i • • |ai bi i
|ai bi ci+1 i |ai bi ci+1 i
|ci+1 i |ai bi ci (ai bi ) ci+1 i
In the above circuit, when ci+1 = 0, this carry gate transforms it to ai bi ci (ai bi ),
which is precisely Cout . Combining all this into a single quantum gate,
4.5 Quantum Adders 175

|ci i |ci i
|ai i |ai i
C
|bi i |ai bi i
|ci+1 i |ai bi ci (ai bi ) ci+1 i

Note in the third row that bi ! ai bi , so we will need to uncompute this later.

4.5.6 Quantum Ripple-Carry Adder

Now, let us construct a quantum adder that was proposed by Vedral, Barenco, and
Ekert in 1996. We order the wires to alternate between ci , ai , and bi :
c0 = 0
a0
b0
c1 = 0
a1
b1
c2 = 0
a2
b2
c3 = 0
a3
b3
b4 = 0
For the first operation, we can either calculate the sum s0 using our sum circuit S,
or we can calculate the carry c1 using our carry circuit C. If we begin by calculating
s0 , then we no longer have b0 , but we need b0 to calculate the carry c1 . So, let us
calculate the carry first:
176 4 Multiple Quantum Bits

c0 = 0 c0 = 0
a0 a0
C
b0 a0 b0
c1 = 0 c01
a1 a1
b1 b1
c2 = 0 c2 = 0
a2 a2
b2 b2
c3 = 0 c3 = 0
a3 a3
b3 b3
b4 = 0 b4 = 0

Now that we have c01 , we can either add it to a1 and b1 , or we can calculate the carry
c02 . Again, if we add first, then we no longer have b1 to calculate the carry. So, let us
calculate the next carry, and repeating this argument, we calculate all the carries:
c0 = 0 c0 = 0
a0 a0
C
b0 a0 b0
c1 = 0 c01
a1 a1
C
b1 a1 b1
c2 = 0 c02
a2 a2
C
b2 a2 b2
c3 = 0 c03
a3 a3
C
b3 a3 b3
b4 = 0 s4

Note the last carry corresponds to the leftmost bit of the sum s4 . Now, to calculate
s3 using our sum circuit S, we need the inputs to be c03 , a3 , and b3 , but currently
the third input is a3 b3 . To make this third input simply b3 , we CNOT a3 with it,
resulting in a3 (a3 b3 ) = (a3 a3 ) b3 = 0 b3 = b3 :
4.5 Quantum Adders 177

c0 = 0 c0 = 0
a0 a0
C
b0 a0 b0
c1 = 0 c01
a1 a1
C
b1 a1 b1
c2 = 0 c02
a2 a2
C
b2 a2 b2
c3 = 0 c03
a3 • a3
C
b3 b3
b4 = 0 s4

Now, we can use our sum circuit S to calculate b3 :


c0 = 0 c0 = 0
a0 a0
C
b0 a0 b0
c1 = 0 c01
a1 a1
C
b1 a1 b1
c2 = 0 c02
a2 a2
C
b2 a2 b2
c3 = 0 c03
a3 • S a3
C
b3 s3
b4 = 0 s4

Next, we need to undo c03 so that we just have c3 = 0. We can do this by inverting
the carry gate:
178 4 Multiple Quantum Bits


• •
C† =
• •

Note since C is a quantum gate, it is unitary, so its inverse is equal to its conjugate
transpose (i.e., C 1 = C† ). Applying this,
c0 = 0 c0 = 0
a0 a0
C
b0 a0 b0
c1 = 0 c01
a1 a1
C
b1 a1 b1
c2 = 0 c02
a2 a2
C C†
b2 b2
c3 = 0 c3 = 0
a3 • S a3
C
b3 s3
b4 = 0 s4

This also converted a2 b2 back to b2 , so we can again use the sum circuit to find
s2 = a2 b2 c02 :
4.5 Quantum Adders 179

c0 = 0 c0 = 0
a0 a0
C
b0 a0 b0
c1 = 0 c01
a1 a1
C
b1 a1 b1
c2 = 0 c02
a2 S a2
C C†
b2 s2
c3 = 0 c3 = 0
a3 • S a3
C
b3 s3
b4 = 0 s4

Repeating this process, we can apply C† to convert c02 back to c2 = 0 and a1 b1


back to b1 , and then use the sum circuit to compute s1 , and so forth, resulting in the
following complete circuit:
c0 = 0 c0 = 0
a0 S a0
C C†
b0 s0
c1 = 0 c1 = 0
a1 S a1
C C†
b1 s1
c2 = 0 c2 = 0
a2 S a2
C C†
b2 s2
c3 = 0 c3 = 0
a3 • S a3
C
b3 s3
b4 = 0 s4

This is our quantum ripple-carry adder, and |bi has been replaced by |si (while
keeping |ai and |ci unchanged), as we wanted.
Note the qubits in this circuit have a different order. Rather than taking

|ai|bi|ci ! |ai|si|ci,
180 4 Multiple Quantum Bits

our circuit takes

|b4 i|b3 i|a3 i|c3 i|b2 i|a2 i|c2 i|b1 i|a1 i|c1 i|b0 i|a0 i|c0 i

to
|s4 i|s3 i|a3 i|c3 i|s2 i|a2 i|c2 i|s1 i|a1 i|c1 i|s0 i|a0 i|c0 i.
Let us verify our quantum circuit in Quirk by adding |ai = |1011i and |bi =
|01110i, which should result in |si = |11001i. With the qubit ordering from above,
where all the carry qubits are |0i at the start and end of the computation, the quantum
ripple-carry adder should take

|0110100110010i ! |1110000010110i.

You can view the circuit in Quirk by going to https://bit.ly/39NzEf9. It is also


shown below:

We see that with the input |0110100110010i, the output is |1110000010110i, as


expected.
Exercise 4.26. Simulate the quantum ripple-carry adder in Quirk, and use it to add 1111 + 1011.

Exercise 4.27. We can use an adder to subtract binary numbers by using the fact that

a b = a + b.
4.5 Quantum Adders 181

In Quirk, modify your circuit from Exercise 4.26 to subtract 1111 1011. Do this by adding X
gates to each bit of the input a (this gives a). Then, the adder computes a + b. Then, add X gates to
each bit of s, except for the extra bit s4 , since it is not needed and should stay 0. This gives a + b.

Exercise 4.28. While teaching a course on quantum computing in Fall 2018, one of my Creighton
University students, Lorenzo Riva, proposed the following change to the quantum ripple-carry
adder:
c0 = 0 c0 = 0
a0 S a0
C C†
b0 s0
c1 = 0 c1 = 0
a1 S a1
C C†
b1 s1
c2 = 0 c2 = 0
a2 S a2
C C†
b2 s2
c3 = 0 • c3 = 0
a3 a3
C
b3 s3
b4 = 0 s4
p
That is, the CNOT between a3 and b3 , and the bottommost S (sum, not the S = Z gate), can be
replaced by a single CNOT between c3 and b3 .
(a) Explain why this simplification is correct.
(b) If each binary number has length n, how many Toffoli gates and how many CNOT gates does
this circuit use?

Exercise 4.29. In this exercise, we will learn about another quantum adder that does not need
carry bits. It is called Draper’s adder, and it uses the “quantum Fourier transform,” which will be
discussed later in the textbook in Section 7.7.3.
First, let us define a single-qubit gate Rr that rotates about the z-axis of the Bloch sphere by
angle 360 /2r . For example, R1 = Z is a rotation by 180 , R2 = S is a rotation by 90 , R3 = T is a
rotation by 45 , and R4 is a rotation by 22.5 . Rotations about axes can be created in Quirk using
the “Make Gate” feature, e.g., R4 is
182 4 Multiple Quantum Bits

We also have the conjugate transpose (or inverse) of the rotation, which we denote R†r , and it rotates
about the z-axis by 360 /2r . For example, R†4 rotates by 22.5 , and since it is a negative angle,
it rotates the “other way.”
Draper’s quantum adder transforms

|ai|bi ! |a + bi|bi,

and it does not use any carry qubits. Instead of using the ripple-carry adder, The circuit for the
adder is a little long, so we break it up over three parts:
Part 1
b0 ...
b1 ...
b2 ...
b3 ...
a0 • • • H ...
a1 • • H R2 ...
a2 • H R2 R3 ...
a3 H R2 R3 R4 ...
... Part 2 ...
• • • •
... • • • ...
... • • ...
... • ...
... R1 ...
... R1 R2 ...
... R1 R2 R3 ...
... R1 R2 R3 R4 ...
4.5 Quantum Adders 183

Part 3
... b0
... b1
... b2
... b3
... H • • • s0

... R2† H • • s1

... R3† R2† H • s2

... R4† R3† R2† H s3

Implement Draper’s adder in Quirk and use it to add |ai = |0111i and |bi = |0011i.

4.5.7 Circuit Complexity

Generalizing this, adding two n-bit strings uses n carry gates C, n 1 inverses of the
carry gate C† , n sum gates S, and an extra CNOT gate. Each C and C† gate uses two
Toffoli gates and one CNOT gate, and each S gate uses two CNOT gates. The total
number of quantum gates to add two n-bit strings is summarized in the following
table:
Gate No. of Gates Total No. of Toffolis Total No. of CNOTs
C n 2n n
C† n 1 2(n 1) n 1
S n 0 2n
Extra CNOT 1 0 1
4n 2 4n
Altogether, the quantum ripple-carry adder uses 4n 2 Toffoli gates and 4n CNOT
gates, which is linear in n, i.e., Q (n), so the algorithm is efficient.
Exercise 4.30. How many Toffoli gates and how many CNOT gates does the quantum ripple-carry
adder need to add two (a) 4-bit strings, (b) 8-bit strings.

Exercise 4.31. To add two binary numbers of length 4, our quantum ripple-carry adder used 13
qubits. How many qubits does the quantum ripple-carry adder need to add two binary numbers of
length n?
184 4 Multiple Quantum Bits

4.5.8 Adding in Superposition

Note our quantum ripple-carry adder is a quantum circuit, so it can also act on
superpositions. For example, if |ai is an equal superposition of 6 and 3, i.e.,

1
|ai = p (|0110i + |0011i) ,
2
and if |bi is 11, then
|bi = |01011i,
then the quantum ripple-carry adder turns |ai|bi into

1
p (|0110i|10001i + |0011i|01110i) .
2
It may appear as though we solved two addition problems at once, i.e., in “paral-
lel,” since both 6 + 11 = 17 and 3 + 11 = 14 appear in the answers as |10001i and
|01110i, respectively, but this is not the case. When we measure the result, we get
one sum with probability 1/2 or the other sum with probability 1/2. In contrast, in
parallel computing, two computers calculate both answers at the same time, so we
get both sums at the end.
It is incorrect to think of a quantum computer as a massively parallel classical
computer because we must measure and only get one result. In fact, this misunder-
standing is so common that it might be best to avoid the term “parallel” altogether
when describing quantum computing.
We have seen our first quantum algorithm: the ripple-carry adder. We will get to
many more quantum algorithms in Chapter 7, but there are several other topics to
cover first.
Exercise 4.32. Read “Quantum Computing: A Soccer Analogy” at

https://medium.com/@thomaswong_8663/quantum-computing-a-soccer-a
nalogy-1335644a1472

Answer the following questions and fill in the blanks.


(a) Who is the author of the article, and what is their relationship with the author of this textbook?
(b) “Analogously, the essence of quantum computing is to change the rules so that a computer
can now use its “ .” That is, the rules of the game are changed from
the laws of classical physics to the laws of physics. As a result, a
quantum computer can solve problems faster by using its “hands.” For
other problems, using one’s “feet” is better, so a quantum computer is
for these problems.”
4.6 Universal Quantum Gates 185

4.6 Universal Quantum Gates

4.6.1 Definition

A set of quantum gates that allows us to approximate any quantum gate to any
desired precision is called a universal gate set. Recall in Section 1.2.5 that we used
the same term to describe a set of logic gates that can reproduce all classical gates.
It is usually clear from the context. For example, if the Hadamard gate is involved,
then we must be discussing quantum gates because there is no classical Hadamard
gate. Or, we might describe a set as “universal for classical computing” or “universal
for quantum computing.”
Proving that a set of gates is universal is a more advanced topic, which we do
not discuss in this textbook. Nielsen and Chuang is a good resource for additional
details. Instead, we provide some intuition below.

4.6.2 Components of a Universal Gate Set

There are several components that we need for a set of quantum gates to be universal.

1. Superposition. We must be able to produce superpositions. For example the


Hadamard gate can create superpositions, such as H|0i = |+i. Other gates are
not. Z, S, and T only apply phases; they do not create superpositions of |0i and
|1i. Similarly, the X and CNOT gates only flip |0i and |1i, so they cannot create
superpositions. Y only applies phases and flips, so again superpositions cannot
be created by it.
2. Entanglement. We must be able to entangle qubits. One-qubit gates, such as H,
cannot do this since they only act on a single qubit. A gate must act on at least
two qubits to produce entanglement. CNOT can produce entanglement since
CNOT|+i|0i = |F + i. Not all two qubit gates produce entanglement, however.
The SWAP gate cannot generate entanglement since it only swaps two qubits.
3. Complex amplitudes. CNOT and H only contain real numbers, so they do not
produce states with complex amplitudes.
Just because a set of gates contains these properties does not mean it is universal. For
example, consider {CNOT, H, S}. Although this set satisfies all of the previous re-
quirements (entanglement, superposition, and complex amplitudes), the Gottesman-
Knill theorem says that a quantum circuit containing only these gates is efficiently
simulated by a classical computer.
Introducing some terminology, the set of gates that can be constructed us-
ing, or generated by, {CNOT, H, S} is called the Clifford group1 Then, the set

1 Mathematically, the Clifford group is the normalizer of the Pauli group, which is generated by
the Pauli matrices.
186 4 Multiple Quantum Bits

{CNOT, H, S} is called a Clifford group generator. Thus, a universal quantum gate


set should generate more than the Clifford group:
4. Generate more than the Clifford group.
It is unknown if a set of quantum gates that generates superposition, entanglement,
complex amplitudes, and more than the Clifford group must be universal. It may be
that a set satisfies all four of these properties, but is still not universal.
Exercise 4.33. What property are each of the following gate sets lacking to be universal for quan-
tum computing?
(a) {Toffoli, H, Z}.
(b) {H, X,Y, Z, S, T }.
(c) {SWAP, H, S, T }.

4.6.3 Examples of Universal Gate Sets

Some examples of universal gate sets are:


• {CNOT, all single-qubit gates} is universal for quantum computing.2
• {CNOT, H, T } is universal for quantum computing.3 That is, although the Clif-
ford group generator {CNOT, H, S} is not universal for quantum computing,
replacing S with T does yield a universal gate set. H and T are sufficient to
approximate all one-qubit gates.
• {CNOT, Rp/8 , S} is universal for quantum computing, where
✓ p p

cos 8 sin 8
Rp/8 = p p .
sin 8 cos 8

Although the Clifford group generator {CNOT, H, S} is not universal for quan-
tum computing, replacing H with Rp/8 does yield a universal gate set.
• {Toffoli, H, S} is universal for quantum computing.4 Although {CNOT, H, S} is
not universal for quantum computing, replacing CNOT with Toffoli does yield
a universal gate set.
• H plus almost any two-qubit unitary.

Exercise 4.34. The Clifford group generator {CNOT, H, S} is not universal for quantum comput-
ing. Give three ways to modify the it so that it is universal for quantum computing.

2 A. Barenco, C. H. Bennett, R. Cleve, D. P. DiVincenzo, N. H. Margolus, P. W. Shor, T. Sleator, J.


A. Smolin, and H. Weinfurter. Elementary gates for quantum computation. Phys. Rev. A 52, 3457
(1995).
3 P. O. Boykin, T. Mor, M. Pulver, V. Roychowdhury, and F. Vatan. A new universal and fault-

tolerant quantum basis. Information Processing Letters, 75, 101 (2000).


4 A. Y. Kitaev. Quantum computations: Algorithms and error correction. RMS: Russian Mathe-

matical Surveys 52, 1191 (1997).


4.6 Universal Quantum Gates 187

4.6.4 Solovay-Kitaev Theorem

The Solovay-Kitaev theorem says that with any universal gate set, we can approx-
imate a quantum gate on n qubits to precision e using Q (2n logc (1/e)) gates for
some constant c. The dependence on the number of qubits 2n is what we might ex-
pect since an operator on n qubits is a matrix of 2n ⇥ 2n entries. The dependence on
the precision logc (1/e) is great! The precision e is the “distance” (in some measure-
ment or metric) that the approximate quantum gate is to the actual quantum gate,
and we want it to be small. So 1/e is big, but taking the logarithm of it makes it
small. A logarithm to a constant power, such as logc , is a polynomial of a logarithm,
so is also called polylog. This is also considered small. Thus, this dependence means
our approximation quickly converges on the actual quantum gate.

4.6.5 Quantum Computing without Complex Numbers

Recall any complex number z has a real part x and an imaginary part y, i.e., z = x+iy.
Since x and y are real numbers, this means we can express any complex number as
two real numbers (x, y) and keep track of the fact that they play different roles. So
in theory, we can formulate all of quantum computing just in terms of real numbers.
Then, a universal set of quantum gates technically does not need to produce states
with complex amplitudes. For example, the following sets are also universal for
quantum computing:

• {Toffoli, any single-qubit gate that is basis-changing} is universal for quantum


computing.5 A gate is basis-changing if it changes the Z-basis {|0i, |1i} to an-
other basis. For example, H is basis-changing, since it changes between the
Z-basis {|0i, |1i} and the X-basis {|+i, | i}, so {Toffoli, H} is universal for
quantum computing. In contrast, Z is not basis-changing since Z|0i = |0i and
Z|1i = |1i ⌘ |1i.
As Dorit Aharonov said, “This is perhaps the simplest universal set of gates that
one can hope for [...] It shows that one only needs to add the Hadamard gate to
make a ‘classical’ set of gates quantum universal.”6
• The controlled-Hadamard gate {CH} is universal for quantum computing.7 In
this gate, H is applied to the right qubit if the left qubit is 1. That is, it acts on
Z-basis states as

5 Y. Shi, Both Toffoli and controlled-NOT need little help to do universal quantum computation,
arXiv:quant-ph/0205115 (2002).
6 D. Aharonov, A Simple Proof that Toffoli and Hadamard are Quantum Universal, arXiv:quant-

ph/0301040 (2003).
7 D. J. Shepherd, T. Franz, and R. F. Werner, Universally Programmable Quantum Cellular Au-

tomaton, Phys. Rev. Lett. 97, 020502 (2006).


188 4 Multiple Quantum Bits

CH|00i = |00i,
CH|01i = |01i,
1
CH|10i = |1+i = p (|10i + |11i) ,
2
1
CH|11i = |1 i = p (|10i |11i) .
2
This can simulate both the Toffoli gate and the Hadamard gate, so from the
previous bullet, it is universal.
• {CNOT, any single-qubit gate whose square is basis-changing} is universal for
quantum computing.8 An example of a single-qubit gate whose square is basis-
changing is the following gate U:
p
3 1
U|0i = |0i + |1i,
2 2
p
1 3
U|1i = |0i + |1i.
2 2
Next, if we apply U again, meaning twice to the Z-basis states, we get
p ! p
2 3 1 1 3
U |0i = U |0i + |1i = |0i + |1i,
2 2 2 2
p ! p
2 1 3 3 1
U |1i = U |0i + |1i = |0i + |1i.
2 2 2 2

This is an orthonormal basis, so U 2 is basis-changing. CNOT and U together


form a universal set of quantum gates.
In contrast, the square of the Hadamard gate is not basis-changing because ap-
plying the Hadamard gate twice does nothing:

H 2 |0i = |0i,
H 2 |1i = |1i.

So, {CNOT, H} is not universal, whereas from the first bullet point, {Toffoli, H}
is universal.

8 Y. Shi (2002).
4.7 Quantum Error Correction 189

4.7 Quantum Error Correction

4.7.1 Decoherence

Recall a qubit can be represented by a point on the Bloch sphere:


z
|0i

y
x

|1i

The north pole corresponds to |0i and the south pole corresponds to |1i. For a clas-
sical bit, these would be the only possible states, and the only error is for the bit to
completely flip between the north and south poles. For a qubit, however, every loca-
tion on the Bloch sphere is a different state. For example, beginning at |0i, instead
of completely flipping to |1i, a qubit could experience a partial bit flip error, where
it only rotates a little toward |1i:
z
|0i

y
x

|1i

Since a full bit flip corresponds to the X gate, and the X gate is a rotation about
the x-axis by p = 180 , a partial bit flip corresponds to rotating about the x-axis by
some angle. So, in the above figure, the state is moving leftward, down the Bloch
sphere, in the yz-plane. This small change is an error.
To further complicate matters, a qubit’s state is not just its latitude up and down
the Bloch sphere, but also its longitude around the Bloch sphere. For example, if a
qubit initially in the |+i state gets bumped to the side, we get a different state:
190 4 Multiple Quantum Bits

|+i y
x

This is called a phase flip error, because rotations around the p z-axis correspond
changes
p in the relative phase. For example, |+i = (|0i + |1i)/ 2 and | i = (|0i
|1i)/ 2 lie on opposite sides of the equator.
Since qubits are more sensitive to errors than classical bits, small interactions
with the environment can move the qubit to a different location on the Bloch sphere.
This process is called decoherence. In practice, decoherence is the biggest obstacle
to building large-scale quantum computers, since it is very difficult to isolate a qubit
from its environment while making it accessible for quantum gates and measure-
ments.
Next, we will see how to correct for bit-flip errors and then phase-flip errors.
Then, we will combine both types of error correction into what is known as the
Shor code.

4.7.2 Bit-Flip Code

To make it possible to correct bit-flip errors, we use three physical qubits to encode
each logical qubit:
|0L i = |000i, |1L i = |111i,
where subscript L denotes a logical qubit. A logical qubit is, in general, a superpo-
sition of |0L i and |1L i:

a|0L i + b |1L i = a|000i + b |111i.

A way to create this encoding is given in Exercise 4.35.


For the moment, let us first consider the case where a bit is completely flipped
(e = 1). For example, say the left qubit flips, so

a|000i + b |111i ! a|100i + b |011i


= b |011i + a|100i.
4.7 Quantum Error Correction 191

We would like to detect this error and correct it. Classically, we could just measure
the bits, see which one disagrees with the others, and then flip it back to correct
it. Quantumly, however, if we measure the bits (or even just a single bit), the state
collapses to |100i or |011i, and we lose the superposition. So, instead of measuring
the bits, we follow Section 1.6.3 and measure the parity of adjacent qubits. Recall
that the parity of two bits, a and b, can be calculated using Exclusive OR. That is,
parity(a, b) = a b. Also recall that CNOT|ai|bi = |ai|a bi. Then, we can use
two CNOTs to calculate the parity of two qubits, putting the answer in an ancilla
qubit:
|ai • |ai

|bi • |bi
|0 ai = |ai
|0i |a bi

With three qubits, we can calculate the parities of adjacent qubits by doing this
twice:
|ai • |ai
|bi • • |bi
|ci • |ci
|0i |a bi
|0i |b ci

In this example, the parity of the left two qubits is 1, and the parity of the right two
qubits is 0. This tells us that the left two qubits differ, and the right two qubits are the
same. Then, we know the left qubit has flipped, and we inferred this without directly
measuring and collapsing the state. This is called an error syndrome. To correct
the error, we can simply apply (X ⌦ I ⌦ I), which results in b |111i + a|000i =
a|000i + b |111i, thus correcting the error.
Now, say there is a partial flip. In Section 2.6.4, it was stated that on the Bloch
sphere, a rotation by angle q about the axis n̂ = (nx , ny , nz ) is given by Eq. (2.10):
 ✓ ◆ ✓ ◆
ia q q
e cos I i sin (nx X + nyY + nz Z) , (2.10 revisited)
2 2

where eia is a global phase, so a can be chosen as we please. Now, a partial bit flip
corresponds to a rotation about the x-axis by some angle q , so we have n̂ = (1, 0, 0).
We also choose a = p/2. Then, the rotation corresponds to
✓ ◆ ✓ ◆
q q
i cos I + sin X.
2 2
q p
Letting e = sin(q /2), we get cos(q /2) = 1 sin2 (q /2) = 1 e 2 , so the rota-
tion is
192 4 Multiple Quantum Bits
p p ◆ ✓ ◆ ✓
10 01
i 1 e I + eX = i 1 e
2 2 +e
01 10
✓p ◆
i 1 e2 p e
= .
e i 1 e2

Thus, the partial bit flip maps


p
|0i ! i e 2 |0i + e|1i,
1
p
|1i ! e|0i + i 1 e 2 |1i.

When q = p, e = 1, and we get |0i ! |1i and |1i ! |0i, which is a complete bit
flip, or the X gate.
For example, if the left qubit partially flips,
⇣p ⌘ ⇣p ⌘
a|000i + b |111i ! a i 1 e 2 |000i + e|100i + b i 1 e 2 |111i + e|011i
p p
= ai 1 e 2 |000i + ae|100i + b i 1 e 2 |111i + b e|011i
p p
= ai 1 e 2 |000i + b e|011i + ae|100i + b i 1 e 2 |111i.

Now, we measure the parity of adjacent qubits. Labeling the qubits |q2 q1 q0 i, we get
the following possible outcomes with corresponding probabilities:
• parity(q2 , q1 ) = 0 and parity(q1 , q0 ) = 0 with probability
p 2 p 2
ai 1 e2 + b i 1 e2 = |a|2 1 e 2 + |b |2 1 e2
= |a|2 + |b |2 1 e2
=1 e 2,

and the state collapses to


⇣ p p ⌘
A ai 1 e 2 |000i + b i 1 e 2 |111i = a|000i + b |111i,
p
where A = 1/i 1 e 2 is a normalization constant. We see that the resulting
state is already corrected, so we do not need to do anything further to correct
the error. That is, the measurement fixed the error.
• parity(q2 , q1 ) = 1 and parity(q1 , q0 ) = 0 with probability

|b e|2 + |ae|2 = |a|2 |e|2 + |b |2 |e|2


= |a|2 + |b |2 |e|2
= |e|2 ,

and the state collapses to


4.7 Quantum Error Correction 193

B (b e|011i + ae|100i) = b |011i + a|100i,

where B = 1/e is a normalization constant. To correct this state, we apply (X ⌦


I ⌦ I) so that it becomes

b |111i + a|000i = a|000i + b |111i,

so we have corrected the error.


• parity(q2 , q1 ) = 0 and parity(q1 , q0 ) = 1 with probability 0.
• parity(q2 , q1 ) = 1 and parity(q1 , q0 ) = 1 with probability 0.
Finally, we need to reset the ancilla qubits to |0i so that we can reuse them, since
we want to repeatedly do error correction to fix any errors that appear. We can do
this by conditionally applying an X gate. If we measured a parity to be 0, we know
that the ancilla qubit is |0i, so we leave it alone. If we measured the parity to be 1,
we know that the ancilla qubit is |1i, and so we apply an X gate to it, turning it into
a |0i.
To summarize, when we have a partial bit flip, the measurement forces it to be
corrected or to become a complete bit flip, which we can correct by applying an X
gate. Here is the quantum circuit for this:
|q0 i • X

|q1 i • • X

|q2 i • X

|0i • • |0i

|0i • • |0i

The first four columns are the CNOTs that calculate the parities of adjacent qubits.
Then, we measure these parities, as shown by the meter symbols, which results
in classical bits. We denote these classical bits/wires using double lines. We end
with three X gates conditioned on these classical bits/parities. If both parities are 1,
then q1 flipped, so we apply an X gate to it to correct it. If parity(q2 , q1 ) = 0 and
parity(q1 , q0 ) = 1, then q0 flipped, so we apply an X gate to it to correct it. Finally,
if parity(q2 , q1 ) = 1 and parity(q1 , q0 ) = 0, then q2 flipped, so we apply an X gate
to it to correct it. We end by resetting the ancillas to |0i, indicated by the boxes with
|0i in them. Simulating this in Quirk (see https://bit.ly/3jZ4zKQ),
194 4 Multiple Quantum Bits

In this simulation, the logical qubit starts as |0L i = |000i. In the first column of the
circuit, we can visualize the states on Bloch spheres and confirm that we have |000i.
In the second column, we introduce a bit-flip error by applying a bit-flip X t , with
t varying from 0 to 360 , to q2 . In the third column, we again visualize the states
on the Bloch sphere, confirming that |q2 i 6= |0i. Then, we have our error correction
circuit, and at the very end of the circuit, the top three qubits are restored to |000i,
as expected. Note Quirk does not have a “reset” tool, so the ancillas have not yet
been restored to |0i. This would need to be done to repeat the circuit.
We can modify the above circuit using the principle of deferred measurement,
which says,

Intermediate measurements that are used to control operations can be moved


after the operations, and the controls can be replaced by quantum controls.

Then, the previous quantum circuit to correct bit flips is equivalent to


|q0 i • X

|q1 i • • X

|q2 i • X

|0i • • • |0i

|0i • • |0i

Phrased another way, we can collapse and then do the controlled operations, or we
can do the controlled operations in superposition, and then collapse. Let us prove
this for our previous example, where the qubits started in the state a|000i + b |111i,
but then the left qubit partially flips with amplitude e. From earlier, if we include
the ancilla qubits, the state after the first four CNOTs is
p p
ai 1 e 2 |00000i + b e|10011i + ae|10100i + b i 1 e 2 |00111i.

Recall the qubits are ordered as |parity(q2 , q1 )i|parity(q1 , q0 )i|q2 i|q1 i|q0 i. Now, if
we apply the controlled- and anti-controlled-X gates to correct the answers, the state
becomes
4.7 Quantum Error Correction 195
p p
ai 1 e 2 |00000i + b e|10111i + ae|10000i + b i 1 e 2 |00111i
p
= i 1 e 2 |00i (a|000i + b |111i) + e|10i (a|000i + b |111i)
⇣p ⌘
= i 1 e 2 |00i + e|10i (a|000i + b |111i) .

Measuring the ancilla qubits now, we get:


• parity(q2 , q1 ) = 0 and parity(q1 , q0 ) = 0 with probability 1 e 2 , and the state
collapses to
|00i (a|000i + b |111i) .
• parity(q2 , q1 ) = 1 and parity(q1 , q0 ) = 0 with probability e 2 , and the state col-
lapses to
|10i (a|000i + b |111i) .
This is the same result as before, where we first measured the ancilla qubits and
then applied the controlled- and anti-controlled-X gates. Finally, if the second
outcome occurs, we apply an X gate to the left ancilla to reset it to 0, yielding
|00i (a|000i + b |111i).
Simulating the circuit with deferred measurement in Quirk (see https://bit.
ly/3EyuBMK),

The top three qubits have been successfully corrected to |000i. Again, we have not
reset the ancilla qubits at the end of this circuit, which would be necessary to repeat
the error correction scheme.
Exercise 4.35. In this exercise, we will work through encoding a qubit in the bit-flip code. Say we
have a single qubit in the state
|yi = a|0i + b |0i.
We want to encode this using the bit-flip code. we add two more qubits to our system, all initially
in |0i, so our three qubits are in the state

|y00i = (a|0i + b |1i) |00i = a|000i + b |100i.

Starting with this state, we apply the following quantum circuit:

|0i
|0i =
| i • • •
196 4 Multiple Quantum Bits

Show the final state, after the circuit, is

a|000i + b |111i = a|0L i + b |1L i.

Exercise 4.36. A logical qubit is in the state


p
3 1
|yi = |0L i + |1L i,
2 2
where we encode the logical qubit using three physical qubits:
p
3 1
|yi = |000i + |111i.
2 2
You suspect that a partial bit flip has occurred to one of the bits, so you measure the parity of
adjacent qubits.
(a) If parity(q2 , q1 ) = 0 and parity(q1 , q0 ) = 0, what quantum gate(s) should you apply to fix the
error, if any?
(b) If parity(q2 , q1 ) = 0 and parity(q1 , q0 ) = 1, what quantum gate(s) should you apply to fix the
error, if any?
(c) If parity(q2 , q1 ) = 1 and parity(q1 , q0 ) = 0, what quantum gate(s) should you apply to fix the
error, if any?
(d) If parity(q2 , q1 ) = 1 and parity(q1 , q0 ) = 1, what quantum gate(s) should you apply to fix the
error, if any?

4.7.3 Phase-Flip Code

We can similarly correct phase-flip errors by using three physical qubits to encode
each logical qubit, but instead of using three |0i’s and |1i’s, we use three |+i’s and
| i’s, i.e.,
|0L i = |+ + +i, |1L i = | i,
so a general superposition is

a|0L i + b |1L i = a|+ + +i + b | i.

A way to create this encoding is given in Exercise 4.37. The reason why we use |+i
and | i is because a complete phase flip (the Z gate) switches between these states:

1 Z 1
|+i = (|0i + |1i) ! (|0i |1i) = | i,
2 2
1 Z 1
| i = (|0i |1i) ! (|0i + |1i) = |+i.
2 2
Say the left qubit experiences a complete phase flip:

a|+ + +i + b | i ! a| + +i + b |+ i.

Then, we detect and correct this just like we did for the bit-flip error, except working
in the X-basis. So, we measure the parity of consecutive qubits in the X-basis, which
4.7 Quantum Error Correction 197

is 0 if the number of minuses is even and 1 if the number of minuses is odd. In


Exercise 4.38 and Exercise 4.39, you will show that the parities can be calculated
using
|ai H • H |ai
|bi H • • H |bi
|ci H • H |ci
|0i |a bi
|0i |b ci

In our example where the left qubit experienced a phase flip, we get parity 1 for the
left two qubits and parity 0 for the right two qubits, implying that the first qubit is
flipped. So we apply (Z ⌦ I ⌦ I), restoring a|+ + +i + b | i.
Now for partial phase flips, a partial phase flip corresponds to a rotation about the
z-axis by some angle q , so again using Eq. (2.10) with a = p/2 and e = sin(q /2),
but now with n̂ = (0, 0, 1), we get that the rotation is
p p ✓ ◆ ✓ ◆
10 1 0
i 1 e 2 I + eZ = i 1 e 2 +e
01 0 1
✓p ◆
i 1 e +e p 0
2
= .
0 i 1 e2 e

Thus, the partial phase flip maps


⇣p ⌘
|0i ! i 1 e 2 + e |0i,
⇣p ⌘
|1i ! i 1 e 2 e |1i.

Note when q = p, e = 1, and we get |0i ! |0i and |1i ! |1i, which is a complete
phase flip, or the Z gate. Let us see how a partial phase flip transforms |+i and | i:

1
|+i = p (|0i + |1i)
2
1 h⇣ p ⌘ ⇣p ⌘ i
!p i 1 e 2 + e |0i + i 1 e 2 e |1i
2
p 1 1
= i 1 e 2 p (|0i + |1i) + e p (|0i |1i)
2 2
p
= i 1 e 2 |+i + e| i,
1
| i = p (|0i |1i)
2
1 h⇣ p ⌘ ⇣p ⌘ i
!p i 1 e 2 + e |0i i 1 e 2 e |1i
2
198 4 Multiple Quantum Bits

1 p 1
= e p (|0i + |1i) + i 1 e 2 p (|0i |1i)
2 2
p
= e|+i + i 1 e 2 | i.

Using this, if we have a logical qubit in the state

a|0L i + b |1L i = a|+ + +i + b | i,

a partial phase flip on the left qubit transforms this to


⇣p ⌘ ⇣ p ⌘
a i 1 e 2 |+ + +i + e| + +i + b e|+ i + i 1 e 2| i
p p
= ai 1 e 2 |+ + +i + ae| + +i + b e|+ i + b i 1 e 2| i
p p
= ai 1 e 2 |+ + +i + b e|+ i + ae| + +i + b i 1 e 2 | i.

Now, we measure the parity of adjacent qubits in the X-basis (i.e., whether the num-
ber of | i’s are even or odd). We get:
• parity(q2 , q1 ) = 0 and parity(q1 , q0 ) = 0 with probability
p 2 p 2
ai 1 e2 + b i 1 e2 = |a|2 1 e 2 + |b |2 1 e2
= |a|2 + |b |2 1 e2
=1 e 2,

and the state collapses to


⇣ p p ⌘
A ai 1 e 2 |+ + +i + b i 1 e 2| i = a|+ + +i + b | i,
p
where A = 1/i 1 e 2 is a normalization constant. We see that the resulting
state is already corrected, so we do not need to do anything further to correct
the error. That is, the measurement fixed the error.
• parity(q2 , q1 ) = 1 and parity(q1 , q0 ) = 0 with probability

|b e|2 + |ae|2 = |a|2 |e|2 + |b |2 |e|2


= |a|2 + |b |2 |e|2
= |e|2 ,

and the state collapses to

B (b e|+ i + ae| + +i) = b |+ i + a| + +i,

where B = 1/e is a normalization constant. To correct this state, we apply (Z ⌦


I ⌦ I) so that it becomes
4.7 Quantum Error Correction 199

b| i + a|+ + +i = a|+ + +i + b | i,

so we have corrected the error.


• parity(q2 , q1 ) = 0 and parity(q1 , q0 ) = 1 with probability 0.
• parity(q2 , q1 ) = 1 and parity(q1 , q0 ) = 1 with probability 0.
To summarize, when we have a partial phase flip, the measurement forces it to be
corrected or to become a complete phase flip, which we can correct by applying a Z
gate. The quantum circuit for this procedure is shown below:
|q0 i H • H Z

|q1 i H • • H Z

|q2 i H • H Z

|0i • • |0i

|0i • • |0i

Simulating this in Quirk (https://bit.ly/3e7dNQR):

The top three qubits are |0L i = |+ + +i, and the bottom two qubits will be used to
calculate the parities. In the first column of the circuit, we can visualize the states
on Bloch spheres and confirm that we have |+ + +i. Next, we simulate an error by
applying a phase-flip Z t , with t varying from 0 to 360 , to the middle qubit. Now,
another set of Bloch spheres confirms that the middle qubit has changed. We want
to correct this so that we end up with |+ + +i again. The rest of our circuit is the
same as the bit-flip circuit, except we apply Hadamard gates before and after it so
that we work in the X-basis. In the output, we see that we have restored |+ + +i.
We can move the phase flip to any of the top three qubits, and our error-correcting
circuit will restore the state to |+ + +i. Note we also need to reset the ancilla qubits.
Exercise 4.37. In this exercise, we will work through an exercise for encoding a qubit in the phase-
flip code. Say we have a single qubit in the state

|yi = a|0i + b |0i.

We want to encode this using the phase-flip code. we add two more qubits to our system, all initially
in |0i, so our three qubits are in the state

|y00i = (a|0i + b |1i) |00i = a|000i + b |100i.


200 4 Multiple Quantum Bits

Starting with this state, we apply the following quantum circuit:


|0i H H
|0i H = H
| i • • H • H
Show the final state, after the circuit, is

a|+ + +i + b | i = a|0L i + b |1L i.


Exercise 4.38. Consider the following quantum circuit:
|ai H • H
|bi H • H
|0i
Show that...
(a) If |ai = |+i and |bi = |+i, find the resulting state at the end of the circuit.
(b) If |ai = |+i and |bi = | i, find the resulting state at the end of the circuit.
(c) If |ai = | i and |bi = |+i, find the resulting state at the end of the circuit.
(d) If |ai = | i and |bi = | i, find the resulting state at the end of the circuit.
(e) Using your answers to the previous parts, explain why this circuit calculates the parity in the
X-basis.
Exercise 4.39. Using two copies of the circuit from Exercise 4.38, we can calculate the parity of
adjacent qubits in the X-basis using the following circuit:
|ai H • H |ai
|bi H • H H • H |bi
|ci H • H |ci
|0i |a bi
|0i |b ci
Explain how this is equivalent to the circuit from the text.
Exercise 4.40. A logical qubit is in the state

a|0L i + b |1L i,

where |0L i and |1L i are encoded using the phase-flip code:

|0L i = |+ + +i, |1L i = | i.

That is, the physical qubits are in the state

a|+ + +i + b | i.

Now, the left physical qubit suffers a slight phase flip, causing the state to become
⇣p ⌘ ⇣p ⌘
a i 1 e 2 |+ + +i + e| + +i + b i 1 e 2 | i + e|+ i .

To detect/correct this, you measure the parity of the left two qubits and the parity of the right two
qubits, both in the X-basis.
4.7 Quantum Error Correction 201

(a) What is the probability that both parities are even? If this probability is nonzero, say you
get this outcome. What is the state after the measurement? What gate(s) should you apply to
correct the error, if any?
(b) What is the probability that the parity of the left two qubits is odd and the parity of the right
two qubits is even? If this probability is nonzero, say you get this outcome. What is the state
after the measurement? What gate(s) should you apply to correct the error, if any?
(c) What is the probability that the parity of the left two qubits is even and the parity of the right
two qubits is odd? If this probability is nonzero, say you get this outcome. What is the state
after the measurement? What gate(s) should you apply to correct the error, if any?
(d) What is the probability that both parities are odd? If this probability is nonzero, say you get
this outcome. What is the state after the measurement? What gate(s) should you apply to
correct the error, if any?

4.7.4 Shor Code

We can combine the phase-flip code and bit-flip code to correct both kinds of errors.
We begin with the phase-flip code, so we can correct phase-flip errors. That is,

|0L i = |+ + +i
1 1 1
= p (|0i + |1i) p (|0i + |1i) p (|0i + |1i)
2 2 2
1
= 3/2 (|0i + |1i) (|0i + |1i) (|0i + |1i) .
2
Then, so we can correct bit-flip errors, we replace each of the three qubits with three
qubits using the bit-flip encoding, i.e., |0i ! |000i and |1i ! |111i, so that each
logical qubit is encoded using nine physical qubits:
1
|0L i = (|000i + |111i) (|000i + |111i) (|000i + |111i) .
23/2
Similarly, we begin with |1L i = | i and replace |0i ! |000i and |1i ! |111i:

1
|1L i = (|000i |111i) (|000i |111i) (|000i |111i) .
23/2
Then, the state of a general logical qubit is
a
a|0L i + b |1L i = (|000i + |111i) (|000i + |111i) (|000i + |111i)
23/2
b
+ 3/2 (|000i |111i) (|000i |111i) (|000i |111i) .
2
This encoding is called the Shor code, and it is named after its inventor, Peter Shor,
who proposed it in 1995 and, by doing so, invented quantum error correction. It uses
nine physical qubits to encode one logical qubit. A way to create this encoding is
given in Exercise 4.41.
202 4 Multiple Quantum Bits

Exercise 4.41. A qubit can be encoded using the Shor code by first encoding it in the three-qubit
phase-flip code (Exercise 4.37) followed by encoding each of the three qubits using the three-qubit
bit-flip code (Exercise 4.35), which results in nine qubits total. Applying these encodings one after
another, a method called concatenation, yields the following circuit:
|0i
|0i
|0i H • H •
|0i
|0i =
|0i H • H •
|0i
|0i
| i • H • • H •

In the above circuit, the large dashed box to the left is the phase-flip encoding, which turns
|0i ! |+ + +i and |1i ! | i. Then, the three dashed boxes in the middle are each the bit-flip
encoding, which turns |0i ! |000i and |1i ! |111i.
If the initial state of the circuit is |y00000000i, where |yi = a|0i + b |1i, show that:
(a) The state of the circuit after the first column (after the CNOT with two targets) is

a|000i|000i|000i + b |100i|100i|100i.

(b) The state of the circuit after the second column (after the Hadamard gates) is
a
p (|000i + |100i) (|000i + |100i) (|000i + |100i)
2
b
+ p (|000i |100i) (|000i |100i) (|000i |100i) .
2
(c) The final state of the circuit is
a
(|000i + |111i) (|000i + |111i) (|000i + |111i)
23/2
b
+ 3/2 (|000i |111i) (|000i |111i) (|000i |111i) .
2
This is precisely a|0L i + b |1L i.
Let us see how to correct bit flips and phase flips using the Shor code, beginning
with bit flips. First, remember that the qubits are ordered q8 q7 . . . q0 . Say q8 and q3
both experience complete bit flips. Then, the state of the system is
a
(|100i + |011i) (|001i + |110i) (|000i + |111i)
23/2
b
+ 3/2 (|100i |011i) (|001i |110i) (|000i |111i) .
2
To detect this, we measure the parities of adjacent qubits within each triplet. In this
example, we would get:
4.7 Quantum Error Correction 203

left triplet: parity(q8 , q7 ) = 1, parity(q7 , q6 ) = 0,


middle triplet: parity(q5 , q4 ) = 0, parity(q4 , q3 ) = 1,
right triplet: parity(q2 , q1 ) = 0, parity(q1 , q0 ) = 0.

This tells us that the eighth qubit and third qubit have flipped, so we can apply
X gates to those two qubits to correct them. This also works with partial bit flips.
Measuring the parities of adjacent qubits might collapse the state and correct the
errors, or it might collapse the state into one with full bit flips, which we correct by
applying X gates to the appropriate qubits.
Exercise 4.42. A logical qubit is encoded using nine physical qubits in the Shor code. In each
triplet, you measure the parity of adjacent qubits and get the following results:

left triplet: parity(q8 , q7 ) = 0, parity(q7 , q6 ) = 1,


middle triplet: parity(q5 , q4 ) = 1, parity(q4 , q3 ) = 0,
right triplet: parity(q2 , q1 ) = 1, parity(q1 , q0 ) = 1.

Are there any bit flip errors? If so, which bits flipped, and what can you do to correct them?

Exercise 4.43. Bit flips can be corrected in the Shor code using the following quantum circuit:
|q0 i • X
|q1 i • • X
|q2 i • X
|q3 i • X
|q4 i • • X
|q5 i • X
|q6 i • X
|q7 i • • X
|q8 i • X
|0i • • |0i • • |0i • • |0i
|0i • • |0i • • |0i • • |0i

The first third of the circuit measures the parities of adjacent qubits in the top three qubits, correct
any errors, and reset the ancillas. The middle third of the circuit calculates the parities of adjacent
qubits in the next triplet, correcting any errors. Finally, it does the same for the last triplet of qubits.
Using Quirk, simulate this circuit by inserting it into the following circuit (see https://bi
t.ly/3D1kRKI):
204 4 Multiple Quantum Bits

The first part of this circuit applies the Hadamard gate to |q8 i, turning it into |+i. Then, it uses
the circuit in Exercise 4.41 to encode this in the Shor code. Then, the X t gates applies a partial bit
flip to one qubit in each triplet. In the middle section, you should add the previously given circuit.
Although there is no reset feature in Quirk, you can use the postselection tool as a workaround. In
Quirk, it is drawn as the outer product |0ih0|). It measures a qubit in the {|0i, |1i} basis, and if the
result is |0i, the calculation continues. Otherwise, the simulation starts over. For our purposes, it
has the effect of guaranteeing that the ancilla qubit is |0i before proceeding. A true “reset” feature
would allow us to continue with the ancilla as |0i without the risk of restarting the simulation. In
the last section of the circuit, we undo the Shor encoding and Hadamard gate so that all the qubits
are |0i again. Verify that your circuit does this.

Next, let us see how the Shor code also allows us to correct phase flips. Say q3
experiences a complete phase flip. Then, the state of the system is
a
(|000i + |111i) (|000i |111i) (|000i + |111i)
23/2
b
+ 3/2 (|000i |111i) (|000i + |111i) (|000i |111i) .
2
Then, we can measure the
p “phase parity” of adjacent triplets, i.e., whether the num-
ber of (|000i |111i)/ 2 triplets is even or odd. This is similar to the phase flip
code, where we measured the parity in the X basis to determine if the number of
| i’s was even or odd. How to measure this parity is shown in Exercise 4.44). In
our example, we would get

parity(triplet2 , triplet1 ) = 1, parity(triplet1 , triplet0 ) = 1.

This indicates that the middle triplet needs to be flipped, so we apply the Z gate
to any one of the three qubits in that triplet. That is, we can apply the Z gate to
either q5 , q4 , or q3 , correcting the error. Similarly, when there is a partial phase flip,
if we measure all the phase parities and get zero, the state collapsed and corrected
the error, and if there was a discrepancy in phase parities, we apply a Z gate to the
appropriate triplet to correct it.
4.7 Quantum Error Correction 205

By alternating between correcting bit-flip errors and phase-flip errors, the Shor
code corrects all quantum errors, assuming each triplet experiences at most one bit-
flip error per correction cycle, and at most one triplet experiences a phase-flip error
per correction cycle.
A quantum computer that accumulates errors slowly enough that errors can be
corrected is called fault tolerant. Depending on the error correcting code that is used,
the maximum correctable error rate can vary, and this is an area of active research.
At the time of this writing, a fault tolerant quantum computer does not yet exist, and
one could argue that building one is the “holy grail” of the field.
Exercise 4.44. Consider the following circuit, which computes the phase parity of adjacent triplets
in the Shor code:
|q0 i
|q1 i
|q2 i • H • H •
|q3 i
|q4 i
|q5 i • H • • H •
|q6 i
|q7 i
|q8 i • H • H •
|0i
|0i
Comparing this circuit with Exercise 4.41, the first two layers of this circuit partially unencode
the qubit. Then the middle four layers (the CNOTs) calculate the parity of adjacent triplets in two
ancilla qubits. Then, the final two layers reencode the qubit. In this exercise, we will work through
this for an example.
(a) A qubit a|0L i + b |1L i is encoded using the nine-qubit Shor code, but a physical qubit in the
middle triplet experienced a phase flip, so the state of the nine qubits is
a
(|000i + |111i) (|000i |111i) (|000i + |111i)
23/2
b
+ 3/2 (|000i |111i) (|000i + |111i) (|000i |111i) .
2
Show that after the first two columns of the circuit (the CNOTs with two targets and the
Hadamards), the state of the nine qubits is

a|000100000i + b |100000100i.

(b) Show that after the middle layers of the circuit (CNOTs), the ancilla qubits now store the
phase parities of adjacent triplets.
(c) Show that at the end of the circuit, the state of the nine qubits is again
206 4 Multiple Quantum Bits
a
(|000i + |111i) (|000i |111i) (|000i + |111i)
23/2
b
+ 3/2 (|000i |111i) (|000i + |111i) (|000i |111i) .
2
(d) From the parities in (b), what gate should be applied to fix the phase flip, and to which qubit?

Exercise 4.45. Construct a quantum circuit that corrects when a triplet experiences a phase flip
error in the Shor code. To check your answer, simulate your circuit in Quirk by inserting it into the
following circuit (see https://bit.ly/3kmbTAm):

The first part of this circuit applies the Hadamard gate to |q8 i, turning it into |+i. Then, it uses the
circuit in Exercise 4.41 to encode this in the Shor code. Then, the Z t gates applies a partial bit flip
to one triplet. In the middle section, you should add the previously given circuit. As described in
Exercise 4.43, postselect on |0i as a workaround for resetting the ancilla qubits. In the last section
of the circuit, we undo the Shor encoding and Hadamard gate so that all the qubits are |0i again.
Verify that your circuit does this. Try moving the Z t gate around to different triplets to ensure that
the phase flip is corrected in all instances, as long as at most one triplet experiences a phase flip.

Exercise 4.46. You have a logical qubit encoded in nine physical qubits using the Shor code. Let
us label the qubits q8 q7 . . . q0 . They are grouped into three triplets (triplet2 , triplet1 , triplet0 ).
(a) You begin by detecting bit flip errors. Within each triplet, you measure the parity of adjacent
qubits in the Z-basis. Here are the results:

left triplet: parity(q8 , q7 ) = 1, parity(q7 , q6 ) = 1,


middle triplet: parity(q5 , q4 ) = 0, parity(q4 , q3 ) = 1,
right triplet: parity(q2 , q1 ) = 1, parity(q1 , q0 ) = 0.

Are there any bit flip errors? If so, which bits flipped, and what can you do to correct them?
(b) Next, you measure the parities of adjacent triplets in the H3 -basis. Here are the results:

parity(triplet2 , triplet1 ) = 0, parity(triplet1 , triplet0 ) = 1.

Was there a phase flip error? If so, which triplet flipped, and what can you do to correct it?
4.8 Summary 207

4.8 Summary

The state of multiple qubits is written as as a tensor product. With n qubits, there
are 2n orthonormal basis states, and a general state is a superposition of these basis
states. In a product state, measuring one qubit cannot affect the others, while in an
entangled state, measuring one qubit can affect the other qubits. A quantum gate on
n qubits is a 2n ⇥ 2n unitary matrix. There are various ways to add binary numbers
on a quantum computer. A universal set of quantum gates can approximate any
quantum gate to any desired precision. Quantum bits can suffer from both bit-flip
and phase-flip errors, but they can be corrected, so building a quantum computer
“only” requires really good qubits, not perfect qubits.

You might also like