0% found this document useful (0 votes)
22 views300 pages

Quantum Algorithms for Data Analysis

quantum

Uploaded by

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

Quantum Algorithms for Data Analysis

quantum

Uploaded by

rafaelucros
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Quantum algorithms for data analysis

Alessandro Luongo

2024-12-08
2
Contents

1 Preface 7
1.1 Abstract . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.2 Changelog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.3 Teaching using this book . . . . . . . . . . . . . . . . . . . . . . . 10

I Bridging the gap 13


2 Quantum computing and quantum algorithms 15
2.1 Getting rid of physics in quantum computing . . . . . . . . . . . 15
2.2 Axioms of quantum mechanics . . . . . . . . . . . . . . . . . . . 17
2.3 Measuring complexity of quantum algorithms . . . . . . . . . . . 20
2.4 Review of famous quantum algorithms . . . . . . . . . . . . . . . 24

3 Classical data and quantum computers 31


3.1 Representing data in quantum computers . . . . . . . . . . . . . 31
3.2 Quantum memory . . . . . . . . . . . . . . . . . . . . . . . . . . 36
3.3 Implementations . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
3.4 Use case: working with classical probability distributions . . . . . 72
3.5 Retrieving Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

4 Classical machine learning 77


4.1 Supervised learning . . . . . . . . . . . . . . . . . . . . . . . . . . 78
4.2 Unsupervised learning . . . . . . . . . . . . . . . . . . . . . . . . 78
4.3 Generative and discriminative models . . . . . . . . . . . . . . . 79
4.4 Dimensionality reduction . . . . . . . . . . . . . . . . . . . . . . 80
4.5 Generalized eigenvalue problems in machine learning . . . . . . . 81
4.6 How to evaluate a classifier . . . . . . . . . . . . . . . . . . . . . 82

5 A useful toolbox 85
5.1 Phase estimation . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
5.2 Grover’s algorithm, amplitude games . . . . . . . . . . . . . . . . 86
5.3 Finding the minimum . . . . . . . . . . . . . . . . . . . . . . . . 90

3
4 CONTENTS

5.4 Quantum linear algebra . . . . . . . . . . . . . . . . . . . . . . . 92


5.5 Distances, inner products, norms, and quadratic forms . . . . . . 98
5.6 Hamiltonian simulation . . . . . . . . . . . . . . . . . . . . . . . 105

II Quantum Machine Learning 109


6 Quantum perceptron 111
6.1 Classical perceptron . . . . . . . . . . . . . . . . . . . . . . . . . 112
6.2 Online quantum perceptron . . . . . . . . . . . . . . . . . . . . . 114
6.3 Version space quantum perceptron . . . . . . . . . . . . . . . . . 117

7 SVE-based quantum algorithms 119


7.1 Spectral norm and the condition number estimation . . . . . . . 119
7.2 Explained variance: estimating quality of representations . . . . 119
7.3 Extracting the SVD representations . . . . . . . . . . . . . . . . 122
7.4 Singular value estimation of a product of two matrices . . . . . . 127
7.5 A last example: Slow algorithms for log-determinant . . . . . . . 130

8 Quantum algorithms for Monte Carlo 133


8.1 Monte Carlo with quantum computing . . . . . . . . . . . . . . . 136
8.2 Bounded output . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
8.3 Bounded ℓ2 norm . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
8.4 Bounded variance . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
8.5 Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144

9 Dimensionality reduction 153


9.1 Unsupervised algorithms . . . . . . . . . . . . . . . . . . . . . . . 154
9.2 Supervised algorithms . . . . . . . . . . . . . . . . . . . . . . . . 163

10 q-means 171
10.1 The k-means algorithm . . . . . . . . . . . . . . . . . . . . . . . . 171
10.2 The 𝑞-means algorithm . . . . . . . . . . . . . . . . . . . . . . . . 173
10.3 Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179

11 Quantum Expectation-Maximization 183


11.1 Expectation-Maximization for GMM . . . . . . . . . . . . . . . . 183
11.2 Expectation-Maximization . . . . . . . . . . . . . . . . . . . . . . 185
11.3 Quantum Expectation-Maximization for GMM . . . . . . . . . . 190

12 QML on real datasets 203


12.1 Theoretical considerations . . . . . . . . . . . . . . . . . . . . . . 203
12.2 Experiments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206

13 Quantum algorithms for graph problems 217


13.1 Connectivity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
13.2 Summary of results . . . . . . . . . . . . . . . . . . . . . . . . . . 220
CONTENTS 5

14 Lower bounds on query complexity of quantum algorithms 221


14.1 Polynomial method . . . . . . . . . . . . . . . . . . . . . . . . . . 221
14.2 Quantum adversary method . . . . . . . . . . . . . . . . . . . . . 224

III Everything else 229


15 Selected works on quantum algorithms 231

16 Solutions to exercises 237

A Math and linear algebra 239


A.1 Norms, distances, trace, inequalities . . . . . . . . . . . . . . . . 239
A.2 Linear algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
A.3 Useful theorems around linear algebra . . . . . . . . . . . . . . . 250
A.4 Inequalities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
A.5 Trigonometry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251

B Series 253

C Probability 255
C.1 Measure theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
C.2 Markov chains . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
C.3 Distributions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
C.4 Concentration inequalities . . . . . . . . . . . . . . . . . . . . . . 259

D Error propagation and approximation 265


D.1 Useful quantum subroutines and folklore results . . . . . . . . . . 268

E Approximation theory 269


E.1 Polynomial approximation of log(𝑥) . . . . . . . . . . . . . . . . 269
E.2 Polynomial approximation of 1/𝑥 . . . . . . . . . . . . . . . . . . 269
E.3 Polynomial approximation of other functions . . . . . . . . . . . 277

F Contributions and acknowledgements 279


F.1 License and citation . . . . . . . . . . . . . . . . . . . . . . . . . 281
F.2 Cookie Policy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281

G References 285
6 CONTENTS
Chapter 1

Preface

This open source project accessible on GitHub is only possible thanks to its
many contributors. The website is licensed under CC BY-NC-SA 4.0. We are
searching for talented people and researchers to contribute.
MEMO: we have some funding for motivated contributors
The aim of this book is twofold:
• First, we want to bridge the gap between introductory material in quan-
tum computation and research material.
• Second, you should be able to use this book as a resource for state-of-the-
art algorithms. Readers and scholars should find statements of theorems
(along with their citations) and runtimes of the best quantum subroutines
in literature, ready to be used in new quantum algorithms or applications.
These lecture notes were used to teach at:
• Politecnico di Milano (2019) - Quantum machine learning in practice.
• Politecnico di Milano (2021) - Applied quantum computing.
Are you using these lecture notes to support your course? Write us an email!
This book is dedicated to all cypherpunks: civil liberties through complex math-
ematics.

1.1 Abstract
In these lecture notes, we explore how we can leverage quantum computers
and quantum algorithms for information processing. It has long been known
that quantum computation can offer computational advantages over classical
computation, and in this book we explore the consequences of this fact in current
research areas of computer science.

7
8 CHAPTER 1. PREFACE

Are there other reasons, besides getting a practical computational advantage for
studying quantum algorithms? We argue that having faster algorithms is not
the only reason for studying quantum computing.
One — perhaps shallow — reason is to satisfy our curiosity by studying how
to use quantum mechanical systems for doing computation, and challenging
yourself in finding a faster-then-classical algorithms. Studying quantum compu-
tation might also reveal profound insights into new ways to process information.
For instance, it can give us ideas on processing data in a secure way (though,
quantum cryptography is not discussed in these notes). A better understanding
of quantum computing might lead to understanding the computational limits of
nature: what can be computed in this world? What can be computed with clas-
sical computers? As an example, because of the interplay between research in
classical and quantum computation, many new classical algorithms have been in-
vented (i.e. the dequantizations of quantum machine learning algorithms, new
classical algorithms for Gibbs sampling, classical simulations of quantum cir-
cuits, etc..). This, in turn, improved our understanding of physics, and ulti-
mately of the world itself. One last reason for studying quantum algorithms —
which a computer scientist can surely appreciate — is that quantum computers
are posing a significant challenge to the extended Church-Turing thesis, which
states that any “reasonable” model of computation can be efficiently simulated
on a probabilistic Turing machine. However, there are many physical processes
that we do not know how to simulate efficiently on classical computers, but for
which we have efficient quantum algorithms! This is strong evidence that the
strong Church-Turing thesis might be false!
You might often hear that there are only two real quantum algorithms: phase
estimation and the Grover’s algorithm. This is true in the same way that we
have only 12 notes in the western temperate scale, yet Pink Floyd was able to
write The Dark Side of the Moon (and other musicians came up with “the rest”
of the music).
The common thread of these algorithms is that they are faster than their best
classical counterpart. Oftentimes, (especially for ML) the runtime will depend
only poly-logarithmically on the number of elements of the dataset, and it is
usually only linear in the number of features (classical algorithms are often ei-
ther linear in the number of elements and quadratic in the number of features,
or depend on the number of nonzero components of the matrix and depend
polynomially on other parameters of the matrix). The runtime of a quantum
machine learning algorithm also often depends on characteristics of the matrix
that represents the data under analysis, such as its rank, the Frobenius norm (or
other matrix norms), the sparsity, the condition number, and the error we toler-
ate in the analysis. For this, along with an error-corrected quantum computer,
we assume to have quantum access to a dataset. In other words, we assume that
the data is stored in a quantum memory: the corresponding quantum version
of the classical random-access memory.
We will see that, for a new QML algorithm, one often needs to make sure
1.2. CHANGELOG 9

that the real performances of the quantum algorithms offer concrete advantages
with respect to the effective runtime and the accuracy that is offered by the best
classical algorithms. As we don’t have access to big-enough quantum computers
yet, we can only assess the performance of these quantum algorithms via a
classical simulation.
These lecture notes should prepare the future quantum data analyst to under-
stand the potential and limitations of quantum computers, so as to unlock new
capabilities in information processing and machine learning. The hope is that
this kind of technology can foster further technological advancements that ben-
efit society and humankind, as soon as the hardware that supports this kind of
computation becomes ready.
Last but not least, we will also cover important algorithms that are not necessar-
ily related to machine learning, but are the quantum counterpart of important
classical algorithms. Don’t get swayed by the “lack” of exponential speedups.
Remember: the square root of 365 days is a little less than 3 weeks. Besides this,
big polynomial speedups, small polynomial speedups in important problems, or
polynomial speedups proposing new algorithmic techniques are all much wel-
come in quantum computer science. All in all, quantum algorithms can be seen
as a way for making impossible things possible.
While reading these lecture notes you should always remember a quote from the
good Simon Martiel:
“(quantum) Theoretical computer science is the fun part of mathematics.”
To all of you, happy reading.

1.2 Changelog
• August 2020: Migrated the old blog on bookdown
• December 2020: Moved thesis in bookdown
• January 2021: First system for typesetting algorithms, more appendix
on linear algebra
• February 2021: New subroutines for estimating ℓ1 norms.
• March 2021: [Link] is proudly supported by the Uni-
tary Fund, and [Link] is a project of the QOSF mentor-
ship program: 5 students started creating new content!
• April 2021: Mobile version working, search functionality added, q-means,
finding the minimum, new algo for dimensionality reduction, and factor
score ratio estimation estimation.
• June 2021: Quantum Monte Carlo algorithms, lower bounds techniques
for query complexity of quantum algorithms, quantum algorithms for
graph problems. The output of the mentorship program of the QOSF
foundation!
• January 2022: In the past months we improved the overall quality of
10 CHAPTER 1. PREFACE

the website (graphics, typos) and added some content (Deutsch-Josza,


Bernstein-Vazirani, swap and Hadamard tests)
• February 2022: We are happy to bring our swag (t-shirts, stickers, lan-
yards) to QIP. We added a whole chapter on perceptron algorithms and
we doubled the chapter on quantum Monte Carlo algorithms with appli-
cations to finance and trace distance!
• June 2022: We are participating to the UnitaryHack! We also presented
this work at QNLP2022 where we distributed our swag! Now the website
can be compiled also with the latest version of RStudio,pandoc,bookdown.
• August 2022: Added in the appendix: polynomial approximation of 1/x,
more on concentration inequalities (these were work started by contrib-
utors that discovered the project during the [Link]! ). Improved
css as a bounty to the [Link]. Working (on a separate project) to
improve chapter 3.
• May 2023: We are improving the overall book with the precious help
from the editor (Hue Jun Hao Alexander) and other contributors.
NEW Submit your solution of the exercises as PR on GitHub and get it pub-
lished in the chapter on Solutions.
Coming soon: - quantum perceptrons - quantum random walk - quantum
algorithms for dynamic programming - quantum convolutional neural networks
- quantum random feature sampling

1.3 Teaching using this book


• Lecture 1 - Axioms of quantum mechanics: Chapter 2, section 2.2
• Lecture 2 - Quantum computer science: oracle model, BPP vs
BQP, from boolean to quantum circuits, Solovay-Kitavev, randomized
algorithms, Markov Inequality, Union bound and applications. Section
2.3.
• Lecture 3 Foundational quantum algorithms, Section 2.4: Deutsch-
Josza, Bernstein-Vazirani, Swap-test, Hadamard-test.
• Lecture 4 - Oracles, data representation and data loaders: Oracles
for accessing the data, data representation, sparse models. Chapter 3.
• Lecture 5 - QFT and Grovers’ algorithm: Section 5.2, Section 5.1
• Lecture 6 - Phase estimation, amplitude amplification, counting,
finding the minimum, and applications: Beginning of Chapter 5.
• Lecture 7 (optional) - More foundational quantum algorithms: Si-
mons’s and Shor’s algorithm (#TODO)
• Lecture 8 (optional): Quantum perceptron models: This is a very
simple quantum machine learning algorithm that shows the applications
of different techniques seen so far. (#TODO, very soon!)
• Lecture 9: Quantum numerical linear algebra pt. 1: HHL algo-
rithm, block-encodings and quantum singular value estimation. Mostly
from Chapter 7.
1.3. TEACHING USING THIS BOOK 11

• Lecture 10: Quantum numerical linear algebra pt. 2: Quantum


singular value transformation, Hamiltonian simulation. Theory and ex-
amples.
• Lecture 11: Distance, inner product, trace estimation: From Chap-
ter 5, especially Section 5.5, (#TODO trace estimations).
• Lecture 12: Quantum monte carlo algorithms and applications:
Content from Chapter 8.
• Lecture 13: Quantum machine learning pt. 1: QPCA and QSFA.
Chapter 9 Hamiltonian simulation with density matrices (#TODO).
• Lecture 14: Quantum machine learning pt. 2: Random feature sam-
pling (#TODO, to convert from .tex to markdown, check github repository).
• Lecture 15: Classical simulation of quantum algorithms: How to
simulate a quantum circuit? (#TODO) How to simulate a quantum machine
learning algorithm? Section 12.
• Lecture 16: Lower bounds: Adversarial and polynomial method in Chap-
ter 14, state discrimination (missing).
• Lecture 17 (optional): Between the qubits and me: what do we have
between the theory of our algorithms and the hardware? An overview of
different hardware architectures, error correction codes, and compilation
techniques. (#TODO).
• Lecture 18: Quantum algorithms on graphs: Backtracking algorithms,
NP-complete problems on graphs (#TODO).
• Lecture 19: Quantum optimization: Introduction to optimization.
Quantum simplex, quantum zero-sum games. (#TODO).
• Lecture 20: Quantum optimization: Quantum SDP algorithms,
quantum interior point methods, quantum branch-and-bound algorithms
(#TODO).
12 CHAPTER 1. PREFACE
Part I

Bridging the gap

13
Chapter 2

Quantum computing and


quantum algorithms

In this chapter we will introduce the preliminaries needed for in this book. We
will extensively use linear algebra (norm of matrices, SVD, properties of par-
ticular matrices, and so on), so the reader is highly encouraged to refer to the
appendix regarding the notations adopted.

2.1 Getting rid of physics in quantum comput-


ing
Following one of the lectures of Susskind, we are going to start from a “hand-
wavy” introduction of quantum mechanics, that starts from few considerations
and lead straight to the Schrödinger equation. With a few mathematical tricks,
we are going to justify the 4 axioms of quantum mechanics stated in the next
sections intuitively. The hope is that the reader can be gently guided from
a tiny physical intuition to a greater understanding of the axioms of quan-
tum mechanics. While “axioms of quantum mechanics” implies that physics
is involved, thanks to some of their formulation (see for instance in (Nielsen
and Chuang, 2002), which we adopt), we can ignore the physics and think of
them as “axioms of quantum computing”. As Scott Aaronson rightly said, if
you are not a physicist, you need to remove physics from quantum mechanics
to understanding it!
The objective is that the reader should not feel the need to dig into quantum
mechanical details of quantum computers, but can start solely from the 4 axioms
of quantum mechanics and build (a lot) from there.
At the beginning of the 20th century, when physicists started to model quan-
tum phenomena, they observed that the time and space evolution of quantum

15
16CHAPTER 2. QUANTUM COMPUTING AND QUANTUM ALGORITHMS

systems had two properties: it was continuous and reversible (as in classical
mechanics). They decided to formalize these properties as follows. First, they
decided to model the state of a quantum system at time 𝑝 as a function 𝜓(𝑝),
and they decided to model the evolution of 𝜓(𝑝) for time 𝑡 as an operator 𝑈 (𝑡)
acting on 𝜓(𝑝)s. Let 𝐼 be the identity operator. Formally, the two requirements
can be written as:
• 𝑈 (𝜖) = 𝐼 − 𝑖𝜖𝐻 (continuity)
• 𝑈 † (𝑡)𝑈 (𝑡) = 𝐼 (reversibility)
The first requirement reads that if we were to apply an evolution for a small
amount of time 𝜖, then 𝑈 would behave almost as the identity 𝐼, differing by a
small amount of another operator 𝐻. The second requirement reads that the
operation 𝑈 can be undone by applying a conjugate transpose of 𝑈 . By doing
this we obtain the identity operator. This means that we return to the initial
state of the system before it evolved. From these two requirements, we can
observe that:

𝐼 = 𝑈 † (𝜖)𝑈 (𝜖) = (𝐼 + 𝑖𝜖𝐻)(𝐼 − 𝑖𝜖𝐻) = 𝐼 − 𝑖𝜖𝐻 + 𝑖𝜖𝐻 † + 𝑂(𝜖2 ).


The only way for this equation to hold is for 𝐻 = 𝐻 † , i.e. the operator 𝐻 should
be equal to its transpose conjugate. In mathematics, we call them Hermitian
operators! (More about these in the appendix!). Now we can ask ourselves what
happens when we apply 𝑈 (𝜖) to a quantum state 𝜓(𝑡)? Well it’s simple to see
now:
𝑈 (𝜖)𝜓(𝑡) = 𝜓(𝑡 + 𝜖) = 𝜓(𝑡) − 𝑖𝜖𝐻𝜓(𝑡).
With a little algebra we can rewrite the previous equation as:

𝜓(𝑡 + 𝜖) − 𝜓(𝑡)
= −𝑖𝐻𝜓(𝑡).
𝜖
Note that the left-hand side part of this equation can be rewritten, under the
limit that 𝜖 ↦ 0 as a derivative:
𝑑
𝜓(𝑡) = −𝑖𝐻𝜓(𝑡).
𝑑𝑡
But this is the well-known Schrödinger equation! Note that, as computer scien-
tists, we take the right to remove some physical constant (ℏ) out of the equa-
tion. What should be the takeaway of these observations? We know that the
Schrödinger equation is a differential equation whose solution is fully determined
if we know the initial state of our system 𝜓(𝑝). Formally the solution can be
written as:

𝜓(𝑝 + 𝑡) = 𝑒−𝑖𝐻𝑡 𝜓(𝑝).


From this last equation we can observe further (more on this in the appendix)
that the exponential of an Hermitian matrix 𝑒−𝑖𝐻𝑡 is defined through its Taylor
2.2. AXIOMS OF QUANTUM MECHANICS 17

expansion is just a unitary matrix: 𝑈 (𝑡) = 𝑒−𝑖𝑡𝐻 . Unitary matrices are exactly
those matrices that describe isometries: applying a unitary matrix to a vector do
not change its length. From this, we see that the two quantum states 𝜓(𝑝+𝑡) and
𝜓(𝑝) could be taken just to be vectors of a fixed length, which - for practicality
- we take to be unit vectors. Notation-wise, we denote unit vectors describing
quantum states as “kets”, i.e. we rewrite this equation as:

|𝜓(𝑝 + 𝑡)⟩ = 𝑈 (𝑡)|𝜓(𝑝)⟩


Hopefully, this introduction should be enough for getting a better intuition of
what comes next, and give you a “justification” for the axioms of quantum
mechanics.

2.2 Axioms of quantum mechanics


The standard formalism used in quantum information is the Dirac’s “bra-ket”
notation, which we will introduce in this section. We also state here the postu-
lates of quantum mechanics, and take this opportunity to settle the quantum
notation and quantum preliminaries used in this book. For the postulates, we
follow the standard formulation in (Nielsen and Chuang, 2002).
Proposition 2.1 (Description of a quantum system). Associated to any isolated
physical system is a complex vector space with inner product (that is, a Hilbert
space) known as the state space of the system. The system is completely described
by its state vector, which is a unit vector in the system’s state space.
As quantum states are described by unit vectors, we write |𝜓⟩ for a unit vec-
tor 𝜓 ∈ ℋ𝑑 , where ℋ𝑑 is a 𝑑 dimensional Hilbert space. So for a non-
normalized vector 𝑥 ∈ ℝ𝑑 , the normalized quantum state is represented as
−1 1 𝑛
|𝑥⟩ = ‖𝑥‖ 𝑥 = ‖𝑥‖ ∑𝑖=0 𝑥𝑖 |𝑖⟩, where ‖𝑥‖ is the ℓ2 norm of the vector 𝑥.. We de-
note as {|𝑖⟩}𝑖∈[𝑑] the canonical (also called computational) basis for the Hilbert
space. The transpose-conjugate of |𝑥⟩ is defined as ⟨𝑥|. We can think of |𝑥⟩ as
a column vector, while ⟨𝑥| as a row vector, whose entries have been conjugated.
In Dirac’s notation, we denote the inner product between two vector as ⟨𝑥|𝑦⟩.
Their outer product is denoted as |𝑥⟩⟨𝑦| = ∑𝑖,𝑗∈[𝑑] 𝑥𝑖 𝑦𝑗 |𝑖⟩⟨𝑗| ∈ ℋ𝑑 ⊗ ℋ𝑑 . The
smallest (non-trivial) quantum system is called a qubit, and is a 2 dimensional
unit vector in ℂ2 . A base for this vector space in quantum notation is denoted
as |0⟩ and |1⟩. In this case, the vector |𝜑⟩ = 𝛼|0⟩ + 𝛽|1⟩ for 𝛼, 𝛽 ∈ ℂ represent
a valid quantum state as long as |𝛼|2 + |𝛽|2 = 1.
Proposition 2.2 (Postulate 2). The evolution of a closed quantum system is
described by a unitary transformation. That is, the state |𝜓⟩ of the system at
time 𝑡1 is related to the state |𝜓⟩ of the system at time 𝑡2 by a unitary operator
𝑈 which depends only on the times 𝑡1 and 𝑡2 .
A matrix 𝑈 ∈ ℂ𝑑×𝑑 is said to be unitary if 𝑈 𝑈 † = 𝑈 † 𝑈 = 𝐼, that is, if the inverse
of 𝑈 equal to its conjugate transpose. From this fact it follows that unitary
18CHAPTER 2. QUANTUM COMPUTING AND QUANTUM ALGORITHMS

matrices are norm-preserving, and thus can be used as suitable mathematical


description of a pure quantum evolution. It is a standard exercise to see that
the following are all equivalent definition of unitary matrices (de Wolf, 2019):
• ⟨𝐴𝑣, 𝐴𝑤⟩ = ⟨𝑣, 𝑤⟩ for all 𝑣, 𝑤.
• ‖𝐴𝑣‖ = ‖𝑣‖ for all 𝑣
• ‖𝐴𝑣‖ = 1 if and only if ‖𝑣‖ = 1.
• 𝐴 is a normal matrix with eigenvalues lying on the unit circle
• The columns and the rows of 𝐴 form an orthonormal basis of 𝒞𝑑
• 𝐴 can be written as 𝑒𝑖𝐻 for some Hermitian operator 𝐻.
Example 2.1 (Determinant=1 is a necessary but not sufficient condition for
being unitary). Any 2 × 2 diagonal matrix 𝐴 with entries 10 and 1/10 has
determinant is 1, but it is not a unitary matrix.
It will be useful to recall that if we have a unitary that performs the mapping
|𝑎𝑖 ⟩ ↦ |𝑏𝑖 ⟩, we can have the “matrix” form of the operator as ∑𝑖 |𝑏𝑖 ⟩⟨𝑎𝑖 |. Recall
also that the Pauli matrices are both unitary and Hermitian, and this fact will
be useful in many places throughout this text.
Exercise 2.1 (From (Huang et al., 2019)). Let 𝑘 ∈ {0, 1}𝑛 be an arbitrary
(1) (𝑛)
𝑛-bitstring. Let 𝐴 = (𝜎𝑥 )𝑘1 ⊗ ⋯ ⊗ (𝜎𝑥 )𝑘𝑛 and |𝑏⟩ = |0𝑛 ⟩. What is the solution
to the equation 𝐴|𝑥⟩ = |𝑏⟩
Proposition 2.3 (Postulate 3). Quantum measurements are described by a
collection {𝑀𝑚 } of measurement operators. These are operators acting on the
state space of the system being measured. The index 𝑚 refers to the measurement
outcomes that may occur in the experiment. If the state of the quantum system
is |𝜓⟩ immediately before the measurement, then the probability that the result
𝑚 occurs is given by

𝑝(𝑚) = ⟨𝜓|𝑀𝑚 𝑀𝑚 |𝜓⟩
and the state of the system after the measurement is

𝑀𝑚 |𝜓⟩

√⟨𝜓|𝑀𝑚 𝑀𝑚 |𝜓⟩

The measurement operators satisfy the completeness equation



∑ 𝑀𝑚 𝑀𝑚 = 𝐼
𝑚

In practice, we will mostly perform projective measurements (also called von


Neumann measurements). A projective measurement is described by an observ-
able: an Hermitian operator 𝑀 on the state space of the system being observed.
The observable has a spectral decomposition:

𝑀 = ∑ 𝑚𝑃𝑚
𝑚
2.2. AXIOMS OF QUANTUM MECHANICS 19

where 𝑃𝑚 is a projector into the eigenspace of 𝑀 associated with the eigen-


value 𝑚. This means that the measurement operator will satisfy the following
properties:

• 𝑃𝑚 is positive definite
• 𝑃𝑚 is Hermitian
• ∑𝑚 𝑃𝑚 = 𝐼
• (𝑃𝑚 )(𝑃𝑛 ) = 𝛿𝑚𝑛 (𝑃𝑚 ) are orthogonal projections.

Recall that an orthogonal projector 𝑃 has the properties that 𝑃 = 𝑃 † and


𝑃 2 = 𝑃 . Note that the second property derives from the first: all positive
definite operators on ℂ are Hermitian (this is not always the case for positive
definite operators on ℝ, as it is simple to find positive definite matrices that are
not symmetric). Projective measurements can be understood as a special case of

Postulate 3: in addition to satisfying the completeness relation ∑𝑚 𝑀𝑚 𝑀𝑚 =
𝐼 they also are orthogonal projectors. Given a state |𝜓⟩, the probability of
measuring outcome 𝑚 is given by:

𝑝(𝑚) = ⟨𝜓|𝑃𝑚 |𝜓⟩. (2.1)

If we were to measure outcome 𝑚, then the state of the quantum system after
the measurement would be:
𝑃𝑚 |𝜓⟩
.
√𝑝(𝑚)

They have some useful properties. For example, the average value of a projective
measurement in a state |𝜓⟩ is defined as:

𝐸(𝑀 ) = ∑ 𝑝(𝑚)𝑚
𝑚

= ∑ 𝑚⟨𝜓|𝑃𝑚 |𝜓⟩
𝑚

= ⟨𝜓|(∑ 𝑚𝑃𝑚 )|𝜓⟩


𝑚
= ⟨𝜓|𝑀 |𝜓⟩ (2.2)

In practice, our projective operators will be projectors in the computational


basis, i.e. 𝑃𝑚 = ∑𝑚∈[𝑑] |𝑚⟩⟨𝑚|. As a conseguence of these rules, the probability
1 2
that a measurement on a state |𝑥⟩ = ‖𝑥‖ ∑𝑖 𝑥𝑖 |𝑖⟩ gives outcome 𝑖 is |𝑥𝑖 |2 / ‖𝑥‖ .

Proposition 2.4 (Postulate 4). The state space of a composite physical system
is the tensor product of the state spaces of the component physical systems. More-
over, if we have systems numbered from 1 through 𝑛, and each state is described
𝑛
as |𝜓𝑖 ⟩, the join state of the total system is ⨂𝑗=1 |𝜓𝑖 ⟩ = |𝜓1 ⟩|𝜓2 ⟩ … |𝜓𝑛 ⟩.
20CHAPTER 2. QUANTUM COMPUTING AND QUANTUM ALGORITHMS

The tensor product between two vectors |𝑦⟩ ∈ ℝ𝑑1 and |𝑦⟩ ∈ ℝ𝑑2 is a vector
|𝑧⟩ ∈ ℝ𝑑1 ×𝑑2 . We can use the tensor operation to describe the joint evolution of
separate quantum system.
Even if it is not explicitly used much in quantum algorithms, it is useful to recall
the definition of entangled pure state.
Definition 2.1 (Entangled state). A quantum state that cannot be expressed
as a tensor product of two quantum state is said to be entangled.
The same thing can be done for operators. Let 𝑈1 be the unitary describing the
evolution of a quantum state |𝑥⟩ and 𝑈2 the unitary describing the evolution
of a quantum state |𝑦⟩. Then 𝑈1 ⊗ 𝑈2 describes the evolution of the quantum
system |𝑥⟩ ⊗ |𝑦⟩.
From the definition of tensor product, we see that the tensor product of 𝑛 qubits
(i.e.𝑛 different 2-dimensional vectors) is a vector of size 2𝑛 . Thus, to build a
quantum state that stores 𝑑 numbers in its amplitudes we need ⌈log 𝑑⌉ qubits.
More precisely, observe that for a vector 𝑣 ⃗ ∈ ℋ𝑑 if we want to build |𝑣]⟩ ⃗ = ‖𝑣‖⃗ 𝑣 ⃗
we need only ⌈log 𝑑⌉ numbers. If 𝑑 is not a power of 2, we consider the vector
padded with 0 to the nearest power of 2 bigger than 𝑑. This will allow us to
1 ⌈log 𝑑⌉
build states in the form of ‖𝑣‖ ⃗ ∑𝑖=0 𝑣𝑖 |𝑖⟩. This fact will used a lot in our
quantum algorithms, especially in quantum machine learning. We will discuss
in chapter @ref(#chap-classical-data-quantum-computers) how to create these
kind of quantum states.

2.2.1 Review of important statements in quantum com-


putation
Before delving into a review of quantum algorithms, we would like to state here
a few important lemmas.
Lemma 2.1 (Hadamard on a bitstring (Nielsen and Chuang, 2002)). Let 𝑥 ∈
{0, 1}𝑛 be a bitstring, and 𝐻 be an Hadamard gate. Then:

1 1 𝑇
𝐻 ⊗𝑛 |𝑥⟩ = √ ∑ (−1)𝑥1 𝑧1 +𝑥2 𝑧2 +⋯+𝑥𝑛 𝑧𝑛 |𝑧1 , … , 𝑧𝑛 ⟩ = √ ∑ (−1)𝑥 𝑧 |𝑧⟩,
2𝑛 𝑧1 ,…𝑧𝑛 ∈{0,1}𝑛 2𝑛 𝑧∈{0,1}𝑛
(2.3)
𝑇
where 𝑥 𝑧 is the bitwise inner product of strings in 𝑍2𝑛 modulo 2.

2.3 Measuring complexity of quantum algo-


rithms
This section is an attempt to organize in a coherent way some fundamental
concepts in quantum computer science. Some refereces for this section are (Dörn,
2.3. MEASURING COMPLEXITY OF QUANTUM ALGORITHMS 21

2008), (de Wolf, 2019), and (Kuperberg, 2011). In this section we assume the
read is comfortable with the big O notation.
Intuitively, the time complexity of an algorithm is the number of operations the
computer has to perform from the beginning to the end of the execution of the
algorithm. This model is easy to understand when we think about a personal
computer with one CPU (more precisely, a von Neumann architecture). What is
the right way of measuring the complexity of (quantum) circuits? For example,
suppose to have a quantum circuit of 𝑛 qubits, and for each qubit we apply one
Hadamard gate: what is the time complexity for running this circuit? Is it 𝑂(𝑛)
or 𝑂(1)?. We will discuss here different ways for measuring the complexity of
a quantum algorithm: the number of gates, the depth of the circuit, and the
number of queries to an oracle. The first two are a direct generalization of the
measure of complexity of boolean circuits, where we measure the number of
gates (serial time) or the depth of the circuit (parallel time). The third measure
of complexity is the query complexity, which is the number of times we use (or
query) an oracle: a circuit or a data structure that we can use as a black box.
In this section we will define more formally the query complexity of a quantum
algorithm, and in the next chapter we will explain possible implementations of
different kinds of oracles. The time complexity, which is ultimately the most
relevant measure of complexity of an algorithm for most practical purposes, is
more tricky to define properly. If we assume that our hardware is capable of
executing all the gates at the same depth in parallel, than the measure of time
complexity becomes the depth of the quantum algorithm. We denote with 𝑇 (𝑈 )
as the time complexity needed to implement a quantum circuit implementing a
unitary 𝑈 , and this is measured in terms of number of gates, i.e. the size of
the circuit (this is quite standard see for example the section the introduction
in (Ambainis et al., 2022)). This is a concept that bears some similarity with
the clock rate of classical CPUs. If our hardware is not capable of executing all
the gates at the same depth in one clock, we might have to consider the time
complexity as the number of gates (eventually divided by the number of gates
that can be executed at the same time). As an important exception to this rule
we have the query complexity, where we consider the cost of a single query of
an oracle as 𝑂(1), i.e. as any other gate. This is somehow justified because for
certain oracles we have efficient (i.e. with depth polylogarithmic in the size of
the oracle) implementations. For this, the (often non said) assumption is that
the part of the quantum computer dedicated to run the main part of the circuit
has to be evaluated with serial time (i.e. the number of gates), while the part of
the circuit dedicated to executing the oracle has to be evaluated for its parallel
time complexity. An example of this, which we will treat in more details in the
next chapter is the QRAM and the QRAG gate. This assumption allows to
justifiably conflate the query complexity of an algorithm as its time complexity.
Last but not least, everything is made even more complicated by error correc-
tion. In fact, in some architecture and some error correction codes, the time
complexity of the algorithm is well approximated by the number of 𝑇 gates of
the circuit.
22CHAPTER 2. QUANTUM COMPUTING AND QUANTUM ALGORITHMS

In this book, we use the standard notation of 𝑂 ̃ to hide the polylogarithmic


factors in the big-O notation of the algorithms: 𝑂(𝑛 log(𝑛)) = 𝑂(𝑛). ̃ The
meticulous reader may notice that in this way we might make the notation am-
biguous, as it might not be clear what is hidden in the 𝑂 ̃ notation. The correct
way of using this notation is to hide only factors that appear with a dependency
̃
bigger than the logarithm (i.e. 𝑂(𝑛 log(𝑛)) = 𝑂(𝑛) but 𝑂(𝑛 log(𝑛) log(1/𝜖)) =
̃
𝑂(𝑛 log(1/𝜖))). Another possibility, to make our runtimes more precise, is to
use a subscript to specify the factors that we choose to hide:

̃ ( 1 ) = 𝑂 ( 1 log(1/𝜖) log(1/𝛿))
𝑂 (2.4)
𝜖,𝛿
𝜖 𝜖

Definition 2.2 (Quantum query or oracle access to a function). Let ℋ be a


finite-dimensional Hilbert space with basis {0, 1}𝑛 . Given 𝑓 ∶ {0, 1}𝑛 → {0, 1}𝑚 ,
we say that we have quantum query access to 𝑓 if we have access to a unitary
𝑚
operator 𝑈𝑓 on ℋ ⊗ ℂ2 such that 𝑈 |𝑥⟩|𝑏⟩ = |𝑥⟩|𝑏 ⊕ 𝑓(𝑥)⟩ for any bit string
𝑏 ∈ {0, 1}𝑚 . One application of 𝑈𝑓 costs 𝑇𝑓 operations.
Definition 2.3 (Quantum computation in the query model). Let 𝑂𝑥 be a
unitary operator that encodes the input of our computation, and acts in a
non-trivial way on its associated Hilbert space. A quantum computation with
𝑇 queries to an oracle 𝑂𝑥 ∶ |𝑖, 𝑏, 𝑧⟩ ↦ |𝑖, 𝑏 ⊕ 𝑥𝑖 , 𝑧⟩ is a sequence of unitary
transformations:

𝑈𝑇 𝑂𝑥 𝑈𝑇 −1 𝑂𝑥 … 𝑈1 𝑂𝑥 𝑈0

Where each 𝑈𝑡 is a unitary that does not depend on the input of the algorithm.
The output of the computation is obtained by measuring the rightmost register
(by convention).
Note that the second register holds the XOR of the 𝑖-th component of the
input with the previous state of the register (i.e. the b). This is to make the
computation reversible. Importantly, the definition 2.2 is just an example of
function for which we can have query access. We can assume query access to
unitaries creating various kind of quantum states as output. We will see many
examples of oracles as definition 3.8, 3.12, 3.13, and ??.
This is the so-called query model, or oracle model of (quantum) computation.
An important thing here is the last statement of Definition 2.2, on the cost
of applying 𝑈𝑓 , which is 𝑂(1). There are multiple reasons for working in this
model, which might appear unrealistic at this time. First, it is often the case
that queries to these oracles are actually efficient (as we will see in many ex-
ample), so the query complexity is actually equivalent (up to multiplicative
polylogarithmic factors) to the depth of the quantum circuit that is going to
be executed. Another reason is that in the oracle model is relatively simple to
prove lower bounds and results about the complexity of an algorithm in terms
of the number of queries to an oracle that encodes the input of the problem. It
2.3. MEASURING COMPLEXITY OF QUANTUM ALGORITHMS 23

is customary, for complex results in quantum algorithms to separate the study


of the query complexity of the problem and the depth or gate complexity of the
quantum circuit which is executed on the real hardware. We formalize more
this difference in the following definition.
Definition 2.4 (Query complexity of an algorithm). The quantum query com-
plexity of a quantum algorithm 𝒜 is the number of queries to a black-box made
by 𝒜 in order to compute 𝑓.
If we just care about the relativized complexity, we might limit ourselves to
compare two algorithms that solve the same problem in terms of the number of
queries to a given oracle, we might observe that one is faster than the other. This
is a relativized speedup. The oppositive is an absolute speedup, i.e. when we
also take into account the complexity of the operations that are not queries to
an oracle. In the case of quantum algorithms, these might simply be the gate
depth of the circuit.
Definition 2.5 (Circuit complexity or time complexity). The quantum circuit
complexity (or time complexity) of a quantum algorithm 𝒜 is the depth of the
quantum circuit implementing 𝒜.
Quantum computing is not the only place where we measure the complexity in
terms of query to an oracle. In fact, it’s sufficient to do a few “queries” (pun
intended) on your search engine to realize that in many computational models
we have adopted this measure of computational complexity.
Note that the query complexity of an algorithm is a lower bound
on the gate complexity of the quantum circuit. It is often simpler to
study first the query complexity of a quantum algorithm and then study the
time complexity. For most quantum algorithms (but not all!) the time com-
plexity coincides with the query complexity, up to a logarithmic factor. Note
that, if we find a way to have an oracle whose depth (i.e. circuit complexity)
is only (poly)logarithmic in the input size, then the query complexity and the
gate complexity coincide up to a negligible polylogarithmic factor. There are
some exceptions. Most notably, there is a quantum algorithm for the important
hidden subgroup problem with only polynomial query complexity, while the clas-
sical counterpart has a query complexity that is exponential in the input size.
Nevertheless, the overall time complexity of the quantum algorithm is (to date)
still exponential, and polynomial-time quantum algorithms are known only for
a few specializations of the problem.
We will clarify better some definitions that are used to describe the probabilistic
behavior of an algorithm:
Definition 2.6 (Randomized algorithms). Let 𝑓 ∶ {0, 1}𝑁 ↦ {0, 1} be a
Boolean function. An algorithm computes 𝑓:
• exactly if the outputs equals 𝑓(𝑥) with probability 1 for all 𝑥 ∈ {0, 1}𝑁
• with zero error if it is allowed to give the answer “UNDEFINED” with
probability smaller than 1/2 (but if the output is 0 or 1 it must be correct)
24CHAPTER 2. QUANTUM COMPUTING AND QUANTUM ALGORITHMS

• with bounded error if the output equals 𝑓(𝑥) with probability greater
than 2/3 for all 𝑥 ∈ {0, 1}𝑁 .
A bounded error (quantum or classical) algorithm that fails with probability
1/3 (or any other constant smaller than 1/2) is meant to fail in the worst-case.
We do not expect the algorithm to fail in the average case, i.e. for most of the
inputs (see Appendix of (de Wolf, 2019)).
If a (quantum or classical) algorithm is said to output the right answer in ex-
pected (oftain said “in expectation”) running time 𝑇 , we can quickly create
another algorithm that has worst-case guarantees on the runtime. This is
obtained using the Markov’s inequality, i.e. theorem C.2 as follows. Run the
algorithm for 𝑘𝑇 steps, i.e.. stop the execution after 𝑘𝑇 steps if it hasn’t termi-
nated already. If 𝑋 is the random variable of the runtime of the computation
(so 𝔼[𝑋] = 𝑇 ), then:

1
𝑃 𝑟 [𝑋 > 𝑘𝑇 ] ≤
𝑘
1
So with probability ≥ 1 − 𝑘 we will have the output of the algorithm.

2.4 Review of famous quantum algorithms


In this Chapter we will explore some introductory quantum algorithms. While
some of them are not directly related to data analysis nor machine learning, it
is important to report them here because they help us better understand the
model of quantum computation we adopt. Others will prove to be really useful
for the quantum machine learning practitioner.

2.4.1 Deutsch-Josza
Definition 2.7 (Constant function). A function 𝑓 ∶ {0, 1}𝑛 ↦ {0, 1} is constant
if 𝑓(𝑥) = 0∀𝑥 ∈ {0, 1}𝑛 or 𝑓(𝑥) = 1∀𝑥 ∈ {0, 1}𝑛 .
Definition 2.8 (Balanced function). A function 𝑓 ∶ {0, 1}𝑛 ↦ {0, 1} is balanced
if 𝑓(𝑥) = 0 for half of the inputs and 𝑓(𝑥) = 1 for the other half.
Theorem 2.1 (Deutsch-Josza (Deutsch and Jozsa, 1992)). Assume to have
quantum access (as definition 2.2 ) to a unitary 𝑈𝑓 that computes the function
𝑓 ∶ {0, 1}𝑛 ↦ {0, 1}, which we are promised to be either constant or balanced.
There is a quantum algorithm that decides which is the case with probabiliy 1,
using 𝑈𝑓 only once and using 𝑂(log(𝑛)) other gates.

Proof. We start our quantum computer initializing 𝑛 qubit as |0⟩ state foll-
wed by a single ancilla qubit initialized in state |1⟩, which we will use for the
phase-kickback. Then, we apply the Hadamard transform on each of them.
Mathematically, we are performing the following mapping:
2.4. REVIEW OF FAMOUS QUANTUM ALGORITHMS 25

1
|0⟩⊗𝑛 |1⟩ ↦ ⎛
⎜√ ∑ |𝑥⟩⎞
⎟ |−⟩ (2.5)
𝑛
⎝ 2 𝑥∈{0,1}𝑛 ⎠
Now we apply 𝑈𝑓 using the first register (i.e. the first 𝑛 qubits) as input and
the ancilla register (the last qubit) as output. Our quantum computer is now
in the state
⎛ 1
⎜√ ∑ (−1)𝑓(𝑥) |𝑥⟩⎞
⎟ |−⟩
2 𝑛
⎝ 𝑥∈{0,1}𝑛 ⎠
Now we apply 𝑛 Hadamard gates to the 𝑛 qubits in the first registers. Recalling
lemma 2.1, this gives the state

⎛ 1 1
⎜ 𝑛 ∑ (−1)𝑓(𝑥) ∑ (−1)𝑥𝑗 |𝑗⟩⎞
⎟ |−⟩ = ⎛
⎜ 𝑛 ∑ ∑ (−1)𝑓(𝑥)+𝑥𝑗 |𝑗⟩⎞
⎟ |−⟩
2 2
⎝ 𝑥∈{0,1}𝑛 𝑗∈{0,1}𝑛 ⎠ ⎝ 𝑥∈{0,1}𝑛 𝑗∈{0,1}𝑛 ⎠

In this state, note that the normalization factor has changed from √1 to 1
2𝑛 2𝑛 ,
and recall that (−1)𝑥𝑗 is read as (−1)∑𝑝 𝑥𝑝 𝑗𝑝 mod2 . The key idea of the proof
of this algorithm lies in asking the right question to the previous state: what
is the probability of measuring the state |0⟩𝑛 in the first register? The answer
to this question will conclude the proof of this theorem. Before looking at the
probability, observe that the amplitude of the state |𝑗 = 0⟩ we will see that it is
just 21𝑛 ∑𝑥 (−1)𝑓(𝑥) , as 𝑥𝑇 𝑗 = 0 if 𝑗 = 01 … 0𝑛 , for all 𝑥. Then,

⎧1 if 𝑓(𝑥) = 0∀𝑥
1 𝑓
{
∑ (−1) (𝑥) = ⎨−1 if 𝑓(𝑥) = 1∀𝑥 (2.6)
2𝑛 𝑖∈{0,1}𝑛 {0
⎩ if 𝑓(𝑥)is balanced

To conclude, reckon that if the function 𝑓 is constant (first two cases), we will
measure |0⟩⊗𝑛 with probability 1, and if the function is balanced, we will measure
some bitstring of 𝑛 bits that is different than the string 01 … 0𝑛 .

It’s simple to see that if we want to solve this problem with a classical deter-
ministic algorithm, we need exactly 2𝑛 /2 + 1 queries. However, with the usage
of a randomized algorithm we can drastically reduce the number of queries by
admitting a small probability of failure.
Exercise 2.2. Can you think of an efficient randomized classical algorithm
for solving this problem? Perhaps you can use the tools in the Appendix for
randomized algorithms.
We now turn our attention to the first learning problem of this book. This
is rarely stressed that the following algorithm can be interpreted as a learning
algorithm.
26CHAPTER 2. QUANTUM COMPUTING AND QUANTUM ALGORITHMS

2.4.2 Bernstein-Vazirani
Theorem 2.2 (Bernstein-Vazirani). Assume to have quantum access (as defini-
tion 2.2 ) to a unitary 𝑈𝑓 that computes the function 𝑓 ∶ {0, 1}𝑛 ↦ {0, 1}, which
𝑛
computes 𝑓𝑎 (𝑥) = (𝑥, 𝑎) = (∑𝑖 𝑥𝑖 𝑎𝑖 ) mod 2 for a secret string 𝑎 ∈ {0, 1}𝑛 .
There is a quantum algorithm that learns 𝑎 with probability 1, using 𝑈𝑓 only
once and 𝑂(log(𝑛)) other gates.

Proof. The algorithm follows exactly the same steps as the Deutsch-Josza al-
gorithm. The proof is slightly different, and start by noting that, after the
application of the oracle 𝑈𝑓 , the register of our quantum computer is in the
following state:

⎛ 1 1
∑ (−1)𝑓(𝑥) |𝑥⟩⎞
⎟ |−⟩ = ⎛ |𝑥⟩⎞
𝑇
⎜√ ⎜√ ∑ (−1)𝑎 𝑥
⎟ |−⟩ (2.7)
𝑛 𝑛
⎝ 2 𝑥∈{0,1}𝑛 ⎠ ⎝ 2 𝑥∈{0,1}𝑛 ⎠

Now we resort again to Lemma 2.1, and we use the fact that the Hadamard it is
also a self-adjoint operator (i.e. it is the inverse of itself: 𝐻 2 = 𝐼). Thus applying
𝑛 Hadamard gates to the first register leads to the state |𝑎⟩ deterministically.

Exercise 2.3. Can you think of an efficient randomized classical algorithm for
solving Berstain-Vazirani problem? You can use the tools in the Appendix for
randomized algorithms.
Other material for learning about Deutsch-Josza and Bernstein-Vazirani algo-
rithms are the lecture notes of Ronald de Wolf that you can find here.

Figure 2.1: Expect to see here Simon’s algorithm - Contribute here!


2.4. REVIEW OF FAMOUS QUANTUM ALGORITHMS 27

2.4.3 Hadamard test


Let 𝑈 be a unitary acting on 𝑛 qubits, and |𝜓⟩ a quantum state on 𝑛 qubit
(generated by another unitary 𝑉 ). We also require to be able to apply the
controlled version of the unitary 𝑈 . Then, the Hadamard test is a quantum
circuit that we can use to estimate the value of ⟨𝜓|𝑈 |𝜓⟩. The circuit is very
simple, it consists in a Hadamard gate applied on an ancilla qubit, the controlled
application of the unitary 𝑈 and another Hadamard gate.
The initial operation leads to (𝐻 ⊗ 𝑉 )|0⟩|0⟩ = |+⟩|𝜓⟩, then we have:
1
|𝜓final ⟩ = (𝐻 ⊗ 𝐼)(𝑐𝑈 )|+⟩|𝜓⟩ = (𝐻 ⊗ 𝐼) √ (|0⟩|𝜓⟩ + |1⟩𝑈 |𝜓⟩)
2
1
= (|0⟩ (|𝜓⟩ + 𝑈 |𝜓⟩) + |1⟩ (|𝜓⟩ − 𝑈 |𝜓⟩))
2

Note that the last state could be written equivalently, by just factoring out
the |𝜓⟩ state as |𝜓final ⟩ = 21 (|0⟩(𝐼 + 𝑈 )|𝜓⟩ + |1⟩(𝐼 − 𝑈 )|𝜓⟩). The probability of
measuring 0 in the first qubit is:

2
1 1
𝑝(0) = ∥ (𝐼 + 𝑈 )|𝜓⟩∥ = (⟨𝜓| + ⟨𝜓|𝑈 † ) (|𝜓⟩ + 𝑈 |𝜓⟩) (2.8)
2 2 4
2 + ⟨𝜓(𝑈 + 𝑈 † )𝜓⟩ 2 + 2Re(⟨𝜓|𝑈 |𝜓⟩)
= = (2.9)
4 4

Where we used Postulate 2.3 with the observable |0⟩⟨0| ⊗ 𝐼. The probability of
measuring 1 in the first register follows trivially.
Exercise 2.4. Can you tell what is the expected value of the observable 𝑍 of
the ancilla qubit? Remember that the possible outcome of the observable 𝑍 are
{+1, −1}.
However, we might be interested in the imaginary part of ⟨𝜓|𝑈 |𝜓⟩. To estimate
that, we need to slightly change the circuit. After the first Hadamard gate, we
apply on the ancilla qubit a phase gate 𝑆, which gives to the state |1⟩ a phase
of −𝑖. To get the intuition behind this, let’s recall that the imaginary part of
∗ 𝑖(𝑧−𝑧∗ )
a complex number 𝑧 = (𝑎 + 𝑖𝑏) is defined as: Im(𝑧) = 𝑧−𝑧 2𝑖 = −2 = −2𝑏
−2 =
𝑏, where after the definition, we just complicated the series of equations by
multiplying the numerator and denominator by 𝑖, a trick that we will use later.
The rest of the circuit of the Hadamard test stays the same. The evolution of
our state in the quantum computer is the following:

1
|𝜓final ⟩ = (𝐻 ⊗ 𝐼)(𝑐𝑈 ) (|0⟩ − 𝑖|1⟩) |𝜓⟩ = (𝐻 ⊗ 𝐼) √ (|0⟩|𝜓⟩ − 𝑖|1⟩𝑈 |𝜓⟩) (2.10)
2
1
= (|0⟩ (|𝜓⟩ − 𝑖𝑈 |𝜓⟩) + |1⟩ (|𝜓⟩ + 𝑖𝑈 |𝜓⟩)) (2.11)
2
28CHAPTER 2. QUANTUM COMPUTING AND QUANTUM ALGORITHMS

The probability of measuring 0 is given by the following equation.

1 1
𝑝(0) = (⟨𝜓| + 𝑖𝑈 ⟨𝜓|) (|𝜓⟩ − 𝑖𝑈 |𝜓⟩) = (2 − 𝑖⟨𝜓|𝑈 |𝜓⟩ + 𝑖⟨𝜓|𝑈 † |𝜓⟩) (2.12)
4 4

Note that when taking the conjugate of our state, we changed the sign of 𝑖. We
now have only to convince ourselves that −𝑖⟨𝜓|𝑈 |𝜓⟩+𝑖⟨𝜓|𝑈 † |𝜓⟩ = 𝑖⟨𝜓|𝑈 † −𝑈 |𝜓⟩
is indeed the real number corresponding to 2Im(⟨𝜓|𝑈 |𝜓⟩), and thus the whole
equation can be a probability.
Exercise 2.5. Can you check if the 𝑆 gate that we do after the first Hadamard
can be performed before the last Hadamard gate instead?

2.4.4 Modified Hadamard test


In this section we complicate a little the results obtained in the previous one, by
finding the number of samples that we need to draw out of a circuit in order to
estimate the expected value or the probability of interested with a certain level
of accuracy and with a certain probability.
Theorem 2.3 (Modified Hadamard test (no amplitude amplification)). Assume
to have access to a unitary 𝑈1 that produces a state 𝑈1 |0⟩ = |𝜓1 ⟩ and a unitary
𝑈2 that produces a state |𝜓2 ⟩, where |𝜓1 ⟩, |𝜓2 ⟩ ∈ ℂ𝑁 for 𝑁 = 2𝑛 , 𝑛 ∈ ℕ. There is
a quantum algorithm that allows to estimate the quantity ⟨𝜓1 |𝜓2 ⟩ with additive
precision 𝜖 using controlled applications of 𝑈1 and 𝑈2 𝑂( log(1/𝛿)
𝜖2 ) times, with
probability 1 − 𝛿

Proof. Create a state |0⟩|0⟩ where the first register is just an ancilla qubit, and
the second register has 𝑛 qubits. Then, apply an Hadamard gate to the first
qubit, so to obtain |+⟩|0⟩. Then, controlled on the first register being 0, we apply
the unitary 𝑈1 , and controlled on the register being 1, we apply the unitary 𝑈2 .
Then, we apply again the Hadamard gate on the ancilla qubit. The state that
we obtain is the following:

1
(𝐻 ⊗ 𝐼) √ (|0⟩|𝜓1 ⟩ + |1⟩|𝜓2 ⟩) (2.13)
2
1
= (|0⟩(|𝜓1 ⟩ + |𝜓2 ⟩) + |1⟩(|𝜓1 ⟩ − |𝜓2 ⟩)) (2.14)
2

Again, now it is easy to state that the probability of measuring 0 is:

2 + 2Re[⟨𝜓1 |𝜓2 ⟩]
𝑝(0) = (2.15)
4
We conclude the proof by recalling the Chernoff bound in theorem C.9, as we
did for the proof of the swap test.
2.4. REVIEW OF FAMOUS QUANTUM ALGORITHMS 29

Can you think of the reasons that might lead one to prefer the swap test over
the Hadamard test, or vice versa? At the end of the day, aren’t they both
computing the same thing? For instance, note that for the Hadamard test, we
are requiring the ability to call the controlled version of the unitaries 𝑈1 , and
𝑈2 , while for the swap test, we can just treat them as black-boxes: these can
be quantum states that we obtain from a quantum process, or that we obtain
from a quantum communication channel.

2.4.5 Swap test


The swap test was originally proposed in (Buhrman et al., 2001a), in the context
of quantum fingerprinting, but it has been quickly extended to many other
context. For us, the swap test is a way to obtain an estimate of an inner
product between two quantum states. The difference between the swap test
and the Hadamard test is that in this case we don’t assume to have access to
the unitary creating the states, hence we cannot perform controlled operations
with this unitary. You can think that we receive the states from a third-party,
i.e. via a communication protocol.
Theorem 2.4 (Swap test (no amplitude amplification)). Assume to have access
to a unitary 𝑈1 that produces a state 𝑈1 |0⟩ = |𝜓1 ⟩ and a unitary 𝑈2 that produces
a state |𝜓2 ⟩, where |𝜓1 ⟩, |𝜓2 ⟩ ∈ ℂ𝑁 for 𝑁 = 2𝑛 , 𝑛 ∈ ℕ. There is a quantum
algorithm that allows to estimate the quantity |⟨𝜓1 |𝜓2 ⟩|2 with additive precision
𝜖 using 𝑈1 and 𝑈2 𝑂( log(1/𝛿)
𝜖2 ) times with probability 1 − 𝛿

Proof. Create a state |0⟩|0⟩|0⟩ where the first register is just an ancilla qubit,
and the second and third register have 𝑛 qubits each. Then, apply an Hadamard
gate to the first qubit, so to obtain |+⟩|0⟩|0⟩. Then, apply 𝑈1 and 𝑈2 to the
second and third register, and then apply a controlled swap gate controlled
on the ancilla qubit, targeting the two registers. More precisely, we apply 𝑛
controlled swap gates, each controlling a single qubit of the second and third
register. Thus, we obtain the state:

1
√ [|0⟩(|𝜓1 ⟩|𝜓2 ⟩) + |1⟩(|𝜓2 ⟩|𝜓1 ⟩)] (2.16)
2

we now apply another Hadamard gate on the ancilla qubit, in order to obtain
the following state:

1 1 1
|𝜙⟩ = √ [ √ (|0⟩(|𝜓1 ⟩|𝜓2 ⟩) + |1⟩(|𝜓1 ⟩|𝜓2 ⟩)) + √ (|0⟩(|𝜓2 ⟩|𝜓1 ⟩) − |1⟩(|𝜓2 ⟩|𝜓1 ⟩))]
2 2 2
(2.17)
1
= [|0⟩ (|𝜓1 ⟩|𝜓2 ⟩) + |𝜓2 ⟩|𝜓1 ⟩) + |1⟩ (|𝜓1 ⟩|𝜓2 ⟩) − |𝜓2 ⟩|𝜓1 ⟩)] (2.18)
2
30CHAPTER 2. QUANTUM COMPUTING AND QUANTUM ALGORITHMS

Now we consider the probability of measuring 0 and 1 in the ancilla qubit.


More in detail, we want to estimate 𝑝(0) = ⟨𝜙|𝑀0 |𝜙⟩. For this, we recall our
Postulate 2.3, and more precisely equation (2.1), with 𝑀0 = |0⟩⟨0| ⊗ 𝐼, where 𝐼
2
is the identiy operator over 𝑛 qubits. It is simple to see that 𝑝(0) = 2−2|⟨𝜓41 |𝜓2 ⟩| .
By repeating this measurement 𝑂(log(1/𝛿)/𝜖2 ) times, duly following the state-
ment of the Chernoff bound in theorem C.9, we have that the number of samples
needed to obtain an error 𝜖 with probability 1−𝛿 is 𝑡 = log(1/𝛿)
2𝜖2 . Once we have ob-
tained an estimate of 𝑝(0), we can estimate the sought-after quantity of interest
as |⟨𝜓1 |𝜓2 ⟩|2 = 1 − 2𝑝(0).

Exercise 2.6 (Obtain the absolute value of the inner product). In the previous
theorem we obtain an estimate of |⟨𝜓1 |𝜓2 ⟩|2 with a certain error 𝜖. If we just
take the square root of that number, what is the error in the estimation of
|⟨𝜓1 |𝜓2 ⟩|? You are encouraged to read the section in the appendix D on error
propagation.
–>
–>
Chapter 3

Classical data and quantum


computers

Contributors: Alessandro Luongo, Jun Hao Hue, Francesco Ghisoni, João F.


Doriguello
Version: 0.7.1
Pending updates
In this chapter discuss how to represent and load classically available data on
a quantum computer. First, we describe how to represent data, which reduces
to understanding the possible ways of storing information in quantum states.
Then, we introduce the quantum memory model of computation, which is the
model that we use to load data (which we assume to know classically) into a
quantum computer. We finally look at the problem of retrieving data from
a quantum computer, discussing the complexity of the problem. The main
takeaway from this chapter is the understanding of the tools that are often used
at the very start and very end of many quantum algorithms, which will set us
up to understanding quantum algorithms in future chapters. This chapter can
be tought as the study of the I/O interface of our quantum computer.

3.1 Representing data in quantum computers


We’ll begin our journey into quantum algorithms by understanding how we can
represent and store data as a quantum state. Data plays a key role and is at
the heart of most modern algorithms and knowing the best way to encode it
on a quantum computer might pave the way for intuitions in solving problems,
an essential step towards quantum advantage (as noted also in (Schuld et al.,
2015)).

31
32 CHAPTER 3. CLASSICAL DATA AND QUANTUM COMPUTERS

There are various ways to achieve this task. Some are borrowed from classical
computation, such as the binary encoding, which consist in representing encod-
ing boolean strings of length 𝑛 using 𝑛 qubits, while some leverage quantum
properties, such as the amplitude encoding, which consits in representing vec-
tors as linear combination of computational basis. We note that some of the
presented schemes depend heavily on the accuracy of the available quantum
computers in manipulating quantum states (i.e. developments in metrology and
sensing). For example, techniques that rely on precise amplitudes of a state
will be hindered by the current noisy hardware, or incour in high overhead of
the quantum error correction. Considerations on the practical feasibility of an
encoding technique are out of scope for this book.

3.1.1 Binary encoding


The first method is a way to represent natural numbers on a quantum computer
by using the binary expansion of the number to determine the state of a sequence
of qubits. Each qubit is set to either the state |0⟩ or |1⟩, corresponding to each
bit in the binary representation of the number. To represent a natural number
𝑥 ∈ ℕ on a quantum computer, we consider the binary expansion of 𝑥 as a list
of 𝑚 bits, and we set the state of the 𝑖𝑡ℎ qubit as the value of the 𝑖𝑡ℎ bit of 𝑥:

𝑚
|𝑥⟩ = ⨂ |𝑥𝑖 ⟩. (3.1)
𝑖=0

When extending this definition to signed integers we can, for example, use an
additional qubit to store the sign of 𝑥 ∈ ℤ. Another possibility, is to represent
signed integer using 2s complement. This is actually the representation of choice
for classical and quantum arithmetic (Luongo et al., 2024). For real numbers
we consider that, as on classical computers, 𝑥 ∈ ℝ can be approximated with
binary representation up to a certain precision. As before, we need a bit to
store the sign, some bits to store the integer part, and some bits to store the
fractional part. This is more precisely stated in the following definition, which
is a possible way to represent number with fixed precision.
Definition 3.1 (Fixed-point encoding of real numbers (Rebentrost et al.,
2021)). Let 𝑐1 , 𝑐2 be positive integers, and 𝑎 ∈ {0, 1}𝑐1 , 𝑏 ∈ {0, 1}𝑐2 , and
𝑠 ∈ {0, 1} be bit strings. Define the rational number as

1 1
𝒬(𝑎, 𝑏, 𝑠) ∶= (−1)𝑠 (2𝑐1 −1 𝑎𝑐1 + ⋯ + 2𝑎2 + 𝑎1 + 𝑏1 + ⋯ + 𝑐 𝑏𝑐2 ) ∈ [−𝑅, 𝑅],
2 22
(3.2)
where 𝑅 = 2𝑐1 − 2−𝑐2 .
If 𝑐1 , 𝑐2 are clear from the context, we use the shorthand notation for a number
𝑧 ∶= (𝑎, 𝑏, 𝑠) and write 𝒬(𝑧) instead of 𝒬(𝑎, 𝑏, 𝑠). Given an 𝑛-dimensional vector
𝑣 ∈ ({0, 1}𝑐1 × {0, 1}𝑐2 × {0, 1})𝑛 the notation 𝒬(𝑣) means an 𝑛-dimensional
vector whose 𝑗-th component is 𝒬(𝑣𝑗 ), for 𝑗 ∈ [𝑛].
3.1. REPRESENTING DATA IN QUANTUM COMPUTERS 33

We note that the choice of 𝑐1 and 𝑐2 in definition 3.1 depends both on the
problem at hand and the implemented algorithm. For the purposes of optimizing
a quantum circuit, these constants can be dynamically changed. For example, if
at some point of a computation we are required to work with numbers between
0 and 1, then we can neglect the 𝑐1 bits.
One of the utilities of having a definition to express numbers on a quantum
computer to a fixed point precision is the analysis of numerical errors, which is
essential to ensure the validity of the solution. This is often done numerically
(via simulations, which we will discuss in Chapter 12 ), or during the implemen-
tation of the algorithm on real hardware. This binary encoding encompasses
other kinds of encoding like 2-complement encoding and a possible quantum im-
plementation of floating point representation. Howevever, we observe that the
floating point encoding has a relatively high circuital overhead and, therefore,
is not a common choice. A further layer of complexity arises in understanding
how to treat arithmetic operations. This is addressed in the section below.

[Link] Arithmetic model


The advantage of using a binary encoding is that we can use quantum cir-
cuits for arithmetic operations. As we will discuss more in depth in [Link]
any Boolean circuit can be made reversible, and any reversible circuit can be
implemented using single-qubit NOT gates and three-qubit Toffoli gates. Since
most of the classical Boolean circuits for arithmetic operations operate with
a number of gates of 𝑂(poly(𝑐1 , 𝑐2 )), this implies a number of quantum gates
of 𝑂(poly(𝑐1 , 𝑐2 )) for the corresponding quantum circuit. Extending the anal-
ogy with classical computation allows us to introduce the arithmetic model of
computation for performing operations on binary encoded numbers in constant
time.
Definition 3.2 (Quantum arithmetic model (Doriguello et al., 2022)). Given
𝑐1 , 𝑐2 ∈ ℕ specifying fixed-point precision numbers as in Definition 3.1, we
say we use a quantum arithmetic model of computation if the four arithmetic
operations can be performed in constant time in a quantum computer.
Beware that using Definition 3.1 is not the only possibile choice. For exam-
ple, most of the non-modular and modular arithemtic circuits are expressed in
2s complement. For a comprehensive and optimized list of results about this
topic, the interest reader can read (Luongo et al., 2024). As for the classical
counterpart, a quantum algorithm’s complexity does not take into account the
cost of performing arithmetic operations, as the number of digits of precisions
used to represents numbers is a constant, and does not depend on the input size.
However, when estimating the resources needed to run an algorithm on a quan-
tum computer, specifying these values becomes important. For a good example
of a complete resource analysis, including arithmetic operations in fixed-point
precision, of common algorithms in quantum computational finance we refer to
(Chakrabarti et al., 2021).
34 CHAPTER 3. CLASSICAL DATA AND QUANTUM COMPUTERS

3.1.2 Amplitude encoding


Amplitude encoding is a way to represent a vector 𝑥 of size 𝑛 (where 𝑛 is a
power of 2) in the amplitudes of an log(𝑛) qubit pure state. We can map a
vector 𝑥 ∈ ℝ𝑁 (or even ∈ ℂ𝑁 ) to the following quantum state:

1 𝑁−1
|𝑥⟩ = ∑ 𝑥 |𝑖⟩ = ‖𝑥‖−1 𝑥, (3.3)
‖𝑥‖ 𝑖=0 𝑖

Sometimes, amplitude encoding is also known as quantum sampling access, as


sampling from a quantum state we prepare can also be interpreted as sampling
from a probability distribution. In fact, if the amplitude of a computational
basis |𝑖⟩ is 𝛼𝑖 , then we sample |𝑖⟩ with probability |𝛼𝑖 |2 . Observe from the state
in the above equation we are actually representing an ℓ2 -normalized version of
the vector 𝑥. Therefore we have “lost” the information on the norm of the
vector 𝑥. However we will see how this is not a problem when we work with
more than one vector. This type of encoding can be generalized to matrices.
Let 𝑥(𝑖) be the 𝑖-th row of 𝑋 ∈ ℝ𝑛×𝑑 , a matrix with 𝑛 rows and 𝑑 columns
(here we take again 𝑛 and 𝑑 to be a power of 2). Then we can encode 𝑋 with
⌈𝑙𝑜𝑔(𝑑)⌉ + ⌈𝑙𝑜𝑔(𝑛)⌉ qubits as:

𝑛
1
|𝑋⟩ = ∑ ‖𝑥(𝑖)‖|𝑖⟩|𝑥(𝑖)⟩ (3.4)
√∑𝑛 ‖𝑥(𝑖)‖2 𝑖=1
𝑖=1

Exercise 3.1. Check that Equation (3.4) is equivalent to

𝑛,𝑑
1
|𝑋⟩ = ∑ 𝑋𝑖𝑗 |𝑖⟩|𝑗⟩, (3.5)
𝑛,𝑑
√∑𝑖,𝑗=1 |𝑋𝑖𝑗 |2 𝑖,𝑗=1

From an algorithms perspective, amplitude encoding is useful because it requires


a logarithmic number of qubits with respect to the vector size, which might seem
to lead to an exponential saving in physical resources when compared to classical
encoding techniques. A major drawback of amplitude encoding is that, in the
worst case, for the majority of states, it requires a circuit of size Ω(𝑁 ).

3.1.3 Block encoding


Block encoding is another type of encoding for working with matrices on a
quantum computer. More precisely, we want to encode a matrix into a unitary
that has a circuit representation on a quantum computer. As it will become
clear in the next chapters, being able to perform such encoding unlocks many
possibilities in terms of new quantum algorithms.
3.1. REPRESENTING DATA IN QUANTUM COMPUTERS 35

Definition 3.3 (Block encoding of a matrix). Let 𝐴 ∈ ℝ𝑁×𝑁 be a square matrix


for 𝑁 = 2𝑛 for 𝑛 ∈ ℕ, and let 𝛼 ≥ 1. For 𝜖 > 0, we say that a (𝑛 + 𝑎)-qubit
unitary 𝑈𝐴 is a (𝛼, 𝑎, 𝜖)-block encoding of 𝐴 if

‖𝐴 − 𝛼(⟨0|⊗𝑎 ⊗ 𝐼)𝑈𝐴 (|0⟩⊗𝑎 ⊗ 𝐼)‖2 ≤ 𝜖 (3.6)

It is useful to observe that an (𝛼, 𝑎, 𝜖)-block encoding of 𝐴 is just a (1, 𝑎, 𝜖)-block


encoding of 𝐴/𝛼. Often, we do not want to take into account the number of
qubits 𝑎 we need to create the block encoding because these are expected to be
negligible. Therefore, some definitions of block encoding in the literature use
the notation (𝛼, 𝜖) or the notation 𝛼-block encoding if the error is 0. Note that
the matrix 𝑈𝐴 ∈ ℝ(𝑁+𝜅)×(𝑁+𝜅) has the matrix 𝐴 encoded in the top-left part:

𝐴 .
𝑈𝐴 = ( ). (3.7)
. .

3.1.4 Angle encoding


Another way to encode vectors, as defined by (Schuld and Petruccione, 2021), is
with angle encoding. This technique encodes information as angles of the Pauli
rotations 𝜎𝑥 (𝜃), 𝜎𝑦 (𝜃), 𝜎𝑧 (𝜃). Given a vector 𝑥 ∈ ℝ𝑛 , with all elements in the
interval [0, 2𝜋]; the technique seeks to apply 𝜎𝛼𝑖 (𝑥𝑖 ), where 𝛼 ∈ {𝑥, 𝑦, 𝑧} and 𝑖
refers to the target qubit. The resulting state is said to be an angle encoding of
𝑥 and has a form given by

𝑛
|𝑥⟩ = ∏ 𝜎𝛼𝑖 (𝑥𝑖 )|0⟩⊗𝑛 (3.8)
𝑖=1

This technique’s advantages lies in its efficient resource utilization, which scales
linearly for number of qubits. One major drawback is that it is difficult to
perform arithmetic operations on the resulting state, making it difficult to apply
to quantum algorithms.

3.1.5 Graph encoding


A graph is as a tuple 𝐺 = (𝑉 , 𝐸), where 𝑉 are the vertices in the graph and
𝐸 are the edges, where 𝐸 ⊆ 𝑉 × 𝑉 . For graph encoding we require unidirected
graphs in which if (𝑣𝑖 , 𝑣𝑗 ) ∈ 𝐸 then (𝑣𝑗 , 𝑣𝑖 ) ∈ 𝐸. Unidirected graphs can be
either simple or multigraphs. A simple unidirected graph is one without self
loops and at most a single edge connecting two vertices, whilst a unidirected
multigraph can have self loops or multiple edges between two vertices. Graph
encoding is possible for unidirected multigraphs with self loops but at most a
single edge between two vertices.
36 CHAPTER 3. CLASSICAL DATA AND QUANTUM COMPUTERS

A graph 𝐺 will be represented as an 𝑁 = |𝑉 | qubit pure quantum state |𝐺⟩


such that

𝑣
𝐾𝐺 |𝐺⟩ = |𝐺⟩, ∀𝑣 ∈ 𝑉 (3.9)

𝑣
where 𝐾𝐺 = 𝜎𝑥𝑣 ∏𝑢∈𝑁(𝑣) 𝜎𝑧𝑢 , and 𝜎𝑥𝑢 and 𝜎𝑧𝑢 are the Pauli operators 𝜎𝑥 and 𝜎𝑧
applied to the 𝑢𝑡ℎ qubit.
Given a graph 𝐺 with 𝑉 vertices and edges 𝐸, take 𝑁 = |𝑉 | qubits in the
|0⟩⊗𝑁 state, apply 𝐻 ⊗𝑁 , producing the |+⟩⊗𝑁 state where |+⟩ = |0⟩+|1⟩

2
. Then
apply a controlled 𝑍 rotation between qubits connected by an edge in 𝐸. It
is worth noting that 2 different graphs can produce the same graph state |𝐺⟩.
In particular if a graph state |𝐺⟩̃ can be obtained from a graph state |𝐺⟩ by
only applying local Clifford group operators, the 2 graphs are said to be LC-
equivalent. The work by (Zhao et al., 2016) has interesting application of this
type of encoding.

3.1.6 One-hot encoding


Another possible way of encoding vectors as quantum states introduced by
(Mathur et al., 2022) is one-hot amplitude encoding, also known as unary
amplitude encoding, which encodes a normalized vector 𝑥 ∈ ℂ𝑛 onto 𝑛 qubits.
The vector values 𝑥𝑖 ∈ ℂ will be stored in the amplitudes of the states that form
the 2𝑛 -dimensional canonical basis, i.e, the states with only one 1 and the rest
0s. This corresponds to preparing the state:

1 𝑛
|𝑥⟩ = ∑ 𝑥 |𝑒 ⟩, (3.10)
||𝑥|| 𝑖=1 𝑖 𝑖

where, for some integer 𝑖, the states 𝑒𝑖 take the form 𝑒𝑖 = 0𝑖−1 10𝑛−𝑖 .

3.2 Quantum memory


Having seen possible ways to represent data on a quantum computer, we will
now take the first step toward understanding how to create quantum states
that are representing numbers using these encodings. The first step involves un-
derstanding quantum memory, which plays a key role in various quantum algo-
rithms/problems such as: Grover’s search, solving the dihedral hidden subgroup
problem, collision finding, phase estimation for quantum chemistry, pattern
recognition, machine learning algorithms, cryptanalysis, and state preparation.
To work with quantum memory we need to define a quantum memory model of
computation, which enables us to accurately calculate the complexity of quan-
tum algorithms. In this framework we divide a quantum computation into a
3.2. QUANTUM MEMORY 37

data pre-processing step and a computational step. Quantum memory allows


us to assume that the pre-processed data can be easily accessed (as in classical
computers). In this model, since the pre-processing is negligible, and has to be
performed only once, the complexity of a quantum algorithm is fully charac-
terized by the computational step. This understanding formalizes a quantum
computation in two distinct components: a quantum processing unit and a
quantum memory device. Two notable examples of quantum memory devices
are the quantum random access memory (QRAM) and the quantum random
access gates (QRAG). It is important to note that having access to a quantum
memory device is associated with fault tolerant quantum computers.
This section will first introduce the quantum memory model of computation
(3.2.1). This will be followed by the formalization of a quantum computation
in the memory model via a quantum processing unit (QPU) and a quantum
memory device (QMD) (3.2.2), where the QRAM and QRAG will be presented
as possible implementation of the QMD.

3.2.1 The quantum model of computation with and with-


out memory
As discussed in the Section 2.3 of the previous chapter, in quantum computing
we often work in a oracle model, also called black-box model of quantum compu-
tation. This section is devoted to the formalization of this model of computation.
The word “oracle”, (a word referencing concepts in complexity theory), is used
to imply that an application of the oracle has 𝒪(1) cost, i.e. we do not care about
the cost of implementing the oracle in our algorithm. A synonym of quantum
oracle model is quantum query model, which stresses the fact that we can only
use the oracle to perform queries.
To appreciate the potential of quantum algorithms, it is important to under-
stand the quantum memory model. This is because we want to compare quan-
tum algorithms with classical algorithms. Understanding the quantum memory
model makes sure that we not favor any of the approaches, ensuring a fair eval-
uation of their performance across different computational models and memory
architectures. Understanding classical memory is also important for classical
algorithms. Memory limitations make the analysis of big datasets challenging.
This limitation is exacerbated when the random-access memory is smaller than
the dataset to analyze, as the bottleneck of computational time switch from
being the number of operations to the time to move data from the disk to the
memory. Hence, algorithms with super linear runtime (such as those based on
linear algebra) become impractical for large input size.
As we will formalize later, the runtime for analyzing a dataset represented by a
matrix 𝐴 ∈ ℝ𝑛×𝑑 using a quantum computer is given by the time to preprocess
the data (i.e., creating quantum accessible data structures) and the runtime
of the quantum algorithm. Importantly, the pre-processing step needs to be
done only once, allowing one to run (different) quantum algorithms on the same
38 CHAPTER 3. CLASSICAL DATA AND QUANTUM COMPUTERS

matrix. We can see this pre-processing step as a way of encoding and/or storing
the data: once the matrix is pre-processed, we can always retrieve the matrix in
the original representation (i.e. it is a loss less encoding). This step bears some
similarities with the process of loading the data from the disk in RAM Therefore,
because the pre-processing step is analyzed differently from the runtime, when
we work with a quantum algorithm that has quantum access to some classical
data, we have the following model in mind.
Definition 3.4 (Costing in the quantum memory model). An algorithm in the
quantum memory model that processes a data-set of size 𝑚 has two steps:
̃
• A pre-processing step with complexity 𝑂(𝑚) that constructs an efficient
quantum access to the data
• A computational step where the algorithm has quantum access to the data
structures constructed in step 1.
The complexity of the algorithm in this model is measured by the cost for step
2.
Let’s consider an example. We will see that many of the quantum algorithms
considered in this book have a computational complexity expressed (in number
of operations of a certain kind) as some functions of the matrix and the problem.
Consider a classical algorithm with a runtime of 𝑂 ̃ ( ‖𝐴‖0 𝜅(𝐴) log(1/𝛿)) calls to
𝜖2
the classical memory (and coincidentally, CPU operations). Here 𝜖 is some
approximation error in the quantity we are considering, 𝜅(𝐴) is the condition
number of the matrix, 𝛿 the failure probability. The quantum counterpart of
this algorithm has a runtime of 𝑂(‖𝐴‖0 ) classical operation for pre-processing
and

̃
𝑂(poly(𝑓(𝐴)), poly(𝜅(𝐴)), poly(1/𝜖), poly(log(𝑛𝑑)), poly(log(1/𝛿))) (3.11)

queries to the quantum memory (and coincidentally, number of operations).


Here, 𝑓(𝐴) represents some size-independent function of the matrix that de-
pends on the properties of 𝐴 which can be chosen to be ‖𝐴‖𝐹 : the Frobenius
norm of the matrix. Importantly, note that in the runtime of the quantum
algorithm there is no dependence on ‖𝐴‖0 .
The first step, i.e., loading data (for example a matrix 𝐴) onto a quantum
memory gives an additive price of 𝑂(‖𝐴‖ ̃ ), and is computationally easy to
0
implement. In some cases this can be done on the fly, with only a single pass
over the dataset, for example while receiving each of the rows of the matrix. For
more complex choices of 𝑓(𝐴), the construction of the data structure needs only
a few (constant) numbers of passes over the dataset. As pre-processing the data
is negligible, we expect quantum data analysis to be faster than classical data
analysis. However, there is no need to employ quantum data analysis for small
datasets if classical data analysis is sufficient.
3.2. QUANTUM MEMORY 39

In the quantum memory model, we assumed that the pre-processing step to be


negligible in cost, and thereby claim that there is significant practical speedup
when using quantum algorithms compared to classical algorithms. However, a
proper comparison for practical applications needs to include the computational
cost of the loading process, which may or may not remove the exponential gap
between the classical and the quantum runtime. Nevertheless, even when the
pre-processing step is included, we expect the overall computational cost to
largely favor the quantum procedure. This analysis can be done only with a
proper understanding of the quantum memory model.

Having a clear and deep understanding of the quantum memory model can help
us understand the power and limitations of classical computers as well. The
past few years saw a trend of works proposing “dequantizations” of quantum
machine learning algorithms. These algorithms explored and sharpened some
ideas (Tang, 2018) to leverage a classical data structure to perform importance
sampling on input data to have classical algorithm with polylogarithmic run-
times in the size of the input. This data structure is very similar to the one
used in many quantum machine learning algorithms (see Section [Link]). As
a result, many quantum algorithms which had an exponential separation with
their classical counterpart now have at most a polynomial speedup compared to
the classical algorithm. However, these classical algorithms have a worse depen-
dence in other parameters (like condition number, Frobenius norm, rank, and so
on) that will make them disadvantageous in practice (i.e., they are slower than
the fastest classical randomized algorithms (Arrazola et al., 2020)). With that
said, having small polynomial speedup is not something to be critical about:
even constant speedups matter a lot in practice! Overall, dequantizations and
polynomial speedups highlight the importance of clearly understanding the tech-
niques behind loading classical data in quantum computers.

3.2.2 The quantum processing unit and quantum memory


device
In this section, we formally define a model of a quantum computer with quantum
access to memory. We can intuitively understand this model by separating the
available Hilbert space in two: a part dedicated to computing, the Quantum
Processing Unit (QPU) and a part dedicated to storing, the Quantum Memory
Device (QMD).

The qubits which comprise the QPU are assigned to either an input register or a
workspace register; whilst the qubits which comprise the QMD are assigned to
either a ancillary register or a memory register. Two other registers, the address
register and the target register, are shared by the QPU and QMD and allow for
communication between the two Hilbert spaces. A depiction of the architecture
of a QPU with access to a QMD can be seen in Figure 3.1. Before defining a
model of a quantum computer with quantum access to memory, we will first
formally define a computation with only the quantum processing unit QPU.
40 CHAPTER 3. CLASSICAL DATA AND QUANTUM COMPUTERS

Definition 3.5 (Quantum Processing Unit (Allcock et al., 2023)). A Quantum


Processing Unit(QPU) of size 𝑚 is defined as a tuple (I, W, 𝒢) consisting of
• an 𝑚I -qubit Hilbert space called input register I;
• an (𝑚 − 𝑚I )-qubit Hilbert space called workspace W;
• a constant-size universal gate set 𝒢 ⊂ 𝒰(ℂ4×4 ).
The qubits in the workspace W are called ancillary qubits or simply ancillae. An
input to the QPU, or quantum circuit, is a tuple (𝑇 , |𝜓I ⟩, 𝐶1 , … , 𝐶𝑇 ) where 𝑇 ∈
ℕ, |𝜓I ⟩ ∈ I, and, for each 𝑡 ∈ {1, … , 𝑇 }, 𝐶𝑡 ∈ ℐ(𝒢) is a set of instructions from a
⊗(𝑚−𝑚I )
set ℐ(𝒢) of possible instructions. Starting from the state |𝜓0 ⟩ ∶= |𝜓I ⟩|0⟩W ,
at each time step 𝑡 ∈ {1, … , 𝑇 } we obtain the state |𝜓𝑡 ⟩ = 𝐶𝑡 |𝜓𝑡−1 ⟩ ∈ I ⊗ W.
𝑚 𝑚
The instruction set ℐ(𝒢) ⊂ 𝒰(ℂ2 ×2 ) consists of all 𝑚-qubit unitaries on I ⊗ W
of the form

𝑘
∏(U𝑖 )→𝐼𝑖 (3.12)
𝑖=1

for some 𝑘 ∈ ℕ, U1 , … , U𝑘 ∈ 𝒢 and pair-wise disjoint non-repeating sequences


𝑘
𝐼1 , … , 𝐼𝑘 ∈ [𝑚]≤2 of at most 2 elements. We say that ∑𝑖=1 |𝐼𝑖 | is the size of the
corresponding instruction. We say that 𝑇 is the depth of the input to the QPU,
while its size is the sum of the sizes of the instructions 𝐶1 , … , 𝐶𝑇 .
Note that in this definition the circuit size differs from the standard notion of
circuit size, which is the number of selected gates from 𝒢, up to a factor of at
most 2.
Exercise 3.2. Can you explain why the circuit size differs from the standard
notion of circuit size by up to a factor of at most 2
Moreover, in this framework, the locations of the address and target registers
are fixed. One could imagine a more general setting where the address and
target registers are freely chosen from the workspace. This case can be handled
by this model with minimal overhead, e.g. by performing ℓ-SWAP gates to move
the desired workspace qubits into the address or target register locations.
Adding access to a QMD changes how we define the model of computation. In
practice, a call to the QMD sees the address register selecting a unitary from a
set of unitaries 𝒱 and applying it to both the target and memory register. It is
important to stress that even though a call to the QMD might require gates from
a universal gate set, the underlying quantum circuit implementing such a call
is fixed, i.e., does not change throughout the execution of a quantum algorithm
by the QPU, or even between different quantum algorithms. Below we find the
full definition of a quantum computation of a QPU with access to a QMD.
Definition 3.6 (Quantum Processing Unit and Quantum Memory Device (All-
cock et al., 2023)). We consider a model of computation comprising a Quantum
Processing Unit(QPU) of size poly log(𝑛) and a Quantum Memory Device (QMD)
3.2. QUANTUM MEMORY 41

of 𝑛 memory registers, where each register is of ℓ-qubit size (for 𝑛 a power of


2). A QPU and a QMD are collectively defined by a tuple (I, W, A, T, Aux, M, 𝒢, V)
consisting of
• two (poly log 𝑛)-qubit Hilbert spaces called input register I and workspace
W owned solely by the QPU;
• a (log 𝑛)-qubit Hilbert space called address register A shared by both QPU
and QMD;
• an ℓ-qubit Hilbert space called target register T shared by both QPU and
QMD;
• a (poly𝑛)-qubit Hilbert space called auxiliary register Aux owned solely by
the QMD;
• an 𝑛ℓ-qubit Hilbert space called memory M comprising 𝑛 registers
M0 , … , M𝑛−1 , each containing ℓ qubits, owned solely by the QMD;
• a constant-size universal gate set 𝒢 ⊂ 𝒰(ℂ4×4 );
2ℓ 2ℓ
• a function V ∶ [𝑛] → 𝒱, where 𝒱 ⊂ 𝒰(ℂ2 ×2 ) is a 𝑂(1)-size subset of
2ℓ-qubit gates.
The qubits in W, A, T, and Aux are called ancillary qubits or simply ancil-
lae. An input to the QPU with a QMD, or quantum circuit, is a tuple
(𝑇 , |𝜓I ⟩, |𝜓M ⟩, 𝐶1 , … , 𝐶𝑇 ) where 𝑇 ∈ ℕ, |𝜓I ⟩ ∈ I, |𝜓M ⟩ ∈ M, and, for each
𝑡 ∈ {1, … , 𝑇 }, 𝐶𝑡 ∈ ℐ(𝒢, V) is an instruction from a set ℐ(𝒢, V) of possible
instructions. The instruction set ℐ(𝒢, V) is the set ℐ(𝒢) acting on I ⊗ W ⊗ A ⊗ T
augmented with the call-to-the-QMD instruction that implements the unitary

|𝑖⟩A |𝑏⟩T |𝑥𝑖 ⟩M𝑖 |0⟩⊗poly𝑛


Aux ↦ |𝑖⟩A (V(𝑖)|𝑏⟩T |𝑥𝑖 ⟩M𝑖 )|0⟩⊗poly𝑛
Aux , ∀𝑖 ∈ [𝑛], 𝑏, 𝑥𝑖 ∈ {0, 1}ℓ .
(3.13)
⊗poly𝑛
Starting from |𝜓0 ⟩|0⟩Aux , where |𝜓0 ⟩ ∶= |𝜓I ⟩|0⟩⊗poly
W
log 𝑛
|0⟩⊗
A
log 𝑛
|0⟩⊗ℓ
T |𝜓M ⟩,
⊗poly𝑛
at each time step 𝑡 ∈ {1, … , 𝑇 } we obtain the state |𝜓𝑡 ⟩|0⟩Aux =
⊗poly𝑛
𝐶𝑡 (|𝜓𝑡−1 ⟩|0⟩Aux ), where |𝜓𝑡 ⟩ ∈ I ⊗ W ⊗ A ⊗ T ⊗ M.
This model can be seen as a refined version of the one described in (Buhrman
et al., 2022), where the authors divide the qubits of a quantum computer into
work and memory qubits. Given 𝑀 memory qubits, their workspace consists
of 𝑂(log 𝑀 ) qubits, of which the address and target qubits are always the first
⌈log 𝑀 ⌉ + 1 qubits. However, address and target qubits are not considered to
be shared by the QMD, and there is no mention of ancillary qubits mediating
a call to the QMD. The inner structure of the QMD is abstracted away by
assuming access to the unitary of a QRAG (see Definition 3.10 later). This
model, in contrast, “opens” the quantum memory device, and allows for general
fixed unitaries, including QRAM and QRAG.
In addition, this model does not include measurements. These can easily be
performed on the output state |𝜓𝑇 ⟩ if need be. Furthermore the position of the
qubits is not fixed within the architecture, allowing for long-range interactions
through, for example, multi-qubit entangling gates. This feature is not always
42 CHAPTER 3. CLASSICAL DATA AND QUANTUM COMPUTERS

Quantum processing unit

Input |ψ⟩I

⊗poly(log n)
Workspace |0⟩W

Address |i⟩A

Target |b⟩T

⊗poly(n)
Ancillae |0⟩Aux

Memory |x0 , x1 , . . . , xn−1 ⟩M

Quantum memory device

Figure 3.1: The architecture of a Quantum Processing Unit(QPU) with access to


a quantum memory device(QMD). The QPU is composed of a poly log(𝑛)-qubit
input register I and workspace W. The QMD is composed of an 𝑛𝑙-qubit memory
array M, composed of 𝑛 memory cells each of size 𝑙-qubits, and a poly(𝑛)-qubit
auxiliary register Aux. Two registers, the log(𝑛)-qubit address register A and an
𝑙-qubit target register T, are shared between the QPU and the QMD.

possible in physical the real world since some quantum devices, such as super-
conducting quantum computers, don’t allow for long-range interactions between
qubits. For a model of computation which take in consideration physically real-
istic device interactions we suggest the work by (Beals et al., 2013).
We stress the idea that call to the QMD is defined by the function V and quan-
tum memory device is defined by the unitary that it implements. In many
applications, one is interested in some form of reading a specific entry from
the memory, which corresponds to the special cases where the V(𝑖) unitaries
are made of controlled single-qubit gates, and to which the traditional QRAM
belongs.

[Link] The LAQCC model of quantum computation


We can also consider an alternative model of quantum computation to the one in
Definition ??: the LAQCC model, which stands for Local Alternating Quantum
Classical Computations. LAQCC is a hybrid quantum-classical computational
framework (Buhrman et al., 2023a). This model assumes quantum hardware
with specific topology and connectivity, enabling the measurement of certain
(but not necessarily all) qubits. The measurement results are then used to
perform intermediate classical computations, which, in turn, control subsequent
quantum circuits. This process can alternate between quantum and classical
layers multiple times, allowing for iterative computation. The authors did not
consider an explicit formulation of the quantum memory device. However, it is
possible to perform amplitude encoding of a certain class of states in constant
depth. Formally, it is defined as follows.
Definition 3.7 (Local Alternating Quantum Classical Computations (Buhrman
et al., 2023a)). Let LAQCC(𝒬, 𝒞, 𝑑) be the class of circuits such that:
• Every quantum layer implements a quantum circuit 𝑄 ∈ 𝒬 constrained to
a grid topology;
3.2. QUANTUM MEMORY 43

• Every classical layer implements a classical circuit 𝐶 ∈ 𝒞;


• There are 𝑑 alternating layers of quantum and classical circuits;
• After every quantum circuit 𝑄, a subset of the qubits is measured;
• The classical circuit receives input from the measurement outcomes of
previous quantum layers;
• The classical circuit can control quantum operations in future layers.
The allowed gates in the quantum and classical layers are given by 𝒬 and 𝒞,
respectively. Furthermore, we require a circuit in LAQCC(𝒬, 𝒞, 𝑑) to determin-
istically prepare a pure state on the all-zeroes initial state.

[Link] The QRAM


A type of QMD of particular interest is the QRAM, which is the quantum equiv-
alent of a classical Random Access Memory (RAM), that stores classical or
quantum data and allows for superposition-based queries. More specifically, a
QRAM is a device comprising a memory register that stores data, an address
register that points to the memory cells to be addressed, and a target register
into which the content of the addressed memory cells is copied. If necessary,
it also includes an auxiliary register supporting the overall operation, which is
reset to its initial state at the end of the computation. Formally, we define it
as:
Definition 3.8 (Quantum Random Access Memory). Let 𝑛 ∈ ℕ be a power of
2 and 𝑓(𝑖) = X for all 𝑖 ∈ [𝑛]. A quantum random access memory QRAM of
memory size 𝑛 is a QMD with V(𝑖) = CM𝑖 -X→T . Equivalently, it is a QMD that
maps

|𝑖⟩A |𝑏⟩T |𝑥0 , … , 𝑥𝑛−1 ⟩M ↦ |𝑖⟩A (𝑓(𝑖)𝑥𝑖 |𝑏⟩T )|𝑥0 , … , 𝑥𝑛−1 ⟩M ∀𝑖 ∈ [𝑛], 𝑏, 𝑥0 , … , 𝑥𝑛−1 ∈ {0, 1}.
(3.14)
A unitary performing a similar mapping often goes under the name of quantum
read-only memory (QROM) The difference with QRAM is that that this term
stresses that they don’t allow data to be added or modified. Oftentimes, the
authors using this term are considering a circuit, as described in section ??.
Instead assuming to have access to a QRAM requires a protocol for the pre-
processing of the data and creation of a data structure in time which is asymp-
totically linear in the data size (as indicated by definition ??).
Equipped with definition 3.8) we can formalize what it means to have quantum
query access, which is also referred to as QRAM access or as having “𝑥 is in the
QRAM”. We will formalize the case of having a vector 𝑥 ∈ ({0, 1}𝑚 )𝑁 stored in
the QRAM.
Definition 3.9 (Quantum query access to a vector stored in the QRAM). Given
𝑥 ∈ ({0, 1}𝑚 )𝑁 , we say that we have quantum query access to 𝑥 stored in the
44 CHAPTER 3. CLASSICAL DATA AND QUANTUM COMPUTERS

QRAM if we have access to a unitary operator 𝑈𝑥 such that 𝑈𝑥 |𝑖⟩|𝑏⟩ = |𝑖⟩|𝑏 ⊕ 𝑥𝑖 ⟩


for any bit string 𝑏 ∈ {0, 1}𝑚 .
In practical terms when analyzing the complexity of a quantum algorithm with
a QRAM we need to take in consideration three factors: the circuit size of
the quantum algorithm as introduced in definition ??, the number of queries
to the QRAM and the complexity each QRAM query. We emphasize that the
complexity that arises due to a query to the QRAM is still an open question.
Details of some possible implementations will be discussed in section 3.3.

Table 3.1: Table for QRAM for 𝑁 = 2𝑛 memory elements of size 𝑚. 2 is


(Giovannetti et al., 2008a), 4 is (Low et al., 2018), 5 and 6 are form (Allcock
et al., 2023), 8 is Lemma 10 from (Yuan and Zhang, 2023). Gate count or
depth with * is expressed in number of 𝑇 gates. Results expressed with + are in
terms of FanOut gates of arity 𝑂(𝑛). TODO number 4 should have a parameter
lambda for number of ancilla qubits?

Method Size Ancilla Depth Comment


1 Multiplexer O(nm) O(nm)
2 Bucket
Brigade
3 FanOut BB Uses
FanOut
gates
4 Trading 𝑂(𝑛) 2𝑛 + 2 𝑂(𝑛)
5 One-hot 6𝑛 log 𝑛 + 2𝑛 log 𝑛 log log 𝑛 + 𝑂(1)
+
encoding 𝑂(𝑛 log log 𝑛) 𝑂(𝑛 log 𝑛)
FanOut
6 One-hot 6𝑛 log 𝑛 + 2𝑛 log 𝑛 log log 𝑛 + 𝑂(1)
+
encoding 𝑂(𝑛 log log 𝑛) 𝑂(𝑛 log 𝑛)
GT-gate
7 Fourier
8 Circuit 𝑂(𝑁 2𝑚 ) 𝜆 𝜆 > 𝑁𝑚

[Link] The QRAG


Another type of quantum memory device is the quantum random access
gate(QRAG). This quantum memory device was introduced in the paper
of (Ambainis, 2007) and performs a SWAP gate between the target register
and some portion of the memory register specified by the address register.
The QRAG finds applications in quantum algorithms for element distinctness,
collision finding and random walks on graphs. The formal definition is:
Definition 3.10 (Quantum Random Access Gate). Let 𝑛 ∈ ℕ be a power of
2. A quantum random access gate QRAG of memory size 𝑛 is a QMD with
V(𝑖) = SWAPM𝑖 ↔T , ∀𝑖 ∈ [𝑛]. Equivalently, it is a QMD that maps
3.2. QUANTUM MEMORY 45

|𝑖⟩A |𝑏⟩T |𝑥0 , … , 𝑥𝑛−1 ⟩M ↦ |𝑖⟩A |𝑥𝑖 ⟩T |𝑥0 , … , 𝑥𝑖−1 , 𝑏, 𝑥𝑖+1 , … , 𝑥𝑛−1 ⟩M ∀𝑖 ∈ [𝑛], 𝑏, 𝑥0 , … , 𝑥𝑛−1 ∈ {0, 1}.
(3.15)
It turns out that the QRAG can be simulated with a QRAM, but the QRAM
can be simulated with the QRAG by requiring single qubit operations (which
are not present in the model of computation of definition 3.6). We will present
the proof for the simulation of the QRAM with a QRAG and leave the opposite
proof as exercise.
Theorem 3.1 (Simulating QRAM with QRAG.). A query to a QRAM of mem-
ory size 𝑛 can be simualted using 2 queries to a QRAG of memory size 𝑛, 3
two-qubit gates, and 1 workspace qubit.

Proof. Start with the input |𝑖⟩A |0⟩Tmp |𝑏⟩T |𝑥0 , … , 𝑥𝑛−1 ⟩M by using an an-
cillary qubit Tmp for the workspace. Use the SWAPT↔Tmp gate to ob-
tain |𝑖⟩A |𝑏⟩Tmp |0⟩T |𝑥0 , … , 𝑥𝑛−1 ⟩M . A query to the QRAG then leads to
|𝑖⟩A |𝑏⟩Tmp |𝑥𝑖 ⟩T |𝑥0 , … , 𝑥𝑛−1 ⟩M . Use a CT -X→Tmp from register T to register
Tmp, and query again the QRAG, followed by a SWAPT↔Tmp gate, to obtain the
desired state |𝑖⟩A |𝑏 ⊕ 𝑥𝑖 ⟩T |𝑥0 , … , 𝑥𝑛−1 ⟩M after discarding the ancillary qubit.

Exercise 3.3. Assuming that single-qubit gates can be freely applied onto the
memory register M of any QRAM, then show that a QRAG of memory size 𝑛
can be simulated using 3 queries to a QRAM of memory size 𝑛 and 2(𝑛 + 1)
Hadamard gates.
TODO make teheorem of the collowing comment.

[Link] Memory compression in sparse QRAG models


Assuming that the data is sparse is a common assumption when developing
quantum algorithms since it significantly simplifies computations. Applying it
to compress quantum algorithms with access to a QRAG was first proposed by
(Ambainis, 2007), elaborated further in (Jeffery, 2014), (Bernstein et al., 2013),
and finally formalized in (Buhrman et al., 2022).
Informally, a quantum algorithm is considered sparse if the number of queries to
a QRAG of size 𝑀 are made with a small number of quantum states. More for-
mally, we start by recalling that in a quantum computational model of definition
3.6 we split the qubits in several registers including a 𝑀 qubit memory register
and a 𝑊 qubit working register. If throughout the computation the queries to
the QRAG are made using only a constant set of quantum states which have
a maximum Hamming weight(which is the number of 1’s in the bit string) of
𝑚 ⋘ 𝑀 , then the algorithm is said to be 𝑚-sparse. The trick to making this
definition work is realizing that the SWAP gate can be used to exchange states
between the working register and the states with low hamming weight of the
target register.
46 CHAPTER 3. CLASSICAL DATA AND QUANTUM COMPUTERS

Confusingly, the authors of (Buhrman et al., 2022) decided to call a machine that
works under this model as QRAM: quantum random-access machine. The formal
definition of an 𝑚-sparse quantum algorithm with a QRAG is the following:
Definition 3.11 (Sparse QRAG algorithm (Buhrman et al., 2022)). Let 𝒞 =
(𝑛, 𝑇 , 𝑊 , 𝑀 , 𝐶1 , … , 𝐶𝑇 ) be a QRAG algorithm using time 𝑇 , 𝑊 work qubits,
and 𝑀 memory qubits. Then, we say that 𝐶 is 𝑚-sparse, for some 𝑚 ≤ 𝑀 , if at
every time-step 𝑡 ∈ {0, … , 𝑇 } of the algorithm, the state of the memory qubits
is supported on computational basis vectors of Hamming weight ≤ 𝑚. i.e., we
always have

[𝑀 ]
|𝜓𝑡 ⟩ ∈ span (|𝑢⟩|𝑣⟩ ∣ 𝑢 ∈ {0, 1}𝑊 , 𝑣 ∈ ( )) (3.16)
≤𝑚

In other words, if |𝜓𝑡 ⟩ is written in the computational basis:


(𝑡)
|𝜓𝑡 ⟩ = ∑ ∑ 𝛼𝑢,𝑣 ⋅ |𝑢⟩
⏟ ⊗ |𝑣⟩
⏟ , (3.17)
𝑢∈{0,1}𝑊 𝑣∈{0,1}𝑀 Work qubits Memory qubits

(𝑡)
then 𝛼𝑢,𝑣 = 0 whenever |𝑣| > 𝑚, where |𝑣| is the Hamming weight of 𝑣.
Now that we have seen sparse QRAG algorithms, we can look at how mem-
ory compression is performed. In particular, any 𝑚-sparse quantum algorithm
running in time 𝑇 and utilizing 𝑀 memory qubits can be simulated up to an
additional error 𝜖 by a quantum algorithm running in time 𝑂(𝑇 log( 𝑇𝜖 ) log(𝑀 ))
using 𝑂(𝑚 log(𝑀 )) qubits.
Theorem 3.2 (Memory compression for m-sparse QRAG algorithms (Buhrman
et al., 2022)). Let 𝑇 , 𝑊 , 𝑚 < 𝑀 = 2ℓ be natural numbers, with 𝑀 and 𝑚 both
powers of 2, and let 𝜖 ∈ [0, 1/2). Suppose we are given an 𝑚-sparse QRAG
algorithm using time 𝑇 , 𝑊 work qubits and 𝑀 memory qubits, that computes a
Boolean relation 𝐹 with error 𝜖.
Then we can construct a QRAG algorithm which computes 𝐹 with error 𝜖′ > 𝜖,
and runs in time 𝑂(𝑇 ⋅ log( 𝜖′𝑇−𝜖 ) ⋅ 𝛾), using 𝑊 + 𝑂(log 𝑀 ) work qubits and
𝑂(𝑚 log 𝑀 ) memory qubits.

3.3 Implementations
In this section we’ll be creating oracles that can perform the encodings that
were presented in section 3.1. Of the presented oracles only 3 will make use of
the quantum memory device introduced in definition 3.6: the bucket brigade,
KP-trees and the block encoding from data structure. It is interesting to note
that these oracles actually aid each other. In fact, KP-trees rely on the existence
of a QMD that can perform binary encoding and similarly block encoding from
data structures requires the existence of a QMD that can perform amplitude en-
coding. The other oracles will either make use of specific properties of the input
3.3. IMPLEMENTATIONS 47

data, such as sparsity, or will encode a probability distribution as a quantum


state. The key insight lies in the fact that all oracles, with or without QMD,
have a constant complexity which allows us to work in the quantum memory
model of computation of definition 3.4. All the presented oracles with their
interconnection can be seen in figure 3.2, where the oracle which require a QMD
have been indicated with a *.

Figure 3.2: This figure shows the different types of data encoding techniques
with the corresponding oracles. The vertical lines on the right hand side indicate
(possible) dependencies between oracles.

3.3.1 Binary encoding


In this section we are discussing implementations a unitary giving query access
to a list of 𝑚-bits values. A possible way of reading this section is throught the
lenses of finding the “best” gate decomposition of that unitary, which has the
following form:

𝑈0
𝑁−1 ⎡ 𝑈1 ⎤
𝑈 = ∑ |𝑖⟩⟨𝑖| ⊗ 𝑈𝑖 = ⎢ ⎥, (3.18)
𝑖=0
⎢ ⋱ ⎥
⎣ 𝑈𝑁−1 ⎦

where 𝑈𝑖 |0⟩ = |𝑥𝑖 ⟩ and 𝑥𝑖 ∈ {0, 1}𝑚 . Importantly, when considering gate de-
compositions of this unitary, we are allowed to act in a larger space, as long as
in the subspace of interested our application acts accoring to Eq.(3.18).
48 CHAPTER 3. CLASSICAL DATA AND QUANTUM COMPUTERS

[Link] Oracle synthesis


As we briefly anticipated in Section 2.3, if we know a function that maps
𝑥𝑖 = 𝑓(𝑖) we can create a circuit for getting query access to 𝑥𝑖 . If our data
is represented by the output of a function, we can consider these techniques for
data loading.
The idea of creating a quantum circuit from a classical Boolean function is
relatively simple and can be found in standard texts in quantum computation
((Nielsen and Chuang, 2002) or the this section on the Lecture notes of Dave
Bacon). There is a simple theoretical trick that we can use to see that for any
(potentially irreversible) Boolean circuit there is a reversible version for it. This
observation is used to show that non-reversible circuits are not more powerful
than reversible circuits. To recall, a reversible Boolean circuit is just bijection
between domain and image of the function. Let 𝑓 ∶ {0, 1}𝑚 ↦ {0, 1}𝑛 be a
Boolean function (which we assume is surjective, i.e. the range of 𝑓 is the whole
{0, 1}𝑛 ). We can build a circuit 𝑓 ′ ∶ {0, 1}𝑚+𝑛 ↦ {0, 1}𝑚+𝑛 by adding some
ancilla qubits, as it is a necessary condition for reversibility that the dimension
of the domain matches the dimension of the range of the function. We define
𝑓 ′ as the function performing the mapping (𝑥, 𝑦) ↦ (𝑥, 𝑦 ⊕ 𝑓(𝑥)). It is simple
to see by applying twice 𝑓 ′ that the function is reversible (check it!).
Now that we have shown that it is possible to obtain a reversible circuits from
any classical circuit, we can ask: what is an (rather inefficient) way of getting
a quantum circuit? Porting some code (or circuit) from two similar level of
abstraction is often called transpiling. Again, this is quite straightforward (Sec-
tion 1.4.1 (Nielsen and Chuang, 2002)). Every Boolean circuit can be rewritten
in any set of universal gates, and as we know, the NAND port is universal for
classical computation. It is simple to see (check the exercise) that we can use a
Toffoli gate to simulate a NAND gate, so this gives us a way to obtain a quan-
tum circuit out of a Boolean circuit made of NAND gates. With these two steps
we described a way of obtaining a quantum circuit from any Boolean function
𝑓.
Exercise 3.4 (Toffoli as NAND). Prove that a Toffoli gate, along with an
ancilla qubit, can be used to obtain a quantum version of the NAND gate?
However, an application of the quantum circuit for 𝑓, will result in a garbage
register of some unwanted qubits. To get rid of them we can use this trick:

|𝑥⟩|0⟩|0⟩|0⟩ ↦ |𝑥⟩|𝑓(𝑥)⟩|𝑘(𝑓, 𝑥)⟩|0⟩ ↦ |𝑥⟩|𝑓(𝑥)⟩|𝑘(𝑓, 𝑥)⟩|𝑓(𝑥)⟩ ↦ |𝑥⟩|𝑓(𝑥)⟩.


(3.19)
Let’s explain what we did here. In the first step we apply the circuit that com-
putes 𝑓 ′ . In the second step we perform a controlled NOT operation (controlled
on the third and targeting the fourth register), and in the last step we undo the
application of 𝑓 ′ , thus obtaining the state |𝑥⟩|𝑓(𝑥)⟩ with no garbage register.
3.3. IMPLEMENTATIONS 49

Importantly, the idea of obtaining a quantum circuit from a classical reversible


circuit is not practical, and is only relevant didactically. The task of obtaining
an efficient quantum circuit from a Boolean function is called “oracle synthesis”.
Oracle synthesis is far from being a problem of only theoretical interest, and it
has received a lot of attention in past years (Soeken et al., 2018) (Schmitt et al.,
2021) (Shende et al., 2006). Today software implementations can be easily found
online in most of the quantum programming languages/library. For this problem
we can consider different scenarios, as we might have access to the function in
form of reversible Boolean functions, non-reversible Boolean function, or the
description of a classical circuit. The problem of oracle syntheses is a particular
case of quantum circuit synthesis (Table 2.2 of (de Brugière, 2020) ) and is a
domain of active ongoing research.
If we want to prove the runtime of a quantum algorithm in terms of gate com-
plexity (and not only number of queries to an oracle computing 𝑓) we need to
keep track of the gate complexity of the quantum circuits we use. For this we
can use the following theorem.
Theorem 3.3 ((Buhrman et al., 2001b) version from (Bausch et al., 2021)).
For a probabilistic classical circuit with runtime 𝑇 (𝑛) and space requirement
𝑆(𝑛) on an input of length 𝑛 there exists a quantum algorithm that runs in time
𝑂(𝑇 (𝑛)log2 (3) and requires 𝑂(𝑆(𝑛) log(𝑇 (𝑛)) qubits.

[Link] Sparse access


Sparse matrices are very common in quantum computing and quantum physics,
so it is important to formalize a quantum access for sparse matrices. This model
is sometimes called in literature “sparse access” to a matrix, as sparsity is often
the key to obtain an efficient circuit for encoding such structures without a
QRAM. Of course, with a vector or a matrix stored in a QRAM, we can also
have efficient (i.e. in time 𝑂(log(𝑛)) if the matrix is of size 𝑛 × 𝑛) query access
to a matrix or a vector, even if they are not sparse. It is simple to see how
we can generalize query access to a list or a vector to work with matrices by
introducing another index register to the input of our oracle. For this reason,
this sparse access is also called quite commonly “query access”.
Definition 3.12 (Query access to a matrix). Let 𝑉 ∈ ℝ𝑛×𝑑 . There is a data
structure to store 𝑉 , (where each entry is stored with some finite bits of pre-
cision) such that, a quantum algorithm with access to the data structure can
perform |𝑖⟩|𝑗⟩|𝑧⟩ → |𝑖⟩|𝑗⟩|𝑧 ⊕ 𝑣𝑖𝑗 ⟩ for 𝑖 ∈ [𝑛], 𝑗 ∈ [𝑑].
A matrix can be accessed also with another oracle.
Definition 3.13 (Oracle access in adjacency list model). Let 𝑉 ∈ ℝ𝑛×𝑑 , there
is an oracle that allows to perform the mappings:
• |𝑖⟩ ↦ |𝑖⟩|𝑑(𝑖)⟩ where 𝑑(𝑖) is the number of non-zero entries in row 𝑖, for
𝑖 ∈ [𝑛], and
50 CHAPTER 3. CLASSICAL DATA AND QUANTUM COMPUTERS

• |𝑖, 𝑙⟩ ↦ |𝑖, 𝑙, 𝜈(𝑖, 𝑙)⟩, where 𝜈(𝑖, 𝑙) is the 𝑙-th nonzero entry of the 𝑖-th row
of 𝑉 , for 𝑙 ≤ 𝑑(𝑖).

The previous definition is also called adjacency array model. The emphasis is
on the word array, contrary to the adjacency list model in classical algorithms
(where we usually need to go through all the list of adjacency nodes for a given
node, while here we can query the list as an array, and thus use superposition)
(Dürr et al., 2004).

It is important to recall that for Definition 3.12 and 3.13 we could use a QRAM,
but we also expect not to use a QRAM, as there might be other efficient circuit
for performing those mapping. For instance, when working with graphs (remem-
ber that a generic weighted and directed graph 𝐺 = (𝑉 , 𝐸) can be seen as its
adjacency matrix 𝐴 ∈ ℝ|𝐸|×|𝐸| ), many algorithms call Definition 3.12 vertex-
pair-query, and the two mappings in Definition 3.13 as degree query and
neighbor query. When we have access to both queries, we call that quantum
general graph model (Hamoudi and Magniez, 2018). This is usually the case
in all the literature for quantum algorithms for Hamiltonian simulation, graphs,
or algorithms on sparse matrices.

[Link] Circuits
TODO

What if we want to use a quantum circuit to have quantum access to a vector


of data? In this section we are going to describe few circuits for the task, each
showcasing different properties and trade-offs between depth and space. For
example the simplest circuit that we can come up with, has a depth that is
linear in the length of the vector. This kind of circuit is often used in literature,
e.g. for computing functions using space-time trade-offs (Krishnakumar et al.,
2022; Gidney and Ekerå, 2021). This circuit (which sometimes goes under the
name QROM, or circuit for table lookups (Hann et al., 2021), or multiplexer,
is simply a series of multi-control operations, each of which is writing (using 𝑋
gates) some binary string on the target register. Controlled on the index register
being in the state |0⟩, we write in the output register the value of our vector in
position 𝑥0 , controlled in the index register being |1⟩, we write on the output
register the value of our vector in position 𝑥1 , etc.. This will result in a circuit
with a depth that is linear in the length of the vector that we are accessing,
however this circuit won’t require any ancilla qubit. We will discuss more some
hybrid architecture that allows a trade off between depth and ancilla qubits in
Section ??. The Toffoli count of this circuit can be improved in various ways
(Babbush et al., 2018; Zhu et al., 2024). Importantly, the depth of this circuit
depends on the number of oracle entries 𝑁 , and in simple implementations
depends also linearly in 𝑚. As an example, consider the following circuit.

The most general version of the circuit is the following, which includes some
optimization.
3.3. IMPLEMENTATIONS 51

Figure 3.3: This is the example of a multiplexer circuit for the list of values
x=[1,1,0,1]. Indeed, if we initialize the first two qubits with zeros, the output
of the previous circuit will be a 1 in the third register, and so on.

Figure 3.4: The implementation of the multiplexer of (Babbush et al., 2018).


Importantly, only one 𝑇 gate is required to write in the target register a single
memory entry. The memory entry is written using a Fan-Out gate (which can
be decomposed into CNOT gates. Note that the depth of the circuit is linear in
the number of memory [Link] angular lines in the gates are representing
the so-called ‘logical-AND’, which is a CCNOT gate targeting an ancilla qubit
starting in a particular state (ground state on which we apply a 𝑇 gate) and
gets uncomputed using measurament-based uncomputation.
52 CHAPTER 3. CLASSICAL DATA AND QUANTUM COMPUTERS

The bucket brigade architecture (in short BB architecture) is another possible


architecture. This protocol was originally developed to be implemented with
qutrits (Giovannetti et al., 2008b) but recent work has shown it can be imple-
mented with qubits as well (Hann et al., 2021). First, we will mention the idea
with qutrits since it is more intuitive to understand. Again, using the terminol-
ogy introduced in definition 3.6, we’ll have: an address register, a target register
(which will be referred to as a bus register) and a memory register. The input
will be a vector of binary numbers 𝑋 ∈ ({0, 1}𝑚 )𝑛 and the aim is to load a
specific entry 𝑋𝑖 ∈ {0, 1}𝑚 on the bus register.
The BB protocol will use the memory register in such a way that it has access
to tree like structure. The tree saves the entries of 𝑋 in the leaves, which are
referred to as memory cells. Each memory cell is connected to a parent node
which form a set of intermediate nodes up until the root of the tree. Each
intermediate node (up to the root) is called a quantum router (Figure 1b of
(Hann et al., 2021)) and is a qutrit (i.e., a three level quantum system), which
can be in state |0⟩ (route left), |1⟩ (route right), and |𝑊 ⟩ (wait).
When we want to perform a query, we prepare the address register with the index
of the memory cell that we want to reach and we set all the router registers to
the |𝑊 ⟩ state. Conditioned on the first qubit of the address register, the root
of the tree changes from |𝑊 ⟩ to either |0⟩(left) or |1⟩(right). This is followed
by a similar operation which uses as control the second qubit of the address
register to change the state of the next node in the tree to either |0⟩ or |1⟩. The
process of changing the state of the routers is repeated until the last layers of the
tree(i.e. the memory cell) is reached. Now, the memory register will be in the
state of the binary number 𝑋𝑖 . This can be copied to the bus register by simply
applying a series of CNOT gates (and thus we do not violate the no-cloning
theorem).
Studying an error model of the BB architecture is hard. An attempt was first
made in (Arunachalam et al., 2015) which gave initial, but rather pessimistic
result. More recently, a series of developments in (Hann et al., 2021) and (Hann,
2021) (accessible here) have shone light on the noise resilience of the BB QRAM.
The results presented in these more recent works are much more positive. Some
resource estimations can be found in (Di Matteo et al., 2020), which do not take
into account the new developements in the study of the error.
The metric of choice to test whether a quantum procedure has faithfully recre-
ated a desired state is the fidelity 𝐹 , with the infidelity defined as 1−𝐹 . Given a
addressable memory of size 𝑁 (i.e. log 𝑁 layers in the binary tree) and a bucket
brigade which requires 𝑇 time-steps with a probability of error per time step of
𝜖, the infidelity of the bucket brigade scales as:

log 𝑁
1 − 𝐹 ≈ ∑ (2−𝑙 )𝜖𝑇 2𝑙 = 𝜖𝑇 log 𝑁 , (3.20)
𝑙=1
3.3. IMPLEMENTATIONS 53

log 𝑁
Exercise 3.5. Calculate ∑𝑙=1 𝑙
The time required to perform a query, owing to the tree structure of the BB, is
log 𝑁−1
𝑇 = 𝑂(log 𝑁 ). This can be seen trivially from the fact that 𝑇 ≈ ∑𝑙=0 𝑙=
1
2 (log 𝑁 )(log 𝑁 + 1), but can be decreased to 𝑂(log 𝑁 ) (Appendix A of (Hann
et al., 2021)). This leaves us with the sought-after scaling of the infidelity
̃
of 𝑂(𝜖) where we are hiding in the asymptotic notation the terms that are
polylogarithmic in 𝑁 . The error that happen with probability 𝜖 can be modeled
with Kraus operators makes this error analysis general and realistic (Appendix
C (Hann et al., 2021)), and is confirmed by simulations. For a proof of Equation
(3.20) see Section 3 and Appendix D of (Hann et al., 2021).

Figure 3.5: A possible implementation of the bucket-brigade QRAM in the


circuit model, from (Hann et al., 2021)

Exercise 3.6. The last block of the circuit depicted in Figure 3.6 has linear
depth in the number of memory elements, i.e. has exponential depth in the
54 CHAPTER 3. CLASSICAL DATA AND QUANTUM COMPUTERS

Figure 3.6: A possible implementation of the bucket-brigade QRAM in the


circuit model, from (Doriguello et al., 2024; Arunachalam et al., 2015). In every
layer, before the parallel layer of Toffoli gates, a log-depth linear-size gadget is
copying the index register. In this way, the Toffoli gates can be executed in
parallel.
3.3. IMPLEMENTATIONS 55

number of qubits in the index regsiter. Eventually using some ancilla qubits,
can you create a gadget that writes to the output register in logarithmic depth?
The following statement gives a resource estimation for a QRAM of logarith-
mic depth using the quantum architecture proposed in (Litinski and Nickerson,
2022).
Lemma 3.1 (Complexity of QRAM using (Doriguello et al., 2024)). One bucket-
brigade QRAM call of size 2𝑛 and precision 𝜅 requires (already including its
uncomputation) 2𝑛 − 2 Toffoli gates, 2𝑛+1 − 𝑛 − 1 dirty ancillae (plus 𝑛 + 𝜅
input/output qubits), and has Toffoli-width of 2𝑛−1 , reaction depth of 2(𝑛 − 1),
and active volume of (25 + 1.5𝜅 + 𝐶|𝐶𝐶𝑍⟩ )2𝑛 .
In the following, we report the resource count of some QRAM constructions
using different techniques.
Theorem 3.4 (Complexity of QRAM using Fourier analysis (Allcock et al.,
2023)). Let 𝑛 ∈ ℕ be a power of 2. A QRAM of memory size 𝑛 can be imple-
mented in 𝑂(1)-depth using
• either 12 𝑛2 log 𝑛 + 𝑂(𝑛2 ) ancillae and 2𝑛2 + 𝑂(𝑛 log 𝑛) Fan-Out gates with
arity ≤ 1 + 𝑛2 ,
• or 2𝑛2 ancillae and 2 GT gates with arity ≤ 12 𝑛2 log 𝑛 + 𝑂(𝑛2 ).
Theorem 3.5 (Complexity of QRAM using one-hot encoding ideas (Allcock
et al., 2023)). For every 𝑛 ∈ ℕ a power of 2, a QRAM of memory size 𝑛 can be
implemented in 𝑂(1)-depth using
• either 2𝑛 log 𝑛 log log 𝑛 + 𝑂(𝑛 log 𝑛) ancillae and 6𝑛 log 𝑛 + 𝑂(𝑛 log log 𝑛)
Fan-Out gates with arity ≤ 𝑛 + 1,
• or 3𝑛 log 𝑛 + 𝑂(𝑛 log log 𝑛) ancillae and 6 GT gates with arity ≤ 𝑛 log 𝑛 +
𝑂(𝑛 log log 𝑛).
Theorem 3.6 (Complexity of QRAM using recursive tricks (Allcock et al.,
2023)). For every 𝑛, 𝑑 ∈ ℕ, a QRAM of memory size 𝑛 can be performed in
𝑂(𝑑)-depth~using
(𝑑) (𝑑+1) (𝑑)
• either 𝑂(𝑛 log 𝑛 log 𝑛) ancillae and 𝑂(𝑛 log 𝑛) Fan-Out gates,
(𝑑)
• or 𝑂(𝑛 log 𝑛) ancillae and 16𝑑 − 10 GT gates.

3.3.2 Amplitude encoding


We now move our attention to amplitude encoding, which was first introduced
in section 3.1.2. In amplitude encoding, we encode a vector of numbers in the
amplitude of a quantum state. Implementing a quantum circuit for amplitude
encoding can be seen as preparing a specific quantum states, for which we know
the amplitudes. In other words, this is actually a state preparation problem in
disguise, and we can use standard state preparation methods to perform ampli-
tude encoding. However, note that amplitude encoding is a specific example of
state preparation, when the amplitudes of the state are known classically or via
56 CHAPTER 3. CLASSICAL DATA AND QUANTUM COMPUTERS

an oracle. There are other state preparation problems that are not amplitude
encoding, like ground state preparation, where the amplitudes of the quantum
state is not known and only the Hamiltonian of the system is given. In the
following, we briefly discuss the main techniques developed in the past decades
for amplitude encoding.

What are the lower bounds for the size and depth complexity of circuits perform-
ing amplitude encoding? Since amplitude encoding can be seen as a quantum
state preparation, without assuming any kind of oracle access, we have a lower
bound of Ω (2𝑛 ) (Plesch and Brukner, 2011; Shende et al., 2004). For the depth,
we have a long history of results. For example, there is a lower bound of Ω(log 𝑛)
that holds for some states (and hence puts a lower bound on algorithms per-
forming generic state preparation ) using techniques from algebraic topology
(Aharonov and Touati, 2018). Without ancilla qubits (Plesch and Brukner,
𝑛
2011) proposed a bound of Ω( 2𝑛 ). The bound on the depth has been refined
to a Ω(𝑛), but only when having arbitrarily many ancilla qubits (Zhang et al.,
4𝑛
2021). The more accurate bound is of Ω (max{𝑛, 𝑛+𝑚 }) (Theorem 3 of (Sun
et al., 2023)), where 𝑚 is the number of ancilla qubits. The algorithms of (Yuan
and Zhang, 2023), which we discuss later, saturates this bound.

We can also study the complexity of the problem in the oracle model. For
example, if we assume an oracle access to 𝑓 ∶ {0, 1}𝑛 ↦ [0, 1], using amplitude
amplification techniques on the state ∑𝑥 |𝑥⟩ (𝑓(𝑥)|0⟩ + √1 − 𝑓(𝑥)|1⟩), there is

̃ 𝑁)
a quadratic improvement in the number of queries to the oracle, yielding 𝑂(
complexity (Grover, 2000), where 𝑁 = 2𝑛 . This can be seen if we imagine a
vector with only one entry with the value 1, where the number of queries
√ to
amplify the subspace associated with the rightmost qubit scales with 𝑁 . Few
years later, we find another work by (Grover and Rudolph, 2002) which, under
some mildly stronger assumptions improved the complexity of the algorithms
for a very broad class of states. This algorithm is better discussed in Section
[Link].

Alternatively, we can assume a direct oracle access to the amplitudes (Sanders


et al., 2019). Under this assumption, we have access to an oracle storing
the 𝑖th amplitude 𝛼𝑖 with 𝑛 bits, (actually, they use a slightly different
(𝑛)
model, where the oracle for the amplitude 𝛼𝑖 is |𝑖⟩|𝑧⟩ ↦ |𝑖⟩|𝑧 ⊕ 𝛼𝑖 ⟩
(𝑛)
where 𝛼𝑖 = ⌊2𝑛 𝛼𝑖 ⌋). Ordinarily, the circuit involves the mapping
(𝑛)
|𝑖⟩|𝛼𝑖 ⟩|0⟩ ↦ |𝑖⟩|𝛼𝑖 ⟩ (sin(𝜃𝑖 )|0⟩ + cos(𝜃𝑖 )|1⟩), which requires control rota-
tions and arithmetic circuits to compute the angles 𝜃𝑖 = arcsin(𝛼𝑖 /2𝑛 ).
However, by substituting the arithmetic circuit by a comparator operator
(Gidney, 2018; Cuccaro et al., 2004; Luongo et al., 2024), the circuit can be
implemented either with 2𝑛 non-Clifford gates or 𝑛 non-Clifford gates and 𝑛
ancilla qubits. This scheme can even be extended to encode complex amplitudes
in both Cartesian and polar forms, or apply to the root coefficient problem of
real amplitudes, where we have an oracle access to the square of the amplitude
𝛼2𝑖 instead of 𝛼𝑖 . For positive or complex amplitudes, this algorithm involves
3.3. IMPLEMENTATIONS 57
√ √
𝜋 𝑁
4 ‖𝛼‖2 exact amplitude amplifications, so it has a runtime of 𝜋4 𝑡‖𝛼‖𝑁 + 𝑂(1)
2
non-Clifford gates, where 𝑡 is the number of bits of precision used to specify an
amplitude (the authors preferred to count the number of non-Clifford gates, as
they are the most expesive one to implement in (most of) the error corrected
architectures, and serves as a lower bound for the size complexity

of a circuit.
𝜋𝑛 𝑁
For the root coefficient problem, the runtime becomes 4 ‖𝛼‖ + 𝑂 (𝑛 log ( 1𝜖 ))
1
non-Clifford gates. For certain sets of coefficients, this model can further be
improved to reduce the number of ancilla qubits needed per bits of precision
from a linear dependence (Sanders et al., 2019) to a log dependence (Table 2
of (Bausch, 2022)). Also the work of (McArdle et al., 2022) works assuming an
𝑁−1
oracle returning the amplitudes of the state we want to build 𝒩1 ∑𝑥=0 𝑓(𝑥)|𝑥⟩
𝑓
(where 𝒩𝑓 is the usual normalization factor), and does not use arithmetic,
and uses 𝑂( ℱ𝑛𝑑[𝑁]
𝜖 ̃ is called “discretized ℓ -norm filling-fraction”,
) (where 𝑓 [𝑁] 2
𝑓̃
and 𝑑𝜖 is the degree of a polynomial approximation that depends on 𝜖, the
approximation error in the quantum state ) and uses only 4 ancilla qubits.

Instead of treating the problem as a state preparation problem, we can also


perform amplitude encoding using multivariable quantum signal processing (M-
QSP) (See Chapter ??). The principle behind this method is to interpret the
amplitude of a quantum state as a function of a multivariable polynomial (McAr-
dle et al., 2022; Mori et al., 2024; Rosenkranz et al., 2024). Particularly, using
Linear Combination of Unitaries techniques, we can approximate the quantum
state as a multivariable function by a truncated Fourier or Chebyshev series
(Rosenkranz et al., 2024). The truncated Fourier series approximation requires
𝑂(𝑑𝐷 + 𝐷𝑛 log 𝑑) two-qubit gates, while the truncated Chebyshev series approx-
imation requires 𝑂(𝑑𝐷 + 𝐷𝑑𝑛 log 𝑛) two-qubit gates, where 𝐷 is the number of
dimensions and 𝑑 is the degree of the polynomial used in the approximation.
The number of qubits in both techniques scales as 𝑂(𝐷𝑛 + 𝐷 log 𝑑). The expo-
nential dependence in 𝐷 can further be improved by the following theorems.

Theorem 3.7 (Bivariate state preparation (Mori et al., 2024)). Given a Fourier
series 𝑓 of degree (𝑑1 , 𝑑2 ) that can be constructed with M-QSP, we can pre-
pare a quantum state |𝜓𝑓 ⟩ using 𝑂((𝑛1 𝑑1 + 𝑛2 𝑑2 )/ℱ𝑓 ) gates, where ℱ𝑓 =
(𝑖) (𝑗)
𝒩𝑓 /(√𝑁1 𝑁2 |𝑓|𝑚𝑎𝑥 ), 𝒩𝑓 = √∑𝑖,𝑗 (𝑓(𝑥1 ), 𝑓(𝑥2 )), whereas 𝑛1 and 𝑛2 are the
number of bits used to specify the value of the variable 𝑥1 and 𝑥2 , respectively.

Theorem 3.8 (Multivariate state preparation (Mori et al., 2024)). Given a


Fourier series 𝑓 of degree (𝑑1 , … , 𝑑𝐷 ) that can be constructed with multivari-
ate quantum signal processing, we can prepare a quantum state |𝜓𝑓 ⟩ using
𝑂(𝑛𝑑𝐷/ℱ𝑓 ) gates, where 𝑛 = max(𝑛1 , … , 𝑛𝐷 ) and 𝑑 = max(𝑑1 , … , 𝑑𝐷 )

Meanwhile, if trade-offs are allowed for state preparation, we can further im-
prove the complexity of the algorithm. For example, we can build a state over 𝑛
qubits with depth 𝑂 ̃ ( 2𝑛 + 𝑛) and size 𝑂̃ (2𝑛 ) if we have 𝑚 available ancillas
𝑚+𝑛
(Sun et al., 2023). On the other hand, we can reduce the number of 𝑇 -gates
58 CHAPTER 3. CLASSICAL DATA AND QUANTUM COMPUTERS

log 𝑁 log 𝑁
to 𝑂( 𝑁 𝑁
𝜆 + 𝜆 log 𝜖 log 𝜖 ) if we allow a tunable number of 𝜆 𝜖 dirty qubits
(Low et al., 2018). A dirty qubit is an auxiliary qubit that is left entangled
with another register at the end of computation. It cannot be reused by subse-
quent computations without being disentangled, but can be uncomputed using
measurement-based uncomputation tricks.
In addition to the algorithms (Sun et al., 2023; Rosenthal, 2021), trade-offs
can introduce additional circuits that can achieve the lower bound of the depth
complexity. For example, using 𝑂 (2𝑛 ) ancilla qubits, we can perform ampli-
tude encoding with circuit depth Θ (𝑛), which further relaxes the connectivity
requirements for M-QSP (Zhang et al., 2022). This technique also improves
upon sparse state preparation, with a circuit depth Θ (log 𝑘𝑁 ), where 𝑘 is the
sparsity. This represents an exponential improvement in circuit depth over pre-
vious works (Gleinig and Hoefler, 2021; de Veras et al., 2022). This leads to a
deterministic algorithm that achieves the lower bounds in circuit depth if we
allow 𝑚 ancilla qubits, which is summarized in the following theorem.
Theorem 3.9 (Circuit for controlled state preparation (Theorem 1 of (Yuan
and Zhang, 2023)) ). For any 𝑘 ∈ ℕ and quantum states {|𝜓𝑖 ⟩|𝑖 ∈ {0, 1}𝑘 } there
is a circuit performing
|𝑖⟩|0⟩ ↦ |𝑖⟩|𝜓𝑖 ⟩, ∀𝑖 ∈ {0, 1}𝑘 ,
𝑛+𝑘
2
which can be implemented by a circuit of depth 𝑂(𝑛 + 𝑘 + 𝑛+𝑘+𝑚 ) and size
𝑂(2𝑛+𝑘 ) with 𝑚 ancillary qubits. These bounds are optimal for any 𝑚, 𝑘 ≥ 0.
Theorem 3.10 (Circuit for state preparation (Theorem 2 of (Yuan and Zhang,
2023)) ). For any 𝑚 > 0, any 𝑛-qubit quantum state |𝜓𝑣 ⟩ can be generated by a
2𝑛
quantum circuit using single qubit gates and CNOT gates, of depth 𝑂(𝑛 + 𝑛+𝑚 )
and size 𝑂(2𝑛 ) with 𝑚 ancillary qubits. These bounds are optimal for any 𝑚 ≥ 0.
There are also other trade-off techniques that can be used, like probabilistic
state preparation via measurements (Zhang et al., 2021) or approximate state
preparation problem (Zhang et al., 2024). However, these techniques are beyond
the scope of this chapter and will not be discussed. Interested readers can refer
to the respective articles. However, even if we allow intermediate measurements
we have lower bounds on the T-count, which is reached by the algorithm of
(Gosset et al., 2024).
Theorem 3.11 (Quantum state preparation with optimal T-count (Gosset
et al., 2024)). Any 𝑛-qubit state can be prepared up to error 𝜖 by a Clifford+T
circuit starting with the all-zeroes state using
𝑂 (√2𝑛 log(1/𝜖) + log(1/𝜖))

𝑇 gates and ancillas. Furthermore, no Clifford+T circuit (even with measure-


ment and adaptivity) can use asymptotically fewer 𝑇 -gates.
In summary, there are many methods to perform amplitude encoding, each with
different complexities through various trade-offs. In general, the data set that
3.3. IMPLEMENTATIONS 59

can be encoded using amplitude encoding lies under two main categories: (i)
those discrete data that come from a vector or a matrix, or (ii) those that come
from a discretized probability distribution. In literature, amplitude encoding of
vectors or matrices is called state preparation via a KP-tree, while amplitude
encoding of discretized probability distribution is called Grover-Rudolph (GR)
state preparation (Grover and Rudolph, 2002). The main difference between the
KP-tree method and the GR state preparation is that the KP-tree method re-
quires a quantum memory to store some precomputed values in a data structure
or a tree, while the GR state preparation does not require a quantum memory.
In fact, GR state preparation is designed such that there are efficient circuits
to implement the oracle in the quantum computer using [Link].

Table 3.2: Recap for the different methods proposed to implement amplitude
encoding, together with the their gate count and ancilla complexity, along with
the function type needed. This table is adapted from (Mori et al., 2024), 1
(Mori et al., 2024), 2 (Grover and Rudolph, 2002), 3 (Rattew and Koczor, 2022)
4 (Sanders et al., 2019; Bausch, 2022) 5 (Moosa et al., 2023) 6 (Rosenkranz
et al., 2024) 7 (Shende et al., 2006) 8 (Sun et al., 2023) 9 (Gosset et al., 2024).
Gate count or depth with * is expressed in number of 𝑇 gates.

Function
Method Size Ancilla Depth type
1 M-SQP 𝑂( 𝑛𝑑𝐷
ℱ ) 1
2 GR 𝑂(𝑛𝑇𝑜𝑟𝑎𝑐𝑙𝑒 ) 𝑂(𝑡𝑜𝑟𝑎𝑐𝑙𝑒 ) log Eff.
int.
3 Adiabatic 𝑂( 𝑇𝑜𝑟𝑎𝑐𝑙𝑒
ℱ4 ) 𝑂(𝑡𝑜𝑟𝑎𝑐𝑙𝑒 ) - Arb.
𝑇𝑜𝑟𝑎𝑐𝑙𝑒
4 Black- 𝑂( ℱ ) 𝑂(𝑡𝑜𝑟𝑎𝑐𝑙𝑒 ) - Arb.
box
5 FSL 𝑂(𝑑𝐷 + 𝐷𝑛2 ) 0 - Arb.
6 LCU- 𝑂(𝑑𝐷 + 𝐷𝑛 log 𝑑) 𝑂(𝐷 log 𝑑) - Arb.
based
7 Circuit 𝑁 log ( 𝑁𝜖 )* 𝑂(𝑛) 𝑁 log ( 𝑁𝜖 )* Arb.
8 Circuit 𝑁 log ( 𝑁𝜖 ) 𝑂 (𝑛 + 𝜆) 𝑁
𝑛+𝜆 log ( 𝑁𝜖 )+ Arb.
𝑛 log ( 𝑁𝜖 ) *
9 Circuit 𝑂 (√2𝑛 log( 1𝜖 ) + log( 1𝜖 ))* 𝑂 (√2𝑛 log( 1𝜖 ) + log(1/𝜖))
? Arb.

By looking at different models of quantum computation, we find that state


preparation can be performed in constant depth assuming unbounded Fan-Out
circuits (Corollary 4.2) (Rosenthal, 2021). The key idea behind this work was
to link state preparation to a DNF (disjunctive normal form) boolean formula,
which is evaluated in the quantum algorithm. Compiling Fan-Out gates using
CNOT gates, this leads to a circuit of depth 𝑂(𝑛) and 𝑂(𝑛2𝑛 ) ancillas. State
preparation can also be studied under a different lens in complexity theory, lead-
ing to new interesting insights. For example, people studied the complexity of
60 CHAPTER 3. CLASSICAL DATA AND QUANTUM COMPUTERS

generating quantum states (Rosenthal and Yuen, 2021; Metger and Yuen, 2023).
For example, the states that can be generated by a (space-uniform) polynomial-
sized quantum circuit, forms the class of StatePSPACE. This class has been
proven to be equivalent to StateQIP (the class of states that a polynomial-
time quantum verifier can generate with interactions with a all-powerful and
untrusted quantum prover), echoing the equivalence between the complexity
classes QIP and PSPACE.
There are many other works in state preparation, and we refer the interested
reader to (Bergholm et al., 2005; Plesch and Brukner, 2011; Araujo et al., 2021;
Bausch, 2022; Rattew and Koczor, 2022; Plesch and Brukner, 2011; Rosenthal,
2021; Zhang et al., 2022; Buhrman et al., 2023b; Rosenthal, 2024; Gleinig and
Hoefler, 2021; Holmes and Matsuura, 2020; Moosa et al., 2023; Zhao et al.,
2021). Now we consider two very didactic and general models of quantum
state preparation. The former is known as Grover-Rudolph state preparation
(Grover and Rudolph, 2002) whilst the latter is known as a state prepration
via a precomputed data structure that is quantum accessible, called KP-tree.
A difference between the Grover-Rudolph and the KP-tree method is that GR
is assuming a query access to an oracle which does not need to be necessarily
needs to be implemented with a quantum memory. While the KP-tree method
assumes some precomputation of a data structure (a tree) which is specifically
stored into the QRAM. In fact, for the kinds of quantum states that GR was
designed to create, there are efficient circuits for the implementing the oracle,
that can be implemented in a quantum computer using Section3.3.1.1. For both,
the total depth of the circuit (considering the QMD as part of the quantum
2
computer) is 𝑂(log (𝑁 )), while the size of the circuit is 𝑂(𝑁 log 𝑁 ).
Finally we note that in (Prakash, 2014) (Section 2.2.1), Prakash shows subrou-
tines for generating |𝑥⟩ for a sparse 𝑥 in time 𝑂(√‖𝑥‖0 ).
In this model is it possible to prepare states with long-range entanglement with
only constant quantum-depth and logarithmic classical depth. However, the
authors do not generalize their algorithm for state preparation for any quantum
state, but only for a restricted class of quantum states with constraints on the
Hamming weights.

[Link] Grover-Rudolph state preparation, its problems, and the so-


lutions
In (Grover and Rudolph, 2002) the authors discussed how to efficiently create
quantum states proportional to functions satisfying certain integrability con-
dition, i.e. the function considered must be square-integrable. An example of
functions with this properties are log-concave probability distributions. Let
𝑝(𝑥) be a probability distribution over ℝ. We denote by 𝑥𝑛𝑖 is the points of
(𝑛)
the discretization over the domain, i.e 𝑥𝑖 = −𝑤 + 2𝑤 2𝑖𝑛 for 𝑖 = 0, … , 2𝑛 , and
[−𝑤, 𝑤] is the window of discretization, for a constant 𝑤 ∈ ℝ+ . In this case,
𝑛 acts as the parameter that controls how coarse or fine is the discretization.
3.3. IMPLEMENTATIONS 61

Consider referencing the appendix for more informations about measure theory
and probability distributions. We want to create the quantum state

2𝑛 −1
(𝑛)
|𝜓𝑛 ⟩ = ∑ √𝑝𝑖 |𝑖⟩ (3.21)
𝑖=0

with

(𝑛)
𝑥𝑖+1
(𝑛)
𝑝𝑖 =∫ 𝑝(𝑥)d𝑥. (3.22)
(𝑛)
𝑥𝑖

(𝑛) 𝑤
Actually, the probabilities 𝑝𝑖 will be normalized by ∫−𝑤 𝑝(𝑥)d𝑥. This is equiv-
alent to discretizing the sample space Ω in 𝑁 = 2𝑛 intervals with 𝑁 + 1 points,
so that we can identify the samples 𝜔 of our discretized random variable with
the elements of the set [𝑁 ]. To create the state |𝜓𝑛 ⟩ we proceed recursiveliy
𝑚
2 −1 (𝑚)
in 𝑛, starting from initial state |0⟩. To go from |𝜓𝑚 ⟩ = ∑𝑖=0 √𝑝𝑖 |𝑖⟩ to
𝑚+1
2 −1
|𝜓𝑚+1 ⟩ = ∑𝑖=0 √𝑝𝑖(𝑚+1) |𝑖⟩ we proceed by performing a query to an oracle
that gives us an angle 𝜃𝑖 , for 𝑖 ∈ [2𝑚 ], which is used to perform the following
rotation:

|𝑖⟩|𝜃𝑖 ⟩|0⟩ ↦ |𝑖⟩|𝜃𝑖 ⟩ (cos 𝜃𝑖 |0⟩ + sin 𝜃𝑖 |1⟩) , (3.23)

In this case, the value 𝜃𝑖 is defined as arccos √𝑓(𝑖), where the function 𝑓 ∶
[2𝑚 ] ↦ [0, 1] is defined as:

𝑥𝑖 𝑖
𝐿 +𝑥𝑅
∫𝑥𝑖 2
𝑝(𝑥)𝑑𝑥
𝑓(𝑖) = 𝐿
𝑥𝑖𝑅
, (3.24)
∫ 𝑥𝑖𝐿
𝑝(𝑥)𝑑𝑥

The value of 𝑓(𝑖) is the probability that the 𝑖-th sample 𝑥𝑖 (which lies in the
interval [𝑥𝑖𝐿 , 𝑥𝑖𝑅 ]) lines in the leftmost part of this interval (i.e. [𝑥𝑖𝐿 , 𝑥𝑖𝑅 + 𝑥𝑖𝐿 /2]).
After the rotation, we undo the mapping that gives us the 𝜃𝑖 . These operations
resulted in the following state:

2𝑚 −1
(𝑚)
∑ √𝑝𝑖 |𝑖⟩ (cos 𝜃𝑖 |0⟩ + sin 𝜃𝑖 |1⟩) = |𝜓𝑚+1 ⟩, (3.25)
𝑖=0

Computing the mapping for the angles 𝜃𝑖 can be done efficiently only for square-
integrable probability distributions, i.e. for probability distribution for which the
integral in Equation (3.23) can be approximated efficiently. Fortunately, this is
the case for most of the probability distribution that we care about.
62 CHAPTER 3. CLASSICAL DATA AND QUANTUM COMPUTERS

Creating quantum sample access to a probability distribution is a task often


used to obtain quadratic speedups. A recent work (Herbert, 2021) pointed out
that in certain cases, the time needed to prepare the oracle used to create |𝜓⟩
might cancel the benefits of the speedup. This is the case when we don’t have
𝑏
an analytical formulation for integrals of the form ∫𝑎 𝑝(𝑥)𝑑𝑥, and we need to
resort to numerical methods.

Often in quantum algorithms we want to estimate expected values of integrals


of the form 𝔼[𝑥] ∶= ∫𝑥 𝑥𝑝(𝑥)𝑑𝑥 (e.g. see Chapter 8), Following a garbage-in-
garbage-out argument, (Herbert, 2021) was able to show that if we require a
precision 𝜖 in 𝔼[𝑥], we also need to require the same kind of precision for the
state preparation of our quantum computer. In particular, in our quantum
Monte Carlo algorithms we have to create a state |𝜓⟩ encoding a (discretized)
2𝑛 −1
version of 𝑝(𝑥) as |𝜓⟩ = ∑𝑖=0 √𝑝(𝑖)|𝑖⟩.

Let’s define 𝜇 as the mean of a probability distribution 𝑝(𝑥) and 𝜇̂ = 𝔼(𝕩) be an


estimate of 𝜇. The error of choice for this kind of problem (which comes from
applications that we will see in Section 8 ) is called the Root Mean Square Error
(RMSE), i.e. 𝜖 ̂ = √𝔼((𝜇̂ − 𝜇)2 ). The proof shows that an error of 𝜖 in the first
rotation of the GR algorithm, due to an error in the computation of the first
𝑓(𝑖), would propagate in the final error of the expected value of 𝜇. To avoid
this error, we should compute 𝑓(𝑖) with accuracy at least 𝜖. The best classical
algorithms allows us to perform this step at a cost of 𝑂( 𝜖12 ), thus canceling the
benefits of a quadratic speedup. Mitigating this problem is currently active area
of research.

However, if we restrict ourselves to considering loading probabilities from a


Gaussian distributions, then we can retain the quadratic speedup of the GR
algorithm. This is because when we create quantum sample access to the Gaus-
sian distribution, we must compute integrals of the form

(𝑚) (𝑚)
𝑥𝑖+1 𝑥 /𝜎
1 2 2
𝑖+1
1 2
𝐼𝑖,𝑚 (𝜎) = ∫ √ 𝑒−𝑥 /𝜎 d𝑥 = ∫ √ 𝑒−𝑥 d𝑥 ,
(𝑚)
𝑥𝑖 𝜎 𝜋 𝑥
(𝑚)
/𝜎 𝜋
𝑖

where the second equality is obtained through the substitution 𝑥 ↦ 𝜎𝑥 in the inte-
gral, 𝑚 = 1, … , 𝑛 determines the size of the interval partition 21𝑚 , 𝑖 = 0, … , 2𝑚
indexes the interval points, 𝜎 is the standard deviation of the Gaussian distri-
bution, and 𝑤 determines the end point of the integration, which is chosen such
(𝑚) 𝑖
that the interval points 𝑥𝑖 = 𝑤𝜎 ( 2𝑚−1 − 1) is linear in 𝜎. By the choice of the
interval points, 𝐼𝑖,𝑚 (𝜎) = 𝐼𝑖,𝑚 (1). Therefore, there is only one set of integrals
to be evaluated for all values of 𝜎, and we can store the integrals classically
to high precision. This iterative construction is thus effective, retaining the
quadratic speedup benefits of the GR algorithm.
3.3. IMPLEMENTATIONS 63

[Link] KP-Trees
We now move to discussing the most used technique to load classical data into
a quantum computer using ampitude encoding. This technique is the same as
the one in the previous section, with the difference that the oracle returning
the angles for the controlled rotations are retrived by a quantum memory. In
their PhD thesis, Prakash (Prakash, 2014) introduced the first procedure to
efficiently perform the amplitude encoding of a matrix using a tree-like classical
data structure. Given a matrix 𝑉 ∈ ℝ𝑛×𝑑 the procedure precomputes a data
̃ | ) and where the time to update the tree with
structure with size scaling 𝑂(|𝑉 0
a new entry scales as 𝑂(poly log(𝑛𝑑)). This technique was called “KP-trees” in
(Rebentrost and Lloyd, 2018), after the authors (Kerenidis and Prakash) used
it in a quantum recommendation system (Kerenidis and Prakash, 2017). The
proof will make use of the following lemma
Lemma 3.2 (Implementing Rotations with Cascades of Controlled Unitary
Gates). Given: a register A composed of 𝑡 qubits with the binary encoding of the
fixed-point representation of a number 𝜃 ∈ (0, 2𝜋], a target qubit b, and a single
qubit rotation parameterized by a single angle R(𝜃) ∈ ℂ2×2 , then the unitary
𝑡−1
CA R↦b (𝜃) = ∏ C𝑖 R↦b (2⌊log2 (𝜃)⌋−𝑖 )
𝑖=0

is equivalent to applying R(𝜃) on the target qubit if the rotation holds the property
𝑅(𝜃1 + 𝜃2 ) = 𝑅(𝜃1 )𝑅(𝜃2 ).

Proof. For a number 𝜃 ∈ (0, 2𝜋] on 𝑡 qubits, the fixed point representation will
be of the form 𝒬(𝑎, 𝑏, 0) ∶= 𝒬(𝑧, 0), with 𝑐1 = ⌊log2 (𝜃)⌋ + 1 and 𝑐2 = 𝑡 − 𝑐1 . \
The application of CA R↦b (𝜃) is equivalent to 𝑡 single qubit application of R(𝜃) on
the target qubit b, with the identity on all other qubits, where the angles have
to be adjusted. %with parameters 𝑧𝑖 2⌊log(𝜃)⌋−𝑖 . In particular:
𝑡−1 𝑡−1
∏ C𝑖 R↦b (2⌊log2 (𝜃)⌋−𝑖 ) = ∏ R↦b (𝑧𝑖 2⌊log2 (𝜃)⌋−𝑖 )
𝑖=0 𝑖=0

where 𝑧𝑖 ∈ {0, 1} is the state of qubit 𝑖 and we have omitted the tensor product
with the identity on all other qubits of register A for simplicity. Then:
𝑡−1 𝑡−1
∏ R↦b (𝑧𝑖 2⌊log2 (𝜃)⌋−𝑖 ) = 𝑅↦b (∑ 𝑧𝑖 2⌊log2 (𝜃)⌋−𝑖 ) = 𝑅↦b (𝜃),
𝑖=0 𝑖=0

where we have used that 𝑅(𝜙1 + 𝜙2 ) = 𝑅(𝜙1 )𝑅(𝜙2 ) and observing that
𝑡−1
∑ 𝑧𝑖 2⌊log(𝜃)⌋−𝑖 is the fixed-point encoding of 𝜃.\ Since the proof only makes
𝑖=0
use of the fact that the parameterized gate needs to have the property
𝑅𝑛 (𝜙1 + 𝜙2 ) = 𝑅𝑛 (𝜙1 )𝑅𝑛 (𝜙2 ), we can easily extend it to the Phase gate 𝑃 and
the y rotation gate 𝑅𝑦 .
64 CHAPTER 3. CLASSICAL DATA AND QUANTUM COMPUTERS

Exercise 3.7. Prove that 𝜎𝑦 (𝜃 + 𝜙) = 𝜎𝑦 (𝜃)𝜎𝑦 (𝜙) for the 𝜎𝑦 rotation given by

cos( 2𝜃 ) − sin( 2𝜃 )
𝜎𝑦 (𝜃) = ( ) (3.26)
sin( 2𝜃 ) cos( 2𝜃 )

Prove the same property for the phase gate 𝑃 (𝜃 + 𝜙) = 𝑃 (𝜃)𝑃 (𝜙) defined by

1 0
𝑃 (𝜃) = ( ) (3.27)
0 𝑒𝑖𝜃

The original work developed a procedure to perform the amplitude encoding of


a matrix 𝑉 ∈ ℝ𝑛×𝑑 with KP-trees in 2 steps: a pre-processing step and circuit
implementation. In the data pre-processing step, for each row 𝑣𝑖 ∈ ℝ𝑛 , which is
composed of elements 𝑣𝑖𝑗 ∈ ℝ, a binary tree is created where the leaves contain
2
the values 𝑣𝑖𝑗 and the sign of 𝑣𝑖𝑗 . Each intermediate node contains the sum
of the leaves of the sub tree rooted at that node. The circuit implementation
makes use of the QMD to access the next layer of the desired tree 𝑣𝑖 until the
leaves are reach.
Here we’ll present an optimized version of KP-trees for state preparation of
complex matrices. In this version each tree is pruned such that it only saves
the angles that are required for the state preparation rather than the partial
norms, which halves the size of the memory. Furthermore, we clearly lay out
the circuits for the implementation of the state preparation, which can be seen
in 3.7. In addition the complex matrices are handled by storing the phase of
each complex number. The circuit implementation of the phase makes use of a
circuit as depicted in figures 3.8.
Theorem 3.12 (Optimized KP-trees for complex vectors). Let 𝑉 ∈ ℂ𝑛×𝑑 ,
where we assume that 𝑛 and 𝑑 are powers of 2, then there is a data structure to
store the rows of 𝑉 such that:
2
• The size of the data structure is 𝑂(‖𝑉 ‖0 log (𝑛𝑑)).
2
• The time to insert, update or delete a single entry 𝑣𝑖𝑗 is 𝑂(log (𝑛𝑑)).
• A quantum algorithm that has quantum access to the data structure can
perform the mapping 𝑈̃ ∶ |𝑖⟩|0⟩ → |𝑖⟩|𝑉𝑖 ⟩ for 𝑖 ∈ [𝑚], corresponding to
the rows of the matrix currently stored in memory and the mapping 𝑉 ̃ ∶
|0⟩|𝑗⟩ → |𝑉 ̃ ⟩|𝑗⟩, for 𝑗 ∈ [𝑛], where 𝑉 ̃ ∈ ℝ𝑚 has entries 𝑉𝑖̃ = ||𝑉𝑖 ||, in time
(2 + 𝑡) log(𝑛𝑑) + 2𝑡, where 𝑡 is the precision of the result.

Proof. The data structure is composed of 𝑛 + 1 binary trees, one for each row of
the matrix, and an additional one for the vector of norms of the rows. For the
𝑖𝑡ℎ row of 𝑉 (i.e. 𝑉𝑖 ) we build the binary tree 𝐵𝑖 . Given that that 𝑑 is a power
of 2, there will be log(𝑑) layers to a tree 𝐵𝑖 .
For an incoming element 𝑗 of the vector 𝑉𝑖 of the form 𝑣𝑖𝑗 𝑒𝑖𝜃𝑖𝑗 , the 𝑗th leaf of
the 𝑖𝑡ℎ tree will store the tuple (𝑣𝑖𝑗
2
, 𝜃𝑖𝑗 ). Once a leaf is updated, the internal
3.3. IMPLEMENTATIONS 65

nodes will also be updated such that an internal node 𝑙 will store the sum of
the moduli 𝑣𝑖𝑗 of the leaves of a sub tree rooted at 𝑙. This procedure continues
until all the matrix is loaded.
At the end of the procedure, we represent an internal node 𝑙 in the 𝑖𝑡ℎ tree at
𝑙
depth 𝑑 as 𝐵𝑖𝑑 . If 𝑗𝑏 represents the 𝑏𝑡ℎ bit of 𝑗 then:

𝑙 2
𝐵𝑖𝑑 = ∑ 𝑣𝑖𝑗 , (3.28)
𝑗1 ,...,𝑗𝑑 =𝑙
𝑗𝑑+1 ,...,𝑗log(𝑛) ∈{0,1}

This implies that the first 𝑑 bits of 𝑗 written in binary are fixed to 𝑙, indicating
2
that we are at depth 𝑑. This procedure requires 𝑂(log (𝑛𝑑)) time.
After the tree has been filled it will be pruned. The pruning involves changing
the values in the internal nodes such that they store the angle required to
2
perform the state preparation. This will allow to remove 𝑣𝑖𝑗 from the leaves
which will now only store the phases 𝜃𝑖𝑗 .
𝑙
Given a node 𝐵𝑖𝑑 , the pruned tree will have nodes given by:

⎧ 𝐵2𝑙

𝑙
{2 arccos (√ 𝐵𝑖,𝑑+1
𝑙 ), if 𝑑 < log(𝑛)
𝐵𝑖,𝑑 =⎨ 𝑖,𝑑 , (3.29)
{𝜃𝑙
⎩ 𝑖,log(𝑛) , if 𝑑 = log(𝑛)

2
The size of the data structure scales as 𝑂(|𝑉 |0 log (𝑛𝑑)).
Since the first log(𝑛) − 1 layers are concerned with preparing the real ampli-

𝑙
tudes, 𝐵𝑖,𝑘 ∈ [0, 𝜋] for 𝑘 ∈ [log(𝑛) − 1], whilst the last layer will be bounded

𝑙
by 𝐵𝑖,log(𝑛) ∈ [0, 2𝜋]. Each angle in the tree will be stored in its fixed-point
representation. Since the first log(𝑛) − 1 layers are concerned with preparing

𝑙
the real amplitudes, 𝐵𝑖,𝑘 ∈ [0, 𝜋] for 𝑘 ∈ [log(𝑛) − 1] meaning their fixed-point
representation 𝒬(𝑧) will have 𝑐1 = 1 and 𝑐2 = 𝑡 for some precision 𝑡. The last

𝑙
layer contains the phases which are bounded by 𝐵𝑖,log(𝑛) ∈ [0, 2𝜋], meaning their
fixed-point representation 𝒬(𝑧) will have 𝑐1 = 2 and 𝑐2 = 𝑡 − 1 for some preci-
sion 𝑡 . This means that for some precision 𝑡 the address register will require
𝑡′ = 𝑡 + 1 qubits.

The circuit will require quantum access to the data structure 𝐵𝑖,𝑑 as well as
3 registers: an index register |𝑖⟩ which contains ⌈log(𝑖)⌉ qubits and the binary
representation of 𝑖; a 𝑡′ -qubit address(angle) register which will load the fixed-
point representation of the angles up to a precision 𝑡; and the main register
composed of log(𝑛) qubits.

A quantum query to the data structure will load from 𝐵𝑖 the fixed-point repre-
sentation of the angle on the address register which will be followed by a cascade
of controlled rotations, as seen in lemma ??, in order to produce the next layer
66 CHAPTER 3. CLASSICAL DATA AND QUANTUM COMPUTERS

of the data structure 𝐵𝑖 . Given the first 𝑘 qubits of the register being in a state
Ψ𝑘 , then the action on the 𝑘 + 1 qubit be as follows:


QMD 𝜎𝑦 (𝐵𝑖,𝑑 ) 1
⊗𝑡′ ′ ′
2𝑙 2𝑙+1
|𝑖⟩|0⟩ |Ψ𝑘 ⟩|0⟩ −−−→ |𝑖⟩|𝐵𝑖,𝑑 ⟩|Ψ𝑘 ⟩|0⟩ −−−−−→ |𝑖⟩|𝐵𝑖,𝑑 ⟩|Ψ𝑘 ⟩ (√𝐵𝑖,𝑑+1 |0⟩ + √𝐵𝑖,𝑑+1 |1⟩) ,
𝑙
√𝐵𝑖,𝑑
(3.30)

𝜎𝑦 (𝐵𝑖,𝑘 )
Where −−−−−→ indicates a cascade of 𝜎𝑦 rotations controlled on the address
register and targeted on the 𝑘 + 1 qubit of the main register.

Repeating this procedure for the first 𝑛 − 1 layers of the tree 𝐵𝑖 will leave the
main register in the state |Ψlog(𝑛) ⟩, i.e. the amplitude encoding of the moduli of
the vector 𝑉𝑖 . The addition of the phases will require a quantum query to the
classical data structure to access the final layer of the binary tree. Following
the query, a cascade of phase gates on the log(𝑛)𝑡ℎ qubit is performed. This is
followed by a 𝜎𝑥 gate and then another cascade of phase rotations and finally
another 𝜎𝑥 gate. The 𝜎𝑥 gate is required since the phase gates only acts on the
state where the last bit is a 1. The transformation will then be:


QMD CP(𝐵𝑖,log(𝑛) )
⊗𝑡′ ′ ′
|𝑖⟩|0⟩ |Ψlog(𝑛) ⟩ −−−→ |𝑖⟩|𝐵𝑖,log(𝑛) ⟩|Ψlog(𝑛) ⟩ −−−−−−−−→ |𝑖⟩|𝐵𝑖,log(𝑛) ⟩𝑒𝑖𝜃𝑖𝑙 |Ψlog(𝑛) ⟩,
(3.31)
Where 𝜃𝑖𝑙 is the phase saved in the leaf 𝑙. From this we can see that performing
𝑈̃ ∶ |𝑖⟩|0⟩ → |𝑖⟩|𝑉𝑖 ⟩ for 𝑖 ∈ [𝑚] requires 2 log(𝑛) + 2 queries to the classical
data structure. In addition, a precision of 𝑡 will require at most 𝑡′ (log(𝑛) + 2)
controlled rotations.
The final tree is for the implementation of 𝑉 ̃ ∶ |0⟩|𝑗⟩ → |𝑉 ̃ ⟩|𝑗⟩, for 𝑗 ∈ [𝑛]. As
before we construct the tree such the leaves store ||𝑉𝑖 ||2 and an internal node
𝑙 stores the entries of the subtree rooted at 𝑙. It is important to note that in
this case the node does not need to store the phases since we are interesting in
the moduli of the rows, which halves the dimension of this tree. Following an
analogous procedure of pruning, a circuit of controlled 𝜎𝑦 rotations will grant
the application of the unitary 𝑉 ̃ to the main register.

We now show an example of the state preparation with pruned KP-trees of a


vector of size 4. Figure 3.9 shows the difference between an original KP-tree
and a pruned version, whilst 3.10 shows the full circuit implementation to load
the vector.
Example 3.1. As a worked example we will take a 4 element vector for which
we will construct a data structure and then, using a QMD, we will load it into
a quantum circuit. The vector is:
3.3. IMPLEMENTATIONS 67

Figure 3.7: A section of the circuit for state preparation with pruned KP-trees.
For a vector 𝑉𝑖 ∈ ℂ𝑛 we require 3 register: an index register |𝑖⟩; a 𝑡-qubit
address register which will load the angles up to a precision 𝑡; and the main
register composed of log(𝑛) qubits. At a intermediate step of the procedure the
main register will hold a state which represents the 𝑘-th layer of the KP-tree
Ψ𝑘 and the aim of the circuit will be to prepare the 𝑘 + 1 layer of the tree, Ψ𝑘+1 .
This starts with a quantum query to the data structure which loads the angles
to the address register. This is followed by a cascade of controlled rotations
and finally an inverse call to the data structure. Repeating this circuit log(𝑛)
times produces the state Ψlog(𝑛) which is a vector which hold the moduli of the
components of 𝑉𝑖 . In total the circuit will have a depth of 𝑡 log(𝑛) and will
require 2 log(𝑛) queries to the data structure.
68 CHAPTER 3. CLASSICAL DATA AND QUANTUM COMPUTERS

Figure 3.8: The circuit that adds the phase in state preparation with pruned KP-
trees. This starts with a quantum query to the data structure which loads the
angles to the address register, which is followed by a cascade of phase rotation,
a NOT gate and another cascade. The requirmenet of 2 cascades is that the
controlled phase rotations only acts on the quantum states with a 1 as the last
bit. The application of this circuit produces the desired vector 𝑉𝑖 .

𝜋 𝜋 𝜋 𝜋
𝑉 𝑇 = (0.4𝑒𝑖 4 , 0.4𝑒𝑖 12 , 0.8𝑒𝑖 3 , 0.2𝑒𝑖 6 ) , (3.32)

In particular our aim is to produce the state:

𝜋 𝜋 𝜋 𝜋
|𝜙⟩ = 0.4𝑒𝑖 4 |00⟩ + 0.4𝑒𝑖 12 |01⟩ + 0.8𝑒𝑖 3 |10⟩ + 0.2𝑒𝑖 6 |11⟩, (3.33)

The first step is the construction of the data structure. Figure 3.9 shows the
initial tree and the pruned tree. The difference between the two is that the
initial tree stores the partial norms of the entries, whilst the pruned tree stores
the angles required to implement the partial norms as 𝜎𝑦 rotations.
Since we are working with a vector we will only have 1 qubit in the index register
which will be set to the state |0⟩. The angle will be stored with a precision of
𝑡 which we will assume is a large number. This will require the angle(address)
register to be composed of 𝑡 qubits. Finally, since the vector has 4 elements, we
will require 2 qubits in the main register.
An initial call to the QMD will load the angle on the address register, this will
be followed by a cascade of 𝜎𝑦 rotations on the first qubit and an inverse call to
the QMD to remove the angle from the address register. This will produce the
state:
3.3. IMPLEMENTATIONS 69

√ √
|0⟩|0⟩⊗𝑡 ( 0.32|0⟩ + 0.68|1⟩) |0⟩, (3.34)

A similar process is done is the second step where in this case the call to the
QMD is made using the index register and the first qubit and will access the
second row of the pruned KP-tree. This will be followed by a similar cascade
of 𝜎𝑦 rotations on the second qubit of the main register and inverse call to the
QMD to remove the angle from the address register. This will produce the state:

√ 0.16 0.16 √ 0.64 0.2


|0⟩|0⟩⊗𝑡 ( 0.32|0⟩ (√ |0⟩ + √ |1⟩) + 0.68|1⟩ (√ |0⟩ + √ |1⟩)) ,
0.32 0.32 0.68 0.68
(3.35)

= |0⟩|0⟩⊗𝑡 (0.4|00⟩ + 0.4|01⟩ + 0.8|10⟩ + 0.2|11⟩) , (3.36)

Now we need to add the phases. As already seen, this will be done with a query
to the QMD to access the final row of the pruned KP-tree, then a cascade of
phase rotations 𝑃 . This will produce the state:

𝜋 𝜋
|0⟩|𝜃⟩ (0.4|00⟩ + 0.4𝑒𝑖 12 |01⟩ + 0.8|10⟩ + 0.2𝑒𝑖 6 |11⟩) , (3.37)

Where the state |𝜃⟩ is some superposition containing the binary representation
of all the leaves of the pruned KP-tree. Because the nature of the phase gate,
a 𝜎𝑥 gate followed by another cascade of phase rotations is required to load
the remaining phases. Finally, a 𝜎𝑥 gate and a inverse query to the QMD will
produce the desired state!

𝜋 𝜋 𝜋 𝜋
|0⟩|0⟩⊗𝑡 (0.4𝑒𝑖 4 |00⟩ + 0.4𝑒𝑖 12 |01⟩ + 0.8𝑒𝑖 3 |10⟩ + 𝑒𝑖 6 0.2|11⟩) , (3.38)

The full circuit for this can be seen in the figure 3.10.

Figure 3.9: The original and pruned tree used for the example. The difference
between the two is that the initial tree stores the partial norms of the vector
entries, whilst the pruned tree only stores the angles required to implement the
required 𝜎𝑦 and phase rotations.
70 CHAPTER 3. CLASSICAL DATA AND QUANTUM COMPUTERS

Figure 3.10: The circuit to perform state preparation of the vector reported in
the worked example. An initial call to the QMD loads the angle on the address
register, which is followed by a cascade of 𝜎𝑦 rotations on the first qubit and
an inverse call to the QMD to remove the angle from the address register. A
similar process is done for the second step where the call to the QMD is made
using the index register and the first qubit and will access the first layer of the
pruned KP-tree. This will be followed by a similar cascade of 𝜎𝑦 rotations on
the second qubit of the main register and inverse call to the QMD. The final
step requires adding the phases. This will be done with a query to the QMD to
access the final row of the pruned KP-tree, then a cascade of phase rotation 𝑃 .
Because the nature of the phase gate, a 𝜎𝑥 gate followed by another cascade of
phase rotations is required to load the remaining phases. Finally, a 𝜎𝑥 gate and
a inverse query to the QMD will produce the amplitude encoding.

The following exercise might be helpful to clarify the relation between quantum
query access to a vector and quantum sampling access.
Exercise 3.8. Suppose you have quantum access to a vector 𝑥 = [𝑥1 , … , 𝑥𝑁 ],
where each 𝑥𝑖 ∈ [0, 1]. What is the cost of creating quantum sampling access
𝑁
to 𝑥, i.e. the cost of preparing the state 𝑍1 ∑𝑖=1 𝑥𝑖 |𝑖⟩. Hint: query the state
in superposition and perform a controlled rotation. Can you improve the cost
using amplitude amplification? What if 𝑥𝑖 ∈ [0, 𝐵] for a 𝐵 > 1?
Lower bounds in query complexity can be used to prove that the worst case for
performing state preparation with the technique
√ used in the exercise (i.e. without
KP-trees/quantum sampling access) are 𝑂( 𝑁 ).

3.3.3 Block encoding


We first turn our attention to creating block encodings from oracles doing am-
plitude encoding. In the following, we use the shortcut notation to define the
(𝑝)
matrix 𝐴(𝑝) to be a matrix where each entry 𝐴𝑖𝑗 = (𝐴𝑖𝑗 )𝑝 .

Exercise 3.9. Let 𝑋 ∈ ℝ𝑛×𝑑 . Suppose you have access to 𝑈𝑅 and 𝑈𝐿 defined
as:
• 𝑈𝑅 |𝑖⟩|0⟩ = |𝑖⟩|𝑥𝑖 ⟩ = |𝑖⟩ ∑𝑗 (𝑥𝑖 )𝑗 |𝑗⟩;
• 𝑈𝐿 |0⟩|𝑖⟩ = |𝑥⟩|𝑖⟩
̃ where 𝑥̃ is the vector of the norms of the rows of the
matrix 𝑥.
3.3. IMPLEMENTATIONS 71

Using once 𝑈𝑅 and 𝑈𝐿 , build a unitary 𝑈𝑋 that performs the mapping |0⟩ ↦
1
‖𝑋‖ ∑𝑖,𝑗 𝑥𝑖𝑗 |𝑖, 𝑗⟩.
𝐹

Theorem 3.13 (Creation of state matrix). Assume to have the unitaries 𝑈𝐿


and 𝑈𝑅 for a matrix 𝑋 ∈ ℝ𝑛×𝑛 . Then 𝑈𝑅† 𝑈𝐿 is a (‖𝑋‖𝐹 , 0)-block encoding of
𝑋.

Proof. Define the matrix 𝑃 ∈ ℝ𝑛𝑚 by the column vectors |𝑖⟩|𝑥𝑖 ⟩ for 𝑖 ∈ [𝑚],
and the matrix 𝑄 by 𝑄 ∈ ℝ𝑛𝑛×𝑛𝑛 defined by the column vectors |𝑥⟩|𝑖⟩. One can
verify that
𝑋𝑖𝑗
(𝑃 † 𝑄)𝑖𝑗 = ⟨𝑖, 𝑥𝑖 |𝑥, 𝑗⟩ = .
‖𝑋‖𝐹
To conclude the proof, it suffices to recall the definition of block encoding:

‖𝑋 − ‖𝑋‖𝐹 (⟨0| ⊗ 𝐼)𝑈𝑅† 𝑈𝐿 (|0⟩ ⊗ 𝐼)‖ = ‖𝑋 − ‖𝑋‖𝐹 𝑃 † 𝑄‖ = 0.

Definition 3.14 (Possible parameterization of � for the KP-trees). For 𝑠𝑝 (𝐴) =


max𝑖∈[𝑛] ∑𝑗∈[𝑑] 𝐴𝑝𝑖𝑗 , we chose 𝜇𝑝 (𝐴) to be:

𝜇𝑝 (𝐴) = min (‖𝐴‖𝐹 , √𝑠2𝑝 (𝐴)𝑠(1−2𝑝) (𝐴𝑇 )). (3.39)


𝑝∈[0,1]

Lemma 3.3 (Block encodings from quantum data structures (Chakraborty


et al., 2019)). Let 𝐴 ∈ ℂ𝑀×𝑁 , and 𝐴 ∈ ℂ(𝑀+𝑁)×(𝑀+𝑁) be the symmetrized
matrix defined as:

0 𝐴
𝐴=[ ]. (3.40)
𝐴† 0

• Fix 𝑝 ∈ [0, 1]. If 𝐴 ∈ ℂ𝑀×𝑁 , and 𝐴(𝑝) and (𝐴(1−𝑝) )† are both
stored in quantum-accessible data structures with sufficient precision,
then there exist unitaries 𝑈𝑅 and 𝑈𝐿 that can be implemented in time
𝑂 (𝑝𝑜𝑙𝑦𝑙𝑜𝑔(𝑀 𝑁 /𝜖)) such that 𝑈𝑅† 𝑈𝐿 is a (𝜇𝑝 (𝐴), ⌈log(𝑁 +𝑀 +1)⌉, 𝜖)-block
encoding of 𝐴.
• On the other hand, if 𝐴 is stored in a quantum-accessible data struc-
ture with sufficient precision, then there exist unitaries 𝑈𝑅 and 𝑈𝐿 that
can be implemented in time 𝑂(𝑝𝑜𝑙𝑦𝑙𝑜𝑔(𝑀 𝑁 )/𝜖) such that 𝑈𝑅† 𝑈𝐿 is a
(‖𝐴‖𝐹 , ⌈log(𝑀 + 𝑁 )⌉, 𝜖)-block encoding of 𝐴.
The second point of the previous theorem is equivalent to what we saw in Section
[Link].
72 CHAPTER 3. CLASSICAL DATA AND QUANTUM COMPUTERS

[Link] Block encoding from sparse access


Using this we can then see how to perform a block encoding. We start by
reporting this result from (Gilyén et al., 2019).
Theorem 3.14 (Block-Encoding from sparse access (Gilyén et al., 2019)). Let
𝑤 𝑤
𝐴 ∈ ℂ2 ×2 be a matrix that is 𝑠𝑟 -row-sparse and 𝑠𝑐 -column-sparse, and each
element of 𝐴 has absolute value at most 1. Suppose that we have access to the
following sparse access oracles acting on two (𝑤 + 1) qubit registers:

𝑂𝑟 ∶ |𝑖⟩|𝑘⟩ ↦ |𝑖⟩|𝑟𝑖𝑘 ⟩∀𝑖 ∈ [2𝑤 ] − 1, 𝑘 ∈ [𝑠𝑟 ], and (3.41)

𝑂𝑐 ∶ |𝑙⟩|𝑗⟩ ↦ |𝑐𝑙 𝑗⟩|𝑗⟩∀𝑙 ∈ [𝑠𝑐 ], 𝑗 ∈ [2𝑤 ] − 1, where (3.42)

𝑟𝑖𝑗 is the index of the 𝑗-th non-zero entry of the 𝑖-th row of 𝐴, or if there are
less than 𝑖 non-zero entries, than it is 𝑗 + 2𝑤 , and similarly 𝑐𝑖 𝑗 is the index for
the 𝑖-th non-zero entry of the 𝑗 − 𝑡ℎ column of 𝐴, or if there are less than 𝑗
non-zero entries, than it is 𝑖 + 2𝑤 . Additionally assume that we have access to
an oracle 𝑂𝐴 that returns the entries of 𝐴 in binary description:

𝑂𝐴 ∶ |𝑖⟩|𝑗⟩|0⟩⊗𝑏 ↦ |𝑖⟩|𝑗⟩|𝑎𝑖𝑗 ⟩∀𝑖, 𝑗 ∈ [2𝑤 ] − 1where (3.43)

𝑎𝑖𝑗 is a 𝑏-bit description of the 𝑖𝑗-matrix element of 𝐴. Then we can implement



a ( 𝑠𝑟 𝑠𝑐 , 𝑤 + 3, 𝜖)-block encoding of 𝐴 with a single use of 𝑂𝑟 , 𝑂𝑐 , two uses
2.5
of 𝑂𝐴 and additionally using 𝑂(𝑤 + log ( 𝑠𝑟𝜖𝑠𝑐 )) one and two qubit gates while
2.5 𝑠𝑟 𝑠𝑐
using 𝑂(𝑏, log 𝜖 ) ancilla qubits.

The previous theorems can be read more simply as: “under reasonable assump-
tions (quantum general graph model for rows and for columns - see previous

section), we can build ( 𝑠𝑟 𝑠𝑐 , 𝑤+3, 𝜖)-block encodings of matrices 𝐴 with circuit
2.5
complexity of 𝑂(log ( 𝑠𝑟𝜖𝑠𝑐 )) gates and constant queries to the oracles”.
The interested reader can read (Camps et al., 2024, @yang2024quantum) to
learn how to create block encodings from sparse access.

3.4 Use case: working with classical probability


distributions
We have 4 ways of working with classical probability distributions in a quantum
computer (Gur et al., 2021):
• Purified query access
• Sample access
• Query access to a frequency vector of a distribution
3.5. RETRIEVING DATA 73

• Drawing samples classically and perform some computation on a quantum


computer
Let’s start with a formal definition of the frequency vector model. This is a kind
of query access, but since it is used only for probability distrubtions we decided
to include it in this section.
Definition 3.15 (Quantum query access to a probability distribution in the
frequency vector model). Let 𝑝 = (𝑝1 , 𝑝2 , … 𝑝𝑛 ) be a probability distribution on
{1, 2, … , 𝑛}, and let 𝑛 ≥ 𝑆 ∈ ℕ be such that there is a set of indices 𝑆𝑖 ⊆ [𝑆]
for which 𝑝𝑖 = |𝑆𝑆𝑖 | . We have quantum access to a probability distribution in
the frequency vector model if there is an quantum oracle that, for ∀𝑠 ∈ [𝑆𝑖 ]
performs the mapping 𝑂𝑝 |𝑠⟩ ↦ |𝑠⟩|𝑖⟩.
𝑛−1
Exercise 3.10. Given a matrix 𝑀 ∶= ∑ 𝑎𝑗 𝑈𝑗 , which is a linear combination
𝑗=0
of unitary matrices 𝑈𝑗 , consider the unitary transformation


𝑈𝑀 = (𝑈PREP ⊗ 𝐼)𝑈SEL (𝑈PREP ⊗ 𝐼) (3.44)

𝑛−1 𝑛−1
where 𝑈PREP |0⟩ = |𝑎⟩ = ∑ 𝑎𝑗 |𝑗⟩ and 𝑈SEL = ∑ |𝑗⟩⟨𝑗| ⊗ 𝑈𝑗 . Then show that
𝑗=0 𝑗=0
𝑈𝑀 is a block encoding of 𝑀 :

𝑛−1
(⟨0| ⊗ 𝐼) 𝑈𝑀 (|0⟩ ⊗ 𝐼) = 𝑀 = |𝑎𝑗 |2 ∑ 𝑏𝑗 𝑈𝑗 (3.45)
𝑗=0

3.5 Retrieving Data


In order to retrieve information from a quantum computer, we are going to use
some efficient procedures that allow to reconstruct classically the information
stored in a quantum state. These procedures can be thought of as ways of
sampling from a pure state |𝑥⟩. The idea for an efficient quantum tomography
is that we want to minimize the number of times that the state |𝑥⟩ is created.
Most of the quantum algorithms discussed here will work with pure quantum
states. We assume to have access to the unitary that creates the quantum state
that we would like to retrieve, and that we have access to the unitary that creates
the state (and that we can control it). Under these conditions, the process of
performing tomography is greatly simplified. According to the different error
guarantees that we require, we can chose among two procedures.
Theorem 3.15 (Vector state tomography with L2 guarantees (Kerenidis and
Prakash, 2018)). Given access to unitary 𝑈 such that 𝑈 |0⟩ = |𝑥⟩ and its
74 CHAPTER 3. CLASSICAL DATA AND QUANTUM COMPUTERS

controlled version, there is a tomography algorithm with calls 𝑈 and its con-
trolled version for 𝑑 log 𝑑 𝑑
𝜖2 ) times, that produces a unit vector 𝑥 ̃ ∈ ℝ such that
‖𝑥̃ − |𝑥⟩‖2 ≤ 𝜖 with probability at least (1 − 1/𝑝𝑜𝑙𝑦(𝑑)).

Theorem 3.16 (Vector state tomography with L∞ guarantees (Kerenidis et al.,


2019b)). Given access to unitary 𝑈 such that 𝑈 |0⟩ = |𝑥⟩ and its controlled
version, there is a tomography algorithm with calls 𝑈 and its controlled version
log 𝑑 𝑑
𝜖2 ) that produces a unit vector 𝑥̃ ∈ ℝ such that ‖𝑥̃ − |𝑥⟩‖ℓ∞ ≤ 𝜖 with probability
at least (1 − 1/𝑝𝑜𝑙𝑦(𝑑)).

Note that in both kinds of tomography the dependence on the error in the de-
nominator is quadratic, and this is because of the Hoeffding inequality. Another
remark on the hypothesis of the algorithms for tomography is that they require
a unitary 𝑈 such that 𝑈 |0⟩ ↦ |𝑥⟩ for the |𝑥⟩ in question. Often times, due to
the random error in the quantum subroutines used inside the algorithms, this
state |𝑥⟩ might slightly change every time.

Exercise 3.11. Can you obtain ℓ2 tomography with error 𝜖 on a 𝑑 dimensional


state if you have have only access to an algorithm that perform ℓ∞ tomography
with error 𝜖∗ on the same state? (I.e. what should you set the value of 𝜖∗ ?).

Exercise 3.12. Consider Theorem 3.15 and Theorem 3.16. What is the sample
complexity of a tomography algorithm returning error in norm ℓ𝑝 ? In other
words, find the sample complexity to return a vector such that ‖𝑥̃ − |𝑥⟩‖ℓ ≤ 𝜖
𝑝
with probability at least (1 − 1/𝑝𝑜𝑙𝑦(𝑑)).

3.5.1 Density matrices


Much of the current literature in quantum tomography is directed towards re-
constructing a classical description of density matrices. This problem is consid-
erably harder than reconstructing a pure state.

Theorem 3.17 (Efficient quantum tomography (O’Donnell and Wright, 2016)).


An unknown rank-r mixed state 𝜌 ∈ ℂ𝑑×𝑑 can be estimated to error 𝜖 in Frobenius
distance using 𝑛 = 𝑂(𝑑/𝜖2 ) copies, or to error 𝜖 in trace distance using 𝑛 =
𝑂(𝑟𝑑/𝜖2 ) copies.

Different techniques have been recently developed in (Zhang et al., 2020). There,
the authors used the assumption on doing tomography on a state |𝑥⟩ that is in
the row space of a rank 𝑟 matrix 𝐴 for which we have quantum access. They
propose an algorithm to obtain the classical description of the coefficients 𝑥𝑖
𝑟
in the base spanned by the rows {𝐴𝑖 }𝑟𝑖=0 of 𝐴, so that |𝑥⟩ = ∑𝑖 𝑥𝑖 |𝐴𝑖 ⟩. This
̃
requires 𝑂(𝑝𝑜𝑙𝑦(𝑟)) ̃
copies of the output states and 𝑂(𝑝𝑜𝑙𝑦(𝑟), 𝜅𝑟 ) queries to
input oracles. While this procedure has the benefit of not being linear in the
output dimension of the final state, the high dependence on the rank might hide
the advantages compared to the previous quantum tomography procedures. For
completeness, the result is as follows.
3.5. RETRIEVING DATA 75

Theorem 3.18 (Improved quantum tomography (Zhang et al., 2020)). For the
state |𝑣⟩ lies in the row space of a matrix 𝐴 ∈ ℝ𝑛×𝑑 with rank 𝑟 and condition
number 𝜅(𝐴), the classical form of |𝑣⟩ can be obtained by using 𝑂(𝑟3 𝜖2 ) queries
to the state |𝑣⟩, 𝑂(𝑟11 𝜅5𝑟 𝜖−2 log(1/𝛿)) queries to QRAM oracles of 𝐴 and 𝑂(𝑟2 )
additional inner product operations between rows, such that the ℓ2 norm error
is bounded in 𝜖 with probability at least 1 − 𝛿.
76 CHAPTER 3. CLASSICAL DATA AND QUANTUM COMPUTERS
Chapter 4

Classical machine learning

Machine learning, also called narrow artificial intelligence, has been defined as
“the study of computer algorithms that allow computer programs to automat-
ically improve through experience (Mitchell et al., 1997). Machine learning is
often divided into supervised and unsupervised methods. We use supervised
learning when the dataset is supervised, i.e. when the dataset consist of pairs
of input objects (usually vectors) and a desired output value (called the super-
vised signal), which can be a label or a number. In case the output is a label
the supervised problem is said to be called classification, and we call regression
the other case. Supervised learning can be thought of as the task of learning
a mapping or a function form pairs of input and output. When the dataset
in unsupervised, the problem is called clustering, and consist in finding hidden
structure of the process that has generated the dataset. Computationally, much
of the machine learning algorithms can be described by operations on vectors

77
78 CHAPTER 4. CLASSICAL MACHINE LEARNING

and matrices. For instance, many machine learning algorithms are reduced to
computing the eigenvectors of matrices obtained from the data. In the last
15 years machine learning has been applied in all the sectors of information
technology. In this chapter, we review and introduce some classical machine
learning. Special emphasis is put on formalizing the connection between the
machine learning problems and their linear-algebraic formulation.
The dataset that we manipulate in this work are represented by a matrix 𝑉 ∈
ℝ𝑛×𝑑 , i.e. each row can be thought as a vector 𝑣𝑖 ∈ ℝ𝑑 for 𝑖 ∈ [𝑛] that represents
a single data point. We denote as 𝑉𝑘 the optimal rank 𝑘 approximation of 𝑉 ,
𝑘
that is 𝑉𝑘 = ∑𝑖=0 𝜎𝑖 𝑢𝑖 𝑣𝑖𝑇 , where 𝑢𝑖 , 𝑣𝑖 are the row and column singular vectors
respectively and the sum is over the largest 𝑘 singular values 𝜎𝑖 . We denote

as 𝑉≥𝜏 the matrix ∑𝑖=0 𝜎𝑖 𝑢𝑖 𝑣𝑖𝑇 where 𝜎ℓ is the smallest singular value which
+
is greater than 𝜏 . For a matrix 𝑀 and a vector 𝑥, we define as 𝑀≤𝜃,𝛿 𝑀≤𝜃,𝛿 𝑥
the projection of 𝑥 onto the space spanned by the singular vectors of 𝑀 whose
corresponding singular values are smaller than 𝜃, and some subset of singular
vectors whose corresponding singular values are in the interval [𝜃, (1 + 𝛿)𝜃].

4.1 Supervised learning


Supervised (or predictive) machine learning is the part of machine learning that
deals with supervised datasets, i.e. data where each sample 𝑥𝑖 comes along with
supervised information, i.e. a piece of data 𝑦𝑖 . It helps the intuition thinking that
the supervised information comes from a stochastic process that maps vectors
𝑥𝑖 to vectors 𝑦𝑖 . The goal is to model the mapping on the whole input space
𝒳 to the output space 𝒴 given a set of input-output pairs 𝐷 = {(𝑥𝑖 , 𝑦𝑖 )}𝑛𝑖=0 .
Usually, the input space is a subset of ℝ𝑑 , and the output space is usually either
ℝ or a finite set 𝐾 of small cardinality. It is practical, for the sake of exposition
to consider the training set organized into a matrix 𝑋 ∈ ℝ𝑛×𝑑 and the matrix
𝑌 ∈ 𝑅𝑛 or 𝑌 ∈ [𝐾]𝑛 . The components of a vector 𝑥𝑖 , i.e. a row of 𝑋 are called
features, attributes, or covariates. The matrix 𝑋 is called design matrix, or
simply the dataset. The vector 𝑦𝑖 is called the response variable. If the response
variable is categorical (or nominal), the problem is known as classification, or
pattern recognition. If the response variable is real-valued we interpret this
problem as learning a function 𝑓 ∶ ℝ𝑑 ↦ ℝ and we call this problem regression.
Different assumptions on the structure of 𝑓 lead to different machine learning
models. Each model can be trained (or fitted) with different algorithms.

4.2 Unsupervised learning


Unsupervised learning (Murphy, 2012), which sometimes goes under the name
of knowledge discovery, is the part of machine learning that deals with under-
standing unlabeled data. In the dataset 𝐷 = {𝑥𝑖 }𝑛𝑖=0 we don’t have anymore
any supervised information. In this case, it is common to understand the struc-
ture of the process generating the samples by formalizing a density estimation
4.3. GENERATIVE AND DISCRIMINATIVE MODELS 79

problem: we want to learn the parameters 𝜃 of a function 𝑝(𝑥𝑖 |𝜃) that models
the distribution of the process that has generated the samples. The importance
of unsupervised learning lies in the stunning similarity with human and animal
learning. Furthermore, most of the dataset that we have are unsupervised, as
it is costly to provide supervised information from experts or humans. The
most common example of unsupervised learning is clustering, where we want
to partition into groups a given dataset. As an example, imagine having a set
comprising of images of cats and dogs, without knowing which image is a cat or
which is a dog. An unsupervised learning algorithm is supposed to learn how
to split the dataset correctly, by understanding the characteristics and features
that allows discriminating between images of different kinds. Just to name a
few of the more concrete examples, in astronomy, clustering is often used to
discover new kinds of stars, in biology, it is used to find new kinds of cells, in
cybersecurity, to perform anomaly detection, and so on.
We refer to the number of clusters in the dataset with a letter 𝐾. The first goal
in clustering is to understand the right number of different groups in the data
(which might not be known a-priori). The second goal is to estimate which
cluster each point 𝑥𝑖 belongs to. We define 𝑧𝑖 for 𝑧𝑖 ∈ [𝐾] as the cluster to
which point 𝑥𝑖 is assigned to. The value of 𝑧𝑖 is often called hidden or latent
variable. Unsupervised learning can be seen as the task of guessing the value
of the hidden variable, by computing 𝑧𝑖 = arg max𝑘 𝑝(𝑧𝑖 = 𝑘|𝑥𝑖 , 𝜃). For this, an
unsupervised learning algorithm has to model (implicitly or explicitly) the joint
probability distribution 𝑝(𝑥, 𝑦).
While latent variables have extensive applications, in this thesis we will focus
on the case where latent variables are used to represent a discrete latent state
(as in clustering).

4.3 Generative and discriminative models


There is another insightful way of organizing machine learning models. They
can either be generative or discriminative. A discriminative model learns just
the mapping 𝑝(𝑦|𝑥), and provides a way to classify points (i.e. infer the value
of 𝑦𝑖 ), without actually knowing “how’ ’ the point 𝑥𝑖 has been generated. Ex-
amples of such models are: k-nearest neighbors, Logistic regression, Support
Vector Machines, Decision Trees, Random Forest, Neural Networks, and so on.
Examples of such models are the QFDC, QSFA in Chapter 9.2.1. On the other
way, generative models output a model for the joint probability distribution
𝑝(𝑥, 𝑦). This is similar to the unsupervised learning case, but in this cases the
dependence on 𝑦 (which can be a hidden variable) is made explicit. In gen-
eral, discriminative models make fewer assumptions, as generative models often
need to do some assumption on the structure of 𝑝(𝑥). Such generative mod-
els are one of the most promising approaches to unsupervised problems. The
goal of a generative model is to learn a probability distribution that is most
likely to have generated the data collected in a training set. Fitting the model
80 CHAPTER 4. CLASSICAL MACHINE LEARNING

consists of learning the parameters of a probability distribution 𝑝 in a certain


parameterized family, that best describes our vectors 𝑥𝑖 , 𝑦𝑖 . In case the data is
unsupervised, generative models learn the probability distribution 𝑝(𝑥𝑖 ) assum-
ing the existence of some hidden variables 𝑧𝑖 . Examples of such models in this
thesis are q-means and GMM, i.e. chapter @ref{chap-q-means} and @ref{chap-
qem}. A possible way to fit a generative model is to formulate the problem of
finding the parameters of the family of distribution as an optimization problem.
This is often done using the so-called maximum likelihood estimation (MLE).
One can think of the likelihood as the function that we use to measure how
good a model is for explaining a given dataset. For a given machine learning
model with parameters 𝛾, the likelihood of our data set 𝑋 is the probability that
the data have been generated by the model with parameters 𝛾, assuming each
point is independent and identically distributed. We think of the likelihood as
a function of 𝛾, holding the dataset 𝑋 fixed. For 𝑝(𝑥𝑖 |𝛾) the probability that a
point 𝑥𝑖 comes from model 𝛾, the likelihood is defined as:

𝑛
𝐿(𝛾; 𝑋) ∶= ∏ 𝑝(𝑥𝑖 |𝛾) (4.1)
𝑖=1

From this formula, we can see that in order to find the best parameters 𝛾 ∗ of our
model we need to solve an optimization problem. For numerical and analytical
reasons, instead of maximizing the likelihood 𝐿, it is common practice to find the
best model by maximizing the log-likelihood function ℓ(𝛾; 𝑋) = log 𝐿(𝛾; 𝑋) =
𝑛
∑𝑖=1 log 𝑝(𝑥𝑖 |𝛾). In this context, we want to find the model that maximizes the
log-likelihood:
𝑛

𝛾𝑀𝐿 ∶= arg max ∑ log 𝑝(𝑥𝑖 |𝛾). (4.2)
𝛾
𝑖=1

The procedure to calculate the log-likelihood depends on the specific algorithm


used to model the data. A possible solution would be to use a gradient-based
optimization algorithm on ℓ. It is often the case that, due to the indented
landscape of the likelihood function, gradient-based techniques often do not
perform well. Therefore, it is common to find other strategies to find do max-
imum likelihood estimation. One of which is the Expectation-Maximization
(EM) algorithm, detailed in chapter 11.

4.4 Dimensionality reduction


Dimensionality reduction (DR), a technique used both in supervised and unsu-
pervised learning, refers to the procedure by which the dimension of the input
data is reduced while retaining most of the meaningful information contained
therein. It is often a necessary step when trying to solve practical problems in
machine learning and there are many techniques for performing it. For instance,
it is used to decrease the variance of a model, since it can lead to models with a
4.5. GENERALIZED EIGENVALUE PROBLEMS IN MACHINE LEARNING81

fewer number of parameters, and it might just reduce the noise in the data. It is
also necessary when the runtime of the algorithm has polynomial dependence on
the number of features, as it is often the case for nowadays datasets. In the con-
text of big data analysis, by removing features that carry low information (like
features that are strictly proportional to other features, or features for which
the data contains too little information), it is possible to optimize the storage
space. It can be also used for data visualization. Most importantly, supervised
algorithms often suffer from the curse of dimensionality: by allowing large di-
mensionality of data, the informative power of the data points in the training
set decreases, thus leading to a degradation in classification performances. One
solution to improve the accuracy would be to increase the number of elements
in the training set, but this is not always possible nor desirable, so the common
route is to decrease the dimension of the data. Mathematically, the idea of the
dimensionality reduction algorithms is to map vectors from a high dimensional
space 𝒳 to a low dimensional space 𝒴, such that the most meaningful informa-
tion (according to some criteria) is preserved. Of course, understanding which
criterion to use is far from trivial.

The choice of the right DR algorithm depends on the nature of the data as well as
on the type of algorithm that will be applied after the dimensionality reduction.
A very well-known DR algorithm is the Principal Component Analysis (PCA),
which projects the data points onto the subspace spanned by the eigenvectors
associated to the 𝑘 largest eigenvalues of the covariance matrix of the data. In
this way, the projection holds “most of the information’ ’ of the dataset. It is
possible to show (Murphy, 2012) that for a subspace of dimension 𝑘, this choice
of eigenvectors minimizes the reconstruction error, i.e. the distance between the
original and the projected vectors. However, PCA is not always the best choice
of dimensionality reduction. PCA projects the data into the subspace along
which the data has more variance. This does not take into consideration the
information that different points might belong to different classes, and there
are cases in which PCA can worsen the performance of the classifier. Other
methods, like Fisher Linear Discriminant and Slow Feature Analysis take into
account the variance of every single class of points. Indeed, FLD projects the
data in a subspace trying to maximize the distance between points belonging to
different clusters and minimizing the distance between points belonging to the
same cluster, thus preserving or increasing the accuracy.

4.5 Generalized eigenvalue problems in machine


learning
Here we review the connection between the so-called Generalized Eigenvalue
Problem (GEP) and some models in machine learning. In classical literature,
this is a well-known subject (Ghojogh et al., 2019), (De Bie et al., 2005), (Borga
et al., 1997).
82 CHAPTER 4. CLASSICAL MACHINE LEARNING

Definition 4.1 (Generalized Eigenvalue Problem). Generalized Eigenvalue


Problem] Let 𝐴, 𝐵 ∈ ℝ𝑑×𝑑 be two SPD matrices. The GEP is defined as:

𝐴𝑊 = 𝐵𝑊 Λ

The columns 𝑤𝑖 ∈ ℝ𝑑 of 𝑊 and the values 𝜆𝑖 = Λ𝑖𝑖 ∈ ℝ of the diagonal matrix


Λ are the so-called generalized eigenvector and eigenvalues.
The generalized eigenvalue problem is denoted by (𝐴, 𝐵) (note that the order
in the pair matters). As is evident, the canonical eigenvalue problem is a spe-
cial case of the GEP where 𝐵 = 𝐼. In this work, we will often consider the
case when matrices 𝐴 and 𝐵 consist of expectation values from stochastic pro-
cesses, that is, these are covariance matrices of some sort. Furthermore, while
𝐴 can be symmetric semi-positive definite, we require 𝐵 to be invertible, and
thus symmetric positive definite. The GEP is related to the so-called Raylight
quotient: a variational extremum problem related to the ratio of two quadratic
forms involving matrix 𝐴 and 𝐵:

𝑤𝑇 𝐴𝑤
𝜌(𝑤) ∶= (4.3)
𝑤𝑇 𝐵𝑤
There many different optimization problems that can be reduced to a GEP,
which we report here for completeness (De Bie et al., 2005), (Ghojogh et al.,
2019). One can see that the norm of 𝑤 does not change the value of the opti-
mization problem. Therefore, we can impose an additional constraint on 𝑤. In
this way, we can reformulate the problem as a constrained optimization problem,
without losing any solution. This constraint is 𝑤𝑇 𝐵𝑤 = 1. We will describe the
relation between Equation (4.3) and Equation in definition 4.1. (To appear)

4.6 How to evaluate a classifier


Practitioners in quantum machine learning should not only build their skills
in quantum algorithms, and having some basic notions of statistics and data
science won’t hurt. In the following the see some ways to evaluate a classifier.
What does it means in practice? Imagine you have a medical test that is able to
tell if a patient is sick or not. You might want to consider the behavior of your
classier with respect to the following parameters: the cost of identifying a sick
patient as healthy is high, and the cost of identifying a healthy patient as sick.
For example, if the patient is a zombie and it contaminates all the rest of the
humanity you want to minimize the occurrences of the first case, while if the
cure for “zombiness” is lethal for a human patient, you want to minimize the
occurrences of the second case. With P and N we count the number of patients
tested Positively or Negatively. This is formalized in the following definitions,
which consists in statistics to be calculated on the test set of a data analysis.
• TP True positives (statistical power) : are those labeled as sick that
are actually sick.
4.6. HOW TO EVALUATE A CLASSIFIER 83

• FP False positives (type I error): are those labeled as sick but that
actually are healthy
• FN False negatives (type II error) : are those labeled as healthy but
that are actually sick.
• TN True negative: are those labeled as healthy that are healthy.
Given this simple intuition, we can take a binary classifier and imagine to do
an experiment over a data set. Then we can measure:
• True Positive Rate (TPR) = Recall = Sensitivity: is the ratio of
correctly identified elements among all the elements identified as sick. It
answer the question: “how are we good at detecting sick people?”.
𝑇𝑃 𝑇𝑃
+ ≃ 𝑃 (𝑡𝑒𝑠𝑡 = 1|𝑠𝑖𝑐𝑘 = 1)
𝑇𝑃 + 𝐹𝑁 𝑃
This is an estimator of the probability of a positive test given a sick indi-
vidual.
• True Negative Rate (TNR) = Specificity is a measure that tells you
how many are labeled as healthy but that are actually sick.
𝑇𝑁
= 𝑝(𝑡𝑒𝑠𝑡 = 0|𝑠𝑖𝑐𝑘 = 0)
𝑇𝑁 + 𝐹𝑃
How many healthy patients will test negatively to the test? How are we
good at avoiding false alarms?
• False Positive Rate = Fallout
𝐹𝑃
𝐹𝑃𝑅 = = 1 − 𝑇 𝑁𝑅
𝐹𝑃 + 𝑇𝑁

• False Negative Rate = Miss Rate


𝐹𝑁
𝐹𝑁𝑅 = = 1 − 𝑇𝑃𝑅
𝐹𝑁 + 𝑇𝑃

• Precision, Positive Predictive Value (PPV):


𝑇𝑃
≃ 𝑝(𝑠𝑖𝑐𝑘 = 1|𝑝𝑜𝑠𝑖𝑡𝑖𝑣𝑒 = 1)
𝑇𝑃 + 𝐹𝑃
How many positive to the test are actually sick?
• 𝐹1 score is a more compressed index of performance which is a possible
measure of performance of a binary classifier. Is simply the harmonic
mean of Precision and Sensitivity:
𝑃 𝑟𝑒𝑐𝑖𝑠𝑖𝑜𝑛 × 𝑆𝑒𝑛𝑠𝑖𝑡𝑖𝑣𝑖𝑡𝑦
𝐹1 = 2
𝑃 𝑟𝑒𝑐𝑖𝑠𝑖𝑜𝑛 + 𝑆𝑒𝑛𝑠𝑖𝑡𝑖𝑣𝑖𝑡𝑦
84 CHAPTER 4. CLASSICAL MACHINE LEARNING

• Receiver Operating Characteristic (ROC) Evaluate the TRP and


FPR at all the scores returned by a classifier by changing a parameter. It
is a plot of the true positive rate against the false positive rate for the
different possible value (cutpoints) of a test or experiment.
• The confusion matrix generalize these 4 combination of (TP TN FP FN)
to multiple classes: is a 𝑙 × 𝑙 where at row 𝑖 and column 𝑗 you have the
number of elements from the class𝑖 that have been classified as elements
of class 𝑗.
Other links: here
Chapter 5

A useful toolbox

5.1 Phase estimation


In this section we report the theorems for the subroutines that are often used
to create new quantum algorithms. Often, we report multiple formulations, so
that the working quantum algorithm researcher can pick the best version for
them.
Theorem 5.1 (Phase estimation (Kitaev, 1996)). Let 𝑈 be a unitary operator
with eigenvectors |𝑣𝑗 ⟩ and eigenvalues 𝑒𝑖𝜃𝑗 for 𝜃𝑗 ∈ [−𝜋, 𝜋], i.e. we have 𝑈 |𝑣𝑗 ⟩ =
𝑒𝑖𝜃𝑗 |𝑣𝑗 ⟩ for 𝑗 ∈ [𝑛]. For a precision parameter 𝜖 > 0, there exists a quantum
algorithm that runs in time 𝑂( 𝑇 (𝑈) 𝜖log(𝑛) )) and with probability 1 − 1/𝑝𝑜𝑙𝑦(𝑛)
maps a state |𝜙𝑖 ⟩ = ∑𝑗∈[𝑛] 𝛼𝑗 |𝑣𝑗 ⟩ to the state ∑𝑗∈[𝑛] 𝛼𝑗 |𝑣𝑗 ⟩|𝜃𝑗̄ ⟩ such that |𝜃𝑗̄ −𝜃𝑗 | <
𝜖 for all 𝑗 ∈ [𝑛].
Theorem 5.2 (Error and probability of failure of phase estimation (Nielsen
and Chuang, 2002) Section 5.2 and (Nannicini, 2019)). Let 0.𝑎 = 𝑎1 , … 𝑎𝑞 be
the output of phase estimation when applied to an eigenstate with phase 𝜙. If
1
we use 𝑞 + ⌈log(2 + 2𝛿 )⌉ qubits of precision, the first 𝑞 bits of 𝑎 will be accurate
with probability at least 1 − 𝛿, i.e.
𝑞
𝑃 𝑟[|𝜙 − ∑ 𝑎𝑗 2−𝑗 | ≤ 2−𝑞 ] ≥ 1 − 𝛿
𝑗=1

While the standard implementation of phase estimation is based on the quan-


tum Fourier transform (QFT) circuit (Nielsen and Chuang, 2002), there have
been various improvements (Ahmadi and Chiang, 2010) which try to soften the
dependence on the QFT circuit, while retaining the accuracy guarantees offered
by the QFT in estimating the angles 𝜃𝑗 .

85
86 CHAPTER 5. A USEFUL TOOLBOX

Note that the same algorithm described in theorem 5.1 can be made ‘’consis-
tent’ ’, in the sense of (Ta-Shma, 2013) and (Ambainis, 2012b). While in the
original formulation of phase estimation two different runs might return differ-
ent estimates for 𝜃𝑗 , with a consistent phase estimation this estimate is fixed,
with high probability. This means that the error between two different runs of
phase estimation is almost deterministic.

5.2 Grover’s algorithm, amplitude games


Theorem 5.3 (Grover’s algorithm). Let 𝑁 = 2𝑛 for 𝑛 > 0. Given quantum
oracle access 𝑂𝑥 ∶ |𝑖⟩ ↦ |𝑖⟩|𝑥𝑖 ⟩ to a vector 𝑥 = {0, 1}𝑁 where only one element
of 𝑥 is 1, there
√ is a quantum algorithm that finds the index of that element using
𝑂𝑥 only 𝑂( 𝑁 ) times.
This problem can be generalized to the case where there are multiple elements
“marked” as good solutions. If we know the number of solutions in advance, the
algorithm can be modified such that it fails with probability 0.

5.2.1 Amplitude estimation


Amplitude amplification and amplitude estimation are two of the workhorses of
quantum algorithms.
Theorem 5.4 (Amplitude estimation, (Brassard et al., 2002)). Given a quan-
tum algorithm

𝐴 ∶ |0⟩ → 𝑝|𝑦, 1⟩ + √1 − 𝑝|𝐺, 0⟩
where |𝐺⟩ is some garbage state, then the amplitude estimation algorithm, using
exactly 𝑃 iterations of the algorithm 𝐴 for any positive integer 𝑃 , outputs 𝑝̃
(0 ≤ 𝑝̃ ≤ 1) such that

√𝑝(1 − 𝑝) 𝜋 2
|𝑝̃ − 𝑝| ≤ 2𝜋 +( )
𝑃 𝑃
with probability at least 8/𝜋2 . If 𝑝 = 0 then 𝑝̃ = 0 with certainty, and if 𝑝 = 1
and 𝑃 is even, then 𝑝̃ = 1 with certainty.
Theorem 5.5 (Amplitude estimation (Brassard et al., 2002), formulation of
(Montanaro, 2015)). There is a quantum algorithm called amplitude estimation
which takes as input one copy of a quantum state |𝜓⟩, a unitary transformation
𝑈 = 2|𝜓⟩⟨𝜓| − 𝐼, a unitary transformation 𝑉 = 𝐼 − 2𝑃 for some projector 𝑃 ,
and an integer 𝑡. The algorithm outputs 𝑎,̃ an estimate of 𝑎 = ⟨𝜓|𝑃 |𝜓⟩, such
that:
√𝑎(1 − 𝑎) 𝜋2
|𝑎̃ − 𝑎| ≤ 2𝜋 + 2
𝑡 𝑡
with probability at least 8/𝜋2 , using 𝑈 and 𝑉 𝑡 times each. If 𝑎 = 0 then 𝑎̃ = 0
with certainty, and if 𝑎 = 1 and 𝑡 is even, then 𝑎̃ = 1 with certainty.
5.2. GROVER’S ALGORITHM, AMPLITUDE GAMES 87

In the original version of the Grover’s algorithm we assume to know the number
of marked elements, and therefore we can derive the correct number of itera-
tions. Later on, a fixed-point version of amplitude amplification was proposed
(Brassard et al., 2002) (Grover, 2005), which was then optimized in (Yoder
et al., 2014). These versions do not require to know the number of iterations
in advance. These results fundamentally leverage the trick that we reported in
Proposition 5.1.
Let’s see in practice how to use Theorem 5.4. Suppose that we want to estimate
𝑎 with relative error 𝜖. What is the number of times that we have to use the
two unitaries? Let’s check that it suffices to take 𝑡 = 𝜖2𝜋
√ , as
𝑎


2𝜋 𝑎√𝑎(1 − 𝑎)𝜖 𝜋2 𝜖2 𝑎 √ 𝜖2 𝑎
|𝑎 − 𝑎|̃ ≤ + 2
= 𝜖𝑎 1 − 𝑎 +
2𝜋 4𝜋 4
𝑎 𝜖2 𝑎 𝑎 𝜖
≤𝜖𝑎(1 − ) + = 𝜖𝑎 (1 − + ) ≤ 𝜖𝑎. (5.1)
2 4 2 4

In the previous
√ equation we used the Taylor expansion of 1 − 𝑥 to the second
order, i.e. 1 − 𝑥 ≤ 1 − 𝑥/2, and the fact that 𝜖, 𝑎 < 1 in the last inequality.
The asymptotic runtime of the algorithm is thus 𝑂( 𝜖√1 𝑎 ).
What if we want to have an absolute error now? We have some of options.
The simplest one is to note that a relative error of a quantity between 0 and 1
automatically translates in an absolute error. But this might not be the most
elegant thing to do: since an absolute error for a quantity between 0 and 1 is
“worse” than the relative error on the same quantity, we might want to save
some resources, i.e. decrease the number of calls to the oracles. Let’s set 𝑡 = 2𝜋
𝜖
and observe that

2𝜋√𝑎(1 − 𝑎)𝜖 𝜋2 𝜖2 √ √ 𝜖2
|𝑎 − 𝑎|̃ ≤ + = 𝜖 𝑎 1 − 𝑎 +
2𝜋 4𝜋2 4
√ 𝑎 𝜖2 √ 𝑎 𝜖
≤𝜖 𝑎(1 − ) + = 𝜖 ( 𝑎(1 − ) + ) ≤ 𝜖. (5.2)
2 4 2 4

Here,
√ in addition to the tricks used in the relative error, we also used that
𝑎 ≤ 1.
Exercise 5.1 ((Hard)). Another idea is to realize that we could run the algo-
rithm returning the relative error as a black box, and set the error to 𝜖′ = 𝜖/𝑎.
In this way we might estimate a relative error 𝜖′ 𝑎 = 𝜖, with the hope to save
some resources. What is the impact of this operation in the runtime √
of the
algorithm? It’s simple to see that the runtime becomes 𝑂( 𝜖 1√𝑎 ) = 𝑂( 𝜖𝑎 ). Can
√ 𝑎

2𝜋 𝑎 𝑎
we check if setting 𝑡 = 𝜖 can give an absolute error in 𝑂( 𝜖 ) runtime? What
is difficult about it?
88 CHAPTER 5. A USEFUL TOOLBOX

The solution to the previous exercise consist in adding a term √1 in the number
√ 𝜖
of iterations 𝑡. If we set 𝑡 = ⌈2𝜋 ( 2 𝜖 𝑎 ) + √1 ⌉
𝜖
we can get an absolute error.
Perhaps a simpler formulation, which hides the complexity of the low-level im-
plementation of the algorithm, and is thus more suitable to be used in quantum
algorithms for machine learning is the following:
Lemma 5.1 (Amplitude amplification and estimation (Kerenidis and Prakash,
2020) ). If there is a unitary operator 𝑈 such that 𝑈 |0⟩𝑙 = |𝜙⟩ = sin(𝜃)|𝑥, 0⟩ +
cos(𝜃)|𝐺, 0⊥ ⟩ then sin2 (𝜃) can be estimated to multiplicative error 𝜂 in time
𝑂( 𝜂𝑇sin(𝜃)
(𝑈) 𝑇 (𝑈)
) and |𝑥⟩ can be generated in expected time 𝑂( sin(𝜃) ) where 𝑇 (𝑈 ) is the
time to implement 𝑈 .
Recently, various researches worked on improvements of amplitude estimation
by getting rid of the part of the original algorithm that performed the phase
estimation (i.e. the Quantum Fourier Transform (Nielsen and Chuang, 2002))
(Grinko et al., 2019), (Aaronson and Rall, 2020). As the QFT is not considered
to be a NISQ subroutine, these results bring more hope to apply these algorithms
in useful scenarios in the first quantum computers.
FIrst proposed MLQAE.
QIP2023 with a particular choice of probability, while before we had results “on
average”.
Theorem 5.6 (Variable Time Search (Ambainis, 2012a)). Let 𝒜1 , … , 𝒜𝑛 be
quantum algorithms that return true or false and run in unknown times 𝑇1 , … , 𝑇𝑛 ,
respectively. Suppose that each 𝒜𝑖 outputs the correct answer with probability
at least 2/3. Then there exists a quantum algorithm with success probability at
least 2/3 that checks whether at least one of 𝒜𝑖 returns true and runs in time

̃ ( √𝑇 2 + … + 𝑇 2 ) .
𝑂 1 𝑛

Definition 5.1 (Variabile-stopping-time algorithm (Ambainis, 2012a)


(Chakraborty et al., 2022)). A quantum algorithms 𝒜 acting on ℋ that can
be written as 𝑚 quantum sub-algorithms 𝒜 = 𝒜𝑚 𝒜𝑚−1 … 𝒜1 is called a
variable stopping time algorithm if ℋ = ℋ𝐶 ⊗ ℋ𝐴 , where ℋ𝐶 ⊗𝑚 𝑖=1 ℋ𝐶𝑖 with
ℋ𝐶𝑖 = 𝑆𝑝𝑎𝑛(|0⟩, |1⟩) and each unitary 𝒜𝑗 acts on ℋ𝐶𝑖 ⊗ ℋ𝐴 controlled on
the first 𝑗 − 1 qubits |0⟩⊗𝑗−1 ∈ ⊗𝑗−1
𝑖=1 ℋ𝐶𝑖 being in the all zero state.

5.2.2 Amplitude amplification


5.2.3 Example: estimating average and variance of a func-
tion
Albeit the ideas treated in this post are somehow well-digested in the mind
of many quantum algorithms developers, this example is very useful to get a
5.2. GROVER’S ALGORITHM, AMPLITUDE GAMES 89

practical understanding of amplitude estimation. Notably, much more precise


and involved discussion around this topic can be found in chapter 8.
Suppose we have a random variable 𝑋 described by a certain probability distri-
bution over 𝑁 different outcomes, and a function 𝑓 ∶ {0, ⋯ 𝑁 } → [0, 1] defined
over this distribution. How can we use quantum computers to evaluate some
properties of 𝑓 such as expected value and variance faster than classical com-
puters?
Let’s start by translating into the quantum realm these two mathematical ob-
jects. The probability distribution is (surprise surprise) represented in our quan-
tum computer by a quantum state over 𝑛 = ⌈log 𝑁 ⌉ qubits.
𝑁−1

|𝜓⟩ = ∑ 𝑝𝑖 |𝑖⟩
𝑖=0

where the probability of measuring the state |𝑖⟩ is 𝑝𝑖 , for 𝑝𝑖 ∈ [0, 1]. Basically,
each bases of the Hilbert space represent an outcome of the random variable.
The quantization of the function 𝑓 is represented by a linear operator 𝐹 acting
on a new ancilla qubit (here on the right) as:

𝐹 ∶ |𝑖⟩|0⟩ → |𝑖⟩ (√1 − 𝑓(𝑖)|0⟩ + √𝑓(𝑖)|1⟩)

If we apply 𝐹 with |𝜓⟩ as input state we get:

𝑁−1 𝑁−1
√ √
∑ √1 − 𝑓(𝑖) 𝑝𝑖 |𝑖⟩|0⟩ + ∑ √𝑓(𝑖) 𝑝𝑖 |𝑖⟩|1⟩
𝑖=0 𝑖=0

𝑁−1
Observe that the probability of measuring |1⟩ in the ancilla qubit is ∑𝑖=0 𝑝𝑖 𝑓(𝑖),
which is 𝐸[𝑓(𝑋)]. By sampling the ancilla qubit we won’t get any speedup
compared to a classical randomized algorithm with oracle access to the function,
but applying amplitude estimation (Brassard et al., 2002) to the ancilla qubit
on the right, we can get an estimate of 𝐸[𝐹 (𝑋)] with precision 𝜖, quadratically
faster than a classical computer: in only 𝑂( 1𝜖 ) queries to 𝑓.
Finally, observe that:
𝑖 𝑋
• if we chose 𝑓(𝑖) = 𝑁−1 we are able to estimate 𝐸[ 𝑁−1 ] (which, since we
know 𝑁 gives us an estimate of the expected value 𝐸[𝑋])
𝑖2 2
• if we chose 𝑓(𝑖) = (𝑁−1) 2 instead, we can estimate 𝐸[𝑋 ] and using this

along with the previous choice of 𝑓 we can estimate the variance of 𝑋:


𝐸[𝑋 2 ] − 𝐸[𝑋]2 .
Exercise 5.2. Can you prove the previous two points?
We will see in Chapter 8 why in many real-world cases this is not the best way
of estimating 𝔼(𝑓(𝑋)).
90 CHAPTER 5. A USEFUL TOOLBOX

5.3 Finding the minimum


We now want to show an algorithm that finds the minimum among 𝑁 unsorted
values 𝑢𝑗∈[𝑁] . As the Grover’s algorithm, we work in the oracle model, so we
assume to have quantum access to a the vector 𝑢. Without loss of generality
we can take 𝑁 = 2𝑛 , but if the length of our list is not a power of 2, we can
just pad the rest of the elements in the list with zeroes. The statement of the
theorem is the following.
Lemma 5.2 (Quantum minimum finding (Durr and Hoyer, 1996)). Given quan-
tum access to a vector 𝑢 ∈ [0, 1]𝑁 via the operation |𝑗⟩|0⟩̄ → |𝑗⟩|𝑢𝑗 ⟩ on 𝒪 (log 𝑁 )
qubits, where 𝑢𝑗 is encoded to additive accuracy 𝒪 (1/𝑁 ). Then, we can find the

minimum 𝑢min = min𝑗∈[𝑁] 𝑢𝑗 with success probability 1 − 𝛿 with 𝒪 ( 𝑁 log ( 1𝛿 ))

queries and 𝒪̃( 𝑁 log ( 1 )) quantum gates.
𝛿

Another formulation is the following:


Theorem 5.7 (Quantum Minimum Finding (Durr and Hoyer, 1996) formula-
tion of (ambainis2019quantum)). Let 𝑎1 , … , 𝑎𝑛 be integers, accessed by a pro-
𝑛
cedure 𝒫. There exists a quantum √ algorithm that finds min𝑖=1 {𝑎𝑖 } with success
probability at least 2/3 using 𝑂( 𝑛) applications of 𝒫.
This algorithm utilizes a subroutine called quantum exponential searching al-
gorithm (QESA), which is again composed of amplitude amplification (Grover)
and amplitude estimation. For simplicity, we assume those values are distinct.
The general idea is marking indices of values below a chosen threshold, return-
ing and picking one of them as the new threshold with equal probability. After
some iterations, it is expected to yield the lowest value. Note that the step of
marking lower values is taken as an oracle with gate complexity of 𝑂(1). We
first present to algorithm and keep the explanation for later.

Figure 5.1: Finding the minimum


5.3. FINDING THE MINIMUM 91

Figure 5.2: Quantum Exponential Searching Algorithm


In the basic Grover’s algorithm with one solution, 𝑚 = 𝐶𝐼 ( 𝜋4 𝑁 ) iterations
give the true output with error probability at most 1/𝑁 for 𝑁 ≫ 1, where
𝐶𝐼(𝑥) is the closest integer to 𝑥. The result can be generalized in the case of
𝑡 ≪ 𝑁 solutions that the error rate is reduced to at most 𝑡/𝑁 after exactly
𝜋−2 arcsin √𝑡/𝑁
𝑚 = 𝐶𝐼 ( 4 arcsin √𝑡/𝑁
) = ⌊ 4 arcsin𝜋 √𝑡/𝑁 ⌋ iterations (and thus oracle calls),

with an upper bound 𝑚 ≤ 𝜋4 √ 𝑁𝑡 . However, a problem arises when we have to


amplify amplitudes corresponding to values below the threshold. In practice,
the number of candidates is unknown and varies for each threshold. QESA is a
generalized algorithm to find a solution for unknown 𝑡 with probability at least
1/4 in 𝑂(√𝑁 /𝑡), which is motivated by the following observation.

Proposition 5.1 (Quantum Exponential Searching Algorithm (Boyer et al.,


1998)). Let 𝑡 be the (unknown) number of solutions and let 𝜃 be such that
sin2 𝜃 = 𝑡/𝑁 . Let 𝑚 be an arbitrary positive integer. Let 𝑘 be an integer chosen
at random according to the uniform distribution between 0 and 𝑚 − 1. If we
observe the register after applying 𝑘 iterations of Grover’s algorithm starting
from the initial state ∑𝑖 √1𝑁 |𝑖⟩, the probability of obtaining a solution is exactly
1 sin (4𝑚𝜃)
𝑃𝑚 = 2 − 4𝑚 sin (2𝜃) . In particular, 𝑃𝑚 ≥ 1/4 when 𝑚 ≥ 1/ sin (2𝜃).

As QESA is expected to be done in 𝑂(√𝑁 /𝑡) queries, one can deduce that
the expected number of queries √ for the minimum-finding algorithm with success
probability at least 1/2 is 𝑂( 𝑁 ). Repeating the algorithm 𝑐 times increases
the success probability to 1 − 1/2𝑐√. In terms of quantum gates, the Grover part
and the initialization part use 𝑂( 𝑁 ) and 𝑂(log 𝑁 ) respectively.
92 CHAPTER 5. A USEFUL TOOLBOX

5.4 Quantum linear algebra


A central tool for quantum algorithm in machine learning are the subroutines
for performing quantum linear algebraic routines on a quantum computer. From
the first work of (Harrow et al., 2009) (known in the literature as HHL algorithm)
that proposed a quantum algorithm for matrix inversion, a lot of progress has
been made in improving quantum algorithms for these problems. In this section,
we briefly recall some of the results, and we conclude by citing the state-of-the art
techniques for performing not only matrix inversion and matrix multiplication,
but also for applying a certain class of functions to the singular values of a matrix.
The HHL algorithm - under suitable assumptions - was able to create a quantum
state proportional to the solution to a sparse linear system of equations 𝐴𝑥 = 𝑏
using only a number of queries to the oracle that was polylogarithmic in the size
of the matrix 𝐴. The assumption are the following: 𝐴 must be symmetric and
sparse (and we have quantum query access to 𝐴, and quantum sample access
to |𝑏⟩, as we defined more precisely in 3 ). The runtime of the first quantum
algorithm for this problem was 𝑂 ̃ (𝑠2 𝜅(𝐴)2 /𝜖), where 𝑠 is the maximum value
of non-zero entries per rows.

5.4.1 Singular value estimation


A notable result after HHL was the ability to perform a quantum version of
the singular value decomposition. You can think of this result as a generalized
phase estimation, i.e. a phase estimation that works on non-unitary matrices.
It was first proposed in (Kerenidis and Prakash, 2017), and later improved in
(Kerenidis and Prakash, 2020) and (Chakraborty et al., 2019). This idea is
detailed in the following theorem.

Theorem 5.8 (Singular Value Estimation (Kerenidis and Prakash, 2020)). Let
𝑀 ∈ ℝ𝑛×𝑑 be a matrix with singular value decomposition 𝑀 = ∑𝑖 𝜎𝑖 𝑢𝑖 𝑣𝑖𝑇 for
which we have quantum access. Let 𝜀 > 0 the precision parameter. There is an
algorithm with running time 𝑂(𝜇(𝑀 ̃ )/𝜀) that performs the mapping ∑𝑖 𝛼𝑖 |𝑣𝑖 ⟩ →
∑𝑖 𝛼𝑖 |𝑣𝑖 ⟩|𝜎̃𝑖 ⟩, where |𝜎𝑖̃ − 𝜎𝑖 | ≤ 𝜀 for all 𝑖 with probability at least 1 − 1/𝑝𝑜𝑙𝑦(𝑛).

Recall that quantum access to a matrix is defined in theorem ??, and the param-
eter 𝜇 is defined in definition 3.14. The relevance of theorem 5.8 for quantum
machine learning is the following: if we are able to estimate the singular values
of a matrix, then we can perform a conditional rotation controlled by these
singular values and hence perform a variety of linear algebraic operations, in-
cluding matrix inversion, matrix multiplication or projection onto a subspace.
Based on this result, quantum linear algebra was done using the theorem stated
below.

Theorem 5.9 (Old method for quantum linear algebra). Let 𝑀 ∶= ∑𝑖 𝜎𝑖 𝑢𝑖 𝑣𝑖𝑇 ∈
ℝ𝑑×𝑑 such that ‖𝑀 ‖2 = 1, and a vector 𝑥 ∈ ℝ𝑑 for which we have quantum access.
There exist quantum algorithms that with probability at least 1−1/𝑝𝑜𝑙𝑦(𝑑) returns
5.4. QUANTUM LINEAR ALGEBRA 93

• a state |𝑧⟩ such that ||𝑧⟩ − |𝑀 𝑥⟩| ≤ 𝜖 in time 𝑂(𝜅̃ 2 (𝑀 )𝜇(𝑀 )/𝜖)
−1
• a state |𝑧⟩ such that ||𝑧⟩ − |𝑀 𝑥⟩| ≤ 𝜖 in time 𝑂(𝜅 ̃ 2 (𝑀 )𝜇(𝑀 )/𝜖)
+
• a state |𝑀≤𝜃,𝛿 𝑀≤𝜃,𝛿 𝑥⟩ in time 𝑂(̃ 𝛿𝜃∥𝑀𝜇(𝑀)‖𝑥‖
+
𝑀 𝑥∥
)
≤𝜃,𝛿 ≤𝜃,𝛿

One can also get estimates of the norms with multiplicative error 𝜂 by increasing
the running time by a factor 1/𝜂.

Recall that we denote as 𝑉≥𝜏 the matrix ∑𝑖=0 𝜎𝑖 𝑢𝑖 𝑣𝑖𝑇 where 𝜎ℓ is the smallest
singular value which is greater than 𝜏 . For a matrix 𝑀 and a vector 𝑥, we define
+
as 𝑀≤𝜃,𝛿 𝑀≤𝜃,𝛿 𝑥 the projection of 𝑥 onto the space spanned by the singular
vectors of 𝑀 whose corresponding singular values are smaller than 𝜃, and some
subset of singular vectors whose corresponding singular values are in the interval
[𝜃, (1 + 𝛿)𝜃].
For a symmetric matrix 𝑀 ∈ ℝ𝑑×𝑑 with spectral norm ‖𝑀 ‖ = 1 for which we
have quantum access, the running time of these algorithms depends on the con-
dition number 𝜅(𝑀 ) of the matrix, that can be replaced by 𝜅𝜏 (𝑀 ), a condition
threshold where we keep only the singular values bigger than 𝜏 , and the parame-
ter 𝜇(𝑀 ), a matrix dependent parameter defined in definition 3.14. The running
time also depends logarithmically on the relative error 𝜖 of the final outcome
state. Recall that these linear algebra procedures above can also be applied to
any rectangular matrix 𝑉 ∈ ℝ𝑛×𝑑 by considering instead the symmetric matrix

0 𝑉
𝑉 =( ).
𝑉𝑇 0

5.4.2 Linear combination of unitaries


We continue our journey in quantum linear algebra by discussing the state-of-
the-art technique beneath quantum linear algebra.
The research of quantum algorithms for machine learning has always used tech-
niques developed in other areas of quantum algorithms. Among the many,
we cite quantum algorithms for Hamiltonian simulation and quantum random
walks. In fact, using quantum random walks, it is possible to decrease the de-
pendence on the error parameter, from polynomial to polylog(1/𝜖) (Childs and
Wiebe, 2012). Stemming from the research in Hamiltonian simulation (Berry
et al., 2015b), (Low and Chuang, 2019), (Berry et al., 2015a), (Low and Chuang,
2017),(Subramanian et al., 2019), these techniques have been further optimized,
pushing them to the limit of almost optimal time and query complexity. Sig-
nificant progress in the direction of quantum algorithms for linear algebra was
the so-called LCU, or linear combination of unitaries (Childs and Wiebe, 2012),
which again was developed in the context of the Hamiltonian simulation prob-
lem.
Lemma 5.3 (Linear combination of unitaries (Childs et al., 2015)). Let 𝑀 =
∑𝑖 𝛼𝑖 𝑈𝑖 be a linear combination of unitaries 𝑈𝑖 with 𝛼𝑖 > 0 for all 𝑖. Let 𝑉 be
94 CHAPTER 5. A USEFUL TOOLBOX

√1

any operator that satisfies 𝑉 |0⊗𝑚 ⟩ ∶= 𝛼
∑𝑖 𝛼𝑖 |𝑖⟩, where 𝛼 ∶= ∑𝑖 𝛼𝑖 . Then
𝑊 ∶= 𝑉 † 𝑈 𝑉 satisfies

1 ⊗𝑚
𝑊 |0⊗𝑚 ⟩|𝜓⟩ = |0 ⟩𝑀 |𝜓⟩ + |Ψ⟂ ⟩ (5.3)
𝛼

for all states |𝜓⟩, where 𝑈 ∶= ∑𝑖 |𝑖⟩⟨𝑖| ⊗ 𝑈𝑖 and (|0⊗𝑚 ⟩⟨0⊗𝑚 | ⊗ 𝐼)|Ψ⟂ ⟩ = 0.

5.4.3 Singular value transformation


The research in quantum linear algebra culminated with the work of
(Chakraborty et al., 2019), (Gilyén et al., 2019) with some improvements in
(Chakraborty et al., 2022). We now briefly go through the machinery behind
these results, as it will be used extensively this work. Before that, we recall the
definition of block-encoding from Chapter 3.
𝑠 𝑠
Definition 5.2 (Block encoding of a matrix). Let 𝐴 ∈ ℂ2 ×2 . We say that a
unitary 𝑈 ∈ ℂ(𝑠+𝑎)×(𝑠+𝑎) is a (𝛼, 𝑎, 𝜖) block encoding of 𝐴 if:

‖𝐴 − 𝛼(⟨0|𝑎 ⊗ 𝐼)𝑈 (|0⟩𝑎 ⊗ 𝐼)‖ ≤ 𝜖

𝑤 𝑤
We will see that having quantum access to a matrix 𝐴 ∈ ℂ2 ×2 , as described in
the setting of theorem 3.8, it is possible to implement a (𝜇(𝐴), 𝑤 + 2, polylog(𝜖))
block-encoding of 𝐴 1 . Given matrix 𝑈 which is a (𝛼, 𝑎, 𝛿) block encoding of 𝐴,
and a matrix 𝑉 which is a (𝛽, 𝑏, 𝜖) block encoding of 𝐵, it is simple to obtain a
(𝛼𝛽, 𝑎 + 𝑏, 𝛼𝜖 + 𝛽𝛿) block encoding of 𝐴𝐵.
For practical purposes, having a block encoding of a matrix 𝐴, allows one to
manipulate its spectra using polynomial approximation of analytic functions. In
the following theorem, the notation 𝑃ℜ (𝐴) means that we apply the polynomial
𝑟
𝑃 to the singular values of the matrix 𝐴, i.e. 𝑃ℜ (𝐴) = ∑𝑖 𝑃 (𝜎𝑖 )𝑢𝑖 𝑣𝑖𝑇 .
Theorem 5.10 (Polynomial eigenvalue transformation of arbitrary parity (Gi-
lyén et al., 2019)). Suppose that 𝑈 is an (𝛼, 𝑎, 𝜖)-block encoding of the Hermitian
matrix 𝐴. If 𝛿 ≥ 0 and 𝑃ℜ ∈ ℝ[𝑥] is a degree-𝑑 polynomial satisfying that:
• for all 𝑥 ∈ [−1, 1], |𝑃ℜ (𝑥)| ≤ 12 .

Then there is a quantum circuit 𝑈̃ , which is an (1, 𝑎+2, 4𝑑√𝜖/𝛼+𝛿)-encoding of


𝑃ℛ (𝐴/𝛼), and consists of 𝑑 applications of 𝑈 and 𝑈 † gates, a single application
of controlled-𝑈 and 𝑂((𝑎 + 1)𝑑) other one- and two-qubit gates. Moreover we
can compute a description of such a circuit with a classical computer in time
𝑂(poly𝑑, log(1/𝛿)).
1 This polylog(𝜖) in the block encoding is due to approximation error that one commits

when creating quantum access to the classical data structures, i.e. is the approximation that
derives from truncating a number 𝑛 ∈ ℝ (which rerepsent an entry of the matrix) up to a
certain precision 𝜖 lemma 25 of [@CGJ18].
5.4. QUANTUM LINEAR ALGEBRA 95

We will discuss in Section 5.4.4 how to use these subroutines for solving the
linear system problems. You can find in Appendix @ref(#polyapprox-1overx)
the polynomial approximation that was originally used in (Childs et al., 2015)
to get what almost-tight gate complexity for this problem. This result has
been improved in (Gribling et al., 2021), leading to a polynomial approximation
allowing several orders of magnitude faster algorithms for linear system solving.
Given a (𝛼, 𝑎, 𝜖)-block encoding for a matrix 𝐴 and a quantum state |𝑏⟩, we can
obtain a good approximation of 𝐴|𝑏⟩/ ‖𝐴𝑏‖ by first creating the state |0𝑎 , 𝑏⟩ and
then applying the block encoding of 𝐴 to it. Then, we can amplify the part
of the subspace associated with the state |0⟩⊗𝑎 𝐴|𝑏⟩. Differently, one might use
advanced amplification techniques and reach a similar result. This concept is
detailed in the following lemma.
Lemma 5.4 (Applying a block-encoded matrix to a quantum state
(Chakraborty et al., 2019)). Fix any 𝜀 ∈ (0, 1/2). Let 𝐴 ∈ ℂ𝑁×𝑁 such
that ‖𝐴‖ ≤ 1 and |𝑏⟩ a normalized vector in ℂ𝑁 , such that ‖𝐴|𝑏⟩‖ ≥ 𝛾. Suppose
that |𝑏⟩ can be generated in complexity 𝑇𝑏 and there is a (𝛼, 𝑎, 𝜖)-block encoding
of 𝐴 for some 𝛼 ≥ 1, with 𝜖 ≤ 𝜀𝛾/2, that can be implemented in cost 𝑇𝐴 . Then
there is a quantum algorithm with complexity

𝛼(𝑇𝐴 + 𝑇𝑏 ) 𝛼𝑇𝐴 log(1/𝜖) + 𝑇𝐵


𝑂 (𝑚𝑖𝑛( , ))
𝛾 𝛾

that terminates with success probability at least 2/3, and upon success generates
the state 𝐴|𝑏⟩/ ‖𝐴|𝑏⟩‖ to precision 𝜀.
For sake of completeness, we briefly discuss how to prove the first upper bound.
Generating |𝑏⟩ and applying the block encoding of 𝐴 to it, we create a state
that is (𝜖/𝛼)-close to:
1
|0⟩⊗𝑎 ( 𝐴|𝑏⟩) + |0⟂ ⟩
𝛼
From the hypothesis, we know that ∥ 𝛼1 𝐴|𝑏⟩∥ ≥ 𝛾/𝛼. We can use 𝑂(𝛼/𝛾)
calls to amplitude amplification on the initial register being |0⟩⊗𝑎 , to get 𝛾𝜖
𝐴|𝑏⟩
close to |0⟩⊗𝑎 ‖𝐴‖|𝑏⟩ . The second upper bound is shown by other techniques
based on amplitude amplification of singular values of block encoded matrices
(i.e. (Chakraborty et al., 2019, lemma 47), (Low and Chuang, 2017, theorem
2,8)).
Regarding the usage of block-encodings for solving with a quantum computer a
linear system of equations (i.e. multiplying a quantum state by the inverse of a
matrix, and creating a state |𝑥⟩ proportional to 𝐴−1 |𝑏⟩) we can proceed in an
analogous way. First, we need to create block encoding access to 𝐴−1 . Using
the following lemma, (where they denoted with 𝜅 the condition number of 𝐴)
we can implement negative powers of Hermitian matrices.
Lemma 5.5 (Implementing negative powers of Hermitian matrices
(Chakraborty et al., 2019) lemma 9). Let 𝑐 ∈ (0, ∞), 𝜅 ≥ 2, and let
96 CHAPTER 5. A USEFUL TOOLBOX

𝐴 be an Hermitian matrix such that 𝐼/𝜅 ≤ 𝐴 ≤ 𝐼. Suppose that


3 1+𝑐
𝛿 = 𝑜(𝜖/(𝜅1+𝑐 (1 + 𝑐) log 𝑘 𝜖 )) and 𝑈 is an (𝛼, 𝑎, 𝛿)-block encoding of 𝐴
that can be implemented using 𝑇𝑈 gates. Then, for any 𝜖, we can implement a
unitary 𝑈̃ that is a (2𝜅𝑐 , 𝑎, 𝜖)-block encoding of 𝐻 −𝑐 in cost:

2 𝑘1+𝑐
𝑂 (𝛼𝜅(𝑎 + 𝑇𝑈 )(1 + 𝑐) log ( ))
𝜖

Nevertheless, the algorithm that we can obtain by using the previous lemma
has a quadratic dependence on 𝜅. To decrease it to an algorithm linear in 𝜅 the
authors used variable time amplitude amplifications(Ambainis, 2012a). Hence,
we can restate the theorem 5.9, with the improved runtimes, as follows.
Theorem 5.11 (Quantum linear algebra (Chakraborty et al., 2019),(Gilyén
et al., 2019)). Let 𝑀 ∶= ∑𝑖 𝜎𝑖 𝑢𝑖 𝑣𝑖𝑇 ∈ ℝ𝑑×𝑑 such that ‖𝑀 ‖2 = 1, and a vector
𝑥 ∈ ℝ𝑑 for which we have quantum access in time 𝑇𝜒 . There exist quantum
algorithms that with probability at least 1 − 1/𝑝𝑜𝑙𝑦(𝑑) return
̃
• a state |𝑧⟩ such that ||𝑧⟩−|𝑀 𝑥⟩| ≤ 𝜖 in time 𝑂(𝜅(𝑀 )(𝜇(𝑀 )+𝑇𝜒 ) log(1/𝜖))
• a state |𝑧⟩ such that ||𝑧⟩ − |𝑀 −1 𝑥⟩| ≤ 𝜖 in time 𝑂(𝜅(𝑀 ̃ )(𝜇(𝑀 ) +
𝑇𝜒 ) log(1/𝜖))
+
• a state |𝑀≤𝜃,𝛿 ̃
𝑀≤𝜃,𝛿 𝑥⟩ in time 𝑂(𝑇 𝜇(𝑀)‖𝑥‖
)
𝜒 𝛿𝜃∥𝑀 + 𝑀 𝑥∥
≤𝜃,𝛿 ≤𝜃,𝛿

One can also get estimates of the norms with multiplicative error 𝜂 by increasing
the running time by a factor 1/𝜂.
This algorithm is leveraging Theorem 5.10 and the low-degree polynomial ap-
proximation of 1/𝑥 in Appendix E.2.
Another important advantage of the new methods is that it provides easy ways
to manipulate sums or products of matrices.
Theorem 5.12 (Quantum linear algebra for product of matrices (Chakraborty
et al., 2019),(Gilyén et al., 2019)). Let 𝑀1 , 𝑀2 ∈ ℝ𝑑×𝑑 such that ‖𝑀1 ‖2 =
‖𝑀2 ‖2 = 1, 𝑀 = 𝑀1 𝑀2 , and a vector 𝑥 ∈ ℝ𝑑 for which we have quantum access.
There exist quantum algorithms that with probability at least 1−1/𝑝𝑜𝑙𝑦(𝑑) return
• a state |𝑧⟩ such that ||𝑧⟩ − |𝑀 𝑥⟩| ≤ 𝜖 in time 𝑂(𝜅(𝑀 ̃ )(𝜇(𝑀1 ) +
𝜇(𝑀2 )) log(1/𝜖))
• a state |𝑧⟩ such that ||𝑧⟩ − |𝑀 −1 𝑥⟩| ≤ 𝜖 in time 𝑂(𝜅(𝑀 ̃ )(𝜇(𝑀1 ) +
𝜇(𝑀2 )) log(1/𝜖))
+
• a state |𝑀≤𝜃,𝛿 𝑀≤𝜃,𝛿 𝑥⟩ in time 𝑂(̃ (𝜇(𝑀 1 )+𝜇(𝑀2 ))‖𝑥‖
𝛿𝜃∥𝑀 + 𝑀 𝑥∥
)
≤𝜃,𝛿 ≤𝜃,𝛿

One can also get estimates of the norms with multiplicative error 𝜂 by increasing
the running time by a factor 1/𝜂.
More generally, applying a matrix 𝑀 which is the product of 𝑘 matrices, i.e. 𝑀 =
𝑘
𝑀1 … 𝑀𝑘 will result in a runtime of 𝜅(𝑀 )(∑𝑖 𝜇(𝑀𝑖 )) log(1/𝜖) factors in the
5.4. QUANTUM LINEAR ALGEBRA 97

runtime.

5.4.4 Matrix inversion after HHL


In this section we briefly recap the progress that we had in the last decade
for solving the quantum linear system problem (QLSP). First, we stress the
fact that the problem solved by this algorithm is fundamentally different than
solving a linear system of equation on a classical computer (i.e. when we obtain
𝑥 = 𝐴−1 𝑏), as with a classical computer, once we finish the computation we
obtain a classical description of the vector 𝑥. Instead, on a quantum computer
we obtain a quantum state |𝑥⟩.
For a few years the techniques developed in (Kerenidis and Prakash, 2017) and
(Kerenidis and Prakash, 2020) were the state of the art
After Ambainis used variable-time amplitude amplification to reduce the depen-
dence on the condition number from quadratic do linear, Childs et al. (Childs
et al., 2015) used the LCU framework, variable-time amplitude amplification,
and the polynomial approximation of 1/𝑥 to solve the QLSP with a runtime
dependece on the condition number of 𝑂(𝜅(𝐴) log(𝜅)), but also with an expo-
nential improvement in the precision, i.e. now the error dependence appear as
𝑂(log(1/𝜖)) in the runtime. The authors used quantum walks to represent 𝑥 as
𝑛
linear combination of polynomials ∑𝑖=1 𝛼𝑛 𝑇𝑛 (𝑥/𝑑) where 𝑇𝑛 is the Chebychev
polynomial of the first kind, 𝑑 is the sparsity of the matrix 𝐴, and 𝛼𝑖 the coeffi-
cients of the polynomial expansions. For this, they had to give the first efficient
polynomial approximation of 1/𝑥 (Lemma 17,18,19 of (Childs et al., 2015) )
that you can find explained in greater deatails in the Appendix E.2. Interest-
ingly, the QLSP has been also studied in the adiabatic setting, first in (Subaşı
et al., 2019), and later improved in (An and Lin, 2022), and with eigenstate
filtering (Lin and Tong, 2020) to an optimal scaling of 𝑂(𝜅(𝐴)) (i.e. without a
𝑂(log(𝜅(𝐴))) factor in the runtime, which to our knowledge remains unbeated
by other gate based quantum algorithms) (Costa et al., 2021).
Last but not least, matrix inversion can be seen as the problem of implementing
the singular value transformation of 𝑥 ↦ 1/𝑥. For this, one needs to get a
polynomial approximation of the function 1/𝑥. While this might seem a simple
task, there are small complications. First, one usually does not consider the
whole interval [−1, 1]. In practice, one excludes the subset of the domain where
the function has singularities (i.e. for 1/𝑥 is around zero). It is preferable to
pick a polynomial of a small degree, as the depth of the circuit depends linearly
on the degree of the polynomial. In short with both LCU and QSVT we can
use polynomial approximations to solve the QLSP problem. With LCU we have
an additional multiplicative factor in the depth of the circuit compared to the
QSVT framework, and some more ancillary qubits (Gribling et al., 2021).
A review of the progress made in the first 9 years after HHL can be found
in (Dervovic et al., 2018) and (Gribling et al., 2021), from which we take this
exercise. More recently, (Gribling et al., 2021) shows the latest techniques for
98 CHAPTER 5. A USEFUL TOOLBOX

the polynomial approximation of 1/𝑥 (and other functions), which improves the
polynomial approximation of (Childs et al., 2015).
Exercise 5.3. In (Gribling et al., 2021) they say the following:

‖𝐴𝑥 − 𝑏‖ ≤ ‖𝑥 − 𝐴−1 𝑏‖ ≤ 𝜅‖𝐴𝑥 − 𝑏‖

can you prove it?

5.5 Distances, inner products, norms, and


quadratic forms
In this section, we report two lemmas that can be used to estimate the in-
ner products, distances, and quadratic forms between vectors. The lemma 5.6
has been developed in the work (Kerenidis et al., 2019a). The lemma 5.8 and
the other lemmas for inner product estimation in the query model come from
(Hamoudi et al., 2020).

5.5.1 Inner products and quadratic forms with KP-trees


We can rephrase this theorem saying that we have quantum access to the ma-
trices, but for simplicity we keep the original formulation. Also, in the remark
following the proof of this lemma, we give the runtime of the same algorithm,
but when we compute all the distances in superposition. Thanks to the union
bound, we incour only in a logarithmic cost.
Lemma 5.6 (Distance and Inner Products Estimation (Kerenidis et al.,
2019a)). Assume for a matrix 𝑉 ∈ ℝ𝑛×𝑑 and a matrix 𝐶 ∈ ℝ𝑘×𝑑 that the
following unitaries |𝑖⟩|0⟩ ↦ |𝑖⟩|𝑣𝑖 ⟩, and |𝑗⟩|0⟩ ↦ |𝑗⟩|𝑐𝑗 ⟩ can be performed in time
𝑇 and the norms of the vectors are known. For any Δ > 0 and 𝜖 > 0, there
exists a quantum algorithm that computes
• |𝑖⟩|𝑗⟩|0⟩ ↦ |𝑖⟩|𝑗⟩|𝑑2 (𝑣𝑖 , 𝑐𝑗 )⟩ where |𝑑2 (𝑣𝑖 , 𝑐𝑗 ) − 𝑑2 (𝑣𝑖 , 𝑐𝑗 )| ⩽ 𝜖 w.p. ≥ 1 − 2Δ
• |𝑖⟩|𝑗⟩|0⟩ ↦ |𝑖⟩|𝑗⟩|(𝑣𝑖 , 𝑐𝑗 )⟩ where |(𝑣𝑖 , 𝑐𝑗 ) − (𝑣𝑖 , 𝑐𝑗 )| ⩽ 𝜖 w.p. ≥ 1 − 2Δ

̃ ( ‖𝑣𝑖 ‖∥𝑐𝑗 ∥𝑇 log(1/Δ) ).


in time 𝑂 𝜖

Proof. Let us start by describing a procedure to estimate the square ℓ2 distance


between the normalized vectors |𝑣𝑖 ⟩ and |𝑐𝑗 ⟩. We start with the initial state

1
|𝜙𝑖𝑗 ⟩ ∶= |𝑖⟩|𝑗⟩ √ (|0⟩ + |1⟩)|0⟩
2

Then, we query the state preparation oracle controlled on the third register to
perform the mappings |𝑖⟩|𝑗⟩|0⟩|0⟩ ↦ |𝑖⟩|𝑗⟩|0⟩|𝑣𝑖 ⟩ and |𝑖⟩|𝑗⟩|1⟩|0⟩ ↦ |𝑖⟩|𝑗⟩|1⟩|𝑐𝑗 ⟩.
5.5. DISTANCES, INNER PRODUCTS, NORMS, AND QUADRATIC FORMS99

The state after this is given by,


1
√ (|𝑖⟩|𝑗⟩|0⟩|𝑣𝑖 ⟩ + |𝑖⟩|𝑗⟩|1⟩|𝑐𝑗 ⟩)
2
Finally, we apply an Hadamard gate on the the third register to obtain,
1 1
|𝑖⟩|𝑗⟩ ( |0⟩ (|𝑣𝑖 ⟩ + |𝑐𝑗 ⟩) + |1⟩ (|𝑣𝑖 ⟩ − |𝑐𝑗 ⟩))
2 2
The probability of obtaining |1⟩ when the third register is measured is,

1 1 1 − ⟨𝑣𝑖 |𝑐𝑗 ⟩
𝑝𝑖𝑗 = (2 − 2⟨𝑣𝑖 ⟩𝑐𝑗 ) = 𝑑2 (|𝑣𝑖 ⟩, |𝑐𝑗 ⟩) =
4 4 2
which is proportional to the square distance between the two normalized vectors.
We can rewrite |1⟩ (|𝑣𝑖 ⟩ − |𝑐𝑗 ⟩) as |𝑦𝑖𝑗 , 1⟩ (by swapping the registers), and hence
we have the final mapping

𝐴 ∶ |𝑖⟩|𝑗⟩|0⟩ ↦ |𝑖⟩|𝑗⟩(√𝑝𝑖𝑗 |𝑦𝑖𝑗 , 1⟩ + √1 − 𝑝𝑖𝑗 |𝐺𝑖𝑗 , 0⟩) (5.4)

where the probability 𝑝𝑖𝑗 is proportional to the square distance between the
normalized vectors and 𝐺𝑖𝑗 is a garbage state. Note that the running time of 𝐴
̃ ).
is 𝑇𝐴 = 𝑂(𝑇
Now that we know how to apply the transformation described in Equation (5.4),
we can use known techniques to conclude our subroutine to perform the distance
estimation within additive error 𝜖 with high probability. The method uses two
tools, amplitude estimation, and the median evaluation lemma D.2 from (Wiebe
et al., 2018), which is a quantum version of the well-known powering-lemma C.1.
First, using amplitude estimation (theorem 5.4 ) with the unitary 𝐴 defined in
Equation (5.4), we can create a unitary operation that maps

𝒰 ∶ |𝑖⟩|𝑗⟩|0⟩ ↦ |𝑖⟩|𝑗⟩ ( 𝛼|𝑝𝑖𝑗 , 𝐺, 1⟩ + √(1 − 𝛼)|𝐺′ , 0⟩)

where 𝐺, 𝐺′ are garbage registers, |𝑝𝑖𝑗 − 𝑝𝑖𝑗 | ≤ 𝜖 and 𝛼 ≥ 8/𝜋2 . The unitary 𝒰
requires 𝑃 iterations of 𝐴 with 𝑃 = 𝑂(1/𝜖). Amplitude estimation thus takes
̃ /𝜖). We can now apply theorem D.2 for the unitary 𝒰 to obtain
time 𝑇𝒰 = 𝑂(𝑇
a quantum state |Ψ𝑖𝑗 ⟩ such that,


‖|Ψ𝑖𝑗 ⟩ − |0⟩⊗𝐿 |𝑝𝑖𝑗 , 𝐺⟩‖2 ≤ 2Δ

̃ 𝑇 log(1/Δ)).
The running time of the procedure is 𝑂(𝑇𝒰 ln(1/Δ)) = 𝑂( 𝜖

Note that we can easily multiply the value 𝑝𝑖𝑗 by 4 in order to have the estimator
of the square distance of the normalized vectors or compute 1 − 2𝑝𝑖𝑗 for the
100 CHAPTER 5. A USEFUL TOOLBOX

normalized inner product. Last, the garbage state does not cause any problem
in calculating the minimum in the next step, after which this step is uncomputed.
The running time of the procedure is thus 𝑂(𝑇𝒰 ln(1/Δ)) = 𝑂( 𝑇𝜖 log(1/Δ)). The
last step is to show how to estimate the square distance or the inner product
of the unnormalized vectors. Since we know the norms of the vectors, we can
simply multiply the estimator of the normalized inner product with the product
of the two norms to get an estimate for the inner product of the unnormalized
vectors and a similar calculation works for the distance. Note that the absolute
error 𝜖 now becomes 𝜖 ‖𝑣𝑖 ‖ ∥𝑐𝑗 ∥ and hence if we want to have in the end an
absolute error 𝜖 this will incur a factor of ‖𝑣𝑖 ‖ ∥𝑐𝑗 ∥ in the running time. This
concludes the proof of the lemma.

𝑛,𝑑
Remark. Lemma 5.6 can be used to compute ∑𝑖,𝑗=1 |𝑖⟩|⟨𝑣𝑖 , 𝑐𝑗 ⟩⟩ where every
⟨𝑣𝑖 , 𝑐𝑗 ⟩ has error 𝜖 with an additional multiplicative cost of 𝑂(log(𝑛𝑑)).

Exercise 5.4. Can you use the Union bound (i.e. Theorem C.1 ) to prove the
following remark? The solution can be found in (Bellante and Zanero, 2022).

It is relatively simple to extend the previous algorithm to one that computes an


estimate of a quadratic form. We will consider the case where we have quantum
access to a matrix 𝐴 and compute the quadratic forms 𝑣𝑇 𝐴𝑣 and 𝑣𝑇 𝐴−1 𝑣. The
extension to the case when we have two different vectors, i.e. 𝑣𝑇 𝐴𝑢 and 𝑣𝑇 𝐴−1 𝑢
is trivial.

Lemma 5.7 (Estimation of quadratic forms). Assume to have quantum access


to a symmetric positive definite matrix 𝐴 ∈ ℝ𝑛×𝑛 such that ‖𝐴‖ ≤ 1, and to a
matrix 𝑉 ∈ ℝ𝑛×𝑑 . For 𝜖 > 0, there is a quantum algorithm that performs the
mapping |𝑖⟩|0⟩ ↦ |𝑖⟩|𝑠𝑖 ⟩, for |𝑠𝑖 − 𝑠𝑖 | ≤ 𝜖, where 𝑠𝑖 is either:

• (|𝑣𝑖 ⟩, 𝐴|𝑣𝑖 ⟩) in time 𝑂( 𝜇(𝐴)


𝜖 )
• (|𝑣𝑖 ⟩, 𝐴 |𝑣𝑖 ⟩) in time 𝑂( 𝜇(𝐴)𝜅(𝐴)
−1
𝜖 )

The algorithm can return an estimate of (𝑣𝑖 , 𝐴𝑣𝑖 ) such that (𝑣𝑖 , 𝐴𝑣𝑖 )−(𝑣𝑖 , 𝐴𝑣𝑖 ) ≤
𝜖 using quantum access to the norm of the rows of 𝑉 by increasing the runtime
2
by a factor of ‖𝑣𝑖 ‖ .

Proof. We analyze first the case where we want to compute the quadratic form
with 𝐴, and after the case for 𝐴−1 . Recall that the matrix 𝐴 can be decomposed
in an orthonormal basis |𝑢𝑖 ⟩. We can use theorem 5.11 to perform the following
mapping:
5.5. DISTANCES, INNER PRODUCTS, NORMS, AND QUADRATIC FORMS101

1 𝑛 1 𝑛
|𝑖⟩|𝑣𝑖 ⟩|0⟩ = |𝑖⟩ ∑ 𝛼𝑖𝑗 |𝑢𝑗 ⟩|0⟩ ↦ |𝑖⟩ ∑ (𝜆𝑖 𝛼𝑖𝑗 |𝑢𝑖 , 0⟩ + √1 − 𝛾 2 |𝐺, 1⟩) =
𝑁𝑖 𝑗 𝑁𝑖 𝑖
(5.5)
|𝑖⟩( ‖𝐴𝑣𝑖 ‖ |𝐴𝑣𝑖 , 0⟩ + √1 − 𝛾 2 |𝐺, 1⟩) = |𝑖⟩|𝜓𝑖 ⟩,
(5.6)

𝑛
where 𝑁𝑖 = √∑𝑗 𝛼2𝑖𝑗 . We define |𝜙𝑖 ⟩ = |𝑣𝑖 , 0⟩. Using controlled operations, we
can then create the state:

1
|𝑖⟩ (|0⟩(|𝜙𝑖 ⟩ + |𝜓𝑖 ⟩) + |1⟩(|𝜙𝑖 ⟩ − |𝜓𝑖 ⟩)) (5.7)
2
It is simple to check that, for a given register |𝑖⟩, the probability of measuring
0 is:
1 + ‖𝐴𝑣𝑖 ‖ ⟨𝐴𝑣𝑖 |𝑣𝑖 ⟩
𝑝𝑖 (0) =
2

We analyze the case where we want to compute the quadratic form for 𝐴−1 . For
a 𝐶 = 𝑂(1/𝜅(𝐴)), we create instead the state:
𝑛
1 𝐶
|𝑖⟩ ∑( 𝛼 |𝑣 , 0⟩ + √1 − 𝛾 2 |𝐺, 1⟩) = |𝑖⟩|𝜓𝑖 ⟩ (5.8)
𝑛
√∑𝑖 𝛼2𝑖 𝑖
𝜆𝑖 𝑖 𝑖

1 √ √
𝑈2 |𝑖⟩|0⟩ ↦ |𝑖⟩ ( 𝛼|𝑝𝑖 (0), 𝑦𝑖 , 0⟩ + 1 − 𝛼|𝐺𝑖 , 1⟩) (5.9)
2

and estimate 𝑝𝑖 (0) such that |𝑝𝑖 (0) − 𝑝𝑖 (0)| < 𝜖 for the case of 𝑣𝑖𝑇 𝐴𝑣𝑖 and
we choose a precision 𝜖/𝐶 for the case of 𝑣𝑖𝑇 𝐴−1 𝑣𝑖 to get the same accuracy.
Amplitude estimation theorem, i.e. theorem @ref(thm:ampest_orig) fails with
probability ≤ 𝜋82 . The runtime of this procedure is given by combining the
runtime of creating the state |𝜓𝑖 ⟩, amplitude estimation, and the median
lemma. Since the error in the matrix multiplication step is negligible, and
assuming quantum access to the vectors is polylogarithmic, the final runtime is
𝑂(log(1/𝛿)𝜇(𝐴) log(1/𝜖2 )/𝜖), with an additional factor 𝜅(𝐴) for the case of the
quadratic form of 𝐴−1 .
Note that if we want to estimate a quadratic form of two unnormalized vectors,
we can just multiply this result by their norms. Note also that the absolute
2
error 𝜖 now becomes relative w.r.t the norms, i.e. 𝜖 ‖𝑣𝑖 ‖ . If we want to obtain
an absolute error 𝜖′ , as in the case with normalized unit vectors, we have to
2
run amplitude estimation with precision 𝜖′ = 𝑂(𝜖/ ‖𝑣𝑖 ‖ ). To conclude, this sub-
routine succeeds with probability 1 − 𝛾 and requires time 𝑂( 𝜇(𝐴) log(1/𝛾)
𝜖
log(1/𝜖? )
),
1
102 CHAPTER 5. A USEFUL TOOLBOX

with an additional factor of 𝜅(𝐴) if we were to consider the quadratic form for
2
𝐴−1 , and an additional factor of ‖𝑣𝑖 ‖ if we were to consider the non-normalized
vectors 𝑣𝑖 . This concludes the proof of the lemma.

Note that this algorithm can be extended by using another index register to
query for other vectors from another matrix 𝑊 , for which we have quantum
access. This extends the capabilities to estimating inner products in the form
|𝑖⟩|𝑗⟩|𝑤𝑖𝑇 𝐴𝑣𝑖 ⟩.

5.5.2 Inner product and l1-norm estimation with query


access
Lemma 5.8 (Quantum state preparation and norm estimation). Let 𝜂 > 0.
Given a non-zero vector 𝑢 ∈ [0, 1]𝑁 , with max𝑗 𝑢𝑗 = 1. Given quantum access
to 𝑢 via the operation |𝑗⟩|0⟩̄ → |𝑗⟩|𝑢𝑗 ⟩ on 𝑂(log 𝑁 + log 1/𝜂) qubits, where 𝑢𝑗 is
encoded to additive accuracy 𝜂. Then:
𝑁 √
• There exists a unitary operator that prepares the state √1𝑁 ∑𝑗=1 |𝑗⟩ ( 𝑢𝑗 |0⟩ + √1 − 𝑢𝑗 |1⟩)
with two queries and number of gates 𝑂(log 𝑁 + log 1/𝜂). Denote this
unitary by 𝑈𝜒 .
• Let 𝜖 > 0 such that 𝜂 ≤ 𝜖/(2𝑁 ) and 𝛿 ∈ (0, 1). There exists a quantum
algorithm that provides an estimate Γ𝑢 of the ℓ1 -norm ‖𝑢‖1 such that
|‖𝑢‖√1 − Γ𝑢 | ≤ 𝜖‖𝑢‖1 , with probability

at least 1 − 𝛿. The algorithm requires
𝑁 ̃ 𝑁
𝑂( 𝜖 log(1/𝛿)) queries and 𝑂( 𝜖 log (1/𝛿)) gates.
• Let 𝜉 ∈ (0, 1] such that 𝜂 ≤ 𝜉/4𝑁 and 𝛿 ∈ (0, 1). An approximation
𝑁 𝑁 𝑢
|𝑝⟩̃ = ∑𝑗=1 √𝑝𝑗̃ |𝑗⟩ to the state |𝑢⟩ ∶= ∑𝑗=1 √ ‖𝑢‖𝑗 |𝑗⟩ can be prepared
√ 1

with probability 1 − 𝛿, using 𝑂( 𝑁 log(1/𝛿)) calls to the unitary of (i)



̃ 𝑁 log(1/𝜉) log (1/𝛿)) gates. The approximation in ℓ -norm of the
and 𝑂( 1
𝑢
probabilities is ∥𝑝̃ − ‖𝑢‖ ∥ ≤ 𝜉.
1 1

Proof. For the first point, prepare a uniform superposition of all |𝑗⟩ with
𝑂(log 𝑁 ) Hadamard gates. With the quantum query access, perform

1 𝑁 1 𝑁
√ ∑ |𝑗⟩|0⟩̄ → √ ∑ |𝑗⟩|𝑢𝑗 ⟩|0⟩
𝑁 𝑗=1 𝑁 𝑗=1

1 𝑁
→ √ ∑ |𝑗⟩|𝑢𝑗 ⟩ (√𝑢𝑗 |0⟩ + √1 − 𝑢𝑗 |1⟩) .
𝑁 𝑗=1

The steps consist of an oracle query and a controlled rotation. The rotation is
well-defined as 𝑢𝑗 ≤ 1 and costs 𝑂(log 1/𝜂) gates. Then uncompute the data
register |𝑢𝑗 ⟩ with another oracle query.
5.5. DISTANCES, INNER PRODUCTS, NORMS, AND QUADRATIC FORMS103


For part 2, define a unitary 𝒰 = 𝑈𝜒 (𝟙 − 2|0⟩⟨̄ 0|)
̄ (𝑈𝜒 ) , with 𝑈𝜒 from part 1,
and here 𝟙 is the identiy matrix. Define another unitary by 𝒱 = 𝟙 − 2𝟙 ⊗ |0⟩⟨0|.
Using 𝐾 applications of 𝒰 and 𝒱, amplitude estimation 5.4 allows to provide
√𝑎(1−𝑎) 𝜋2
an estimate 𝑎̃ of the quantity 𝑎 = ‖𝑢‖
𝑁 to accuracy |𝑎 ̃ − 𝑎| ≤ 2𝜋
1
𝐾 +𝐾 2.

Following the idea in (van Apeldoorn et al., 2020) (of dividing the elements
that we are summing using amplitude estimation by their maximum, √ that we
can find using the finding the minimum subroutine), take 𝐾 > 6𝜋 𝜖 𝑁 , which
obtains
𝜋 √ 𝜋 𝜖 1 √ 𝜖 1
|𝑎̃ − 𝑎| ≤ (2 𝑎 + ) < √ (2 𝑎 + √ )
𝐾 𝐾 6 𝑁 6 𝑁
𝜖 1 √ 𝜖√‖𝑢‖1
≤ √ (3 𝑎) = . (5.10)
6 𝑁 2𝑁
𝜖‖𝑢‖1
Since ‖𝑢‖1 ≥ 1 by assumption, we have |𝑎̃ − 𝑎| ≤ 2𝑁 .

Also, there is an inaccuracy arising from the additive error 𝜂 of each 𝑢𝑗 . As it was
assumed that 𝜂 ≤ 𝜖/(2𝑁 ), the overall multiplicative error 𝜖 is obtained for the es-
timation. For performing

a single run of amplitude estimation

with 𝐾 steps, we
require 𝑂(𝐾) = 𝑂( 𝜖𝑁 ) queries to the oracles and 𝑂 ( 𝜖𝑁 (log 𝑁 + log(𝑁 /𝜖)))
gates.
For part 3, rewrite the state from part 1 as
𝑁 𝑁
𝑢 1 − 𝑢𝑗
√ ‖𝑢‖1 ∑√ 𝑗 |𝑗⟩|0⟩ + √1 − ‖𝑢‖1 ∑ √ |𝑗⟩|1⟩.
𝑁 𝑗=1 ‖𝑢‖1 𝑁 𝑗=1 𝑁 − ‖𝑢‖1

Now amplify the |0⟩ part using Amplitude Amplification (Brassard et al., 2002)
via the exponential search technique without knowledge of the normalization, to
𝑁 𝑢
prepare ∑𝑗=1 |𝑗⟩√ ‖𝑢‖𝑗 with success probability 1−𝛿. The amplification requires
1

𝑁

𝑂(√ ‖𝑢‖ log(1/𝛿)) = 𝑂( 𝑁 log(1/𝛿)) calls to the unitary of part 1, as ‖𝑢‖1 ≥ 1.
1
The gate complexity derives from the gate complexity of part 1.
Denote the 𝜂-additive approximation to 𝑢𝑗 by 𝑢̃𝑗 , and evaluate the ℓ1 -distance
𝑢
of the probabilities. First, |‖𝑢‖1 − ‖𝑢‖̃ 1 | ≤ 𝑁 𝜂. One obtains ∥𝑝̃ − ‖𝑢‖ ∥ =
1 1
𝑢̃ 𝑢 𝑢̃ 𝑢𝑗 𝑢 𝑢𝑗 𝑁𝜂 𝑁𝜂
∥ ‖𝑢‖
̃ − ‖𝑢‖1 ∥1 ≤ ∑𝑗 ∣ ‖𝑢‖̃ 𝑗 − ‖𝑢‖̃ 1 ∣ + ∑𝑗 ∣ ‖𝑢‖̃ 𝑗 − ‖𝑢‖1 ∣ ≤ ‖𝑢‖̃ 1 + ‖𝑢‖̃ 1 .
1 1 1

We also obtain
1 1 2
≤ ≤
‖𝑢‖̃ 1 ‖𝑢‖1 − 𝑁 𝜂 ‖𝑢‖1
𝑢
for 𝜂 ≤ ‖𝑢‖1 /2𝑁 .$ Since 𝜂 ≤ ‖𝑢‖1 𝜉/(4𝑁 ), the distance is ∥𝑝̃ − ‖𝑢‖1 ∥1 ≤ 𝜉 as
desired.

Lemma 5.9 (Quantum inner product estimation with relative accuracy). Let
𝜖, 𝛿 ∈ (0, 1). Given quantum access to two vectors 𝑢, 𝑣 ∈ [0, 1]𝑁 , where 𝑢𝑗 and
104 CHAPTER 5. A USEFUL TOOLBOX

𝑣𝑗 are encoded to additive accuracy 𝜂 = 𝑂1/𝑁 . Then, an estimate 𝐼 for the


inner product can be provided such that |𝐼 − 𝑢 ⋅ 𝑣/‖𝑢‖1 | ≤√𝜖 𝑢 ⋅ 𝑣/‖𝑢‖1 with success
probability 1 − 𝛿. This estimate is obtained with 𝑂 ( 𝜖𝑁 log ( 1𝛿 )) queries and

𝑂̃ ( 𝑁 log ( 1 )) quantum gates.
𝜖 𝛿

Proof. Via lemma 5.2, determine 𝑢max with success probability 1 − 𝛿 with
√ √
̃ ( 𝑁 log ( 1 )) quantum gates.
𝑂 ( 𝑁 log 1𝛿 ) queries and 𝑂 𝛿
𝑢
Apply lemma 5.8 with the vector 𝑢max to obtain an estimate Γ𝑢 of the norm
𝑢
∥𝑢 ∥ to relative accuracy 𝜖𝑢 = 𝜖/2 with success probability 1 − 𝛿.
max 1
√ √
This estimation takes 𝑂( 𝑁 ̃
log ( 1𝛿 )) queries and 𝑂( 𝑁
log ( 1𝛿 )) quantum gates.
𝜖 𝜖

Define the vector 𝑧 with 𝑧𝑗 = 𝑢𝑗 𝑣𝑗 . Via lemma 5.2, determine 𝑧max with success
√ √
probability 1−𝛿 with 𝑂 ( 𝑁 log 1𝛿 ) queries and 𝑂̃ ( 𝑁 log ( 1 )) quantum gates.
𝛿
If 𝑧max = 0 up to numerical accuracy, the estimate is 𝐼 = 0 and we are done.
Otherwise, apply lemma 5.8 with the vector 𝑧 𝑧 to obtain an estimate Γ𝑧 of the
max

norm ∥ 𝑧 𝑧 ∥ to relative accuracy 𝜖𝑧 = 𝜖/2 with success probability 1 − 𝛿. This


max 1 √ √
estimation takes 𝑂 ( 𝑁 ̃(
log ( 1𝛿 )) queries and 𝑂 𝑁
log ( 1𝛿 )) quantum gates.
𝜖 𝜖

With lemma D.1, which gives a nice bound for the ratio between two relative
errors, we have

Γ𝑧 𝑢 𝑢⋅𝑣 𝑢max 𝑢 ⋅ 𝑣 𝜖𝑧 + 𝜖𝑢
∣ − max ∣≤ (5.11)
Γ𝑢 𝑧max ‖𝑢‖1 𝑧max ‖𝑢‖1 (1 − 𝜖𝑢 )
𝑢 𝑢⋅𝑣
≤ 2𝜖 max , (5.12)
𝑧max ‖𝑢‖1

since 𝜖𝑢 < 1/2. Set

𝑧max Γ𝑧
𝐼= , (5.13)
𝑢max Γ𝑢

and we have |𝐼 − 𝑢 ⋅ 𝑣/‖𝑢‖1 | ≤ 2𝜖 𝑢 ⋅ 𝑣/‖𝑢‖1 . The total success probability of


the four probabilistic steps is at least 1 − 4𝛿 via a union bound (theorem C.1).
Choosing 𝜖 → 𝜖/2 and 𝛿 → 𝛿/4 leads to the result.

Lemma 5.10 (Quantum inner product estimation with additive accuracy).


Let 𝜖, 𝛿 ∈ (0, 1). Given quantum access to a non-zero vector 𝑢 ∈ [0, 1]𝑁 and
another vector 𝑣 ∈ [−1, 1]𝑁 , where 𝑢𝑗 and 𝑣𝑗 are encoded to additive accuracy
𝜂 = 𝑂1/𝑁 . Then, an estimate 𝐼 for the inner product can be provided such that
|𝐼 −√𝑢 ⋅ 𝑣/‖𝑢‖1 | ≤ 𝜖 with success probability

1 − 𝛿. This estimate is obtained with
𝑁 1 ̃ 𝑁 1
𝑂 ( 𝜖 log ( 𝛿 )) queries and 𝑂 ( 𝜖 log ( 𝛿 )) quantum gates.
Note that as a byproduct, the value 𝑢max and an estimate of ‖𝑢/𝑢max ‖1 with
relative accuracy 𝜖 can be provided with probability at least 1 − 𝛿.
5.6. HAMILTONIAN SIMULATION 105

Proof. Via lemma 5.2, determine ‖𝑢‖max with success probability 1 − 𝛿 with
√ √
̃ ( 𝑁 log ( 1 ) log ( 1 )) quantum gates. Apply
𝑂 ( 𝑁 log 1𝛿 ) queries and 𝑂 𝜂 𝛿
𝑢
lemma 5.8 with the vector 𝑢max to obtain an estimate Γ𝑢 of the norm ∥ 𝑢 𝑢 ∥
max 1
to relative accuracy 𝜖𝑢 = 𝜖/2 with success probability 1 − 𝛿.
√ √
This estimation takes 𝑂 ( 𝑁 ̃(
log ( 1𝛿 )) queries and 𝑂 𝑁
log ( 1𝛿 )) quantum
𝜖 𝜖
gates.
Similarily, consider the vector 𝑧 with elements 𝑧𝑗 ∶= 𝑢𝑗 (𝑣𝑗 + 3) ∈ [0, 4]. De-

termine ‖𝑧‖max with success probability 1 − 𝛿 with 𝑂 ( 𝑁 log 1𝛿 ) queries and

̃ ( 𝑁 log ( 1 )) quantum gates. Apply lemma 5.8 with the vector 𝑧/𝑧
𝑂 𝛿 max to
obtain an estimate Γ𝑧 of the norm ‖𝑧/𝑧max ‖1 to relative accuracy 𝜖𝑧 = 𝜖/2 with
success probability 1 − 𝛿.
√ √
This estimation takes 𝑂 ( 𝑁 ̃(
log ( 1𝛿 )) queries and 𝑂 𝑁
log ( 1𝛿 )).
𝜖 𝜖

It takes some steps to see that the exact quantities are related via
𝑧
𝑢⋅𝑣 𝑧max ‖ 𝑧max ‖1
= − 3. (5.14)
‖𝑢‖1 𝑢max ‖ 𝑢 𝑢 ‖1
max

𝑧max Γ𝑧
Considering the estimator 𝐼 = 𝑢max Γ𝑢 − 3, from lemma D.1, we have

𝑢⋅𝑣 𝑧max Γ𝑧 ‖ 𝑧 𝑧 ‖1
∣𝐼 − ∣= ∣ − max ∣ (5.15)
‖𝑢‖1 𝑢max Γ𝑢 ‖ 𝑢 𝑢 ‖1
max

𝜖𝑢 + 𝜖𝑧 ‖𝑧‖1
≤ ≤ 8𝜖.
1 − 𝜖𝑢 ‖𝑢‖1

In the last steps we have used the observation that

‖𝑧‖1 ∑𝑗 𝑢𝑗 (𝑣𝑗 + 3) 4 ∑ 𝑗 𝑢𝑗
≡ ≤ = 4, (5.16)
‖𝑢‖1 ∑𝑗 𝑢𝑗 ∑𝑗 𝑢𝑗
√ √
and 𝜖𝑢 < 1/2. All steps together take 𝑂 ( 𝜖𝑁 log 1𝛿 ) queries and 𝑂 ̃ ( 𝑁 log ( 1 ))
𝜖 𝛿
gates. The total success probability of all the probabilistic steps is at least 1−4𝛿
via a union bound. Choosing 𝜖 → 𝜖/8 and 𝛿 → 𝛿/4 leads to the result.

5.6 Hamiltonian simulation


These notes based on Childs’ Lecture notes, i.e. (Andrew, 2017), Section 5

5.6.1 Introduction to Hamiltonians


The only way possible to start a chapter on Hamiltonian simulation would be
to start from the work of Feynman, who had the first intuition on the power
106 CHAPTER 5. A USEFUL TOOLBOX

of quantum mechanics for simulating physics with computers. We know that


the Hamiltonian dynamics of a closed quantum system, weather its evolution
changes with time or not is given by the Schrödinger equation:

𝑑
|𝜓(𝑡)⟩ = 𝐻(𝑡)|𝜓(𝑡)⟩
𝑑𝑡

Given the initial conditions of the system (i.e. |𝜓(0)⟩ ) is it possible to know the
state of the system at time 𝑡 ∶ |𝜓(𝑡)⟩ = 𝑒−𝑖(𝐻1 𝑡/𝑚) |𝜓(0)⟩.
As you can imagine, classical computers are supposed to struggle to simulate
the process that builds |𝜓(𝑡)⟩, since this equation describes the dynamics of
any quantum system, and we don’t think classical computers can simulate that
efficiently for any general Hamiltonian 𝐻. But we understood that quantum
computers can help to simulate the dynamics of another quantum system.
Why we might want to do that?
An example would be the following. Imagine you are a quantum machine learn-
ing scientist, and you have just found a new mapping between an optimization
problem and an Hamiltonian dynamics, and you want to use quantum computer
to perform the optimization (Otterbach et al., 2017). You expect a quantum
computers to run the Hamiltonian simulation for you, and then sample useful
information from the resulting quantum sate. This result might be fed again
into your classical algorithm to perform ML related task, in a virtuous cycle of
hybrid quantum-classical computation, which we will discuss more in another
chapter.
Another example, perhaps more akin to the original scope of Hamiltonian sim-
ulation, is related to quantum chemistry. Imagine that are a chemist, and you
have developed a hypothesis for the Hamiltonian dynamics of a chemical com-
pound. Now you want to run some experiments to see if the formula behaves
according to the experiments (and you cannot simulate numerically the exper-
iment). Or maybe you are testing the properties of complex compounds you
don’t want to synthesize.
We can formulate the problem of Hamiltonian simulation in this way:
Definition 5.3 (Hamiltonian simulation problem). Given a state |𝜓(0)⟩ and
an Hamiltonian 𝐻, obtain a state |𝜓(𝑡)⟩ such that ‖|𝜓(𝑡)⟩ − 𝑒−𝑖𝐻𝑡 |𝜓(0)⟩‖ ≤ 𝜖 in
some norm.
(Note that also this problem can be reformulated in the context of density ma-
trices, where usually the trace norm is used as a distance between quantum
states).
This leads us to the definition of efficiently simulable Hamiltonian:
Definition 5.4 (Hamiltonian simulation). Given a state |𝜓(0)⟩ and an Hamilto-
nian 𝐻 acting on 𝑛 qubits, we say 𝐻 can be efficiently simulated if, ∀𝑡 ≥ 0, ∀𝜖 ≥
5.6. HAMILTONIAN SIMULATION 107

0 there is a quantum circuit 𝑈 such that ‖𝑈 − 𝑒−𝑖𝐻𝑡 ‖ < 𝜖 using a number of


gates that is polynomial in 𝑛, 𝑡, 1/𝜖.
108 CHAPTER 5. A USEFUL TOOLBOX
Part II

Quantum Machine Learning

109
Chapter 6

Quantum perceptron

Contributors: Armando Bellante, Samantha Buck

Figure 6.1: This section is a work in progress

The following chapter is an investigation into the quantum version of the classical
perceptron algorithm, and is based on the previous works of (Kapoor et al., 2016)

The chapter is organized as follows: we first introduce the fundamentals of


the classical version of the perceptron, then we present the online quantum
perceptron algorithm and the version space quantum perceptron algorithm.

111
112 CHAPTER 6. QUANTUM PERCEPTRON

6.1 Classical perceptron


The perceptron is a machine learning algorithm that can be thought of as the
most basic fundamental building block of more complex artificial neural net-
works (ANNs), or alternatively as a very simple form of neural network in and
of itself.
The perceptron is a linear classifier used for binary predictions: its goal is to
classify incoming data in one of two given categories. Like in any supervised
learning tasks, the classifier is trained using a dataset of couples data points-
labels and its goal is to generalize to previously unseen data points.
Unlike more complex learners, the textbook perceptron can only deal with lin-
early separable datasets. A dataset is said to be linearly separable if there exists
at least one hyperplane that can successfully separate the elements of the dataset
into distinct groups.
Two sets, A and B, in an 𝑛−space are linearly separable only if there exists
an (𝑛 − 1) hyperplane that shatters the two sets. In a 2-dimension space, the
hyperplane is a line. In a 3D space it is a plane, and so on. (Note that in 2D,
for instance, it could not be a curve! The linearity of this classifier make it so
that you can only shatter the sets using hyperplanes. One could overcome this
limitation by introducing kernels in the perceptron formulation or by projecting
the data in a space, via “feature engineering”, so that they are linearly separable
in the new space.)
Let us introduce the concept of linear separability using proper mathematical
formalism.
Definition 6.1 (Linear Separability). Two sets A and B of points in an 𝑛-
dimensional space are called absolutely linearly separable if 𝑛 + 1 real numbers
𝑤1 , …, 𝑤𝑛 , 𝑏 exist, such that every point (𝑥1 , 𝑥2 , …, 𝑥𝑛 ) in A satisfies :
𝑛
∑ 𝑤𝑖 𝑥𝑖 > 𝑏 (6.1)
𝑖=1

every point B satisfies :


𝑛
∑ 𝑤𝑖 𝑥𝑖 < 𝑏 (6.2)
𝑖=1

𝑛
The general equation of the separation hyperplane would then be ∑𝑖=1 𝑤𝑖 𝑥𝑖 +
𝑏 = 0. The numbers 𝑤𝑖 and 𝑏 are often referred to as weights and bias respec-
tively. Without the bias term, the hyperplane that 𝑤 defines would always have
to go through the origin. It is common practise to absorb 𝑏 into the vector 𝑤 by
adding one additional constant dimension to the data points and the weigths
𝑥 𝑤
vector. In doing so, 𝑥 becomes [ ], and 𝑤 becomes [ ].
1 𝑏
6.1. CLASSICAL PERCEPTRON 113

We can then verify that their inner product will yield,



𝑥 𝑤
[ ] [ ] = 𝑤⊤ 𝑥 + 𝑏 (6.3)
1 𝑏

From now on, we will write 𝑥 and 𝑤 assuming the bias is included in this way.
We will soon focus on how the perceptron learns the weights 𝑤𝑖 and 𝑏. However,
assume for a while that the perceptron knows these numbers (i.e., it has been
trained) and only needs to use them to classify the incoming data points in one
of the two classes.
Given a data point 𝑥, its coordinates 𝑥𝑖 are weighted in a sum ∑ 𝑤𝑖 𝑥𝑖 and this
result is passed to one “neuron” that has an activation function 𝑔. The output
of this activation function 𝑦 = 𝑔(∑ 𝑤𝑖 𝑥𝑖 ) is a binary value that represents one of
the two possible classes. In general, the activation function can take many forms
(ex: the sigmoid function, hyperbolic, step function, etc.) and return whichever
couple of values (e.g., {0,1}, {-1,1}). For the remainder of this chapter, we will
assume the sign function is used.
In other words, given a data point 𝑥 and the weights 𝑤, the perceptron classifies
the point in the following way:

𝑦 (𝑥) = sign (𝑤⊤ 𝑥) (6.4)

where 𝑦(𝑥) = −1 means that the sample belongs to one class and 𝑦(𝑥) = +1
means it belongs to the other, by a matter of convention.
The hyperplane identified by the weigths 𝑤 is also called decision boundary
as, using the sign activation function, the position of the data points w.r.t. it
determines the output class.

6.1.1 Training the perceptron


In this book, we focus only on the online training algorithm, as this is handy for
our quantum algorithms. We invite the interested reader to read more about
the batch training.
The perceptron, like we should do, learns from its own errors but it also need
somewhere to start from. Its training process happens in the following way. We
initiate the perceptron with some random weights, feed it with many training
couples data point-label, and let it shot its guess for each point. If the guess is
correct, nothing happens. If the guess is wrong, the weights need to be updated.
Using the sign function, and considering a couple data point-label (𝑥(𝑖) ,
𝑦(𝑖) ) from the training set, the perceptron classifies the point correctly if
𝑦(𝑖) (𝑤⊤ 𝑥(𝑖) ) > 0 (this is because the class 𝑦(𝑖) has been encoded using values in
{−1, +1}).
114 CHAPTER 6. QUANTUM PERCEPTRON

If a classification error is detected, the weights get modified by an amount that


is proportional to the input 𝑥(𝑖) . This process continues for a certain number of
iterations, known as “epochs.” In the online learning regime, which is the one
we investigate in this chapter, the update to the weight and bias vectors occurs
for each and every misclassified data point iteratively throughout every epoch.
During an epoch, each training data point is considered once. The training
ends when there are no misclassified points in one epoch. We remind the reader
that the training goal is to determine the weights that produce a linear decision
boundary that correctly classifies the predictions.
The following pseudocode highlights the structure of the perceptron algorithm
and identifies at which step in the processing schedule the error calculation and
subsequent parametric updates occur.
The update is computed by adding the amount Δ𝑤𝑖 = 𝜂 ⋅ 𝑒𝑟𝑟𝑜𝑟 ⋅ 𝑥(𝑖) to the
weights 𝑤, where 𝜂 is a learning rate end 𝑒𝑟𝑟𝑜𝑟 = 𝑤⊤ 𝑥 − 𝑦(𝑖) . Notice that if
(𝑖)
𝑒𝑟𝑟𝑜𝑟 and 𝑥𝑗 have the same sign, the increment of 𝑤𝑗 is positive (the strength
increases) and otherwise decreases.
To sum up in an overall picture, the perceptron iteratively updates the linear
boundary function (i.e., the hyperplane equation) that acts as the classifying
condition between the two classes of the data, until no errors are detected and
the algorithm converges. The training happens by minimizing the error on the
training data set provided to the algorithm. Ultimately the identification of the
weights allows for the distinction of data points belonging on one side of the
boundary or the other.
Of course, if the data were not linearly separable, the training algorithm would
run forever. The online training requires the existence of a margin between the
two classes.
Definition 6.2 (Margin of a dataset). Let {(𝑥(1) , 𝑦(1) ), (𝑥(2) , 𝑦(2) ), … , (𝑥(𝑛) , 𝑦(𝑛) )}
a dataset of 𝑛 couples data points-labels, with 𝑥(𝑖) ∈ ℝ𝑚 and 𝑦(𝑖) ∈ {−1, +1}
for all 𝑖 ∈ [𝑛]. We define the margin of this dataset as:

𝑦(𝑖) 𝑞 ⊤ 𝑥(𝑖)
𝛾 = max min . (6.5)
𝑚
𝑞∈ℝ 𝑖∈[𝑛] ‖𝑞‖‖𝑥(𝑖) ‖

It naturally follows that a dataset is linearly separable if and only if its margin
is different from 0.

6.2 Online quantum perceptron


General Idea: Uses Grover’s search to more efficiently search for misclassified
data points in the data set. This allows the perceptron algorithm to more
quickly converge on a correct classifying hyperplane.
6.2. ONLINE QUANTUM PERCEPTRON 115

Where the quantum version of the online perceptron differs from that of its
classical analogue is in how the data points are accessed for use within each
individual epoch and in the number of times the perceptron needs to be used
to classify the data points. In the classical version of the online perceptron, the
training points are fed into the classification algorithm successively one by one,
and a weight update is performed every time a point is misclassified. Imagine
we have 𝑛 data points and only the last ones of the epoch get misclassified: this
requires 𝑂(𝑛) evaluations of the classification function before the weights can
be updated. The quantum version of the online perceptron deviates away from
this mechanism of accessing the data points within an epoch in a ”one at a time”
fashion and lowers the number of time we need to call the classification func-
tion. The idea is to access the data points in superposition in a quantum state
and apply the classification function to this state, so to apply the classification
function linearly to all the data points at once, searching for the misclassified
one.
Assume we have a dataset of {𝑥(1) , … , 𝑥(𝑁) } vectors and {𝑦(1) , … , 𝑦(𝑁) } labels.
Without loss of generality, we assume that the training set consists of unit
vectors and one-bit labels. Furthermore, we assume that the {𝑥(1) , … , 𝑥(𝑁) }
vectors can be classically represented using 𝐵 bits. Then, with |𝑥(1) ⟩, … , |𝑥(𝑛) ⟩
we denote the (𝐵 + 1)-bit representations of the data vectors, followed by the
label bit. Note that each state |𝑥(𝑗) ⟩ corresponds to a state of the computational
basis of the (𝐵 + 1)-dimensional Hilbert space.
Next, in order to construct our desired online quantum perceptron, we will need
to have a mechanism with which to access the training data. We assume that
the data is accessible via the following oracle 𝑈 .

𝑈 |𝑗⟩|0⟩ = |𝑗⟩|𝑥(𝑗) ⟩ (6.6)


† (𝑗)
𝑈 |𝑗⟩|𝑥 ⟩ = |𝑗⟩|0⟩ (6.7)

As we discussed in previous chapters, because 𝑈 and 𝑈 † are linear operators,


𝑛 𝑛
we have that 𝑈 √1𝑛 ∑𝑗=1 |𝑗⟩|0⟩ = √1𝑛 ∑𝑗=1 |𝑗⟩|𝑥(𝑗) ⟩. A quantum computer can
therefore access each training vector simultaneously using a single operation,
while only requiring enough memory to store one of the |𝑥(𝑗) ⟩.
Next, we need a mechanism to test if a given weight configuration 𝑤, correctly
classifies a data point. First of all, we need to build a quantum circuit that im-
plements the Boolean function 𝑓 ∶ (𝑤, 𝑥(𝑗) , 𝑦(𝑗) ) ↦ {0, 1}, where 𝑓 (𝑤, 𝑥(𝑗) , 𝑦(𝑗) )
is 1 if and only if the perceptron with weights 𝑤 misclassifies the training sample
(𝑥(𝑗) , 𝑦(𝑗) ). This circuit needs to adapt to the current weight configuration 𝑤,
which can be either “hardcoded” in the circuit (and the circuit would need to
be updated everytime the vector changes) or be given as an input via use of
extra qubits. Given access to such circuit, then we can define an operator, ℱ𝑤 :
(𝑗)
,𝑦(𝑗) )
ℱ𝑤 |𝑥(𝑗) ⟩ = (−1)𝑓(𝑤,𝑥 |𝑥(𝑗) ⟩. (6.8)
116 CHAPTER 6. QUANTUM PERCEPTRON

ℱ𝑤 is easily implemented on a quantum computer using a multiply controlled


phase gate and a quantum implementation of the perceptron classification algo-
rithm 𝑓𝑤 .
Now, we can use the unitary ℱ𝑤 as an oracle for Grover’s algorithm (see Section
5.2). This allows for a quadratic reduction in the number of times that the
training vectors need to be accessed by the classification function.
The following pseudocode sums up the online quantum perceptron algorithm.
This algorithm gives birth to the following theorem, which formalizes the
quadratic speedup.
Theorem 6.1 (Online quantum perceptron (Kapoor et al., 2016)). Given a
training set that consists of unit vectors {𝑥(1) , … , 𝑥(𝑛) } and labels {𝑦(1) , … , 𝑦(𝑛) },
with margin 𝛾, the number of applications of 𝑓 needed to learn the weights 𝑤
such that 𝑃 (∃𝑗 ∶ 𝑓𝑤 (𝑥(𝑗) , 𝑦(𝑗) ) = 1) ≤ 𝜖 using a quantum computer is 𝑛quant
where √
√ 𝑛 1
Ω( 𝑛) ∋ 𝑛quant ∈ 𝑂 ( 2 log ( 2 )) (6.9)
𝛾 𝜖𝛾
whereas the number of queries to 𝑓 needed in the classical setting, 𝑛class , where
the training vectors are found by sampling uniformly from the training data is
bounded by
𝑛 1
Ω(𝑛) ∋ 𝑛class ∈ 𝑂 ( 2 log ( 2 )) . (6.10)
𝛾 𝜖𝛾

Note that if the training data is supplied as a stream (as in the standard on-
line model), then the upper bound for the classical model changes to 𝑛class ∈
𝑂 (𝑛/𝛾 2 ) because all 𝑛 training vectors can be deterministically checked to see
if they are correctly classified by the perceptron. A quantum advantage is
2
therefore obtained if 𝑛 ≫ log (1/𝜖𝛾 2 ). (see (Kapoor et al., 2016) for a better
explaination.)
Theorem 6.1 can easily be proved using Grover’s theorem (with exponential
search, since we do not know the exact number of answers to the search problem.
i.e., multiple data points can be misclassified) and two lemmas.
Lemma 6.1. Given only the ability to sample uniformly from the training
vectors, the number of queries to 𝑓𝑤 needed to find a training vector that the
curnent perceptron model fails to classify correctly, or conclude that no such
example exists, with probability 1 − 𝜖𝛾 2 is at most 𝑂 (𝑛 log (1/𝜖𝛾 2 )).
Lemma 6.2. Assuming that the training vectors {𝑥(1) , … , 𝑥(𝑛) } are unit vectors
and that they are drawn from two classes separated by a maryin of 𝛾 in feature
space, the online quantum perceptron algorithm will either update the perceptron
weights, or conclude that the current model provides a separating hyperplane
between
√ the two classes, using a number of queries to 𝑓𝑤 that is bounded above
by 𝑂 ( 𝑛 log (1/𝜖𝛾 2 )) with probability of failure at most 𝜖𝛾 2 .
6.3. VERSION SPACE QUANTUM PERCEPTRON 117

The interested reader is encouraged consult the appendix of (Kapoor et al.,


2016) for proofs of those lemmas. Furthermore, Novikoff’s theorem states that
the 1/𝛾 2 is an upper bound in the number of times the algorithms described
in these lemmas need to be applied, which is the reason for the first line of the
algorithm and the 1/𝛾 2 term in the runtime.

6.3 Version space quantum perceptron


General idea: Discretize the space in which weight vectors live and use
Grover’s search algorithm to find one vector that correctly classifies all the data
points. Instead of searching among the data points, we are searching among
weight vectors.
The key of the version space training algorithm is to search, among the possible
weight vectors, one that correctly shatters the data points. Instead of iterating
over the data points to update a weight vector, we will iterate over a discrete set
of weight vectors to search a good one. The reason why this algorithm is called
version space quantum perceptron lies in the space where the weight vector live,
which is referred to as the version space.
Theorem 6.2. Given a training set with margin 𝛾, a weight vector 𝑤 sampled
from a spherical gaussian distribution 𝒩(0, 1) perfectly separates the data with
probability Θ(𝛾).
The main idea is to sample 𝑘 sample hyperplanes 𝑤(1) , … , 𝑤(𝑘) from a spherical
Gaussian distribution 𝒩(0, 𝟙) such that 𝑘 is large enough to guarantee us that
there is at least one good weight vector. Theorem 6.2 tells us that the expected
number of samples 𝑘 scales as 𝑂(1/𝛾), and classically we would need to test all
the 𝑛 data points for at least 𝑂(1/𝛾) different vectors, with a cost Ω(𝑛/𝛾). By
exploiting the power of Grover’s search we can have a quadratic speedup on 𝑘

and achieve 𝑂(𝑛/ 𝛾).
Like in the previous case, to use Grover, we need one unitary 𝑈 that creates
the weight vectors among which we search and one oracle ℱ that modifies the
phase of the correct weight vectors.
The oracle 𝑈 must do the following job:
𝑈 |𝑗⟩|0⟩ = |𝑗⟩|𝑤(𝑗) ⟩ (6.11)
for 𝑗 ∈ {1, … , 𝑘}, giving access to the 𝑘 sampled weight vectors. Clearly 𝑈 is a
linear operator and can be used with indexes in superposition, to give access to
𝑘 𝑘
all the weight vectors simultaneously 𝑈 √1𝑘 ∑𝑗=1 |𝑗⟩|0⟩ = √1𝑘 ∑𝑗=1 |𝑗⟩|𝑤(𝑗) ⟩.
On the other hand, the oracle ℱ should perform the following operation:
(𝑗)
,𝑥(1) ,𝑦(1) )∨⋯∨𝑓(𝑤(𝑗) ,𝑥(𝑛) ,𝑦(𝑛) ))
ℱ|𝑤(𝑗) ⟩ = (−1)1+(𝑓(𝑤 |𝑤(𝑗) ⟩. (6.12)
(𝑗) (𝑖) (𝑖)
Here 𝑓 (𝑤 , 𝑥 , 𝑦 ) works as in the quantum online perceptron algorithm:
returns 1 if the data sample (𝑥(𝑖) , 𝑦(𝑖) ) is not correctly predicted by the weight
118 CHAPTER 6. QUANTUM PERCEPTRON

𝑤(𝑗) . Basically, 1 + (𝑓 (𝑤(𝑗) , 𝑥(1) , 𝑦(1) ) ∨ ⋯ ∨ 𝑓 (𝑤(𝑗) , 𝑥(𝑛) , 𝑦(𝑛) )) returns 1 if the
vector 𝑤(𝑗) correctly classifies all the data points and 0 if there exists a training
sample that is not correctly classified. Similarly to the previous case, this circuit
can be built by “hardcoding” the knowledge of the data samples in each of the
𝑛 functions or by creating one flexible function that accepts the vector and the
points as input (by using additional qubits for the data points). This operation
can be implemented with 𝑂(𝑛) queries to 𝑓.
Once we have the oracles 𝑈 and ℱ, we can sum up the algorithm in pseudocode.
The following theorem formalizes the runtime of the algorithm.
Theorem 6.3 (Version space quantum perceptron (kapoor2016quantum)).
Given a training set that consists of unit vectors 𝑥(1) , … , 𝑥(𝑛) and labels
𝑦(1) , … , 𝑦(𝑛) , separated by a margin of 𝛾, the number of queries to 𝑓 needed to
infer a perceptron model 𝑤, with probability at least 1 − 𝜖, using a quantum
computer is 𝑂 ( √𝑛𝛾 log ( 1𝜖 )).

The proof of this theorem is straightforward from the statement of Grover’s


algorithm and some statistics to bound the failure probability.
Chapter 7

SVE-based quantum
algorithms

In the following section, we will cover some quantum algorithms based on sin-
gular value estimation. Some of them are here just because they are simple
enough to have a good pedagogical value, while some of them we believe will be
really useful in performing data analysis.

7.1 Spectral norm and the condition number es-


timation
We will elaborate more on this result soon. For the moment, we report the main
statement.
Theorem 7.1 (Spectral norm estimation). Let there be quantum access to the
matrix 𝐴 ∈ ℝ𝑛×𝑚 , and let 𝜖 > 0 be a precision parameter. There exists a
̃ ( log(1/𝜖) ‖𝐴‖𝐹 ).
quantum algorithm that estimates ‖𝐴‖ to error 𝜖‖𝐴‖𝐹 in time 𝑂 𝜖 ‖𝐴‖

7.2 Explained variance: estimating quality of


representations
The content of this section is extracted from (Bellante and Zanero, 2022).
Let 𝐴 = 𝑈 Σ𝑉 𝑇 be the singluar value decomposition of a matrix 𝐴 ∈ ℝ𝑛×𝑚 .
We call factor scores of 𝐴, and denote them with 𝜆𝑖 = 𝜎𝑖2 , the squares of its
singular values. Similarly, we call factor score ratios the relative magnitudes of
𝜆𝑖 𝜎𝑖2
the factor scores 𝜆(𝑖) = 𝑟𝑎𝑛𝑘(𝐴) = 𝑟𝑎𝑛𝑘(𝐴) 2
. The factor score ratios are a
∑𝑗 𝜆𝑗 ∑𝑗 𝜎𝑗
measure of the amount of variance explained by the singular values.

119
120 CHAPTER 7. SVE-BASED QUANTUM ALGORITHMS

We state here some nice examples of SVE based algorithms: the first allows us to
assess whether a few singular values/factor scores explain most of the variance
of the matrix of the dataset; the second one allows computing the cumulative
sum of the factor score ratios associated to singular values grater or equal than
a certain threshold; the third one is a modified version of the spectral norm
estimation result and allows us to define a threshold for the smallest singular
value such that the the sum of the above explains more than a given percentage
of the total variance; finally, the last two algorithms allow retrieving a classical
description of the singular vectors that correspond to the most relevant singular
values.
The main intuition behind the first algorithm is that it is possible to create
𝑟√
the state ∑𝑖 𝜆(𝑖) |𝑢𝑖 ⟩|𝑣𝑖 ⟩|𝜎𝑖 ⟩ and that the third register, when measured in the
computational basis, outputs the estimate 𝜎𝑖 of a singular value with probability
equal to its factor score ratio 𝜆(𝑖) . This allows us to sample the singular values
of 𝐴 directly from the factor score ratios’ distribution. When a matrix has a
huge number of small singular values and only a few of them that are very big,
the ones with the greatest factor score ratios will appear many times during the
measurements, while the negligible ones are not likely to be measured. This
intuition has already appeared in literature (Gyurik et al., 2020) and (Cade
and Montanaro, 2017). Nevertheless, the analysis and the problem solved are
different, making the run-time analysis unrelated. This idea in the context of
data representation and analysis, this intuition has only been sketched for sparse
or low rank square symmetric matrices, by (Lloyd et al., 2013), without a precise
formalization. We thoroughly formalize it, in a data representation and analysis
context, for any real matrix.

Figure 7.1: Quantum factor score ratio estimation

Theorem 7.2 (Quantum factor score ratio estimation). Assume to have quan-
tum access to a matrix 𝐴 ∈ ℝ𝑛×𝑚 and 𝜎𝑚𝑎𝑥 ≤ 1. Let 𝛾, 𝜖 be precision parameters.
7.2. EXPLAINED VARIANCE: ESTIMATING QUALITY OF REPRESENTATIONS121

̃ ( 12 𝜇(𝐴) ), estimates:
There exists a quantum algorithm that, in time 𝑂 𝛾 𝜖

(𝑖)
• the factor score ratios 𝜆(𝑖) , such that ‖𝜆(𝑖) − 𝜆 ‖ ≤ 𝛾, with high probability;
• the correspondent singular values 𝜎𝑖 , such that ‖𝜎𝑖 − 𝜎𝑖 ‖ ≤ 𝜖, with proba-
bility at least 1 − 1/poly(𝑛);
• the correspondent factor scores 𝜆𝑖 , such that ‖𝜆𝑖 −𝜆𝑖 ‖ ≤ 2𝜖, with probability
at least 1 − 1/poly(𝑛).

The parameter 𝛾 is the one that controls how big a factor score ratio should be
for the singular value/factor score to be measured. If we choose 𝛾 bigger than
the least factor scores ratio of interest, the estimate for the smaller ones is likely
to be 0, as ‖𝜆(𝑖) − 0‖ ≤ 𝛾 would be a plausible estimation.

Often in data representations, the cumulative sum of the factor score ratios is a
measure of the quality of the representation. By slightly modifying Algorithm
in Figure 7.1 to use Theorem 3.16, it is possible to estimate this sum such that
𝑘 𝑘 (𝑖)
‖ ∑𝑖 𝜆(𝑖) − ∑𝑖 𝜆 ‖ ≤ 𝑘𝜖 with probability 1 − 1/poly(𝑟).

However, a slight variation of the algorithm of Theorem 7.1 provides a more


accurate estimation in less time, given a threshold 𝜃 for the smallest singular
value to retain.

Theorem 7.3 (Quantum check on the factor score ratios’ sum). Assume to
have efficient quantum access to the matrix 𝐴 ∈ ℝ𝑛×𝑚 , with singular value
decomposition 𝐴 = ∑𝑖 𝜎𝑖 𝑢𝑖 𝑣𝑖𝑇 . Let 𝜂, 𝜖 be precision parameters and 𝜃 be a
threshold for the smallest singular value to consider. There exists a quantum
∑𝑖∶𝜎 𝜎2
𝑖 ≥𝜃 𝑖
algorithm that estimates 𝑝 = 𝑟 2
∑𝑗 𝜎𝑗
, where ‖𝜎𝑖 − 𝜎𝑖 ‖ ≤ 𝜖, to relative error 𝜂
̃ ( 𝜇(𝐴) √1 ).
in time 𝑂 𝜖 𝜂 𝑝

Moreover, we borrow an observation from (Kerenidis and Prakash, 2020) on


Theorem 7.1, to perform a binary search of 𝜃 given the desired sum of factor
score ratios.

Theorem 7.4 (Quantum binary search for the singular value threshold). As-
sume to have quantum access to the matrix 𝐴 ∈ ℝ𝑛×𝑚 . Let 𝑝 be the factor ratios
sum to retain. The threshold 𝜃 for the smallest singular value to retain can be
̃ ( log(1/𝜖)𝜇(𝐴)
estimated to absolute error 𝜖 in time 𝑂 √ ).
𝜖 𝑝

We will see in the next chapters that in problems such as PCA, CA, and LSA, the
desired sum of factor score ratios to retain is a number in the range 𝑝 ∈ [1/3, 1]
with precision up to the second decimal digit. In practice, the complexity of
these last two algorithms scales as 𝑂̃ ( 𝜇(𝐴) ).
𝜖
122 CHAPTER 7. SVE-BASED QUANTUM ALGORITHMS

7.3 Extracting the SVD representations


After introducing the procedures to test for the most relevant singular values,
factor scores and factor score ratios of 𝐴, we present an efficient routine to ex-
tract the corresponding right/left singular vectors. The inputs of this algorithm,
other than the matrix, are a parameter 𝛿 for the precision of the singular vectors,
a parameter 𝜖 for the precision of the singular value estimation, and a threshold
𝜃 to discard the non interesting singular values/vectors. The output guaran-
tees a unit estimate 𝑥𝑖 of each singular vector such that ||𝑥𝑖 − 𝑥𝑖 ||ℓ ≤ 𝛿 for
ℓ ∈ {2, ∞}, ensuring that the estimate has a similar orientation to the original
vector. Additionally, this subroutine can provide an estimation of the singular
values greater than 𝜃, to absolute error 𝜖.

Figure 7.2: Quantum algorithm for top-k singular vector extractor

Theorem 7.5 (Top-k singular vectors extraction). Let there be efficient quan-
tum access to the matrix 𝐴 ∈ ℝ𝑛×𝑚 , with singular value decomposition 𝐴 =
𝑟
∑𝑖 𝜎𝑖 𝑢𝑖 𝑣𝑖𝑇 and 𝜎𝑚𝑎𝑥 ≤ 1. Let 𝛿 > 0 be a precision parameter for the singular
vectors, 𝜖 > 0 a precision parameter for the singular values, and 𝜃 > 0 be a
∑𝑖∶𝜎 𝜎𝑖2
𝑖 ≥𝜃
threshold such that 𝐴 has 𝑘 singular values greater than 𝜃. Define 𝑝 = 𝑟
∑𝑗 𝜎𝑗2
.
There exist quantum algorithms that estimate:
• The top 𝑘 left singular vectors 𝑢𝑖 of 𝐴 with unit vectors 𝑢𝑖 such that ‖𝑢𝑖 −
𝑢 ‖ ≤ 𝛿 with probability at least 1 − 1/𝑝𝑜𝑙𝑦(𝑛), in time 𝑂 ̃ ( 1 √1 𝜇(𝐴) 𝑘𝑛2 );
𝑖 2 𝜃 𝑝 𝜖 𝛿
• The top 𝑘 right singular vectors 𝑣𝑖 of 𝐴 with unit vectors 𝑣𝑖 such that ‖𝑣𝑖 −
𝑣 ‖ ≤ 𝛿 with probability at least 1 − 1/𝑝𝑜𝑙𝑦(𝑚), in time 𝑂 ̃ ( 1 √1 𝜇(𝐴) 𝑘𝑚
2 ).
𝑖 2 𝜃 𝑝 𝜖 𝛿
7.3. EXTRACTING THE SVD REPRESENTATIONS 123

• The top 𝑘 singular values 𝜎𝑖 and factor scores 𝜆𝑖 of 𝐴 to precision 𝜖 and


̃ ( 1 √1 𝜇(𝐴)𝑘 ) or any
2𝜖 with probability at least 1 − 1/poly(𝑚), in time 𝑂 𝜃 𝑝 𝜖
of the two above.
Besides 𝑝 being negligible, it is interesting to note that the parameter 𝜃 can be
computed using:
• the procedures of Theorems @ref(thm:factor_score_estimation) and
@ref(thm:check_explained_variance);
• the binary search of Theorem ??;
• the available literature on the type of data stored in the input matrix 𝐴.
About the latter, the original paper of latent semantic indexing (Deerwester
et al., 1990) states that the first 𝑘 = 100 singular values are enough for a good
representation. We believe that, in the same way, fixed thresholds 𝜃 can be
defined for different machine learning applications. The experiments that you
can read in Chapter 12 on the run-time parameters of the polynomial expansions
of the MNIST dataset support this expectation: even though in qSFA they
keep the 𝑘 smallest singular values and refer to 𝜃 as the biggest singular value
to retain, this value does not vary much when the the dimensionality of their
dataset grows. In our experiments, we observe that different datasets for image
classification have similar 𝜃s.
A similar statement to Theorem @ref(thm:top-k_sv_extraction) can be stated
with ℓ∞ guarantees on the vectors (see Corollary 13 of (Bellante and Zanero,
2022)).
As we discussed before, given a vector with 𝑑 non-zero entries, performing ℓ∞
tomography with error √𝛿𝑑 provides the same guarantees of ℓ2 tomography with
error 𝛿.
In practice, this result implies that the extraction of the singular vectors, with
ℓ2 guarantees, can be faster if we can assume some prior assumptions on their
sparseness: 𝑂̃ ( 1 √1 𝜇(𝐴) 𝑘𝑑2 ).
𝜃 𝑝 𝜖 𝛿

The main√intuition behind these algorithms is that it is possible to create the


𝑟
state ∑𝑖 𝜆(𝑖) |𝑢𝑖 ⟩|𝑣𝑖 ⟩|𝜎𝑖 ⟩.
The first algorithm uses a parameter 𝛾 to control how big a factor score ratio
should be for the corresponding singular value/factor score to be measured. If
we choose 𝛾 bigger than the least factor scores ratio of interest, only the biggest
singular values/factor scores will be likely to be measured.
Theorem 7.6 (Quantum factor score ratio estimation). Let there be quantum
access to a matrix 𝐴 ∈ ℝ𝑛×𝑚 , with singular value decomposition 𝐴 = ∑𝑖 𝜎𝑖 𝑢𝑖 𝑣𝑖𝑇
and 𝜎𝑚𝑎𝑥 ≤ 1. Let 𝛾, 𝜖 be precision parameters. There exists a quantum algo-
̃ ( 12 𝜇(𝐴) ), estimates:
rithm that, in time 𝑂 𝛾 𝜖

(𝑖)
• the factor score ratios 𝜆(𝑖) , such that ‖𝜆(𝑖) − 𝜆 ‖ ≤ 𝛾, with high probability;
124 CHAPTER 7. SVE-BASED QUANTUM ALGORITHMS

• the correspondent singular values 𝜎𝑖 , such that ‖𝜎𝑖 − 𝜎𝑖 ‖ ≤ 𝜖, with proba-


bility at least 1 − 1/poly(𝑛);
• the correspondent factor scores 𝜆𝑖 , such that ‖𝜆𝑖 −𝜆𝑖 ‖ ≤ 2𝜖, with probability
at least 1 − 1/poly(𝑛).

Proof. We provide an algorithm that satisfies the above guarantees. As a first


step, one creates the state
𝑛 𝑚 𝑟
1 1
|𝐴⟩ = ∑ ∑ 𝑎𝑖𝑗 |𝑖⟩|𝑗⟩ = 𝑟 2 ∑ 𝜎𝑖 |𝑢𝑖 ⟩|𝑣𝑖 ⟩.
‖𝐴‖𝐹 𝑖 𝑗 ∑𝑗 𝜎𝑗 𝑖

̃
This step costs 𝑂(1), assuming that the data are stored in an adeguate data
̃
structure. From this state we apply SVE in time 𝑂(𝜇(𝐴)/𝜖)
𝑟
1
|𝐴′ ⟩ = 𝑟 ∑ 𝜎𝑖 |𝑢𝑖 ⟩|𝑣𝑖 ⟩|𝜎𝑖 ⟩ (7.1)
∑𝑗 𝜎𝑗2 𝑖

encoding the singular values with absolute precision 𝜖. If we ignore the first two
𝑟√
registers, we have the state |𝐴″ ⟩ = ∑𝑖 𝜆(𝑖) |𝜎𝑖 ⟩, from which we can measure
the singular values (and factor scores) with probability equal to their factor
score ratios. To evaluate the number 𝑆 of measurements needed on |𝐴″ ⟩ to
satisfy the guarantees of the theorem, we can model the measurement process
(𝑖)
as performing 𝑟 Bernoulli trials: one for each 𝜆 , so that if we measure 𝜎𝑖 it
is a success for the 𝑖𝑡ℎ Bernoulli trial and a failure for all the others. We use
(𝑖) 𝜁
the estimator 𝜆 = 𝑆𝜎𝑖 , where 𝜁𝜎𝑖 is the number of times 𝜎𝑖 appears in the
measurements and 𝑆 is the number of total measurements. Given a confidence
level 𝑧 and an absolute error 𝛾, it is possible to use the Wald confidence interval
(𝑖)
to determine a value for 𝑆 such that ‖𝜆(𝑖) − 𝜆 ‖ ≤ 𝛾 with confidence level 𝑧. It
is possible to show that 𝛾 ≤ 2√𝑧 𝑆 (Schuld and Petruccione, 2018), from which
𝑧2
we get 𝑆 = 4𝛾 2 .
Since 𝑧 is a small number, we can state that the complexity of
̃ ( 12 𝜇(𝐴) ).
the algorithm is 𝑂 𝛾 𝜖

Finally, note that the error on the factor scores is 2𝜖. Suppose that we run SVE
with precision 𝜏 . For each 𝜆𝑖 , the worst estimate is 𝜆𝑖 = (𝜎𝑖 ±𝜏 )2 = 𝜎𝑖2 ±2𝜏 𝜎𝑖 +𝜏 2
and since 0 ≤ 𝜎𝑖 ≤ 1, we can say that the worst √ case is 𝜎𝑖2 + (2𝜏 + 𝜏 2 ). Solving
2
the equation 2𝜏 + 𝜏 = 𝜖 for 𝜏 > 0 leads to 𝜏 = 1 + 𝜖 − 1. Finally,
√ √
√ ( 1 + 𝜖 − 1)( 1 + 𝜖 + 1) 1+𝜖−1 𝜖 𝜖
𝜏 = 1+𝜖−1= √ =√ =√ ∼
( 1 + 𝜖 + 1) 1+𝜖+1 1+𝜖+1 2

which proves the error guarantees.

Theorem 7.7 (Quantum check on the factor score ratios’ sum). Let there be
efficient quantum access to the matrix 𝐴 ∈ ℝ𝑛×𝑚 , with singular value decom-
position 𝐴 = ∑𝑖 𝜎𝑖 𝑢𝑖 𝑣𝑖𝑇 . Let 𝜂, 𝜖 be precision parameters and 𝜃 be a threshold
7.3. EXTRACTING THE SVD REPRESENTATIONS 125

for the smallest singular value to consider. There exists a quantum algorithm
∑𝑖∶𝜎 𝜎𝑖2
𝑖 ≥𝜃
that estimates 𝑝 = 𝑟
∑𝑗 𝜎𝑗2
, where ‖𝜎𝑖 − 𝜎𝑖 ‖ ≤ 𝜖, to relative error 𝜂 in time
̃ ( 𝜇(𝐴) √1 ).
𝑂 𝜖 𝜂 𝑝

𝑟√
Proof. As reported in the proof above, creating the state |𝐴″ ⟩ = ∑𝑖 𝜆(𝑖) |𝜎𝑖 ⟩
̃
costs 𝑂(𝜇(𝐴)/𝜖). From this state it is possible to append a quantum regis-

ter that is |0⟩ if 𝜎𝑖 < 𝜃 and |1⟩ otherwhise: |𝜑⟩ = ∑𝑖∶𝜎 ≥𝜃 𝜆(𝑖) |𝜎𝑖 ⟩|0⟩ +
√ 𝑖

∑𝑗∶𝜎 <𝜃 𝜆(𝑖) |𝜎𝑖 ⟩|1⟩. The probability of measuring |0⟩ is 𝑝 = ∑𝑖∶𝜎 ≥𝜃 𝜆(𝑖) =
𝑗 𝑖
∑𝑖∶𝜎 𝜎2
𝑖 ≥𝜃 𝑖
𝑟 2
∑𝑗 𝜎𝑗
. Using amplitude estimation (Lemma 5.1), we can estimate 𝑝 in time
̃ ( 𝜇(𝐴)
𝑂 √ ).
𝑝𝜖

Theorem 7.8 (Top-k singular vectors extraction). Let there be efficient quan-
tum access to the matrix 𝐴 ∈ ℝ𝑛×𝑚 , with singular value decomposition 𝐴 =
𝑟
∑𝑖 𝜎𝑖 𝑢𝑖 𝑣𝑖𝑇 and 𝜎𝑚𝑎𝑥 ≤ 1. Let 𝛿 > 0 be a precision parameter for the singular
vectors, 𝜖 > 0 a precision parameter for the singular values, and 𝜃 > 0 be a
∑𝑖∶𝜎 𝜎2
𝑖 ≥𝜃 𝑖
threshold such that 𝐴 has 𝑘 singular values greater than 𝜃. Define 𝑝 = 𝑟 2
∑𝑗 𝜎𝑗
.
There exist quantum algorithms that estimate:
• The top 𝑘 left singular vectors 𝑢𝑖 of 𝐴 with unit vectors 𝑢𝑖 such that ||𝑢𝑖 −
𝑢 || ≤ 𝛿 with probability at least 1 − 1/𝑝𝑜𝑙𝑦(𝑛), in time 𝑂̃ ( 1 √1 𝜇(𝐴) 𝑘𝑛2 );
𝑖 2 𝜃 𝑝 𝜖 𝛿
• The top 𝑘 right singular vectors 𝑣𝑖 of 𝐴 with unit vectors 𝑣𝑖 such that ||𝑣𝑖 −
𝑣 || ≤ 𝛿 with probability at least 1 − 1/𝑝𝑜𝑙𝑦(𝑚), in time 𝑂 ̃ ( 1 √1 𝜇(𝐴) 𝑘𝑚
2 );
𝑖 2 𝜃 𝑝 𝜖 𝛿
• The top 𝑘 singular values 𝜎𝑖 and factor scores 𝜆𝑖 of 𝐴 to precision 𝜖 and
̃ ( 1 √1 𝜇(𝐴)𝑘 ) or any
2𝜖 with probability at least 1 − 1/poly(𝑚), in time 𝑂 𝜃 𝑝 𝜖
of the two above.

Proof. As reported in the proofs above, creating the state |𝐴′ ⟩ =


𝑟 √ (𝑖) ̃
∑𝑖 𝜆 |𝑢𝑖 ⟩|𝑣𝑖 ⟩|𝜎𝑖 ⟩ costs 𝑂(𝜇(𝐴)/𝜖). On this state we append an addi-
tional register, set to |0⟩ if 𝜎𝑖 ≥ 𝜃 and to |1⟩ otherwise. The cost of this
operation is negligible as it only depends on the binary encoding of |𝜎𝑖 ⟩. On
this state we perform amplitude amplification (Lemma 5.1) on |0⟩ and obtain
the state
𝑘
|𝜑⟩ = ∑ √𝜆(𝑖) |𝑢𝑖 ⟩|𝑣𝑖 ⟩|𝜎𝑖 ⟩ (7.2)
𝑖

with a superposition of the 𝑘 most relevant singular values and vectors. Creating
̃ ( 𝜇(𝐴)
|𝜑⟩ costs 𝑂 √ ). On this state we append an additional register and perform
𝑝𝜖
a conditional rotation
126 CHAPTER 7. SVE-BASED QUANTUM ALGORITHMS

𝑘 𝑘
𝐶 𝜎𝑖 1 𝐶2
𝑘
∑ |𝑢𝑖 ⟩|𝑣𝑖 ⟩|𝜎𝑖 ⟩|0⟩ + 𝑘 ∑ √1 − 2 |𝑢𝑖 ⟩|𝑣𝑖 ⟩|𝜎𝑖 ⟩|1⟩ (7.3)
∑𝑖 𝜎𝑖2 𝑖
𝜎𝑖 ∑𝑖 𝜎𝑖2 𝑖 𝜎𝑖

The constant 𝐶 is a normalization factor in the order of 𝑂(1/𝜅(𝐴 ̃ (𝑘)


)) where
(𝑘) 𝜎𝑚𝑎𝑥
𝜅(𝐴 ) = 𝜎 is the condition number of the low-rank (𝑘-rank) matrix 𝐴(𝑘) .
𝑚𝑖𝑛
Since for construction 𝜎𝑚𝑎𝑥 ≤ 1 and 𝜎𝑚𝑖𝑛 ≥ 𝜃, we can bound the condition
number 𝜅(𝐴(𝑘) ) ≤ 1𝜃 . From the famous work of Harrow, Hassidim and Lloyd
(Harrow et al., 2009) we know that applying amplitude amplification on the
state above, with the the third register being |0⟩, would cost 𝑂(𝜅(𝐴 ̃ (𝑘)
)𝑇 (𝑈 ),
where 𝑇 (𝑈 ) is the run-time to create the state. In our case, the cost till this
̃ ( 1 √1 𝜇(𝐴) ), and amplitude amplification leaves the registers in the
step is 𝑂 𝜃 𝑝 𝜖
state
𝑘
1 𝜎𝑖 1 𝑘
∑ |𝑢𝑖 ⟩|𝑣 𝑖 ⟩|𝜎 𝑖 ⟩ ∼ √ ∑ |𝑢𝑖 ⟩|𝑣𝑖 ⟩|𝜎𝑖 ⟩
√∑ 𝜎𝑖2 𝑖 𝜎𝑖
𝑘 2
𝑘 𝑖
𝑖 𝜎𝑖

where 𝜎𝑖 ∈ [𝜎𝑖 − 𝜖, 𝜎𝑖 + 𝜖] and 𝜎𝜎±𝜖 𝑖


→ 1 for 𝜖 → 0. The last step of the
𝑖
proof is to compute the time complexity of the state-vector tomography on
𝑘
√1 ∑ |𝑢 ⟩|𝑣 ⟩|𝜎 ⟩. When measuring the last register of state in the compu-
𝑘 𝑖 𝑖 𝑖 𝑖
tational basis and obtaining |𝜎𝑖 ⟩, the first two registers collapse in the state
|𝑢𝑖 ⟩|𝑣𝑖 ⟩. On |𝑢𝑖 ⟩|𝑣𝑖 ⟩, it is possible to perform ℓ2 vector-state tomography us-
ing Theorem 3.15 either on the first register, to retrieve 𝑢𝑖 , or on the second
one, to retrieve 𝑣𝑖 . Since 𝑢𝑖 ∈ 𝑅𝑛 and 𝑣𝑖 ∈ 𝑅𝑚 , performing state-vector to-
mography on the first register takes time 𝑂( 𝑛 log 𝑛
𝛿2 ) and performing it on the
𝑚 log 𝑚
second takes time 𝑂( 𝛿2 ). Using a coupon collector’s argument, if the 𝑘
states |𝜎𝑖 ⟩ are uniformly distributed, to get all the 𝑘 possible couples |𝑢𝑖 ⟩|𝑣𝑖 ⟩
at least once we would need 𝑘 log 𝑘 measurements on average. This proves
that it is possible to estimate all the singular values greater than 𝜃, with the
guarantees above, in time 𝑂( ̃ 1 √1 𝜇(𝐴)𝑘 ). To perform tomography on each state-
𝜃 𝑝 𝜖
vector, one should satisfy the coupon collector the same number of times as
the measurements needed by the tomography procedure. The costs of the to-
mography for all the vectors {𝑢𝑖 }𝑘𝑖 and {𝑣𝑖 }𝑘𝑖 are 𝑂 (𝑇 (𝑈 ) 𝑘 log 𝑘⋅𝑛
𝛿2
log 𝑛
), and
𝑂 (𝑇 (𝑈 ) 𝑘 log 𝑘⋅𝑚
𝛿2
log 𝑚
), where 𝑇 (𝑈 ) is the run-time to create the state on which
to perform tomography. It easily follows that the following complexities are
proven: 𝑂̃ ( 1 √1 𝜇(𝐴) 𝑘𝑛2 ) , 𝑂
̃ ( 1 √1 𝜇(𝐴) 𝑘𝑚
𝜃 𝑝 𝜖 𝛿 𝜃 𝑝 𝜖 𝛿2 ) .

Corollary 7.1 (Fast top-k singular vectors extraction). The run-times of the
̃ ( 1 √1 𝜇(𝐴) 𝑘2 ) with estimation guarantees
theorem above can be improved to 𝑂 𝜃 𝑝 𝜖 𝛿
on the ℓ∞ norms.
The proof of this corollary consists in a variant of the proof above that uses ℓ∞
tomography (Theorem 3.16) to extract the singular vectors.
7.4. SINGULAR VALUE ESTIMATION OF A PRODUCT OF TWO MATRICES127

Besides 𝑝 being negligible, it is interesting to note that the parameter 𝜃 can be


computed using:
• the procedures of Theorems 7.6 and 7.7;
• the binary search of Theorem ??;
• the available literature on the type of data stored in the input matrix 𝐴.
About the latter, for instance, the experiments of (Kerenidis and Luongo, 2020)
on the run-time parameters of the polynomial expansions of the MNIST dataset
support this expectation: even though in qSFA they keep the 𝑘 smallest singular
values and refer to 𝜃 as the biggest singular value to retain, this value does not
vary much when the the dimensionality of their dataset grows. In the experi-
ments chapter, we observe similar 𝜃s in different datasets for image classification.
Note that, given a vector with 𝑑 non-zero entries, performing ℓ∞ tomography
with error √𝛿𝑑 provides the same guarantees of ℓ2 tomography with error 𝛿. In
practice, this result implies that the extraction of the singular vectors, with
ℓ2 guarantees, can be faster if we can assume some prior assumptions on their
sparseness: 𝑂̃ ( 1 √1 𝜇(𝐴) 𝑘𝑑2 ).
𝜃 𝑝 𝜖 𝛿

7.4 Singular value estimation of a product of two


matrices
This is an example of an algorithm that has been superseded by recent develop-
ment in singular value transformation. Nevertheless, it is a non-trivial way of
using SVE, which a nice mathematical error analysis.
Theorem 7.9 (SVE of product of matrices). Assume to have quantum access
to matrices 𝑃 ∈ ℝ𝑑×𝑑 and 𝑄 ∈ ℝ𝑑×𝑑 . Define 𝑊 = 𝑃 𝑄 = 𝑈 Σ𝑉 𝑇 and 𝜖 > 0
an error parameter. There is a quantum algorithm that with probability at
least 1 − 𝑝𝑜𝑙𝑦(𝑑) performs the mapping ∑𝑖 𝛼|𝑣𝑖 ⟩ → ∑𝑖 𝛼𝑖 |𝑣𝑖 ⟩|𝜎𝑖 ⟩ where 𝜎𝑖 is
an approximation of the eigenvalues 𝜎𝑖 of 𝑊 such that |𝜎𝑖 − 𝜎𝑖 | ≤ 𝜖, in time
𝑂̃ ( (𝜅(𝑃 )+𝜅(𝑄))(𝜇(𝑃
𝜀
)+𝜇(𝑄))
).

Proof. We start by noting that for each singular value 𝜎𝑖 of 𝑊 there is a cor-
responding eigenvalue 𝑒−𝑖𝜎𝑖 of the unitary matrix 𝑒−𝑖𝑊 . Also, we note that we
know how to multiply by 𝑊 by applying theorem 5.9 sequentially with 𝑄 and 𝑃 .
This will allow us to approximately apply the unitary 𝑈 = 𝑒−𝑖𝑊 . The last step
will consist of the application of phase estimation to estimate the eigenvalues of
𝑈 and hence the singular values of 𝑊 . Note that we need 𝑊 to be a symmetric
matrix because of the Hamiltonian simulation part. In case 𝑊 is not symmetric,
we redefine it as
0 𝑃𝑄
𝑊 =[ ]
(𝑃 𝑄)𝑇 0
Note we have 𝑊 = 𝑀1 𝑀2 for the matrices 𝑀1 , 𝑀2 stored in QRAM and defined
as
128 CHAPTER 7. SVE-BASED QUANTUM ALGORITHMS

𝑃 0 0 𝑄
𝑀1 = [ ] , 𝑀2 = [ 𝑇 ].
0 𝑄𝑇 𝑃 0

We now show how to approximately apply 𝑈 = 𝑒−𝑖𝑊 efficiently. Note that for
a symmetric matrix 𝑊 we have 𝑊 = 𝑉 Σ𝑉 𝑇 and using the Taylor expansion of
the exponential function we have

∞ ∞
(−𝑖𝑊 )𝑗 (−𝑖Σ)𝑗 𝑇
𝑈 = 𝑒−𝑖𝑊 = ∑ =𝑉 ∑ 𝑉
𝑗=0
𝑗! 𝑗=0
𝑗!

With 𝑈 ̃ we denote our first approximation of 𝑈 , where we truncate the sum


after ℓ terms.

ℓ 𝑗 ℓ 𝑗
̃ = ∑ (−𝑖𝑊 ) = 𝑉 ∑ (−𝑖Σ) 𝑉 𝑇
𝑈
𝑗=0
𝑗! 𝑗=0
𝑗!

̃∥ < 𝜖/4. We have:


We want to chose ℓ such that ∥𝑈 − 𝑈

∞ ℓ ∞ ∞ ∞
̃∥ (−𝑖𝑊 )𝑗 (−𝑖𝑊 )𝑗 (−𝑖𝑊 )𝑗 (−𝑖𝑊 )𝑗 1
∥𝑈 − 𝑈 ≤ ‖∑ −∑ ‖≤‖ ∑ ‖≤ ∑ ‖ ‖≤ ∑
𝑗=0
𝑗! 𝑗=0
𝑗! 𝑗=ℓ+1
𝑗! 𝑗=ℓ+1
𝑗! 𝑗=ℓ+1
𝑗!

1
≤ ∑ 𝑗−1
≤ 2−ℓ+1
𝑗=ℓ+1
2

where we used triangle inequality and that ∥𝑊 𝑗 ∥ ≤ 1. Choosing ℓ = 𝑂(log 1/𝜀)


makes the error less than 𝜖/4. %We can approximate a positive series where the
term 𝑎𝑛 satisfy the following two conditions: 0 ≤ 𝑎𝑛 ≤ 𝐾𝑟𝑛 with 𝐾 > 0, 0 <
𝑁+1
𝑟 < 1 by expressing the error as the geometric series 𝐾𝑟
1−𝑟 . In our case 𝐾 = 1
( 12 )ℓ+1
and 𝑟 = 1/2. For a given 𝜖 we have to find ℓ such that 1−( 12 )
≤ 𝜖. By taking
ℓ = 𝑂(log 1/𝜖) we can easily satisfy the error guarantee.
In fact, we cannot apply 𝑈 ̃ exactly but only approximately, since we need
to multiply with the matrices 𝑊 𝑗 , 𝑗 ∈ [ℓ] and we do so by using the matrix
multiplication algorithm for the matrices 𝑀1 and 𝑀2 . For each of these ma-
𝜖 𝜖
trices, we use an error of 8ℓ which gives an error for 𝑊 of 4ℓ and an error
for 𝑊 𝑗 of at most 4𝜖 . The running time for multiplying with each 𝑊 𝑗 is at
most 𝑂(ℓ(𝜅(𝑀1 )𝜇(𝑀1 ) log(8ℓ/𝜖) + 𝜅(𝑀2 )𝜇(𝑀2 ) log(8ℓ/𝜖))) by multiplying se-
quentially. Hence, we will try to apply the unitary 𝑈 by using the Taylor
expansion up to level ℓ and approximating each 𝑊 𝑗 , 𝑗 ∈ [ℓ] in the sum through
our matrix multiplication procedure that gives error at most 4𝜖 .
7.4. SINGULAR VALUE ESTIMATION OF A PRODUCT OF TWO MATRICES129

In order to apply 𝑈 on a state |𝑥⟩ = ∑𝑖 𝛼𝑖 |𝑣𝑖 ⟩, let’s assume ℓ + 1 is a power of


𝑙 𝑗
two and define 𝑁𝑙 = ∑𝑗=0 ( (−𝑖) 2
𝑗! ) . We start with the state

𝑙
1 −𝑖𝑗
∑ |𝑗⟩|𝑥⟩
√𝑁𝑙 𝑗=0 𝑗!

Controlled on the first register we use our matrix multiplication procedure to


multiply with the corresponding power of 𝑊 and get a state at most 𝜖/4 away
from the state

𝑙
1 −𝑖𝑗
∑ |𝑗⟩|𝑊 𝑗 𝑥⟩.
√𝑁𝑙 𝑗=0 𝑗!

We then perform a Hadamard on the first register and get a state 𝜖/4 away from
the state

𝑙
1 1 −𝑖𝑗
√ |0⟩ ( √ ∑ |𝑊 𝑗 𝑥⟩) + |0⊥ ⟩|𝐺⟩
ℓ 𝑁 ′ 𝑗=0 𝑗!

where 𝑁 ′ just normalizes the state in the parenthesis. Note that after the
Hadamard on the first register, the amplitude corresponding to each |𝑖⟩ is the
first register is the same. We use this procedure√ inside an amplitude ampli-
fication procedure √ to increase the amplitude 1/ ℓ of |0⟩ to be close to 1, by
incurring a factor ℓ in the running time. The outcome will be a state 𝜖/4
away from the state

𝑙
1 −𝑖𝑗
(√ ∑ |𝑊 𝑗 𝑥⟩) = |𝑈̃ 𝑥⟩
𝑁 ′ 𝑗=0 𝑗!

which is the application of 𝑈̃. Since ∥𝑈 − 𝑈̃∥ ≤ 𝜖/4, we have that the above
procedure applies a unitary 𝑈 such that ∥𝑈 − 𝑈 ∥ ≤ 𝜖/2. Note that the running
time of this procedure is given by the amplitude amplification and the time to
multiply with 𝑊 𝑗 , hence we have that the running time is

𝑂(ℓ3/2 (𝜅(𝑀1 )𝜇(𝑀1 ) log(8ℓ/𝜖) + 𝜅(𝑀2 )𝜇(𝑀2 ) log(8ℓ/𝜖))

Now that we know how to apply 𝑈 , we can perform phase estimation on it with
error 𝜖/2. This provides an algorithm for estimating the singular values of 𝑊
with overall error of 𝜖. The final running time is

ℓ3/2
𝑂( (𝜅(𝑀1 )𝜇(𝑀1 ) log(8ℓ/𝜖) + 𝜅(𝑀2 )𝜇(𝑀2 ) log(8ℓ/𝜖))
𝜖
130 CHAPTER 7. SVE-BASED QUANTUM ALGORITHMS

We have 𝜇(𝑀1 ) = 𝜇(𝑀2 ) = 𝜇(𝑃 ) + 𝜇(𝑄) and 𝜅(𝑀1 ) = 𝜅(𝑀2 ) =


𝑄
𝑚𝑎𝑥{𝜆𝑃
𝑚𝑎𝑥 ,𝜆𝑚𝑎𝑥 }
𝑚𝑖𝑛{𝜆𝑃 𝑄 ≤ 𝜅(𝑃 ) + 𝜅(𝑄), and since ℓ = 𝑂(log 1/𝜖)the running
𝑚𝑖𝑛 ,𝜆𝑚𝑖𝑛 }
time can be simplified to

(𝜅(𝑃 ) + 𝜅(𝑄))(𝜇(𝑃 ) + 𝜇(𝑄))


𝑂(̃ ).
𝜖

7.5 A last example: Slow algorithms for log-


determinant
A very simple example of the utility of the SVE subroutines is to estimate
quantities associated to a given matrix. In this case we are going to study the
log-determinant. As the name sais, this is just the logarithm of the determinant
of a (symmetric positive definite) SPD matrix.
Definition 7.1 (Log-determinant of an SPD matrix). Let 𝐴 ∈ ℝ𝑛×𝑛 be a SPD
matrix with singular value decomposition 𝐴 = 𝑈 Σ𝑉 𝑇 . The log-determinant of
𝐴 is defined as:
𝑛 𝑛
log det(𝐴) = log(∏ 𝜎𝑖 ) = ∑ log(𝜎𝑖 )
𝑖 𝑖

Please keep in mind that this is not the fastest algorithm for estimating the
log-determinant (we will see that in the appropriate chapter on spectral sums),
but it’s worth mentioning here because it perhaps the first thing one would try
to do in order to estimate this quantity. It also is a good example of the power
of quantum singular value estimation, and checking the correctness of this proof
might be a good exercise to learn more some mathematical tricks that are very
useful to upper bound quantities that appear in the error analysis or the runtime
analysis of algorithms.
Theorem 7.10 (SVE based algorithm for log-determinant). Assuming to
have quantum access to an SPD matrix 𝐴, the algorithm in figure 7.3 returns
̃
log det(𝐴) such that |log det(𝐴) − log det(𝐴)| < 𝜖| log det(𝐴)| in time 𝑂(𝜇𝜅 3 2
/𝜖 ).

Proof. We can rewrite the quantum state encoding the representation of 𝐴


(which we can create with quantum access to 𝐴) as follow:
𝑛 𝑛
1 1
|𝐴⟩ = ∑ 𝑎𝑖𝑗 |𝑖, 𝑗⟩ = ∑ 𝜎𝑗 |𝑢𝑗 ⟩|𝑢𝑗 ⟩. (7.4)
‖𝐴‖𝐹 𝑖,𝑗=1 ‖𝐴‖𝐹 𝑗=1

Starting from the state |𝐴⟩, we can apply SVE (see lemma 5.8 to |𝐴⟩ up to
precision 𝜖1 to obtain
𝑛
1
∑ 𝜎𝑗 |𝑢𝑗 ⟩|𝑢𝑗 ⟩|𝜎̃𝑗 ⟩,
‖𝐴‖𝐹 𝑗=1
7.5. A LAST EXAMPLE: SLOW ALGORITHMS FOR LOG-DETERMINANT131

Figure 7.3: SVE based algorithm to estimatethe log-determinant of a matrix

where |𝜎̃𝑗 − 𝜎𝑗 | ≤ 𝜖1 . Since ‖𝐴‖ ≤ 1, using controlled operations, we can prepare

1 𝑛 √− log 𝜎̃𝑗
⎛ ⎞
∑ 𝜎𝑗 |𝑢𝑗 ⟩|𝑢𝑗 ⟩|𝜎̃𝑗 ⟩ ⎜
⎜𝐶 |0⟩ + |0⊥ ⟩⎟
⎟, (7.5)
‖𝐴‖𝐹 𝑖=1 𝜎̃𝑗
⎝ ⎠


where 𝐶 = min𝑗 𝜎̃𝑗 /√| log 𝜎̃𝑗 | ≈ 𝜎min /√| log 𝜎min | = 1/𝜅 log 𝜅. The probabil-
ity of |0⟩ is

𝐶 2 𝑛 𝜎𝑗2
𝑃 =− ∑ log 𝜎̃𝑗 .
‖𝐴‖2𝐹 𝑗=1 𝜎̃𝑗2
132 CHAPTER 7. SVE-BASED QUANTUM ALGORITHMS

First, we do the error analysis. Note that


𝑛
𝜎𝑗2 𝑛 𝑛
𝜎𝑗2 𝑛
𝜎𝑗2 𝑛
𝜎𝑗2 𝑛
∣∑ 2
log 𝜎̃𝑗 − ∑ log 𝜎𝑗 ∣ ≤ ∣∑ 2
log 𝜎̃𝑗 − ∑ 2 log 𝜎𝑗 ∣ + ∣∑ 2 log 𝜎𝑗 − ∑ log 𝜎𝑗 ∣
𝑗=1
𝜎̃𝑗 𝑗=1 𝑗=1
𝜎̃𝑗 𝜎̃
𝑗=1 𝑗
𝜎̃
𝑗=1 𝑗 𝑗=1
(7.6)
𝑛
𝜎𝑗2 𝑛
|𝜎𝑗2 − 𝜎̃𝑗2 |
≤ ∑ 2 | log 𝜎̃𝑗 − log 𝜎𝑗 | + ∑ | log 𝜎𝑗 |
𝜎̃
𝑗=1 𝑗 𝑗=1
𝜎̃𝑗2
(7.7)
𝑛
𝜖1 2 𝜖1 𝜖2
≤ ∑(1 + ) ( + 𝑂( 12 )) + (2𝜅𝜖1 + 𝜅2 𝜖21 )| log det(𝐴)|
𝑗=1
𝜎̃𝑗 𝜎̃𝑗 𝜎̃𝑗
(7.8)
≤ 𝑛(𝜅𝜖1 + 𝑂(𝜅2 𝜖21 )) + (2𝜅𝜖1 + 𝜅2 𝜖21 )| log det(𝐴)|
(7.9)
= (𝑛 + 2| log det(𝐴)|)(𝜅𝜖1 + 𝑂(𝜅2 𝜖21 )).
(7.10)

In the third inequality, we use the result that 𝜎𝑗 ≤ 𝜎̃𝑗 + 𝜖1 .


Denote 𝑃 ′ as the 𝜖2 -approximation of 𝑃 obtained by amplitude estimation,
then the above analysis shows that −‖𝐴‖2𝐹 𝑃 ′ /𝐶 2 is an (𝑛 + 2| log det(𝐴)|)(𝜅𝜖1 +
𝑂(𝜅2 𝜖21 )) + 𝜖2 ‖𝐴‖2𝐹 /𝐶 2 approximation of log det(𝐴). Note that

(𝑛 + 2| log det(𝐴)|)(𝜅𝜖1 + 𝑂(𝜅2 𝜖21 )) + 𝜖2 ‖𝐴‖2𝐹 /𝐶 2 (7.11)


= (𝑛 + 2| log det(𝐴)|)(𝜅𝜖1 + 𝑂(𝜅2 𝜖21 )) + 𝜖2 ‖𝐴‖2𝐹 𝜅2 log 𝜅 (7.12)
≤ (𝑛 + 2𝑛 log 𝜅)(𝜅𝜖1 + 𝑂(𝜅2 𝜖21 )) + 𝑛𝜖2 𝜅2 log 𝜅 (7.13)
= 𝑂(𝑛𝜖1 𝜅 log 𝜅 + 𝑛𝜖2 𝜅2 log 𝜅). (7.14)

To make sure the above error is bounded by 𝑛𝜖 it suffcies to choose 𝜖1 = 𝜖/𝜅 log 𝜅
and 𝜖2 = 𝜖/𝜅2 log 𝜅.
Now we do the runtime analysis. The runtime of the algorithm mainly comes
from the using of SVE and the performing of amplitude estimation on the state
in ((7.5)). Using quantum singular value estimation, the complexity to obtain
̃
the state (7.5) is 𝑂(𝜇/𝜖1 ). The complexity to perform amplitude estimation is
̃ ̃
𝑂(𝜇/𝜖1 𝜖2 ) = 𝑂(𝜇𝜅 (log 𝜅)2 /𝜖2 ).
3
Chapter 8

Quantum algorithms for


Monte Carlo

Contributors: Michele Vischi, Alessandro Luongo


In this chapter we focus on how quantum computing speeds up classical Monte
Carlo techniques. Monte Carlo methods are ubiquitous across science and find
many broad applications such as the evaluation of integrals and many more
specific applications such as the pricing of financial derivatives, the computation
of distances among probability distributions and so on. The essence of Monte
Carlo methods is to estimate some expected value of a function 𝑓 of one (or
more) random variable 𝑋, 𝔼[𝑓(𝑋)]. As already discussed in chapter 3, in the
quantum setting, one needs a procedure to load data on quantum registers. In
solving Monte Carlo problems, one needs access to the probability distributions
pertaining to the random variables. In this chapter we will usually implicitly
assume to have quantum query or oracle access to functions 2.2. We will try
to state clearly whenever it is not the case or whenever we need more specific
quantum access such as ??.
In the first part of the chapter we review the work done on the quantum speedup
of Monte Carlo techniques found in this paper (Montanaro, 2015). Previous
works (upon which (Montanaro, 2015) is based) on the same topic can be found
in (Brassard et al., 2011), (Wocjan et al., 2009) and (Heinrich, 2002). In re-
viewing the paper, we will focus on the most important conceptual steps, while
also presenting the statements of the main theorems. In the second part of the
chapter, we present some of the most appealing applications of Monte Carlo
quantum speedup, such as option pricing (Rebentrost et al., 2018) and the esti-
mation of the total variation distance between probability distributions (Mon-
tanaro, 2015). Our main contributions are the statements of the theorems that
allow for quantum speedup in both the option pricing and the total variation
distance problems.

133
134 CHAPTER 8. QUANTUM ALGORITHMS FOR MONTE CARLO

Notation We recap the notation that we will be using in the following. As


already mentioned, the main goal of Monte Carlo methods is to estimate the
expected value 𝜇 of a randomized algorithm 𝐴. The idea is that we have a
random variable 𝑋 taking values in a subset 𝜒 of ℝ𝑑 , for some dimension 𝑑. The
random variable 𝑋 has probability density 𝑓 and typically there is a function
Φ ∶ 𝜒 → ℝ+ . Monte Carlo methods want to approximate:

𝜇 = 𝔼[Φ(𝑋)] = ∫ Φ(𝑥)𝑓(𝑥)𝑑𝑥 (8.1)


𝜒

They do so by producing an appropriate number 𝑁 of i.i.d. samples, each


corresponding to an independent execution of 𝐴. The sample mean 𝜇̃ is then
used as an approximation of 𝜇.
We now give a general definition for the sample mean. We will use the symbol
𝜇,̃ which should not be confused with the above sample mean pertaining to
the algorithm 𝐴. In general, for some random variable 𝑋𝑖 , for 𝑖 = 1, … , 𝑁 the
sample mean is defined as (Kennedy, 2016):

1 𝑁
𝜇𝑁
̃ = ∑𝑋 . (8.2)
𝑁 𝑖=1 𝑖

The 𝜇𝑁̃ is a linear combination of the random variables 𝑋𝑖 , and so it is itself


a random variable. In the language of statistics, the 𝜇𝑁
̃ is called an estimator.
Note that:
• we do not know how many samples 𝑁 we need to get a good estimate of
𝜇;
• even worse, we still don’t know whether this procedure leads to a good
estimate of 𝜇;
• if the estimate is good for some 𝑁 we don’t know how much good it is.
Two fundamental theorems in probability theory help the way out. The
law of large numbers ensures that the sample mean 𝜇𝑁 ̃ is a good approx-
imation of 𝜇 for large enough 𝑁 , while the central limit theorem states
how close is 𝜇𝑁
̃ to 𝜇 for a given value of 𝑁 .
Theorem 8.1 (Law of large numbers). Let 𝑋1 , … , 𝑋𝑁 be independent and
identically distributed random variables. Assume that their expected value is
finite and call it 𝜇. Then, as 𝑁 tends to infinity:

1 𝑁
𝜇𝑁
̃ = ∑ 𝑋 → 𝜇, (𝑎.𝑠), (8.3)
𝑁 𝑖=1 𝑖

which means that:


1 𝑁
𝑃 ( lim ∑ 𝑋𝑘 = 𝜇) = 1 . (8.4)
𝑛→∞ 𝑁
𝑘=1
135

Note that since all the 𝑋𝑖 random variables have expected value 𝜇 the expected
value of the sample mean 𝜇𝑁 ̃ is:

1 1
𝔼[𝜇𝑁
̃ ]= 𝔼[𝑋1 + ⋯ + 𝑋𝑁 ] = 𝑁 𝜇 = 𝜇 . (8.5)
𝑁 𝑁
When this happens we say that 𝜇𝑁 ̃ is an unbiased estimator of 𝜇. The law of
large numbers tells us that 𝜇𝑁
̃ converges to 𝜇 for 𝑁 going to infinity. However in
a computation we can not have 𝑁 going to infinity: we must choose a (eventually
large but) finite 𝑁 . How close is 𝜇𝑁̃ to 𝜇 for a given value of 𝑁 ? The law of
large numbers does not reply to that question (Kennedy, 2016). To get a first
answer, suppose that 𝑋𝑖 have finite variance and call it 𝜎2 . The variance of the
sample mean is then:

1 1 2 𝜎2
𝑣𝑎𝑟(𝜇𝑁
̃ )= 𝑣𝑎𝑟(𝑋 1 + ⋯ + 𝑋 𝑁 ) = 𝑁 𝜎 = . (8.6)
𝑁2 𝑁2 𝑁

This shows that the difference of 𝜇𝑁
̃ from 𝜇 should be of order 𝜎/ 𝑁 (Kennedy,
2016). The central limit theorem gives a more refined statement on the accuracy
of the approximation (Kennedy, 2016).
Theorem 8.2 (Central limit theorem). Let 𝑋𝑖 be a sequence of independent
and identically distributed random variables, such that they have finite mean 𝜇
and finite variance 𝜎2 . The random variable:
𝑁
1
√ ∑(𝑋𝑖 − 𝜇) (8.7)
𝜎 𝑁 𝑖=1

converges in distribution to a standard normal random variable. This means


that:
𝑁 𝑏
1 1 2
lim 𝑃 (𝑎 ≤ √ ∑(𝑋𝑘 − 𝜇) ≤ 𝑏) = ∫ √ 𝑒−𝑥 /2 𝑑𝑥 . (8.8)
𝑛→∞ 𝜎 𝑁 𝑘=1 𝑎 2𝜋

The central limit theorem can be used to construct confidence intervals for our
estimate 𝜇,̃ indeed the probability to estimate 𝜇 up to additive error 𝜖 is:
√ √ √
𝜖 𝑁 (𝜇̃ − 𝜇) 𝑁 𝜖 𝑁
𝑃 (−𝜖 ≤ 𝜇̃ − 𝜇 ≤ 𝜖) = 𝑃 ( − ≤ ≤ ) (8.9)
𝜎 𝜎 𝜎
√ √
𝜖 𝑁 𝜖 𝑁
≈ 𝑃 (− ≤𝑍≤ ), (8.10)
𝜎 𝜎
where 𝑍 is a standard normal random variable. We can find values of 𝑁 such
that the probability to have a good estimate 𝜇𝑁 ̃ up to fixed additive error 𝜖 is
almost 1. Usual values for this probability are√95% or 99%. So for√ example if
we want 𝑃 (−𝑧𝑐 ≤ 𝑍 ≤ 𝑧𝑐 ) = 0.99 where 𝑧𝑐 = 𝜖 𝑁 /𝜎 then 𝑧𝑐 = 𝜖 𝑁 /𝜎 = 2.58
because of the properties of the normal distribution. Estimating 𝜇 with additive
error 𝜖 would require 𝑁 = 6.6564 𝜎2 /𝜖2 samples.
136 CHAPTER 8. QUANTUM ALGORITHMS FOR MONTE CARLO

You can feel the power of Monte Carlo!! All of the above does not depend on
the dimension of the sample space of the random variables 𝑋𝑖 , but just on the
number of repetitions 𝑁 and on the variance 𝜎2 .
This is amazing at first sight but we want to make two remarks. First note
we don’t know the value 𝜇 because we are trying to estimate it. How can we
then know the value of 𝜎2 , and use it to construct the confidence intervals?
To address this problem we use another estimator: the sample variance. It is
defined as:
𝑁
1
𝑠2 = ∑(𝑋𝑖 − 𝜇)̃ 2 (8.11)
𝑁 − 1 𝑘=1

where the prefactor is chosen in such a way so that 𝔼[𝑠2 ] = 𝜎2 , i.e. 𝑠2 is an


unbiased estimator. One can prove that confidence intervals for 𝜇 can be built
as above but with 𝜎 replaced by 𝑠 (Kennedy, 2016).
Second we highlight the main flaw of the Monte Carlo procedure. We saw
that estimating 𝜇 up to additive error 𝜖 with 99% success probability requires
𝑛 = 𝑂(𝜎2 /𝜖2 ) repetitions, independently on the dimension of the sample space.
This is remarkable but not so efficient. It means that if we want to maintain
the confidence at 99% and we want to decrease the additive error 𝜖 by a factor
of 10 we need to increase the number of iteration by a factor of 102 . Imagine
if we want to estimate 𝜇 up to four digits. We would need to run 𝐴 more than
100 million times (Montanaro, 2015).

8.1 Monte Carlo with quantum computing


Here is where quantum computing comes to help. The number of uses of 𝐴 can
be reduced almost quadratically beyond the classical bound (Montanaro, 2015).
The result is based on amplitude estimation.
We first show the quadratic advantage for an algorithm 𝐴 whose output is
bounded between 0 and 1. This speedup will be smartly used to speedup more
general classes of algorithms. This section is also meant to give insights on why
quantum speedup happens in the first place.
Now we will make use of the notation introduced at the beginning of the chapter.
Without loss of generality, we assume that 𝐴 is a quantum algorithm operated
on an 𝑛 qubit quantum register, whose initial state is the |0⊗𝑛 ⟩ state. We
assume that 𝐴 makes no measurements until the end of the algorithm, when
𝑘 ≤ 𝑛 qubits are measured in the computational basis. The outcome of the
measurement 𝑥 ∈ {0, 1}𝑘 is then plugged in a function Φ ∶ {0, 1}𝑘 → [0, 1]. We
call 𝜈(𝐴) the random variable representing the output of 𝐴. Our aim is to find
an estimate of 𝔼[𝜈(𝐴)]. As usual, we also assume to have access to the inverse
of the unitary part of the algorithm1 , which we write as 𝐴−1 .
1 This is needed to run amplitude estimation
8.2. BOUNDED OUTPUT 137

The algorithm 𝐴, as a classical randomized algorithm, is built in such a way that


when we run it k times, we get some random Φ(𝑥1 ), … , Φ(𝑥𝑘 ) with probabilities
|𝛼𝑥𝑖 |2 (for some, in general, complex 𝛼𝑥𝑖 ).
That is to say values of the random variable 𝜈(𝐴) are distributed according to the
probabilities 𝑝𝑥 = |𝛼𝑥 |2 . We will see that with quantum computers, there is a
smarter way to estimate 𝔼[𝜈(𝐴)], instead of repeatedly sampling from 𝐴? Using
a quantum computer we can assume that 𝐴 is now a quantum algorithm (by
taking the classical circuit, making it reversible, and then obtaining a quantum
circuit for it). Then, we can use various tricks to encode the value of 𝜈(𝐴)
in the amplitude of a quantum register, and then estimate it using amplitude
estimation.

8.2 Bounded output


In this section we will show a direct application of the amplitude estimation
theorem, and we will formulate everything using the notation found in (Monta-
naro, 2015). The procedure when the output of 𝐴 is bounded between 0 and
1 is the following. Instead of doing the measurement at the end of the circuit,
we add an ancillary qubit and perform the unitary operation 𝑊 on 𝑘 + 1 qubits
defined as follows:

𝑊 |𝑥⟩|0⟩ = |𝑥⟩(√1 − Φ(𝑥)|0⟩ + √Φ(𝑥)|1⟩) (8.12)

This is a controlled operation which in general requires to first encode Φ(𝑥) in a


register. This is done by performing 𝑘 subsequent controlled rotations for some
specific angle on the 𝑘 + 1th qubit for each of the 𝑘 controlling qubits. Then it
is easy to rotate back the 𝑘 register to |𝑥⟩ (more on this can be found in (Duan
et al., 2020)).
Assuming that we know how to do 𝑊 , when 𝐴 is run with its final measurement
replaced with operation 𝑊 , we would formally end up in a state of the form:

|𝜓⟩ = (𝐼 ⊗𝑊 )(𝐴⊗𝐼)|0𝑛 ⟩|0⟩ = ∑ 𝛼𝑥 |𝜓𝑥 ⟩|𝑥⟩(√1 − Φ(𝑥)|0⟩+ √Φ(𝑥)|1⟩) . (8.13)


𝑥

Why is this state useful?


When the sum over 𝑥 is developed, it turns out that |𝜓⟩ is such that it can be
viewed as a superposition of two orthogonal states. A “good” state, |Ψ𝐺 ⟩ which
is a superposition of all the states in the expansion whose qubit sequence ends
up with a 1 (i.e. the ancilla qubit is in state |1⟩ and a “bad” state |Ψ𝐵 ⟩, which
is a superposition of all the other states. Unfortunately there is no ugly state,
otherwise we would have been screening a spaghetti western cult. The good
and bad states are orthogonal to each other and thus they can be viewed as
spanning two orthogonal sub-spaces in the Hilbert space, which without fantasy
we’ll call good and bad sub-spaces.
138 CHAPTER 8. QUANTUM ALGORITHMS FOR MONTE CARLO

Projecting |𝜓⟩ onto the good subspace is equivalent to find the amplitude of the
good state, which for construction is the expected value of 𝜈(𝐴) (exaclty what
we wanted!!). Indeed calling 𝑃 the projector onto the good subspace, which is
in our case 𝑃 = 𝐼 ⊗ |1⟩⟨1|, we have that:

⟨𝜓|𝑃 |𝜓⟩ = ∑ |𝛼𝑥 |2 Φ(𝑥) = 𝔼[𝜈(𝐴)] . (8.14)


𝑥

Notice that the bound on the output of 𝐴 between 0 and 1 and the form of the
operation 𝑊 leads to a normalized state |𝜓⟩. This means that we can write:

|𝜓⟩ = sin 𝜃|Ψ𝐺 ⟩ + cos 𝜃|Ψ𝐵 ⟩ (8.15)

for some angle 𝜃. We can restate our problem as follows: we want to estimate the
amplitude squared of the good state, i.e. sin2 (𝜃). Indeed we created a circuit
that create a state where the expected value of 𝜈(𝐴) is now encoded in that
amplitude of the quantum state, more specifically it is encoded in the probability
of measuring 1 in an ancilla qubit. The latter is estimated with amplitude
estimation, see theorem 5.4. This algorithm actually returns an estimate of the
angle 𝜃 for which we can derive an estimate of sin2 (𝜃), which in turns return
the expectation of the random variable 𝔼[𝜈(𝐴)].
Let’s recap how to use this algorithm. Amplitude estimation takes as input a
unitary operator on 𝑛 + 1 qubits such that:
√ √
|𝜓⟩ = 1 − 𝑎|Ψ𝐵 ⟩|0⟩ + 𝑎|Ψ𝐺 ⟩|1⟩ (8.16)

The final qubit acts as a label to distinguish good states from bad states.
Then it applies for a number of times 𝑡 the following sequence of projections:
first apply 𝑉 = 𝐼 − 2𝑃 where 𝑃 is some projector and then 𝑈 = 2|𝜓⟩⟨𝜓| − 𝐼.
The form of 𝑃 depends in general on the good state (in our case 𝑃 = 𝐼 ⊗ |1⟩⟨1|).
The projector 𝑈 could be seen as a reflection through |𝜓⟩ and 𝑉 as a reflection
through the bad state |Ψ𝐵 ⟩ in a plane spanned by the good and the bad states
(de Wolf, 2019). The output of amplitude estimation is an estimate 𝑎̃ of 𝑎 =
⟨𝜓|𝑃 |𝜓⟩ = sin2 (𝜃).
𝑈 can also be written as 𝐴𝑆0 𝐴−1 where 𝑆0 changes the phase from +1 to −1
of all the basis states but the |0𝑛 ⟩ state. This is why before we required to have
access to the inverse of 𝐴. 𝑉 is instead the operation of changing the phase
of all the basis states of the good sub-space√from +1 to −1. This operation is
usually done by setting a target qubit to 1/ 2(|0⟩ − |1⟩) as we have:
√ |0⟩ − |1⟩ |0⟩ − |1⟩
𝑈𝑓 |𝑥⟩1/ 2( √ ) = (−1)𝑓(𝑥) |𝑥⟩( √ ) (8.17)
2 2
for any function 𝑓(𝑥) with binary values 0 or 1. The target qubit will always
be just one and applying 𝑈𝑓 is an eigenstate. So we can ignore its presence and
consider 𝑈𝑓 as acting only on the first register.
8.2. BOUNDED OUTPUT 139

We are then ready to state the quantum algorithm to estimate 𝔼[𝜈(𝐴)] when the

output of 𝐴 is bounded between 0 and 1.


Applying amplitude estimation together with the powering lemma C.1, one can
prove the following theorem valid for algorithm ??.
Theorem 8.3 (Quantum Monte Carlo with bounded output). Let |𝜓⟩ as in
Eq.(8.13) and set 𝑈 = 2|𝜓⟩⟨𝜓| − 𝐼. Algorithm in figure ?? uses 𝑂(log(1/𝛿))
copies of |𝜓⟩ = 𝐴|0𝑛 ⟩, uses 𝑈 𝑂(𝑡 log(1/𝛿)) times, and outputs an estimate 𝜇̃
such that
√𝔼[𝜈(𝐴)] 1
|𝜇̃ − 𝔼[𝜈(𝐴)]| ≤ 𝐶( + 2)
𝑡 𝑡
with probability at least 1 − 𝛿, where 𝐶 is a universal constant. In particular for
any fixed 𝛿 > 0 and any 𝜖 such that 0 ≤ 𝜖 ≤ 1, to produce an estimate 𝜇̃ such
that with probability at least 1 − 𝛿, |𝜇̃ − 𝔼[𝜈(𝐴)]| ≤ 𝜖𝔼[𝜈(𝐴)] it suffices to take
𝑡 = 𝑂(1/(𝜖√𝔼[𝜈(𝐴)])). To achieve |𝜇̃ − 𝔼[𝜈(𝐴)]| ≤ 𝜖 with probability at least
1 − 𝛿 it suffices to take 𝑡 = 𝑂(1/𝜖).
We already described the main idea to get quantum speedup: encode the ex-
pected value of 𝜈(𝐴) in a suitably defined amplitude of the quantum register
and then estimate it. The error bound of theorem 8.3 is the error bound of the
amplitude estimation algorithm 5.4. The same applies to the success probabil-
ity which, in this 5.4 formulation of the amplitude estimation theorem, is 8/𝜋2 .
This can be improved to 1 − 𝛿 with the powering lemma C.1. That is why,
for example, 𝑈 is used 𝑂(𝑡 log(1/𝛿)) times: 𝑡 times by amplitude estimation
which is repeated log(1/𝛿) to apply the powering lemma. To get the absolute
error to 𝜖 we just need to set 𝑡 = 𝑂(1/𝜖), and to obtain a relative error we set
𝑡 = 𝑂(1/(𝜖√𝔼[𝜈(𝐴)])).
140 CHAPTER 8. QUANTUM ALGORITHMS FOR MONTE CARLO

8.3 Bounded ℓ2 norm


The algorithm described by theorem 8.3 is limited by the requirement of having
an output value bounded between 0 and 1. We want more. We want a quantum
algorithm to compute the expected value of any random variable. We start by
relaxing the requirement of having bounded output, and just requiring bounded
ℓ2 norm.
To arrive at this result, the first step is to show quantum speedup for the class
of algorithms whose output value is positive and has bounded 𝑙2 norm. This
means that there is a bound on ‖𝜈(𝐴)‖2 = √𝔼[𝜈(𝐴)2 ]. The key idea is the
following: given an algorithm 𝐴 belonging to this class, we consider its possible
output value as the sum of numbers belonging to intervals of the type [0, 1),
[1, 2), [2, 4), [4, 8) and so on. Notice that besides the first interval ([0, 1]), all
the others can be compactly written as [2𝑙−1 , 2𝑙 ] for 𝑙 = 1, ..., 𝑘. If we divide
all of these intervals by 2𝑙 we would get 𝑘 intervals bounded between 0 and 1
(actually 1/2 and 1). In this way we can apply algorithm 8.3 for the interval
[0, 1] and for all these other 𝑘 intervals. If we multiply each of the 𝑘 estimates
we get by 2𝑙 (for 𝑙 = 1, ..., 𝑘 ) and add them together with the estimate for the
[0, 1] interval, we would get an estimate for 𝔼[𝜈(𝐴)].
You may have noticed that the index 𝑙 goes from 1 to 𝑘 and wondered what is
this 𝑘? If not, we wonder for you. Set for example 𝑘 = 2 and imagine that the
expected value of the algorithm is 16. Surely we can not obtain 16 as a sum
of three numbers in the intervals [0, 1], [1, 2], [2, 4]. So how must 𝑘 be chosen?
And even if 𝑘 is chosen properly, how we can be sure that what is left in this
approximation is negligible? We will see in a moment that assuming a bound
on the 𝑙2 norm of 𝜈(𝐴) gives us a way to solve this problem elegantly.
Before going on, we introduce a useful notation. Given any algorithm 𝐴 we
write as 𝐴<𝑥 , 𝐴𝑥,𝑦 , 𝐴≥𝑦 the algorithms defined by executing 𝐴 to produce a
value 𝜈(𝐴) and:
• 𝐴<𝑥 : if 𝜈(𝐴) < 𝑥, output 𝜈(𝐴) otherwise output 0;
• 𝐴𝑥,𝑦 : if 𝑥 ≤ 𝜈(𝐴) < 𝑦, output 𝜈(𝐴) otherwise output 0;
• 𝐴≥𝑦 : if 𝜈(𝐴) ≥ 𝑦, output 𝜈(𝐴) otherwise output 0.
Moreover whenever we have an algorithm 𝐴 and a function 𝑓 ∶ ℝ → ℝ, we
write as 𝑓(𝐴) the algorithm produced by evaluating 𝜈(𝐴) and then computing
𝑓(𝜈(𝐴)).
We can now state the second quantum algorithm which estimates the mean
value of 𝜈(𝐴) with bounded ℓ2 norm.
One can prove the following theorem.
Theorem 8.4 (Quantum algorithms with bounded l2 norm). Let |𝜓⟩ as in
Eq.(8.13), 𝑈 = |𝜓⟩⟨𝜓| − 1. Algorithm in figure 8.1 uses 𝑂(log(1/𝜖) log log(1/𝜖))
3/2
copies of |𝜓⟩, uses 𝑈 𝑂((1/𝜖) log (1/𝜖) log log(1/𝜖)) times, and estimates
8.3. BOUNDED ℓ2 NORM 141

Figure 8.1: Quantum algorithm for Monte Carlo (bounded l2 norm)

𝔼[𝜈(𝐴)] up to additive error 𝜖(||𝜈(𝐴)|| + 1)2 with probability at least 4/5.


We will give here a sketch of the proof for this theorem. The curious can
check it on (Montanaro, 2015). The resource bounds follow from the re-
source bounds of algorithm 8.3, multiplied by the number of times we use
it. Indeed 𝛿 = Ω(1/𝑙𝑜𝑔(1/𝜖)) and we are using algorithm 8.3 𝑂(log(1/𝜖))
times. So the overall number of copies of |𝜓⟩ in all of the uses of algo-
rithm 8.3 is 𝑂(log(1/𝜖) log log(1/𝜖)) and the total number of uses of 𝑈 is
3/2
𝑂((1/𝜖) log (1/𝜖) log log(1/𝜖)).
To estimate the total error (supposing that every use of algorithm in theorem
8.3 succeed) we write:
𝑘
𝔼[𝜈(𝐴)] = [𝜈(𝐴0,1 )] + ∑ 2𝑙 𝔼[𝜈(𝐴2𝑙−1 ,2𝑙 )/2𝑙 ] + 𝔼[𝜈(𝐴≥2𝑘 )] . (8.18)
𝑙=1

Now substituting this expression in the one for the error and using the triangle
inequality we have that:
𝑘
|𝜇̃ − 𝔼[𝜈(𝐴)]| ≤ |𝜇0̃ − 𝔼[𝜈(𝐴0,1 )]| + ∑ 2𝑙 |𝜇𝑙̃ − 𝔼[𝜈(𝐴2𝑙−1 ,2𝑙 )/2𝑙 ]| + 𝔼[𝜈(𝐴≥2𝑘 )] .
𝑙=1
(8.19)
You can see that the last term is a term that we did not estimate with 8.3. This
is exactly the leftover we were talking about some lines above. What the last
equation says is that when choosing 𝑘 as in algorithm 8.1, this term is bounded
by the 𝑙2 norm squared of 𝜈(𝐴). Indeed denoting with 𝑝(𝑥) the probability that
𝐴 outputs 𝑥 we have that:
1 ‖𝜈(𝐴)‖2
𝔼[𝜈(𝐴≥2𝑘 )] = ∑ 𝑝(𝑥)𝑥 ≤ 𝑘
∑ 𝑝(𝑥)𝑥2 = ,. (8.20)
𝑥≥2𝑘
2 𝑥 2𝑘
142 CHAPTER 8. QUANTUM ALGORITHMS FOR MONTE CARLO

Getting the error bound of theorem 8.4 is not really interesting from the con-
ceptual point of view. It is just a matter of math and the usage of previous
results. Indeed, using the error bound obtained for algorithm in theorem 8.3 for
|𝜇0̃ − 𝔼[𝜈(𝐴0,1 )]| and all the |𝜇𝑙̃ − 𝔼[𝜈(𝐴2𝑙−1 ,2𝑙 )/2𝑙 ]|, Cauchy-Schwartz, and other
techqnieus ( refer to (Montanaro, 2015) for the full calculations), one could
finally write that:

𝐶 5
|𝜇̃ − 𝔼[𝜈(𝐴)]| = 𝜖( (1 + + 2||𝜈(𝐴)||2 ) + ||𝜈(𝐴)||22 ) (8.21)
𝐷 𝐷

which for a sufficiently large constant 𝐷 is upper bounded by 𝜖(||𝜈(𝐴)||2 +


1)2 . Here 𝐶 another constant that comes from the error bound of algorithm
of theorem 8.3, wich in turns comes from the constant factors of amplitude
estimation.
Finally we comment on the success probability: it is at least 4/5, when one
uses the union bound, i.e. theorem C.1 on the success probability of all the uses
of theorem 8.3. Note that we can exploit the powering lemma to increase this
success probability up to 1 − 𝛿 for any 𝛿, by repeating this algorithm 𝑂(log(1/𝛿)
times and taking the median.

8.4 Bounded variance


We are ready to demonstrate quantum speedup for the most general case: algo-
rithms whose random output have bounded variance. In this case one obtains
quantum speedup combining the classical Chebyeshev inequality and the use of
quantum speedup of algorithm 8.1. For clarity, we recall that the bound on the
2
variance of 𝜈(𝐴) means that 𝑉 𝑎𝑟(𝜈(𝐴)) = 𝔼[(𝜈(𝐴) − 𝔼[𝜈(𝐴)]) ] ≤ 𝜎2 .
To get to our desired result, we will also need to scale and shift the random
variables of interest. Starting with a random variable 𝑋 distributed according
to some distribution with mean 𝜇𝑥 and standard deviation 𝜎𝑥 , whenever we
scale the random variable by a factor 𝜆, we obtain a random variable 𝑍 = 𝜆𝑋
with a new distribution with mean 𝜇𝑧 = 𝜆𝜇𝑥 and standard deviation 𝜎𝑧 = 𝜆𝜎𝑥 .
When we shift the random variable by a scalar 𝑘, we obtain a random variable
𝑍 = 𝑋 + 𝑘 with a new distribution with mean 𝜇𝑧 = 𝜇𝑥 + 𝑘 and standard
deviation 𝜎𝑧 = 𝜎𝑥 .
The first step of our algorithm is to run the algorithm 𝐴′ = 𝐴/𝜎 obtained by
scaling 𝐴 with 𝜆 = 1/𝜎. For what we said above 𝜈(𝐴′ ) will be a random variable
with mean and standard deviation bounded by 𝜇′ ≤ 𝜇/𝜎 and 𝜎′ ≤ 1 respectively.
Having a standard deviation of order unity means that the output 𝑚 ̃ of a run of
algorithm 𝐴′ is with high probability pretty close to the actual mean 𝜇′ . This
is because of Chebyeshev inequality, i.e. theorem C.4:

1
𝑃 (|𝜈(𝐴′ ) − 𝜇′ | ≥ 3) ≤ . (8.22)
9
8.4. BOUNDED VARIANCE 143

𝑚 − 𝜇′ | ≤ 3. The second
Therefore we can assume with high confidence that |̃
step is to consider algorithm 𝐵, which is produced by executing 𝐴′ and shift
it by subtracting 𝑚
̃ . The random variable 𝜈(𝐵) has a bound on the ℓ2 norm.
Indeed:
||𝜈(𝐵)||2 = 𝔼[𝜈(𝐵)2 ]1/2 = 𝔼[((𝜈(𝐴′ ) − 𝜇′ ) + (𝜇′ − 𝑚
̃ ))2 ]1/2
≤ 𝔼[(𝜈(𝐴′ ) − 𝜇′ )2 ]1/2 + 𝔼[(𝜇′ − 𝑚
̃ )2 ]1/2 = 𝜎′ + 𝔼[(𝜇′ − 𝑚
̃ )2 ]1/2 (8.23)
≤4

This bound can also be stated as ||𝜈(𝐵)/4||2 ≤ 1.


This means that the expected value of 𝜈(𝐵)/4 could be estimated with algorithm
8.1. Actually algorithm 8.1 also requires a positive 𝜈(𝐵) ≥ 0. We will estimate
𝔼[𝜈(𝐵≥0 )/4] and 𝔼[𝜈(−𝐵<0 )/4] using algorithm 8.1 with accuracy 𝜖/(32𝜎) and
failure probability 1/9. Notice that both 𝜈(𝐵≥0 )/4 and 𝜈(−𝐵≤0 )/4 are positive
and the bound ||𝜈(𝐵)/4||2 ≤ 1 implies ||𝜈(𝐵<0 )/4||2 ≤ 1 and ||𝜈(𝐵≥0 )/4||2 ≤ 1.

This algorithm has a quadratic speedup over the classical Monte Carlo method.
Theorem 8.5 (Quantum Monte Carlo with bounded variance - additive
error). Let |𝜓⟩ as in Eq.(8.13), 𝑈 = 2|𝜓⟩⟨𝜓| − 𝐼. Algorithm ?? uses
3/2
𝑂(log(𝜎/𝜖) log log(𝜎/𝜖)) copies of |𝜓⟩, uses 𝑈 𝑂((𝜎/𝜖) log (𝜎/𝜖) log log(𝜎/𝜖))
times and estimates 𝔼[𝜈(𝐴)] up to additive error 𝜖 with success probability at
least 2/3.
The additive error for this theorem is 𝜖 because we required accuracy 𝜖/32𝜎 for
both uses of algorithm 8.1. Indeed, this implies that both the estimates we would
get are accurate up to (𝜖/32𝜎)(||𝜈(𝐵≥0 /4)||2 +1)2 ≤ (𝜖/32𝜎)(1+1)2 = 𝜖/8𝜎. Now
we just multiply by a 4 factor the estimates of 𝔼[𝜈(𝐵≥0 )/4] and 𝔼[𝜈(𝐵<0 )/4] to
get the estimates of 𝔼[𝜈(𝐵≥0 )] and 𝔼[𝜈(𝐵<0 )]. The error then gets 4𝜖/8𝜎 = 𝜖/2𝜎.
Combining these two errors, one has a total additive error for the estimate of
𝐴′ given by 𝜖/𝜎. Since 𝐴 = 𝜎𝐴′ the error for 𝐴 is exactly 𝜖 = 𝜎(𝜖/𝜎).
The success probability is at least 2/3 when using the union bound (theorem
C.1 ) on the success probability of the uses of algorithm 8.1 and the success
144 CHAPTER 8. QUANTUM ALGORITHMS FOR MONTE CARLO

̃ to be close to 𝜇′ . Also in this case we can exploit the powering


probability for 𝑚
lemma to increase this probability up to 1 − 𝛿 for any 𝛿 by repeating this
algorithm 𝑂(log(1/𝛿) times and take the median.

8.5 Applications
We have developed some tools that show how Monte Carlo methods can run
faster in a quantum computer than in a classical computer. As it happens for
most of the algorithm found in this book, all of the above is an advantage at
the level of the mathematical formulation of the algorithm and it is detached
from the problem at hand. Indeed, Monte Carlo methods are used to compute
the expectation value of a function of random variables. A little more effort
is needed to formulate a specific problem that is currently solved by classical
Monte Carlo methods and to exploit the quantum speedup. When a problem is
identified, one need to adapt the general quantum algorithms that we described
above to the peculiar form of the problem. As we have already highlighted,
two main ingredients are required: the creation of a quantum state distributed
according to the right probability distribution, and a query to an oracle function,
what we called 𝜈, in order to perform amplitude estimation.

8.5.1 Pricing of financial derivatives


A wide usage of Monte Carlo methods is devoted to the problem of pricing
of financial derivatives. Through the financial market, buyers and sellers ex-
change so called financial market instruments. These can be divided into two
species. The “underlying” such as stocks, bonds, commodities etc., and their
“derivatives”. These are usually claims that, for example, promise some pay-
ment in the future contingent on an underlying stock’s behavior. An example
of a derivative is a contract agreeing to pay off the difference between a stock
price and some agreed future price. Given our ignorance on the dynamics of
price of stocks, we can model it as a random process. This randomness filters
through to the price of derivatives, they appear to be random too, so that a
certain amount of risk seems to be involved when agreeing on some derivative.
But still, math is a powerful tool and can suggest a way to cope with this ran-
domness. Sometimes math can give us nice analytic solutions, sometimes we
need to use approximate solutions. Monte Carlo integration is such a technique
for the pricing of financial derivatives. We consider a stock driven by a single
Brownian motion, and the European call option (Rebentrost et al., 2018). One
of the simplest framework to model option pricing is the so called Black-Scholes-
Merton (BSM) model. This model considers a single benchmark asset (“stock”),
the price of which is driven by a Brownian motion. In addition, it assumes a
risk-free investment into a bank account (“bond”).
A Brownian motion 𝑊𝑡 is a stochastic process characterized by the following
properties: 1) 𝑊0 = 0; 2) 𝑊𝑡 is continuous; 3) 𝑊𝑡 has independent increments;
4) 𝑊𝑡 − 𝑊𝑠 ∼ 𝑁 (0, 𝑡 − 𝑠) for 𝑡 > 𝑠. Here 𝑁 (𝜇, 𝜎) is the normal distribution with
8.5. APPLICATIONS 145

mean 𝜇 and standard deviation 𝜎. We denote by ℙ the probability measure


under which 𝑊𝑡 is a Brownian motion.
In modeling our problem, we have a genuine uncertainty on the evolution of
the price of the asset over time, so we model it as a stochastic process, which
depends on the value of a Brownian motion. More formally the price dynamics
is governed by a stochastic differential equation:

𝑑𝑆𝑡 = 𝑆𝑡 𝛼 𝑑𝑡 + 𝑆𝑡 𝜎 𝑑𝑊𝑡

where 𝛼 is called drift, 𝜎 volatility and 𝑑𝑊𝑡 is a Brownian increment. 𝛼 dictates


a deterministic rate of change of the stock price over time, while the volatility 𝜎
indicates a stochastic variation of the price. Indicating with 𝑆0 the initial stock
price, the formal solution of this equation is given by:
2
𝑆𝑡 = 𝑆0 𝑒𝜎 𝑊𝑡 +(𝛼−𝜎 /2)𝑡
(8.24)

which is to say, that the value of the stock price over time is a stochastic process
built out of the Brownian process 𝑊𝑡 . We called this solution formal, in the
sense that in it infinitely many realizations are included: at every time the stock
price takes a value that depends on the value of 𝑊𝑡 , which is a random variable.
This leads to infinitely many different trajectories of the price over time. Of
course trying to take into account all the different trajectories becomes soon an
intractable task.
Among the different derivatives we consider options. We take one of the simplest
option: the European call option. This option gives the owner of the option the
right to buy the stock at a fixed moment in time 𝑇 ≥ 0, the maturity date,for
a pre-agreed strike price 𝐾.
A buyer is interested in the following problem: how can he know in advance if it
is convenient to enter the contract? To answer this question, we need a method
to price the option payoff. This is done by defining the payoff function. For the
European call option it is defined as:

𝑓(𝑆𝑇 ) = max{0, 𝑆𝑇 − 𝐾} . (8.25)

It clearly depends on the stock price at the maturity date 𝑇 only. If the strike
price 𝐾 is lower than the stock price 𝑆𝑇 at the maturity date, their difference is
the amount of money one could earn, the payoff, by buying the stock today. The
last statement is not exactly correct, it comes with a little subtlety. We have
to take into account that also the bond evolves over time. In our model we will
make the simpplyfing assumption that the bond price follows a deterministic
equation: \begin{equqtion} dB_t = rB_t,dt \end{equation} with a constant
𝑟. We can informally view this equation as a formulation of the fact that as
the time passes, the value of money changes. If I have 1 euro/dollar/yen now,
it will have a different value in the future. But the pricing of an option must
be performed in the present, or the payoff, that clearly depends on the stock
price at the future time 𝑇 , should be discounted to its present value. One need
146 CHAPTER 8. QUANTUM ALGORITHMS FOR MONTE CARLO

to estimate the amount of money he/she could make by entering the contract
today. The discount factor in this model is just 𝑒−𝑟𝑇 , the inverse of the growth
factor for the value of money over time 𝑒𝑟𝑇 . This is clear by the above equation,
as its solution is given by 𝐵𝑇 = 𝑒𝑟𝑇 𝐵0 . For this reason 𝑟 is also called interest
rate.
We are almost done, but there is another subtlety. Indeed we require that
pricing should be performed under a probability measure that shall not allow
for arbitrage. One can show that this measure, usually denoted by ℚ, is the one
for which the drift of the stock price 𝛼 is equal to the interest rate 𝑟. This may
sound a little confusing, so instead of going into all the details of arbitrage, we
will just comment on the main property that ℚ satisfies, as this is sufficient to
get the main idea:
𝑆0 = 𝑒−𝑟𝑇 𝔼ℚ [𝑆𝑇 ] (8.26)
This is usually referred to as the Martingale property: the expectation value
(under ℚ) of the stock price at time 𝑇 multiplied by the discount factor, is the
present stock price 𝑆0 . This means that at any time, and on average (!!), the
price of the stock can not increase (decrease) above (below) the market rate
𝑟. Or informally we might say that the expected value of the stock price, on
average (!!), will not change over time, so that there is no chance for the buyer
or seller of any option to earn money out of nothing. The price dynamics under
the arbitrage probability measure is described by:

𝑑𝑆𝑡 = 𝑆𝑡 𝑟𝑑𝑡 + 𝑆𝑡 𝜎𝑑𝑊̃ 𝑡 (8.27)

where 𝑊̃ 𝑡 is again a Brownian motion under the probability measure ℚ. (One


can define 𝑊̃ 𝑡 out of 𝑊𝑡 and show that it is a Brownian motion da verificare
questa cosa!). The whole problem of option pricing is then the evaluation of the
following quantity:

Π = 𝑒−𝑟𝑇 𝔼ℚ [𝑓(𝑆𝑇 )] (8.28)

This is the expected value of the option payoff discounted to its present value
under the arbitrage free probability measure. The function 𝑓() ̇ is now any
generic payoff function for the given option. This is in essence the BSM model.
When 𝑓(𝑆𝑇 ) is the payoff function of the European call option that we saw
above, one can find an analytical solution to Π. Notice that this can not always
be true. For complicated payoff functions or more complex asset price dynamics,
analytical methods are useless and one often resorts to Monte Carlo methods,
because the task is to estimate an expected value of some function of random
variables. So what can be exactly different with respect to European option?
European options’ payoff function depends on the asset price at a single future
time 𝑇 . Given another such payoff function, if it is nonlinear or there are
different asset prices that are assumed to be correlated, one can not find an
analytical solution. Another complication enters when the option can be claimed
8.5. APPLICATIONS 147

at different times and not just at a single future time. American options, for
example, allow the buyer to exercise the option at any point in time between
the option start and the option maturity. These options are priced using Monte
Carlo methods. When the pricing of an option requires Monte Carlo methods,
we expect to use all of the quantum machinery developed above to solve this
problem in the quantum realm, speeding up the computation.

[Link] European option pricing


We consider a stock driven by a single Brownian motion and the European
option payoff function. Even if in this case Π has an analytical solution, we will
use this case to simplify the discussion and as a first representative example.
We can write:
Π = 𝑒−𝑟𝑇 𝔼ℚ [𝑣(𝑊𝑇 )] (8.29)
where 𝑊𝑇 is the Brownian motion at time 𝑇 and 𝑣(𝑥) is derived from the payoff
function 𝑓(𝑥) (𝑣(𝑥) plays the role of 𝜈 in the previous sections). As we saw,
𝑊𝑇 is a Gaussian random variable 𝑁 (0, 𝑇 ) with zero mean and 𝑇 variance, and
with probability density given by:

1 𝑥2
𝑝𝑇 (𝑥) = √ 𝑒− 2𝑇 (8.30)
2𝜋𝑇
To use our quantum algorithms, we need to prepare a state which is a super-
position with the square root of these probabilities at each value 𝑥, which are
infinitely many. In real life, we will have a finite register of qubits and we
can only prepare approximately this quantum state because we can only take
a finite set of values 𝑥𝑖 . To do so, we take the support of the density dis-
tribution from ] − ∞, +∞[ to [−𝑥𝑚𝑎𝑥 , 𝑥𝑚𝑎𝑥 ] and discretize this interval with
2𝑛 points, where 𝑛 is the integer number of qubits. We can define the dis-
cretization points as 𝑥𝑗 ∶= −𝑥𝑚𝑎𝑥 + 𝑗Δ𝑥, with Δ𝑥 = 2𝑥𝑚𝑎𝑥 /(2𝑛 − 1) and
𝑗 = 0, … , (2𝑛 − 1). We then define the probabilities 𝑝𝑗 = 𝑝𝑇 (𝑥𝑗 )/𝐶 where the
2𝑛 −1
normalization 𝐶 = ∑𝑗=0 𝑝𝑇 (𝑥𝑗 ) is required so to have 2𝑛 probabilities that
sum up to 1. Through an oracle that gives us quantum sampling access ?? to
the probability distribution, we can run a quantum circuit 𝐺 such that we can
prepare:
2𝑛 −1
𝑛
𝐺|0 ⟩ = ∑ √𝑝𝑗 |𝑗⟩ (8.31)
𝑗=0

Note that we are implicitly identifying |𝑗⟩ with |𝑥𝑗 ⟩, the circuit 𝐺 prepares
the superposition state, and thus it plays the role of 𝐴 found in the previous
sections.
Having the right superposition state, we need to compute the function and per-
form the controlled rotation. For the European call option, the payoff function
is:
2
𝑣𝑒𝑢𝑟𝑜 (𝑥) = max{0, 𝑆0 𝑒𝜎𝑥+(𝑟−1/2𝜎 )𝑇 − 𝐾} (8.32)
148 CHAPTER 8. QUANTUM ALGORITHMS FOR MONTE CARLO

At the discretization points of the Brownian motion we set 𝑣(𝑗) ∶= 𝑣𝑒𝑢𝑟𝑜 (𝑥𝑗 ).
One can find a binary approximation to this function over 𝑛 bits, i.e. 𝑣(𝑗)̃ ∶
{0, 1}𝑛 → {0, 1}𝑛 , because remember that now 𝑗 is a sequence of 𝑛 bits, and we
need 𝑣(𝑗)
̃ to be encoded as a binary expansion in a quantum register, thus to
be another sequence of bits. We can then implement the operation:

|𝑗⟩|0𝑛 ⟩ → |𝑗⟩|𝑣(𝑗)⟩
̃ (8.33)

thanks to an auxiliary register of 𝑛 qubits, initialized in the state |0𝑛 ⟩. Using


the arithmetic model 3.1, we can then apply the controlled rotation 𝑊 to a
further ancillary qubit to end up with:

|𝑗⟩|𝑣(𝑗)⟩
̃ → |𝑗⟩|𝑣(𝑗)⟩(
̃ √1 − 𝑣(𝑗)|0⟩
̃ + √𝑣(𝑗)|1⟩)
̃ (8.34)

Now we can inverse the circuit that got us from |𝑗⟩|0𝑛 ⟩ to |𝑗⟩|𝑣(𝑗)⟩
̃ so that the
auxiliary register goes back to |0𝑛 ⟩ and we can omit it. Probably you have seen
this in many other places, and you will use this fact again.
Note that now, since we discretized the probability distribution and we approx-
imated the function to 𝑣,̃ an estimate 𝜇̂ of the option price is already character-
ized by an error 𝜈, that can be shown to be 𝑂(2−𝑛 ) (Rebentrost et al., 2018).
This makes sense, as the more qubits we have, the better the approximation
will be.
Everything is set up to apply theorem 8.5, except for the fact that we need
to show that the payoff function have bounded variance. One can show
that the European call option has bounded variance 𝕍ℚ [𝑓(𝑆𝑇 )] ≤ 𝜆2 , where
2
𝜆2 = 𝑂(𝑝𝑜𝑙𝑦(𝑆0 , 𝑒𝑟𝑇 , 𝑒𝜎 𝑇 , 𝐾)). Thus we know that through theorem 8.5, using
𝑂(log(𝜆/𝜖) log log(𝜆/𝜖)) copies of the state |𝜓⟩ = (𝕀 ⊗ 𝑊 )(𝐺 ⊗ 𝕀)|0𝑛 ⟩|0⟩ and
3/2
𝑂((𝜆/𝜖) log (𝜆/𝜖) log log(𝜆/𝜖)) applications of 𝑈 = 2|𝜓⟩⟨𝜓| − 𝐼 to provide an
estimate for 𝜇 up to additive error 𝜖 with success probability at least 2/3. As
usual, the success probability can be increased to 1 − 𝛿 for any 𝛿 by taking
𝑂(log(1/𝛿)) repetitions C.1. The total error is then

|𝜇̂ − 𝔼ℚ [𝑓(𝑆𝑇 )]| ≤ 𝜖 + 𝜈 (8.35)

which takes into account the additive error 𝜖 from theorem 8.5 and the discretiza-
tion error 𝜈. Discounting 𝜇̂ then retrieves an estimation of the option price Π̂
up to additive error 𝜈 + 𝜖.

[Link] Asian option pricing


As we already pointed out, the European call option can be priced analytically in
the BSM framework, and thus Monte Carlo methods are not required. Another
type of option is the so called Asian option, whose payoff depends on the average
8.5. APPLICATIONS 149

asset price before the maturity date. The payoff function for an Asian call option
is defined as:
𝑓(𝐴𝑇 ) = max{0, 𝐴𝑇 − 𝐾} (8.36)
where 𝐾 is the strike price and 𝑇 is the maturity date. The definition of 𝐴𝑇 is
not unique. Arithmetic mean Asian option value is defined via:

1 𝐿
𝐴𝑎𝑟𝑖𝑡ℎ = ∑𝑆 (8.37)
𝑇
𝐿 𝑙=1 𝑡𝑙

while the geometric mean option value is defined via:

1 𝐿
𝐴𝑔𝑒𝑜
𝑇 = exp ∑ log 𝑆𝑡𝑙 (8.38)
𝐿 𝑙=1

for predefined time points 0 < 𝑡1 < … < 𝑡𝐿 ≤ 𝑇 with 𝐿 ≥ 1. Note that
if you develop the summation in the geometric mean, and use the facts that
𝑎 log 𝑥 = log 𝑥𝑎 and exp log 𝑥 = 𝑥, one retrives the more common definition of
1/𝐿
𝐿
the geometric mean 𝐴𝑔𝑒𝑜
𝑇 = ( ∏𝑙=1 𝑆𝑡𝑙 ) . We assume in the following that all
adjacent time points are separated by the interval Δ𝑡, i.e. 𝑡𝑙+1 − 𝑡𝑙 = Δ𝑡 = 𝑇 /𝐿
for all 𝑙 = 1, … , 𝐿 − 1. Analogously to the European option, we assume to
have quantum sampling access ?? to a state that corresponds to the Gaussian
distribution with variance Δ𝑡:

2𝑚 −1
|𝑝Δ𝑡 ⟩ = 𝐺|0𝑚 ⟩ = ∑ √𝑝Δ𝑡 (𝑥𝑗 )|𝑗⟩ (8.39)
𝑗=0

where now 𝑚 is the number of discrete points over which one can define a value
for the stock price. The above state has 𝑚 qubits and it can be prepared thanks
to suitable quantum sampling access ??. With such a state we performed the
first key step to apply Monte Carlo techniques in the quantum regime: we stored
the right probability distribution in the amplitudes of the qubit register for a
given time 𝑡𝑖 . Indeed for a given 𝑖, the stock price is distributed according to
a normal random variable with variance Δ𝑡. We want to prepare the product
of such states for every 𝑡𝑖 with 𝑖 = 1, … , 𝐿. To do so, we use 𝐿 registers of 𝑚
qubits and prepare the state |𝑝Δ𝑡 ⟩ in each register:

|𝑝⟩ = |𝑝Δ𝑡 ⟩ … |𝑝Δ𝑡 ⟩ (8.40)

Next we define the operation:

|𝑗1 , … , 𝑗𝐿 ⟩|0⟩ → |𝑗1 , … , 𝑗𝐿 ⟩|𝐴(𝑆𝑡1 (𝑥𝑗1 ), … , 𝑆𝑡𝐿 (𝑥𝑗𝐿 ))⟩ (8.41)

here 𝐴(𝑆𝑡1 (𝑥𝑗1 ), … , 𝑆𝑡𝐿 (𝑥𝑗𝐿 )) is the average stock price corresponding to the
path 𝑥𝑗1 , … 𝑥𝑗𝐿 . If you wonder why to introduce such operation, consider a
150 CHAPTER 8. QUANTUM ALGORITHMS FOR MONTE CARLO

state |𝑗1 , … , 𝑗𝐿 ⟩. This is associated to the following stock price path: at time 𝑡1
the stock price is 𝑆𝑡1 (𝑥𝑗1 ), at time 𝑡2 the stock price is 𝑆𝑡2 (𝑥𝑗2 ) and so on (with
their corresponding probabilities). To this stock price path is associated the
corresponding average value 𝐴(𝑆𝑡1 (𝑥𝑗1 ), … , 𝑆𝑡𝐿 (𝑥𝑗𝐿 )). In this way, when using
such operation on the state |𝑝⟩ we will get a superposition in which the ancillary
registers encode the averages associated to any possible stock price path. Since
we want an estimate of the mean of these averages, we should be not surprised
anymore.
To be able to apply such a transformation, each index 𝑗 is mapped to its corre-
sponding point 𝑥𝑗 via 𝑥𝑗 = −𝑥𝑚𝑎𝑥 + 𝑗Δ𝑥. Starting from the known 𝑆0 , we can
compute the stock price at each time point by iteration:
2
𝑆𝑡𝑙+1 (𝑥) = 𝑆𝑡𝑙 𝑒𝜎𝑥+(𝑟−𝜎 /2)Δ𝑡
(8.42)

Notice that we embedded the values of 𝜎 and 𝑟 in the circuit. In this way we
can get a state where the label |𝑗1 , … , 𝑗𝐿 ⟩ is associated to the corresponding
stock price path
|𝑗1 , … , 𝑗𝐿 ⟩|𝑆𝑡1 (𝑥𝑗1 ), … , 𝑆𝑡𝐿 (𝑥𝑗𝐿 )⟩ (8.43)
Now the average can be computed in a sequential manner. What we mean is
that we can implement the step:

|𝑗1 , … , 𝑗𝐿 ⟩|𝑆𝑡𝑙 (𝑥𝑗𝑙 )⟩|𝐴(𝑆𝑡1 (𝑥𝑗1 ), … , 𝑆𝑡𝑙 (𝑥𝑗𝑙 ))⟩ →


(8.44)
|𝑗1 , … , 𝑗𝐿 ⟩|𝑆𝑡𝑙+1 (𝑥𝑗𝑙+1 )⟩|𝐴(𝑆𝑡1 (𝑥𝑗1 ), … , 𝑆𝑡𝑙+1 (𝑥𝑗𝑙+1 ))⟩

these steps are repeated until the final time 𝑡𝐿 is reached and 𝐴(𝑆𝑡1 (𝑥𝑗1 ), … , 𝑆𝑡𝐿 (𝑥𝑗𝐿 ))
is stored in a register of qubits. Then we just reverse the quantum operation in
the ancillary registers storing the intermediate steps, so that ancillary registers
go back to an all |0⟩ product state.
Applying these operations to the product state prepared before one finally gets:
2𝑚 −1
∑ √𝑝𝑗1 ,…,𝑗𝐿 |𝑗1 , … , 𝑗𝐿 ⟩|𝐴(𝑆𝑡1 (𝑥𝑗1 ), … , 𝑆𝑡𝐿 (𝑥𝑗𝐿 ))⟩ (8.45)
𝑗1 ,…,𝑗𝐿 =0


where 𝑝𝑗1 ,…,𝑗𝐿 = √𝑝Δ𝑡 (𝑥1 ) … √𝑝Δ𝑡 (𝑥𝐿 ). Now we can use append an ancillary
qubit in |0⟩ state and apply the controlled rotation encoding the value of the
payoff function on the |1⟩ subspace. Using theorem 8.5 on this state gives the
expectation value that we want.
Notice that we are allowed to use theorem 8.5: Asian options have a bounded
variance (the arithmetic mean upper bounds the geometric mean) and it is upper
bounded by the expected maximum of the stock price max{𝑆𝑡1 , … , 𝑆𝑡𝐿 }. The
variance of this maximum can be bounded. We thus get a quantum algorithms
for the pricing of Asian option that needs 𝑁 queries for accuracy 𝜖, while, as we
explained at the beginning of the chapter, classical Monte Carlo methods would
need 𝑁 2 samples to get the same accuracy 𝜖.
8.5. APPLICATIONS 151

Note that the algorithms that we presented to price European and Asian options
have a running time that depends on a bound on the variance of this variables.
Of course if the bound is tight, this means that we can have an optimal running
time. As we will see there exist a quantum algorithm to estimate the expectation
value of random variables that does not require to know beforehand a bound on
the variance.
152 CHAPTER 8. QUANTUM ALGORITHMS FOR MONTE CARLO
Chapter 9

Dimensionality reduction

Contributors: Alessandro Luongo, Armando Bellante

We devote this chapter to the study of quantum algorithms for dimensionality


reduction. We first delve into unsupervised methods, and then look at the
supervised case. In both case we discuss two main subroutines. In one case we
can use quantum computers to fit a machine learning model. This means that
we can obtain, from a quantum computer, a classical description of the machine
learning model (i.e. a set of vectors). In the second case we can imagine using
a quantum computer to perform the mapping from an original feature space to
the dimensionality-reduced feature space.

153
154 CHAPTER 9. DIMENSIONALITY REDUCTION

9.1 Unsupervised algorithms


In this section we describe three algorithms: the QPCA, QCA and QLSA. These
algorithms are mainly from (Bellante and Zanero, 2022), which solves in a sin-
gle framework many of these eigenvalue problems that appears in fitting some
simple machine learning models.

9.1.1 Quantum PCA


Principal component analysis is a widely-used multivariate statistical method
for continuous variables that finds many applications in machine learning, rang-
ing from outlier detection to dimensionality reduction and data visualization.
Consider a matrix 𝐴 ∈ ℝ𝑛×𝑚 that stores information about 𝑛 data points using
𝑚 coordinates (e.g. think of 𝑛 images described through 𝑚 pixels each), its prin-
cipal components are the set of orthogonal vectors along which the variance of
the data points is maximized. The goal of PCA is to compute the principal com-
ponents, with the amount of variance they capture, and rotate the data-points
to make the axis coincide with the principal components. During the process
it is possible to perform dimensionality reduction and reduce the number of
variables taken into account, i.e. reducing 𝐴 ∈ ℝ𝑛×𝑚 to 𝐴 ∈ ℝ𝑛×𝑘 where 𝑘 ≤ 𝑚,
and express the original data in terms of fewer latent variables that account for
the majority of the variance of the original data. If it is possible to find a few
latent variables that retain a large amount of variance of the original variables,
it is possible to use PCA to visualize even high dimensional datasets.

[Link].1 Connection to Singular Value Decomposition The model of


PCA is closely related to the singular value decomposition of the data matrix 𝐴,
shifted to row mean 0. The principal components coincide with the right singular
vectors 𝑣𝑖 . The factor scores 𝜆𝑖 = 𝜎𝑖2 represent the amount of variance along
each of them and the factor score ratios 𝜆(𝑖) = ∑𝜆𝑟 𝑖𝜆 express the percentage of
𝑗 𝑗

the variance retained. For datasets with 0 mean, the transformation consists in
a rotation along the principal components: 𝑌 = 𝐴𝑉 = 𝑈 Σ𝑉 𝑇 𝑉 = 𝑈 Σ ∈ ℝ𝑛×𝑚 .
Therefore, the data points in the new subspace can be computed using the left
singular vectors and the singular values of 𝐴. When performing dimensionality
reduction it suffice to use only the top 𝑘 singular values and vectors 𝑌 (𝑘) =
𝐴𝑉 (𝑘) = 𝑈 Σ𝑉 𝑇 𝑉 (𝑘) = 𝑈 (𝑘) Σ(𝑘) ∈ ℝ𝑛×𝑚 .

[Link].2 Quantum algorithms for PCA Using the procedures from sec-
tion 7.2 it is possible to extract the model for principal component analysis.
Theorems 7.6, 7.7, ?? allow to retrieve information on the factor scores and
on the factor score ratios, while Theorem 7.8 allows extracting the principal
components. The run-time of the model extraction is the sum of the run-times
of the theorems: 𝑂 ̃ (( 12 + 𝑘𝑚2 ) 𝜇(𝐴) ). The model comes with the following
𝛾 𝜃𝛿 𝜖
(𝑖)
guarantees: ‖𝜎𝑖 − 𝜎𝑖 ‖ ≤ 2𝜖 ; ‖𝜆𝑖 − 𝜆𝑖 ‖ ≤ 𝜖; ‖𝜆(𝑖) − 𝜆 ‖ ≤ 𝛾; ‖𝑣𝑖 − 𝑣𝑖 ‖ ≤ 𝛿 for
𝑖 ∈ {0, 𝑘 − 1}. This run-time is generally smaller than the number of elements
9.1. UNSUPERVISED ALGORITHMS 155

of the input data matrix, providing polynomial speed-ups on the best classical
routines for non-sparse matrices. In writing the time complexity of the routines,
we omitted the term √1𝑝 because usually the amount of variance to retain 𝑝 is
chosen to be a number greater than 0.5 (generally in the order of 0.8/0.9).
When performing dimensionality reduction, the goal is to obtain the matrix
𝑌 = 𝑈 Σ ∈ ℝ𝑛×𝑘 , where 𝑈 ∈ ℝ𝑛×𝑘 and Σ ∈ ℝ𝑘×𝑘 are composed respectively by
the top 𝑘 left singular vectors and singular values. When this is the case, the user
might want to extract the top 𝑘 𝑢𝑖 and 𝜎𝑖 rather than the principal components,
to avoid matrix multiplication. For this reason, we provide a lemma to bound
the error on the retrieved mode. For sake of completeness, the error bound is
also stated for 𝑉 Σ.
Lemma 9.1 (Accuracy of qPCA’s representation (classical)). Let 𝐴 ∈ ℝ𝑛×𝑚
be a matrix with 𝜎𝑚𝑎𝑥 ≤ 1. Given some approximate procedures to retrieve
estimates 𝜎𝑖 of the singular values 𝜎𝑖 such that ‖𝜎𝑖 − 𝜎𝑖 ‖ ≤ 𝜖 and unit estimates
𝑢𝑖 of the left singular vectors 𝑢√𝑖 such that ‖𝑢𝑖 − 𝑢𝑖 ‖2 ≤ 𝛿, the error on
√ 𝑈 Σ can
be bounded as ‖𝑈 Σ − 𝑈 Σ‖𝐹 ≤ 𝑘(𝜖 + 𝛿). Similarly, ‖𝑉 Σ − 𝑉 Σ‖𝐹 ≤ 𝑘(𝜖 + 𝛿).

Proof. The first step of the proof consists in bounding the error on the columns
of the matrices: ||𝜎𝑖 𝑢𝑖 − 𝜎𝑖 𝑢𝑖 ||.

‖𝜎𝑖 𝑢𝑖 − 𝜎𝑖 𝑢𝑖 ‖ ≤ ‖(𝜎𝑖 ± 𝜖)𝑢𝑖 − 𝜎𝑖 𝑢𝑖 ‖ = ‖𝜎𝑖 (𝑢𝑖 − 𝑢𝑖 ) ± 𝜖𝑢𝑖 ‖


Because of the triangular inequality, ‖𝜎𝑖 (𝑢𝑖 − 𝑢𝑖 ) ± 𝜖𝑢𝑖 ‖ ≤ 𝜎𝑖 ‖𝑢𝑖 − 𝑢𝑖 ‖ + 𝜖‖𝑢𝑖 ‖.
Also by hypothesis, ‖(𝑢𝑖 − 𝑢𝑖 )‖ ≤ 𝛿 and ||𝑢𝑖 || = 1 . Thus, 𝜎𝑖 ‖𝑢𝑖 − 𝑢𝑖 ‖ + 𝜖‖𝑢
√𝑖 ‖ ≤
𝜎𝑖 𝛿 + 𝜖. From the error bound on the columns and the fact that 𝑓(𝑥) = 𝑥 is
an increasing monotone function, it is possible to prove the error bound on the
matrices:
√ 𝑛 𝑘 √ 𝑘
√ √ 2
‖𝑈 Σ − 𝑈 Σ‖𝐹 = ∑ ∑ ‖𝜎𝑗 𝑢𝑖𝑗 − 𝜎𝑗 𝑢𝑖𝑗 ‖ = √∑ (‖𝜎𝑗 𝑢𝑗 − 𝜎𝑗 𝑢𝑗 ‖)
√ 2

⎷ 𝑖 𝑗 ⎷ 𝑗
√ 𝑘 √
√ 2
≤ √∑ (𝜖 + 𝛿𝜎𝑗 ) ≤ √𝑘 (𝜖 + 𝛿𝜎𝑚𝑎𝑥 ) ≤ 𝑘(𝜖 + 𝛿‖𝐴‖)
2

⎷ 𝑗

Finally, since 𝜎𝑚𝑎𝑥 ≤ 1, we get that ‖𝑈 Σ − 𝑈 Σ‖𝐹 ≤ 𝑘(𝜖 + 𝛿).

The fact that the matrix has been normalized to have a spectral norm smaller
than one is usually not relevant for the final applications of PCA. However, if
one desires to represent transformation of the not-normalized matrix 𝐴, the
error bounds become the ones of the lemma below.
Lemma 9.2 (Non-normalized accuracy of qPCA’s representation (classical)).
The estimated representations of the lemma above, for the not-normalized matrix
156 CHAPTER 9. DIMENSIONALITY REDUCTION

𝐴, are ‖𝐴‖𝑈 Σ and ‖𝐴‖𝑉 Σ. The error bounds become ∣∣||𝐴||𝑈 Σ − ||𝐴||𝑈 Σ∣∣𝐹 ≤
√ √
𝑘||𝐴||(𝜖 + 𝛿) and ∣∣||𝐴||𝑉 Σ − ||𝐴||𝑉 Σ∣∣𝐹 ≤ 𝑘||𝐴||(𝜖 + 𝛿)

Proof. Firstly, it is easy to see that to get the desired data representations it
suffices to multiply the output matrix by ‖𝐴‖. Indeed, in our quantum memory,
1
the singular values of the non-normalized matrix are scaled by a factor ‖𝐴‖ ,
while the singular vectors remain the same. To prove the bounds, we can just
multiply both sides of the inequalities from Lemma 9.1 by ||𝐴||, which is a
positive quantity:
√ √
∥‖𝐴‖𝑈 Σ − ||𝐴||𝑈 Σ∥𝐹 ≤ 𝑘‖𝐴‖(𝜖 + 𝛿), ∥‖𝐴‖𝑉 Σ − ‖𝐴‖𝑉 Σ∥𝐹 ≤ 𝑘‖𝐴‖(𝜖 + 𝛿).

Based on Lemma 5.4, we also provide algorithms to produce quantum states


proportional to the data representation in the new feature space. After 𝑉 (𝑘) ∈
ℝ𝑚×𝑘 has been extracted, these routines create the new data points in almost
constant time and are therefore useful when these states are used in a quantum
machine learning pipeline.
Corollary 9.1 (qPCA: vector dimensionality reduction). Let 𝜉 be a precision
parameter. Let there be efficient quantum access to the top 𝑘 right singular
(𝑘) (𝑘)
vectors 𝑉 ∈ ℝ𝑚×𝑘 of a matrix 𝐴 = 𝑈 Σ𝑉 𝑇 ∈ ℝ𝑛×𝑚 , such that ‖𝑉 (𝑘) − 𝑉 ‖ ≤
√𝜉 . Given efficient quantum access to a row 𝑎 of 𝐴, the quantum state |𝑦 ⟩ =
2 𝑖 𝑖
1 𝑘
‖𝑦𝑖 ‖ ∑𝑖 𝑦𝑘 |𝑖⟩, proportional to its projection onto the PCA space, can be created in
time 𝑂 ̃ ( ‖𝑎𝑖 ‖ ) with probability at least 1 − 1/poly(𝑚) and precision ‖|𝑦 ⟩ − |𝑦 ⟩‖ ≤
‖𝑦𝑖 ‖ 𝑖 𝑖
‖𝑎𝑖 ‖ ̃
𝜉. An estimate of ‖𝑦 ‖, to relative error 𝜂, can be computed in 𝑂(1/𝜂).
‖𝑦𝑖 ‖ 𝑖

Proof. In the proof we use 𝑉 to denote the matrix 𝑉 (𝑘) ∈ ℝ𝑚×𝑘 . Given a vector
𝑎𝑖 , its projection onto the k-dimensional PCA space of 𝐴 is 𝑦𝑖𝑇 = 𝑎𝑇𝑖 𝑉 , or
equivalently 𝑦𝑖 = 𝑉 𝑇 𝑎𝑖 . Note that ‖𝑦𝑖 ‖ = ‖𝑉 𝑇 𝑎𝑖 ‖. It is possible to use Lemma
5.4 to multiply the quantum state |𝑎𝑖 ⟩ by 𝑉 𝑇 , appropriately padded with 0s
to be a square ℝ𝑚×𝑚 matrix. Lemma 5.4 states that it is possible to create
an approximation |𝑦𝑖 ⟩ of the state |𝑦𝑖 ⟩ = |𝑉 𝑇 𝑎𝑖 ⟩ in time 𝑂̃ ( 𝜇(𝑉 𝑇 ) log(1/𝜖) ) with
𝛾
probability 1 − 1/poly(𝑚), such that ‖|𝑦𝑖 ⟩ − |𝑦𝑖 ⟩‖ ≤ 𝜖. Since 𝑉 𝑇 has rows with
unit ℓ2 norm, we can use a result from Theorem IV.1 of (Kerenidis and Prakash,
2020) to prepare efficient quantum access to it with 𝜇(𝑉 𝑇 ) = 1. Choosing the
parameter as 𝛾 = ‖𝑉 𝑇 𝑎𝑖 ‖/‖𝑎𝑖 ‖, we get a run-time of 𝑂(̃ ‖𝑎𝑖 ‖ log(1/𝜖)). We can
‖𝑦𝑖 ‖
consider the term log(1/𝜖) to be negligible, as, for instance, an error 𝜖 = 10−17
would not be relevant in practice, while accounting for a factor 17 in the run-
time. We conclude that the state |𝑦𝑖 ⟩ can be created in time 𝑂 ̃ ( ‖𝑎𝑖 ‖ ) with
‖𝑦𝑖 ‖
probability 1 − 1/poly(𝑚) and that its norm can be estimated to relative error
𝜂 in time 𝑂̃ ( ‖𝑎𝑖 ‖ 1 ).
‖𝑦 ‖ 𝜂
𝑖
9.1. UNSUPERVISED ALGORITHMS 157

For what concerns the error, we start by bounding ‖𝑦𝑖 − 𝑦𝑖 ‖ and use Lemma D.4
to bound the error on the quantum states. We assume to have estimates 𝑣𝑖 of
the columns of 𝑉 such that ‖𝑣𝑖 − 𝑣𝑖 ‖ ≤ 𝛿.

√ 𝑛 𝑘 √
√ 2
‖𝑉 − 𝑉 ‖𝐹 = √∑ ∑ (𝑣𝑖𝑗 − 𝑣𝑖𝑗 ) ≤ 𝑘𝛿
⎷ 𝑖 𝑗
(𝑘) √
Considering that ‖𝑦𝑖 − 𝑦𝑖 ‖ = ‖𝑎𝑇𝑖 𝑉 (𝑘) − 𝑎𝑇𝑖 𝑉 ‖ ≤ ‖𝑎𝑖 ‖ 𝑘𝛿, we can use Lemma
D.4 to state

‖𝑎𝑖 ‖ √ ‖𝑎 ‖
‖|𝑦𝑖 ⟩ − |𝑦𝑖 ⟩‖ ≤ 2𝑘𝛿 = 𝑖 𝜉.
‖𝑦𝑖 ‖ ‖𝑦𝑖 ‖
We can set 𝛿 = √𝜉 and require ‖𝑉 − 𝑉 ‖𝐹 ≤ √𝜉 .
2𝑘 2

This result also holds when 𝑎𝑖 is an new data point, not necessarily stored in
‖𝑦𝑖 ‖
𝐴. Note that ‖𝑎 ‖ is expected to be close to 1, as it is the percentage of support
𝑖
of 𝑎𝑖 on the new feature space spanned by 𝑉 (𝑘) . We formalize this better using
Definition 9.1 below.
Corollary 9.2 (qPCA: matrix dimensionality reduction). Let 𝜉 be a precision
parameter and 𝑝 be the amount of variance retained after the dimensionality
reduction. Let there be efficient quantum access to 𝐴 = 𝑈 Σ𝑉 𝑇 ∈ ℝ𝑛×𝑚 and
(𝑘) (𝑘) √
𝜉 𝑝
to its top k right singular vectors 𝑉 ∈ ℝ𝑚×𝑘 , such that ‖𝑉 (𝑘) − 𝑉 ‖ ≤ √2 .
There exists a quantum algorithm that, with probability at least 1 − 1/poly(𝑚),
𝑛
creates the state |𝑌 ⟩ = ‖𝑌1‖ ∑𝑖 ‖𝑦𝑖,⋅ ‖|𝑖⟩|𝑦𝑖,⋅ ⟩, proportional to the projection of 𝐴
𝐹

in the PCA subspace, with error ‖|𝑌 ⟩ − |𝑌 ⟩‖ ≤ 𝜉 in time 𝑂(1/ ̃ √𝑝). An estimate
of ‖𝑌 ‖ , to relative error 𝜂, can be computed in 𝑂( ̃ √1 ).
𝐹 𝑝𝜂

Proof. In the proof we use 𝑉 to denote the matrix 𝑉 (𝑘) ∈ ℝ𝑚×𝑘 . Using the same
reasoning as the proof above and giving a closer look at the proof of Lemma 5.4
(Lemma 24 (Chakraborty et al., 2019)), we see that it is possible to create the
𝑇
̃
state |0⟩(𝑉 |𝑎𝑖 ⟩) + |0⟂ ⟩ in time 𝑂(1) and that the term ̃
1
𝛾 is introduced to boost
the probability of getting the right state. If we apply Lemma 5.4 without the
amplitude amplification step to the superposition of the rows of 𝐴, we obtain
the following mapping in time 𝑂(1):̃
𝑛 𝑛
1 1
|𝐴⟩ = ∑ ‖𝑎𝑖,⋅ ‖|𝑖⟩|𝑎𝑖,⋅ ⟩ ↦ ∑(‖𝑦𝑖,⋅ ‖|0⟩|𝑖⟩|𝑦𝑖,⋅ ⟩ + ‖𝑦𝑖,⋅⟂ ‖|0⟂ ⟩), (9.1)
‖𝐴‖𝐹 𝑖 ‖𝐴‖𝐹 𝑖

𝑟
where ‖𝑦𝑖,⋅⟂ ‖ are normalization factors. Keeping in mind that ‖𝐴‖𝐹 = √∑𝑖 𝜎𝑖2
𝑛 𝑘
and ‖𝑌 ‖𝐹 = √∑𝑖 ‖𝑦𝑖,⋅ ‖2 = √∑𝑖 𝜎𝑖2 , we see that the amount of ex-
158 CHAPTER 9. DIMENSIONALITY REDUCTION

𝑘
∑𝑖 𝜎𝑖2 2
plained variance is 𝑝 = 𝑟
∑𝑗 𝜎𝑗2
= ( ‖𝑌 ‖𝐹
‖𝐴‖ ) . The probability of obtaining
𝐹
𝑛
𝑛 ‖𝑌 ‖2𝐹 ∑𝑖 ‖𝑦 ‖2
|𝑌 ⟩ = ‖𝑌1‖ ∑𝑖 ‖𝑦𝑖,⋅ ‖|𝑖⟩|𝑦𝑖,⋅ ⟩ is 𝑝 = = ‖𝐴‖2𝑖,⋅ . We conclude that, using
‖𝐴‖2𝐹
𝐹 𝐹
̃ √𝑝) rounds of amplitude amplification, we obtain |𝑌 ⟩ with proability
𝑂(1/
1 − 1/poly(𝑚) (5.1).
(𝑘) √
Considering that ‖𝑌 − 𝑌 ‖ = ‖𝐴𝑉 (𝑘) − 𝐴𝑉 ‖ ≤ ‖𝐴‖ 𝑘𝛿, we can use Lemma
D.4 to state
‖𝐴‖𝐹 √
‖|𝑌 ⟩ − |𝑌 ⟩‖ ≤ 2𝑘𝛿 = 𝜉. (9.2)
‖𝑌 ‖𝐹
√ √
𝜉 𝑝 𝜉 𝑝
We can set 𝛿 = √𝜉 ‖𝑌 ‖𝐹 = √ , so we require ‖𝑉 − 𝑉 ‖𝐹 ≤ √ .
2𝑘 ‖𝐴‖𝐹 2𝑘 2

The error requirements of the two corollary propagate to the run-time of the
model extraction in the following way.
Corollary 9.3 (qPCA: fitting time). Let 𝜖 be a precision parameter and 𝑝 =
∑𝑖∶𝜎 𝜎𝑖2
𝑖 ≥𝜃
𝑟
∑𝑗 𝜎𝑗2
the amount of variance to retain, where ‖𝜎𝑖 − 𝜎𝑖 ‖ ≤ 𝜖. Given efficient
quantum access to a matrix 𝐴 ∈ ℝ𝑛×𝑚 , the run-time to extract 𝑉 (𝑘) ∈ ℝ𝑚×𝑘 for
̃ ( 𝜇(𝐴)𝑘22 𝑚 ).
corollaries 9.1, @ref{cor:qpca:matrix} is 𝑂 𝜃𝜖𝜉

We state the proof for Corollary 9.2, as its error is more demanding than the
one of Corollary 9.1. This way, the proof stands for both cases. ::: {.proof}
The procedure to train the model consists in using Theorem ?? to extract the
threshold 𝜃, given the amount of variance to retain 𝑝, and to leverage Theorem
7.8 to extract the 𝑘 right singular vectors that compose 𝑉 ∈ ℝ𝑚×𝑘 . The run-time
of Theorem ?? is smaller than the one of Theorem 7.8, so we can focus on the √
𝜉 𝑝
last one. From the proof of Corollary 9.2, we know that to have ‖𝑉 −𝑉 ‖𝐹 ≤ √2
√ √
𝜉 𝑝 𝜉 𝑝
we need ‖𝑣𝑖 − 𝑣𝑖 ‖ ≤ √2𝑘 . Substituting 𝛿 = √2𝑘 in the run-time of Theorem 7.8,
2
̃ 𝜇𝐴𝑘
we get 𝑂( 𝑚
). If we consider that 𝑝 to be a reasonable number (e.g., at
𝑝3/2 𝜃𝜖𝜉2
least grater than 0.05), we can consider it a constant factor that is independent
from the input’s size. The asymptotic run-time is proved to be 𝑂( ̃ 𝜇𝐴𝑘22𝑚 ). :::
𝜃𝜖𝜉

We see that is the algorithm is training the model for Corollary 9.2, the run-
time has a dependency on 1/𝑝3/2 , but this term is constant and independent
from the size of the input dataset. With this additional 1/𝑝3/2 cost, the error
of Corollary 9.1 drops to 𝜉 for every row of the matrix and generally decreases
in case of new data points.
Definition 9.1 (PCA-representable data). A set of 𝑛 data points described by
𝑟
𝑚 coordinates, represented through a matrix 𝐴 = ∑𝑖 𝜎𝑖 𝑢𝑖 𝑣𝑖𝑇 ∈ ℝ𝑛×𝑚 is said to
be PCA-representable if there exists 𝑝 ∈ [ 21 , 1], 𝜀 ∈ [0, 1/2], 𝛽 ∈ [𝑝 − 𝜀, 𝑝 + 𝜀], 𝛼 ∈
𝑘
∑𝑖 𝜎𝑖2
[0, 1] such that: - ∃𝑘 ∈ 𝑂(1) such that 𝑚
∑𝑖 𝜎𝑖2
= 𝑝 - for at least 𝛼𝑛 points 𝑎𝑖 it
9.1. UNSUPERVISED ALGORITHMS 159

‖𝑦𝑖 ‖ 𝑘
holds ‖𝑎𝑖 ‖ ≥ 𝛽, where ‖𝑦𝑖 ‖ = √∑𝑖 |⟨𝑎𝑖 |𝑣𝑗 ⟩|2 ‖𝑎𝑖 ‖.

Thanks to the this statement, it is possible to bound the run-time of Corollary


9.1 with a certain probability.

Lemma 9.3 (qPCA on PCA-representable datasets). Let 𝑎𝑖 be a row of 𝐴 ∈


ℝ𝑛×𝑑 . Then, the runtime of Corollary 9.1 is ‖𝑎𝑖‖
∥𝑦𝑖 ∥
= 𝛽1 = 𝑂(1) with probability
greater than 𝛼.

It is known that, in practical machine learning datasets, 𝛼 is a number fairly


close to one. We have tested the value of 𝜌 for the MNIST dataset, the interested
reader can read more about it in the section about the experiments. Using the
same framework and proof techniques, it is possible to produce similar results for
the representations of Correspondence Analysis and Latent Semantic Analysis,
that are introduced in the next two sections.

Remark: Note that Theorem 1 from (Yu et al., 2019) propose a lower bound for
a quantity similar to 𝛼. However, their result seems to be a loose bound: using
their notation and setting 𝜂 = 1, 𝜃 = 1 they bound this quantity with 0, while
a tight bound should be 1.

9.1.2 Quantum Correspondence Analysis


Correspondence analysis is a multivariate statistical tool, from the family of fac-
tor analysis methods, used to explore relationships among categorical variables.
Consider two random variables 𝑋 and 𝑌 with possible outcomes in {𝑥1 , ⋯ , 𝑥𝑛 }
and {𝑦1 , ⋯ , 𝑦𝑚 } respectively, the model of Correspondence Analysis allows to
represent the outcomes as vectors in two related Euclidean spaces. These spaces
can be used for analysis purposes in data visualization, exploration and in other
unsupervised machine learning tasks.

[Link].1 Connection to Singular Value Decomposition Given


a contingency table for 𝑋 and 𝑌 , it is possible to compute the matrix
−1/2 ̂ −1/2 ̂
𝐴 = 𝐷𝑋 (𝑃𝑋,𝑌 ̂ 𝑝𝑌̂𝑇 )𝐷𝑌
− 𝑝𝑋 ∈ ℝ𝑛×𝑚 , where 𝑃𝑋,𝑌 ∈ ℝ𝑛×𝑚 is the estimated
𝑛 𝑚
matrix of joint probabilities, 𝑝𝑋 ̂ ∈ 𝑅 and 𝑝𝑋 ̂ ∈ ℝ are the vectors of marginal
−1/2 −1/2
probabilities, and 𝐷𝑋 = 𝑑𝑖𝑎𝑔(𝑝𝑋 ̂ ), 𝐷𝑌 = 𝑑𝑖𝑎𝑔(𝑝𝑌̂ ). The computation of
𝐴 can be done in time proportional to the number of non zero entries of the
contingency table. The singular value decomposition of 𝐴 is strictly related to
the model of correspondence analysis (Greenacre, 1984), (Hsu et al., 2019). The
−1/2 −1/2
vector space for 𝑋 is 𝐷𝑋 𝑈 ∈ ℝ𝑛×𝑘 , while the one for 𝑌 is 𝐷𝑌 𝑉 ∈ ℝ𝑚×𝑘 .
Note that these spaces are not affected by the normalization of 𝐴. Like in PCA,
it is possible to choose only a subset of the orthogonal factors as coordinates
for the representation. Factor scores and factor score ratios measure of how
much “correspondence’ ’ is captured by the respective orthogonal factor, giving
an estimate of the quality of the representation.
160 CHAPTER 9. DIMENSIONALITY REDUCTION

[Link].2 Quantum algorithms for CA Similarly to what we have al-


ready discussed, it is possible to extract the model for CA by creating quan-
tum access to the matrix 𝐴 and using Theorems 7.6, 7.7, and 7.8 to extract
the orthogonal factors, the factor scores and the factor score ratios in time
̃ (( 12 + 𝑘(𝑛+𝑚)
𝑂 𝜇(𝐴)
𝛾 𝜃𝛿2 ) 𝜖 ). We provide a theoretical bound for the data represen-
tations in Lemma 9.4.
Lemma 9.4 (Accuracy of qCA’s representation (classical)). Let 𝐴 ∈ ℝ𝑛×𝑚
be a matrix. Given some approximate procedures to retrieve unit estimates
𝑢𝑖 of the left singular vectors 𝑢𝑖 such that ‖𝑢𝑖 − 𝑢𝑖 ‖ ≤ 𝛿, the error on
−1/2 −1/2 −1/2 −1/2 √
𝐷𝑋 𝑈 can be bounded as ∣∣𝐷𝑋 𝑈 − 𝐷𝑋 𝑈 ∣∣ ≤ ‖𝐷𝑋 ‖𝐹 𝑘𝛿. Similarly,
√ 𝐹
−1/2 −1/2 −1/2
∣∣𝐷𝑌 𝑉 − 𝐷𝑌 𝑉 ∣∣ ≤ ‖𝐷𝑌 ‖𝐹 𝑘𝛿.
𝐹

Proof.
−1/2 −1/2 −1/2 −1/2

∣∣𝐷𝑋 𝑈 − 𝐷𝑋 𝑈 ∣∣ ≤ ‖𝐷𝑋 ‖𝐹 ∣∣𝑈 − 𝑈 ∣∣𝐹 ≤ ‖𝐷𝑋 ‖𝐹 𝑘𝛿.
𝐹

Note that CA’s representation does is independent of the scaling of the singular
vectors, so the normalization of the dataset does not affect the representation
in any way.

9.1.3 Quantum Latent Semantic Analysis


Latent semantic analysis is a data representation method to represent words
and text documents as vectors in Euclidean spaces so that it is possible to
make comparisons among terms, among documents and between terms and doc-
uments. The representation spaces of LSA automatically model synonymy and
polysemy (Deerwester et al., 1990), and their applications in machine learning
range from topic modeling to document clustering and retrieval.

[Link].1 Connection to Singular Value Decomposition The input of


LSA is a contingency table of 𝑛 words and 𝑚 documents 𝐴 ∈ ℝ𝑛×𝑚 . Inner
products of rows 𝐴𝐴𝑇 = 𝑈 Σ2 𝑈 𝑇 express the distances between words. Inner
products of columns 𝐴𝑇 𝐴 = 𝑉 Σ2 𝑉 𝑇 express the distances between documents.
The 𝑎𝑖𝑗 element of 𝐴 = 𝑈 Σ𝑉 𝑇 expresses the distance between word 𝑖 and
document 𝑗. With this definitions it is possible to compute: - a space for words
comparisons 𝑈 Σ ∈ ℝ𝑛×𝑘 ; - a space for documents comparisons 𝑉 Σ ∈ ℝ𝑚×𝑘 ; - two
spaces for words and documents comparisons 𝑈 Σ1/2 ∈ ℝ𝑛×𝑘 and 𝑉 Σ1/2 ∈ ℝ𝑚×𝑘 .
When using LSA for latent semantic indexing, one wishes to represent the query
as a vector in the document comparison space. The new vector is computed in
the following way 𝑣𝑞𝑇 = 𝑥𝑇𝑞 𝑈 Σ−1 , where 𝑥𝑞 ∈ ℝ𝑛 is obtained using the same
criteria used to store a document in 𝐴. The orthogonal factors used to compare
documents can be seen as latent topics whose importance is proportional to the
corresponding factor score ratios.
9.1. UNSUPERVISED ALGORITHMS 161

[Link].2 Quantum algorithms for LSA As previously discussed, the cost


of model extraction is 𝑂 ̃ (( 12 + 𝑘(𝑛+𝑚) 𝜇(𝐴)
𝛾 𝜃𝛿2 ) 𝜖 ). In some applications, such as
document retrieval, the data analyst maintains a fixed number of singular values
and vectors, regardless of the factor score ratios. In (Deerwester et al., 1990),
𝑘 = 100 is found to be a good number for document indexing. Similarly, we
believe that it is possible to empirically determine a threshold 𝜃 to use in practice.
Determining such threshold would reduce the complexity of model computation
to the one of Theorem 7.8: 𝑂 ̃ ( 𝑘(𝑛+𝑚) 𝜇(𝐴)
𝜃𝛿2 𝜖 ).

For what concerns the error bounds on the retrieved data representation models,
we already know from Lemma √9.1 that it is possible to retrieve an approximation
𝑈 Σ and 𝑉 Σ with precision 𝑘(𝛿 + 𝜖), where 𝛿 is the precision on the singular
vectors and 𝜖 the precision on the singular values. To provide bounds on the
estimations of 𝑈 Σ1/2 , 𝑉 Σ1/2 , and 𝑈 Σ−1 we introduce Lemma 9.5 and Lemma
@ref{lem:accuracyUE-1eVE-1}.
Lemma 9.5 (Accuracy of qLSA’s representations (classical)). Let 𝐴 ∈ ℝ𝑛×𝑚
be a matrix with 𝜎𝑚𝑎𝑥 ≤ 1. Given some approximate procedures to retrieve
estimates 𝜎𝑖 of the singular values 𝜎𝑖 such that ‖𝜎𝑖 − 𝜎𝑖 ‖ ≤ 𝜖 and unitary
estimates 𝑢𝑖 of the left singular vectors 𝑢𝑖 such that ‖𝑢𝑖 − 𝑢𝑖 ‖ ≤ 𝛿, the error
1/2 √
on 𝑈 Σ1/2 can be bounded as ∣∣𝑈 Σ1/2 − 𝑈 Σ ∣∣ ≤ 𝑘 (𝛿 + 2√1 𝜃 ). Similarly,
𝐹
1/2 1/2 √ 1
∣∣𝑉 Σ − 𝑉 Σ ∣∣ ≤ 𝑘 (𝛿 + 2 𝜃 ). √
𝐹

√ √
Proof. We start by bounding ‖ 𝜎𝑖 − 𝜎𝑖 ‖. Let’s define 𝜖 = 𝛾𝜎𝑖 as a relative
error:
√ √ √
‖√𝜎𝑖 + 𝜖 − 𝜎𝑖 ‖ = ‖√𝜎𝑖 + 𝛾𝜎𝑖 − 𝜎𝑖 ‖ = ‖ 𝜎𝑖 (√1 + 𝛾 − 1)‖ =
√ √
√ ( 1 + 𝛾 − 1)( 1 + 𝛾 + 1) √ 𝛾+1−1 √ 𝛾
𝜎𝑖 ∥ √ ∥ = 𝜎𝑖 ∥ √ ∥ ≤ 𝜎𝑖 .
1+𝛾+1 1+𝛾+1 2

𝜖
By definition 𝛾 = 𝜎𝑖 and we know that 𝜎𝑚𝑖𝑛 ≥ 𝜃:

√ 𝜎𝑖 𝜖 𝜖 𝜖
‖√𝜎𝑖 − 𝜎𝑖 ‖ ≤ = √ ≤ √ .
𝜎1 2 2 𝜎𝑖 2 𝜃

1/2
Using the bound on the square roots, we can bound the columns of 𝑈 Σ :

√ √ 𝜖 √
∥√𝜎𝑖 𝑢𝑖 − 𝜎𝑖 𝑢𝑖 ∥ ≤ ∥( 𝜎𝑖 + √ ) 𝑢𝑖 − 𝜎𝑖 𝑢𝑖 ∥ =
2 𝜃

√ 𝜖 √ 𝜖 𝜖
∥ 𝜎𝑖 (𝑢𝑖 − 𝑢𝑖 ) + √ 𝑢𝑖 ∥ ≤ 𝜎𝑖 𝛿 + √ ≤ 𝛿 √‖𝐴‖ + √ .
2 𝜃 2 𝜃 2 𝜃
162 CHAPTER 9. DIMENSIONALITY REDUCTION

From the error bound on the columns we derive the bound on the matrices:
√ 𝑘 √
1/2 √ 2 𝜖
∥𝑈 Σ − 𝑈 Σ1/2 ∥ = √∑ (∥√𝜎𝑗 𝑢𝑗 − √𝜎𝑗 𝑢𝑗 ∥) ≤ 𝑘 (𝛿 √‖𝐴‖ + √ ) .
𝐹 2 𝜃
⎷ 𝑗

1/2 √ 𝜖
Finally, since 𝜎𝑚𝑎𝑥 ≤ 1, we get that ‖𝑈 Σ − 𝑈 Σ1/ ‖𝐹 ≤ 𝑘(𝛿 + √
2 𝜃
).

Lemma 9.6 (Accuracy of qLSA’s representation for new document queries


(classical)). Let 𝐴 ∈ ℝ𝑛×𝑚 be a matrix. Given some approximate procedures to
retrieve estimates 𝜎𝑖 of the singular values 𝜎𝑖 such that |𝜎𝑖 − 𝜎𝑖 | ≤ 𝜖 and unitary
estimates 𝑢𝑖 of the left singular vectors 𝑢𝑖 such that ‖𝑢𝑖 − 𝑢𝑖 ‖ ≤ 𝛿, the error
−1 √
on 𝑈 Σ−1 can be bounded as ∣∣𝑈 Σ−1 − 𝑈 Σ ∣∣ ≤ 𝑘 ( 𝜃𝛿 + 𝜃2 −𝜃𝜖 𝜖
). Similarly,
𝐹
−1 √
∣∣𝑉 Σ−1 − 𝑉 Σ ∣∣ ≤ 𝑘( 𝜃𝛿 + 𝜃2 −𝜃𝜖 𝜖
).
𝐹

Proof. We start by bounding ‖ 𝜎1 − 1


𝜎𝑖 ‖, knowing that 𝜎𝑚𝑖𝑛 ≥ 𝜃 and 𝜖 < 𝜃:
𝑖

1 1 1 1 𝜖
∣∣ − ∣∣ ≤ ∣∣ − ∣∣ ≤ 2 .
𝜎𝑖 𝜎𝑖 𝜎𝑖 − 𝜖 𝜎𝑖 𝜃 − 𝜃𝜖

From the bound on the inverses, we can obtain the bound on the columns of
−1
𝑈Σ :

1 1 1 𝜖 1 1 𝜖 𝛿 𝜖
∥ 𝑢 − 𝑢 ∥ ≤ ∥( ± 2 ) 𝑢𝑖 − 𝑢𝑖 ∥ ≤ 𝛿 + 2 ≤ + 2 .
𝜎𝑖 𝑖 𝜎𝑖 𝑖 𝜎𝑖 𝜃 − 𝜃𝜖 𝜎𝑖 𝜎𝑖 𝜃 − 𝜃𝜖 𝜃 𝜃 − 𝜃𝜖

To end the proof, we can compute the bound on the matrices:

√ 𝑘 2
√ 𝛿
−1 −1

√ 1 1 𝜖
∥𝑈 Σ − 𝑈 Σ ∥ = ∑ (∥ 𝑢𝑗 − 𝑢𝑗 ∥) ≤ 𝑘 ( + 2 ).
𝐹 𝜎 𝑗 𝜎 𝑗 𝜃 𝜃 − 𝜃𝜖
⎷ 𝑗

As for qPCA, we provide the bounds in case we want to undo data normalization
step. The proofs for these lemmas proceeds like the one of Lemma 9.2.
Lemma 9.7 (Non-normalized accuracy of qLSA’s representations (classi-
cal)). The estimated representations of Lemma 9.5, for the not-normalized
1/2 1/2
matrix 𝐴, are √‖𝐴‖ 𝑈 Σ and √‖𝐴‖ 𝑉 Σ . The error bounds become
1/2 1/2 1/2
∣∣√‖𝐴‖ 𝑈 Σ − √‖𝐴‖𝑈 Σ ∣∣ ≤ √𝑘‖𝐴‖(𝜖+𝛿) and ∣∣√‖𝐴‖ 𝑉 Σ − √‖𝐴‖𝑉 Σ1/2 ∣∣ ≤
𝐹 𝐹
√𝑘‖𝐴‖(𝜖 + 𝛿).
9.2. SUPERVISED ALGORITHMS 163

Lemma 9.8 (Non-normalized accuracy of qLSA’s representation for new docu-


ment queries (classical)). The estimated representations of Lemma 9.6, for the
1 −1 1 −1
not-normalized matrix 𝐴, are ||𝐴|| 𝑈 Σ and ||𝐴|| 𝑉 Σ . The error bounds become
−1 √ −1
1 1 1/2 𝑘 𝛿 𝜖 1 1
∣∣ ||𝐴|| 𝑈Σ − ||𝐴|| 𝑈 Σ ∣∣ ≤ ||𝐴|| ( 𝜃 + 𝜃2 −𝜃𝜖 ) and ∣∣ ||𝐴|| 𝑉 Σ − ||𝐴|| 𝑉 Σ1/2 ∣∣ ≤

𝑘
||𝐴|| ( 𝜃𝛿 + 𝜖
𝜃2 −𝜃𝜖 ).

9.2 Supervised algorithms


9.2.1 Quantum Slow Feature Analysis
Slow Feature Analysis (SFA) is a dimensionality reduction technique proposed
in the context of computational neurosciences as a way to model part of the
visual cortex of humans. In the last decades, it has been applied in various
areas of machine learning. In this chapter we propose a quantum algorithm for
slow feature analysis, and detail its application for performing dimensionality
reduction on a real dataset. We also simulate the random error that the quantum
algorithms might incur. We show that, despite the error caused by the algorithm,
the estimate of the model that we obtain is good enough to reach high accuracy
on a standard dataset widely used as benchmark in machine learning. Before
providing more details on this result, we give a brief description of dimensionality
reduction and introduce the model of slow feature analysis in this context.
SFA has been shown to model a kind of neuron (called complex cell) situated in
the cortical layer in the primary visual cortex (called V1) (Berkes and Wiskott,
2005). SFA can be used in machine learning as a DR algorithm, and it has been
successfully applied to enhance the performance of classifiers (Zhang Zhang and
Dacheng Tao, 2012), (Berkes, 2005). SFA was originally proposed as an online,
nonlinear, and unsupervised algorithm (Wiskott Laurenz and Wiskott, 1999). Its
task was to learn slowly varying features from generic input signals that vary
rapidly over time (Berkes, 2005) (Wiskott Laurenz and Wiskott, 1999). SFA
has been motivated by the temporal slowness principle, that postulates that
while the primary sensory receptors (like the retinal receptors in an animal’s
eye) are sensitive to very small changes in the environment and thus vary on
a very fast time scale, the internal representation of the environment in the
brain varies on a much slower time scale. The slowness principle is a hypothesis
for the functional organization of the visual cortex and possibly other sensory
areas of the brain (Wiskott et al., 2011) and it has been introduced as a way to
model the transformation invariance in natural image sequences (Zhang Zhang
and Dacheng Tao, 2012). SFA is an algorithm that formalizes the slowness
principle as a nonlinear optimization problem. In (Blaschke and Wiskott, 2004,
sprekeler2014extension), SFA has been used to do nonlinear blind source sep-
aration. Although SFA has been developed in the context of computational
neurosciences, there have been many applications of the algorithm to solve ML
related tasks. A prominent advantage of SFA compared to other algorithms
is that it is almost hyperparameter-free. The only parameters to chose are in
164 CHAPTER 9. DIMENSIONALITY REDUCTION

the preprocessing of the data, e.g. the initial PCA dimension and the nonlinear
expansion that consists of a choice of a polynomial of (usually low) degree 𝑝.
Another advantage is that it is guaranteed to find the optimal solution within
the considered function space (Escalante-B and Wiskott, 2012). For a detailed
description of the algorithm, we suggest (Sprekeler and Wiskott, 2008). With
appropriate preprocessing, SFA can be used in conjunction to a supervised al-
gorithm to acquire classification capabilities. For instance it has been used for
pattern recognition to classify images of digits in the famous MNIST database
(Berkes, 2005). SFA can be adapted to be used to solve complex tasks in super-
vised learning, like face and human action recognition (Gu et al., 2013) , [Zhang
Zhang and Dacheng Tao (2012; Sun et al., 2014).
We can use SFA for classification in the following way. One can think of the
training set a set of vectors 𝑥𝑖 ∈ ℝ𝑑 , 𝑖 ∈ 𝑛. Each 𝑥𝑖 belongs to one of 𝐾 different
classes. A class 𝑇𝑘 has |𝑇𝑘 | vectors in it. The goal is to learn 𝐾 − 1 functions
𝑔𝑗 (𝑥𝑖 ), 𝑗 ∈ [𝐾 − 1] such that the output 𝑦𝑖 = [𝑔1 (𝑥𝑖 ), ⋯ , 𝑔𝐾−1 (𝑥𝑖 )] is very similar
for the training samples of the same class and largely different for samples of
different classes. Once these functions are learned, they are used to map the
training set in a low dimensional vector space. When a new data point arrive,
it is mapped to the same vector space, where classification can be done with
higher accuracy. SFA projects the data points onto the subspace spanned by the
eigenvectors associated to the 𝑘 smallest eigenvalues of the derivative covariance
matrix of the data, which we define in the next section.

[Link] The SFA model


Now we introduce the optimization problem in its most general form as it is
𝐾
commonly stated for classification (Berkes, 2005). Let 𝑎 = ∑𝑘=1 (|𝑇2𝑘 |). For all
𝑗 ∈ [𝐾 − 1], minimize:

1 𝐾 2
Δ(𝑦𝑗 ) = ∑ ∑ (𝑔𝑗 (𝑥𝑠 ) − 𝑔𝑗 (𝑥𝑡 ))
𝑎 𝑘=1 𝑠,𝑡∈𝑇
𝑘
𝑠<𝑡

with the following constraints:


1 𝐾
• 𝑛 ∑𝑘=1 ∑𝑖∈𝑇 𝑔𝑗 (𝑥𝑖 ) = 0 ∀𝑗 ∈ [𝐾 − 1]
𝑘
1 𝐾 2
• 𝑛 ∑𝑘=1 ∑𝑖∈𝑇 𝑔𝑗 (𝑥𝑖 ) = 1 ∀𝑗 ∈ [𝐾 − 1]
𝑘
1 𝐾
• 𝑛 ∑𝑘=1 ∑𝑖∈𝑇 𝑔𝑗 (𝑥𝑖 )𝑔𝑣 (𝑥𝑖 ) = 0 ∀𝑣 < 𝑗
𝑘

The minimization of the delta values Δ(𝑦𝑗 ) encodes the requirement on the
output signal to vary “as slow as possible”, and thus the delta values are our
measure of slowness. They are the average of the square of the first order
derivative (over time) of the 𝑗-th component of the output signal 𝑦𝑡 . The first
requirement states that the average over time of each component of the signal
should be zero, and it is stated just for convenience, such that the other two
requirements take a simple form. The second requirement asks for the variance
9.2. SUPERVISED ALGORITHMS 165

over time of each component of the signal to be 1. It is equivalent to saying that


each signal should carry some information and avoid the trivial solution 𝑔𝑗 (⋅) = 0.
The third requirement is to say that we want the signals to be decorrelated with
each other. This also introduces an order, such that the first signal is the slowest,
the second signal is the second slowest and so on. The first and the second
constraint also avoid the trivial solution 𝑦𝑖 = 0. Intuitively, the decorrelation
constraint forces different functions 𝑔𝑗 to encode different “aspects’ ’ of the input,
maximizing the information carried by the output signal.
In order for the minimization problem to be computationally feasible at scale,
the 𝑔𝑗 ’s are restricted to be linear functions 𝑤𝑗 such that the output signal
becomes 𝑦𝑖 = [𝑤1𝑇 𝑥𝑖 , ⋯ 𝑤𝐾−1
𝑇
𝑥𝑖 ]𝑇 or else 𝑌 = 𝑋𝑊 , where 𝑋 ∈ ℝ𝑛×𝑑 is the
matrix with rows the input samples and 𝑊 ∈ ℝ𝑑×(𝐾−1) the matrix that maps
the input matrix 𝑋 into a lower dimensional output 𝑌 ∈ ℝ𝑛×(𝐾−1) . In case it is
needed to capture nonlinear relations in the dataset, one performs a standard
nonlinear polynomial expansion on the input data as preprocessing. Usually, a
polynomial expansion of degree 2 or 3 is chosen. For example we can take:

𝑥 = [𝑥1 , 𝑥2 , 𝑥3 ] → [𝑥21 , 𝑥1 𝑥2 , 𝑥1 𝑥3 , 𝑥22 , 𝑥2 𝑥3 , 𝑥23 , 𝑥1 , 𝑥2 , 𝑥3 ] .

The choice of the nonlinear expansion is important for using SFA in machine
learning contexts. If it is a low dimensional expansion, it might not solve the
task with high accuracy, while if the dimension is too high, it might overfit the
training data, and therefore not generalize properly to test data. This technique
also goes under the name of polynomial kernel.
We also need to satisfy the constraint on the average of the signal being zero and
have unit variance. This is not a strong requirement, since it can be enforced
beforehand, by preprocessing the dataset. This requires only linear time with
respect to the dimensions of the data, and in practice consist in removing the
mean and scale the components by their variance. Namely, we assume that the
𝑗-th component of the 𝑖-th vector in the dataset satisfies the condition:

(𝑥𝑖̃ )𝑗 − 𝐸[(𝑥𝑖̃ )𝑗 ]
(𝑥𝑖 )𝑗 ∶= ,
√𝐸[((𝑥𝑖̃ )𝑗 − 𝐸[(𝑥𝑖̃ )𝑗 ])2 ]

where with 𝑥(𝑖)


̃ we define a raw signal with arbitrary mean and variance, 𝐸[𝑥𝑗̃ (𝑖)]
the expected value of a single component of the vectors. This allows us to
rewrite the minimization problem including the constraints of zero mean and
unit variance. We can restate the definition of the delta function as a generalized
eigenvalue problem:

𝑤𝑗𝑇 𝐴𝑤𝑗
Δ(𝑦𝑗 ) = , (9.3)
𝑤𝑗𝑇 𝐵𝑤𝑗
166 CHAPTER 9. DIMENSIONALITY REDUCTION

where the matrix 𝐵 is called the sample covariance matrix and defined as:

1
𝐵 ∶= ∑ 𝑥 𝑥𝑇 = 𝑋 𝑇 𝑋 (9.4)
𝑛 𝑖∈[𝑛] 𝑖 𝑖

and the matrix 𝐴 is called the sample derivative covariance matrix and defined
as:

1 𝐾 1 𝐾 𝑇
𝐴 ∶= ∑ ∑ (𝑥𝑖 − 𝑥𝑖′ )(𝑥𝑖 − 𝑥𝑖′ )𝑇 = ∑ 𝑋𝑘̇ 𝑋𝑘̇ ∶= 𝑋̇ 𝑇 𝑋.̇ (9.5)
𝑎 𝑘=1 ′ 𝑎 𝑘=1
𝑖,𝑖 ∈𝑇𝑘
𝑖<𝑖′

Note also, that we can approximate the matrix 𝐴 by subsampling from all pos-
sible pairs (𝑥𝑖 , 𝑥𝑖′ ) from each class and this is indeed what happens in practice.

[Link].1 Slowly varying signals We formalize the concept of slowly vary-


ing signals. While this won’t have any utility in the classical algorithm, it will
allow us to bound nicely the runtime of the quantum algorithm, in the case
when the data has “structure’ ’ that can be extracted by the SFA algorithm. In
general, a slow signal is a signal that change slowly over time. This concept is
formalized in the context of SFA by requiring that the whitened signal can be
reconstructed without too much error from the projection on a few slow feature
vectors. Formally, for a given 𝐾, and a set of slow feature vectors 𝑤1 … 𝑤𝐾−1 ,
we define a slowly varying signal as follows.
Definition 9.2 (Slowly varying signal). Let 𝑋 ∈ ℝ𝑛×𝑑 and 𝑌 ∈ [𝐾]𝑛 be a
dataset and its labels. Let the rows 𝑥𝑖 of 𝑋 have whitened representation
𝑧𝑖 . For the 𝐾 − 1 slow feature vectors 𝑤𝑗 , 𝑗 ∈ [𝐾], let 𝑦𝑖 be the slow feature
representation of 𝑥𝑖 . We say that 𝑋 is 𝛾𝐾 -slow if:
𝑛
∑𝑖=0 ‖𝑧𝑖 ‖
𝑛 ≤ 𝛾𝐾
∑𝑖=0 ‖𝑦𝑖 ‖

If we use SFA for doing dimensionality reduction in the context of supervised


learning, a dataset is slowly varying if all the elements in the same class are
similar to each other. In this way, by projecting the original images in the
subspace spanned by a small number of slow feature vectors, we can reconstruct
most of the information of the original dataset. We stress that this assumption
is not needed for the quantum algorithm to work, but instead it will only be
useful to give guarantees on the runtime of the algorithm.

[Link].2 The SFA algorithm The SFA algorithm basically provides a so-
lution to the generalized eigenvalue problem 𝐴𝑊 = Λ𝐵𝑊 and outputs the
eigenvectors corresponding to the smallest eigenvalues. As we said we assume
that the data has been normalized and polynomially expanded.
9.2. SUPERVISED ALGORITHMS 167

The first step of the algorithm is to whiten the data. This will reduce the
problem into a normal eigenvalue problem; the second step is to perform PCA
in order to find the eigenvalues and eigenvectors. We refer to (Escalante-B and
Wiskott, 2012) for a more complete description.

[Link].2.1 Step 1: Whitening the data Recall that 𝑋 ∈ ℝ𝑛×𝑑 , 𝐴, 𝐵 ∈


ℝ𝑑×𝑑 . We now show how to whiten the data by right multiplying with the matrix
𝐵−1/2 = [(𝑋 𝑇 𝑋)]−1/2 . Then, the input matrix becomes 𝑍 = 𝑋𝐵−1/2 and the
covariance matrix of the whitened data 𝑍 𝑇 𝑍 is thus the identity.
Lemma 9.9. Let $Z:=XB^{-1/2} $ be the matrix of whitened data. Then
𝑍 𝑇 𝑍 = 𝐼.% and 𝐵−1/2 is symmetric.

Proof. Let 𝑋 = 𝑈 Σ𝑉 𝑇 . We defined 𝐵 = 𝑉 Σ2 𝑉 𝑇 . As 𝑍 = 𝑈 Σ𝑉 𝑇 (𝑉 Σ−1 𝑉 𝑇 ) =


𝑈 𝐼𝑉 It follows that 𝑍 𝑇 𝑍 = 𝐼.

As in the classical algorithm, we will whiten the data by left-applying the whiten-
ing matrix 𝐵−1/2 . We will use matrix multiplication algorithms to create a state
|𝑍⟩ proportional to the whitened data.

[Link].2.2 Step 2: Projection in slow feature space The second step


of SFA consists of outputting the 𝐾 − 1 “slowest’ ’ eigenvectors of the derivative
covariance matrix of the whitened data 𝐴 ∶= 𝑍 ̇𝑇 𝑍,̇ where 𝑍 ̇ is defined similar to
𝑋̇ by using the whitened samples instead of the original ones. Note that taking
the derivatives of the whitened data is equal to whitening the derivatives.
Lemma 9.10. Let 𝐴 = 𝑍 ̇𝑇 𝑍.̇ Then 𝐴 = (𝐵−1/2 )𝑇 𝑋̇ 𝑇 𝑋𝐵
̇ −1/2 .

Proof.

1 𝐾
𝐴 = 𝑍 ̇𝑇 𝑍 ̇ = ∑ ∑ (𝑧𝑖 − 𝑧𝑖′ )(𝑧𝑖 − 𝑧𝑖′ )𝑇
𝑎 𝑘=1 ′
𝑖,𝑖 ∈𝑇𝑘
𝑖<𝑖′

1 𝐾
= (𝐵−1/2 )𝑇 ∑ ∑ (𝑥𝑖 − 𝑥′𝑖 )(𝑥𝑖 − 𝑥𝑖′ )𝑇 𝐵−1/2
𝑎 𝑘=1 ′
𝑖,𝑖 ∈𝑇𝑘
𝑖<𝑖′

= (𝐵−1/2 )𝑇 𝑋̇ 𝑇 𝑋𝐵
̇ −1/2

This observation allow us to whiten the data with a quantum procedure. Recall
that the matrix 𝐴 is usually approximated with a small fraction of all the
possible derivatives, roughly linear (and not quadratic) on the number of data
points. In our case we take the number of rows of the derivative matrix to be
just double the number of data points, and in the experiment we show that this
does not compromise the accuracy.
168 CHAPTER 9. DIMENSIONALITY REDUCTION

[Link] Quantum Slow Feature Analysis


We are finally ready to put forward a quantum procedure for SFA. Specifically,
we want to map the input matrix 𝑋 to the output matrix 𝑌 = 𝑋𝑊 , and then
we will see how to estimate classically the slow feature vectors 𝑊 ∈ ℝ(𝐾−1)×𝑑 .
For this, we assume to have quantum access to the matrices 𝑋 and 𝑋,̇ as in
definition ??. We start by describing a circuit that approximately performs
the unitary 𝑈𝑄𝑆𝐹 𝐴 ∶ |𝑋⟩ → |𝑌 ⟩ where |𝑋⟩ is the quantum state we obtain
𝑛
by having quantum access to 𝑋, the dataset, and |𝑌 ⟩ ∶= ‖𝑌1‖ ∑𝑖=0 ‖𝑦𝑖 ‖ |𝑖⟩|𝑦𝑖 ⟩.
𝐹
As the classical algorithm, QSFA is divided in two parts. In the first step we
whiten the data, i.e. we map the state |𝑋⟩ to the state |𝑍⟩ = |𝑋𝐵−1/2 ⟩, and in
the second step we approximately project |𝑍⟩ onto the subspace spanned by the
smallest eigenvectors of the whitened derivative covariance matrix 𝐴 = 𝑍 ̇𝑇 𝑍.̇

[Link] Step 1: Whitening the data


Recall that 𝑋 = ∑𝑖 𝜎𝑖 𝑢𝑖 𝑣𝑖𝑇 ∈ ℝ𝑛×𝑑 , and 𝐴, 𝐵 ∈ ℝ𝑑×𝑑 . We now show how to
whiten the data having quantum access to the matrix 𝑋. As 𝐵−1/2 is a symmet-
ric matrix with eigenvectors the column singular vectors of 𝑋 and eigenvalues
equal to 1/|𝜎𝑖 |. Using quantum linear algebra procedure, i.e. theorem 5.11, we
can multiply with 𝐵−1/2 our state |𝑋⟩. Thus, we have the following corollary.

Corollary 9.4 (Whitening algorithm). Assume to have quantum access to 𝑋 =


∑𝑖 𝜎𝑖 𝑢𝑖 𝑣𝑖𝑇 ∈ ℝ𝑛×𝑑 , as in theorem ??. Let 𝑍 = 𝑋𝐵−1/2 the matrix of whitened
data. There exists a quantum algorithm that produces as output a state |𝑍⟩̄ such
̃
that ||𝑍⟩̄ − |𝑍⟩| ≤ 𝜀 in expected time 𝑂(𝜅(𝑋)𝜇(𝑋) log 1/𝜀)).

[Link] Step 2: Projection in slow feature space


The previous Corollary gives a way to build quantum access to the rows of
the whitened matrix 𝑍, up to some error 𝜖. Now we want to project this
state onto the subspace spanned by the eigenvectors associated to the 𝐾 − 1
“slowest’ ’ eigenvectors of the whitened derivative covariance matrix 𝐴 ∶= 𝑍 ̇𝑇 𝑍,̇
where 𝑍 ̇ is the whitened derivative matrix 𝑍 ̇ = 𝑋𝐵 ̇ −1/2 . Let 𝜃 a threshold
value and 𝛿 a precision parameter, that governs the error we tolerate in the
projection threshold. Recall that 𝐴≤𝜃,𝛿 we denote a projection of the matrix 𝐴
onto the vector subspace spanned by the union of the singular vectors associated
to singular values that are smaller than 𝜃 and some subset of singular vectors
whose corresponding singular values are in the interval [𝜃, (1 + 𝛿)𝜃].

To perform the projection, we will need a threshold for the eigenvalues that
will give us the subspace of the 𝐾 − 1 slowest eigenvectors. A priori, we don’t
know the appropriate threshold value, and thus it must be found experimentally
through binary search since it depends on the distribution of singular values of
the matrix representing the dataset. We can now describe and analyse the entire
QSFA algorithm.
9.2. SUPERVISED ALGORITHMS 169

As in the previous section, we note that the eigenvalues of 𝐴𝑍̇ are the squares of
the singular values of 𝑍,̇ and the two matrices share the same column space: 𝑍 ̇ =
𝑈 Σ𝑉 𝑇 , and 𝐴𝑍̇ = 𝑉 Σ2 𝑉 𝑇 . Claim 9.10 tells us that whitening the derivatives
of the signal is equal to taking the derivatives of the whitened data. theorem
5.12 provides exactly the procedure for accessing the rows of 𝑍,̇ since we know
how to multiply with 𝑋̇ and with 𝐵−1/2 .
Theorem 9.1 (QSFA algorithm). Assume to have quantum access to 𝑋 =
∑𝑖 𝜎𝑖 𝑢𝑖 𝑣𝑖𝑇 ∈ ℝ𝑛×𝑑 and its derivative matrix 𝑋̇ ∈ ℝ𝑛 log 𝑛×𝑑 . Let 𝜖, 𝜃, 𝛿, 𝜂 >
0. There exists a quantum algorithm that produces as output a state |𝑌 ⟩ with
||𝑌 ⟩ − |𝐴+≤𝜃,𝛿 𝐴≤𝜃,𝛿 𝑍⟩| ≤ 𝜖 in time

̇
(𝜅(𝑋) + 𝜅(𝑋))(𝜇(𝑋) ̇
+ 𝜇(𝑋))
𝑂̃ ( 𝛾𝐾−1 )
𝛿𝜃

and an estimator ‖𝑌 ‖ with |‖𝑌 ‖ − ‖𝑌 ‖ | ≤ 𝜂 ‖𝑌 ‖ with an additional 1/𝜂 factor.

Proof. QSFA consists of two steps. The first step is the whitening, which can
̃
be performed in time 𝑂(𝜅(𝑋)𝜇(𝑋) log(1/𝜖)) and provide the state |𝑍⟩ using
Corollary 9.4. It is simple to verify that creating a state |𝑍⟩ of whitened data
such that 𝑍 𝑇 𝑍 = 𝐼 can be done using quantum access just to the matrix 𝑋,
as 𝑍 = 𝑋𝐵−1/2 . The second step is the projection of whitened data in the
slow feature space, which is spanned by the eigenvectors of 𝐴 = 𝑍 ̇𝑇 𝑍.̇ This
matrix shares the same right eigenvectors of 𝑋𝐵 ̇ −1/2 , which is simple to check
that we can efficiently access using the QRAM constructions of 𝑋 and 𝑋.̇ Us-
ing the algorithm for quantum linear algebra, i.e. theorem 5.12, we know that
the projection (without the amplitude amplification) takes time equal to the
ratio 𝜇(𝑋) + 𝜇(𝑋)̇ over the threshold parameter, in other words it takes time
̇
𝑂(̃ (𝜇(𝑋)+𝜇(
𝛿𝜃
𝑋)
). Finally, the amplitude amplification and estimation depends on
the size of the projection of |𝑍⟩ onto the slow eigenspace of 𝐴, more precisely
∥𝑍∥
it corresponds to the factor 𝑂( ∥𝐴+ ), which is roughly the same if we
≤𝜃,𝜅 𝐴≤𝜃,𝜅 𝑍∥

look at 𝑍 instead of 𝑍. Note also that 𝑍 is the whitened data, which means
that each whitened vector should look roughly the same on each direction. This
implies that the ratio should be proportional to the ratio of the dimension of
the whitened data over the dimension of the output signal. The final runtime
of the algorithm is:

̇
(𝜅(𝑋) + 𝜅(𝑋))(𝜇(𝑋) ̇
+ 𝜇(𝑋)) ‖𝑍‖
𝑂̃ ((𝜅(𝑋)𝜇(𝑋) log(1/𝜀) + ) + )
𝛿𝜃 ∥𝐴≤𝜃,𝛿 𝐴≤𝜃,𝛿 𝑍∥

Note that the last ratio in this runtime was defined as 𝛾𝐾−1 in definition 9.2.
From this, the runtime in the statement of the theorem follows.
170 CHAPTER 9. DIMENSIONALITY REDUCTION

Figure 9.1: Quantum algorithm for Slow Feature Analysis


Chapter 10

q-means

Contributors: Alessandro Luongo - based on work (Kerenidis et al., 2019a)


In this section we detail a quantum algorithm for unsupervised learning, which
can be seen as the quantum version of the well known k-means algorithm. This
algorithm is one of the simplest, yet most commonly used clustering algorithms.
We first introduce the classical algorithm, then propose a definition of the k-
mean model that makes is robust to error in the model. Then, we explain how
to derive a quantum version of the k-means algorithm and show its performance
on experimental data.

10.1 The k-means algorithm


The 𝑘-means algorithm was introduced in (Lloyd, 1982), and is extensively used
for unsupervised problems. The inputs to 𝑘-means algorithm are vectors 𝑥𝑖 ∈ ℝ𝑑
for 𝑖 ∈ [𝑛]. These points must be partitioned in 𝑘 subsets according to a
similarity measure, which in k-means is the Euclidean distance between points.
The output of the 𝑘-means algorithm is a list of 𝑘 cluster centers, which are
called centroids. The algorithm starts by selecting 𝑘 initial centroids randomly
or using efficient heuristics like the 𝑘-means++ (Arthur and Vassilvitskii, 2007).
It then alternates between two steps: (i) Each data point is assigned the label
of the closest centroid. (ii) Each centroid is updated to be the average of the
data points assigned to the corresponding cluster. These two steps are repeated
until convergence, that is, until the change in the centroids during one iteration
is sufficiently small.
More precisely, we are given a dataset 𝑋 of vectors 𝑥𝑖 ∈ ℝ𝑑 for 𝑖 ∈ [𝑛]. At step
𝑡, we denote the 𝑘 clusters by the sets 𝐶𝑗𝑡 for 𝑗 ∈ [𝑘], and each corresponding
centroid by the vector 𝑐𝑗𝑡 . At each iteration, the data points 𝑥𝑖 are assigned to
a cluster 𝐶𝑗𝑡 such that 𝐶1𝑡 ∪ 𝐶2𝑡 ⋯ ∪ 𝐶𝐾 𝑡
= 𝑉 and 𝐶𝑖𝑡 ∩ 𝐶𝑙𝑡 = ∅ for 𝑖 ≠ 𝑙. Let

171
172 CHAPTER 10. Q-MEANS

𝑑(𝑥𝑖 , 𝑐𝑗𝑡 ) be the Euclidean distance between vectors 𝑥𝑖 and 𝑐𝑗𝑡 . The first step of
the algorithm assigns each 𝑥𝑖 a label ℓ(𝑥𝑖 )𝑡 corresponding to the closest centroid,
that is
ℓ(𝑥𝑖 )𝑡 = argmin𝑗∈[𝑘] (𝑑(𝑥𝑖 , 𝑐𝑗𝑡 )).
The centroids are then updated, 𝑐𝑗𝑡+1 = 1
|𝐶𝑗𝑡 |
∑𝑖∈𝐶 𝑡 𝑥𝑖 , so that the new centroid
𝑗
is the average of all points that have been assigned to the cluster in this iteration.
We say that we have converged if for a small threshold 𝜏 (which might be data
dependent) we have:
1 𝑘
∑ 𝑑(𝑐𝑗𝑡 , 𝑐𝑗𝑡−1 ) ⩽ 𝜏 .
𝑘 𝑗=1
The loss function that this algorithm aims to minimize is the RSS (residual sums
of squares), the sum of the squared distances between points and the centroid
of their cluster.
RSS ∶= ∑ ∑ 𝑑(𝑐𝑗 , 𝑥𝑖 )2
𝑗∈[𝑘] 𝑖∈𝐶𝑗

As the RSS decrease at each iteration of the 𝑘-means algorithm, the algorithm
therefore converges to a local minimum for the RSS. The number of iterations
𝑇 for convergence depends on the data and the number of clusters. A single
iteration has complexity of 𝑂(𝑘𝑛𝑑) since the 𝑛 vectors of dimension 𝑑 have to
be compared to each of the 𝑘 centroids. The centroids obtained at time 𝑡 are
stored in the matrix 𝐶 𝑡 ∈ ℝ𝑘×𝑑 , such that the 𝑗𝑡ℎ row 𝑐𝑗𝑡 for 𝑗 ∈ [𝑘] represents
the centroid of the cluster 𝒞𝑡𝑗 .
From a computational complexity point of view, we recall that it is NP-hard to
find a clustering that achieves the global minimum for the RSS. There are clas-
sical clustering algorithms based on optimizing different loss functions, however
the k-means algorithm uses the RSS as the objective function. The algorithm √
can be super-polynomial in the worst case (the number of iterations is 2𝜔( 𝑛)
(Arthur and Vassilvitskii, 2006)), but the number of iterations is usually small
in practice. The 𝑘-means algorithm with a suitable heuristic like 𝑘-means++ (
described later on ) to initialize the centroids finds a clustering such that the
value for the RSS objective function is within a multiplicative 𝑂(log 𝑛) factor of
the minimum value (Arthur and Vassilvitskii, 2007).

10.1.1 𝛿−k-means
We now consider a 𝛿-robust version of the 𝑘-means in which we introduce some
noise. The noise affects the algorithms in both of the steps of k-means: label
assignment and centroid estimation.
• Let 𝑐𝑖∗ be the closest centroid to the data point 𝑥𝑖 . Then, the set of possible
labels 𝐿𝛿 (𝑥𝑖 ) for 𝑥𝑖 is defined as follows:
𝐿𝛿 (𝑥𝑖 ) = {𝑐𝑝 ∶ |𝑑2 (𝑐𝑖∗ , 𝑥𝑖 ) − 𝑑2 (𝑐𝑝 , 𝑥𝑖 )| ≤ 𝛿 }
The assignment rule selects arbitrarily a cluster label from the set 𝐿𝛿 (𝑥𝑖 ).
10.2. THE 𝑞-MEANS ALGORITHM 173

• We add 𝛿/2 noise during the calculation of the centroid. Let 𝒞𝑡+1 𝑗 be
the set of points which have been labeled by 𝑗 in the previous step. For
𝛿-k-means we pick a centroid $c^{t+1}_j $ with the property that:

1 𝛿
∥𝑐𝑗𝑡+1 − ∑ 𝑥𝑖 ∥ < .
|𝒞𝑡+1
𝑗 | 𝑥 ∈𝒞𝑡+1
2
𝑖 𝑗

One way to see this is to perturb the centroid with some noise.
Let us add two remarks on the 𝛿-𝑘-means. First, for a dataset that is expected to
have clusterable data, and for a small 𝛿, the number of vectors on the boundary
that risk to be misclassified in each step, that is the vectors for which |𝐿𝛿 (𝑥𝑖 )| > 1
is typically much smaller compared to the vectors that are close to a unique
centroid. Second, we also increase by 𝛿/2 the convergence threshold from the
𝑘-means algorithm. All in all, 𝛿-𝑘-means is able to find a clustering that is
robust when the data points and the centroids are perturbed with some noise of
magnitude 𝑂(𝛿). As we will see in this work, 𝑞-means is the quantum equivalent
of 𝛿-𝑘-means.

10.2 The 𝑞-means algorithm


The 𝑞-means algorithm is given as Algorithm 10.1. At a high level, it follows
the same steps as the classical 𝑘-means algorithm (and the EM algorithm for
GMM), where we now use quantum subroutines for distance estimation, finding
the minimum value among a set of elements, matrix multiplication for obtaining
the new centroids as quantum states, and efficient tomography. First, we pick
some random initial points, using the quantum version of a classical techniques
(like the 𝑘-means++ idea (Arthur and Vassilvitskii, 2007), for which we give a
quantum algorithm later ). Then, in Steps 1 and 2 all data points are assigned
to a cluster. In Steps 3 and 4 we update the centroids of the clusters and retrieve
the information classically. The process is repeated until convergence.

10.2.1 Step 1: Centroid distance estimation


The first step of the algorithm estimates the square distance between data points
and clusters using a quantum procedure.
Theorem 10.1 (Centroid Distance estimation). Let a data matrix 𝑉 ∈ ℝ𝑛×𝑑
and a centroid matrix 𝐶 ∈ ℝ𝑘×𝑑 be stored in QRAM, such that the following uni-
taries |𝑖⟩|0⟩ ↦ |𝑖⟩|𝑥𝑖 ⟩, and |𝑗⟩|0⟩ ↦ |𝑗⟩|𝑐𝑗 ⟩ can be performed in time 𝑂(log(𝑛𝑑))
and the norms of the vectors are known. For any Δ > 0 and 𝜖1 > 0, there exists
a quantum algorithm that performs the mapping

1 𝑛 1 𝑛
√ ∑ |𝑖⟩ ⊗𝑗∈[𝑘] (|𝑗⟩|0⟩) ↦ √ ∑ |𝑖⟩ ⊗𝑗∈[𝑘] (|𝑗⟩|𝑑2 (𝑥𝑖 , 𝑐𝑗 )⟩),
𝑛 𝑖=1 𝑛 𝑖=1
174 CHAPTER 10. Q-MEANS

Figure 10.1: The q-means algorithm


10.2. THE 𝑞-MEANS ALGORITHM 175

where |𝑑2 (𝑥𝑖 , 𝑐𝑗 ) − 𝑑2 (𝑥𝑖 , 𝑐𝑗 )| ⩽ 𝜖1 with probability at least 1 − 2Δ, in time


̃ (𝑘 𝜂 log(1/Δ)) where 𝜂 = max (‖𝑥 ‖2 ).
𝑂 𝜖1 𝑖 𝑖

The proof of the theorem follows rather straightforwardly from lemma 5.6. In
fact one just needs to apply the distance estimation procedure 𝑘 times. Note
also that the norms of the centroids are always smaller than the maximum norm
of a data point which gives us the factor 𝜂.

10.2.2 Step 2: Cluster assignment


At the end of Step 1, we have coherently estimated the square distance between
each point in the dataset and the 𝑘 centroids in separate registers. We can now
select the index 𝑗 that corresponds to the centroid closest to the given data point,
written as ℓ(𝑥𝑖 ) = argmin𝑗∈[𝑘] (𝑑(𝑥𝑖 , 𝑐𝑗 )). As taking the square of a number is a
monotone function, we do not need to compute the square root of the distance
in order to find ℓ(𝑥𝑖 ).
Lemma 10.1 (Circuit for finding the minimum of 𝑘 registers). Given 𝑘 different
log 𝑝-bit registers ⊗𝑗∈[𝑘] |𝑎𝑗 ⟩, there is a quantum circuit 𝑈𝑚𝑖𝑛 that maps in time
𝑂(𝑘 log 𝑝)
(⊗𝑗∈[𝑝] |𝑎𝑗 ⟩)|0⟩ → (⊗𝑗∈[𝑘] |𝑎𝑗 ⟩)|argmin(𝑎𝑗 )⟩.

Proof. We append an additional register for the result that is initialized to |1⟩.
We then repeat the following operation for 2 ≤ 𝑗 ≤ 𝑘, we compare registers 1
and 𝑗, if the value in register 𝑗 is smaller we swap registers 1 and 𝑗 and update
the result register to 𝑗. The cost of the procedure is 𝑂(𝑘 log 𝑝).

̃
The cost of finding the minimum is 𝑂(𝑘) in step 2 of the 𝑞-means algorithm,
while we also need to uncompute the distances by repeating Step 1. Once we
apply the minimum finding lemma 10.1 and undo the computation we obtain
the state
1 𝑛
|𝜓𝑡 ⟩ ∶= √ ∑ |𝑖⟩|ℓ𝑡 (𝑥𝑖 )⟩. (10.1)
𝑁 𝑖=1

10.2.3 Step 3: Centroid state creation


𝑛
The previous step gave us the state |𝜓𝑡 ⟩ = √1𝑁 ∑𝑖=1 |𝑖⟩|ℓ𝑡 (𝑥𝑖 )⟩. The first register
of this state stores the index of the data points while the second register stores
the label for the data point in the current iteration. Given these states, we need
to find the new centroids |𝑐𝑗𝑡+1 ⟩, which are the average of the data points having
the same label.
Let 𝜒𝑡𝑗 ∈ ℝ𝑁 be the characteristic vector for cluster 𝑗 ∈ [𝑘] at iteration 𝑡 scaled
to unit ℓ1 norm, that is (𝜒𝑡𝑗 )𝑖 = |𝐶1𝑡 | if 𝑖 ∈ 𝒞𝑗 and 0 if 𝑖 ∉ 𝒞𝑗 . The creation of the
𝑗
quantum states corresponding to the centroids is based on the following simple
claim.
176 CHAPTER 10. Q-MEANS

Proposition 10.1. Let 𝜒𝑡𝑗 ∈ ℝ𝑁 be the scaled characteristic vector for 𝒞𝑗 at


iteration 𝑡 and 𝑋 ∈ ℝ𝑛×𝑑 be the data matrix, then 𝑐𝑗𝑡+1 = 𝑋 𝑇 𝜒𝑡𝑗 .

Proof. The 𝑘-means update rule for the centroids is given by 𝑐𝑗𝑡+1 =
1
|𝐶 𝑡 |
∑𝑖∈𝐶 𝑥𝑖 . As the columns of 𝑋 𝑇 are the vectors 𝑥𝑖 , this can be rewritten
𝑗 𝑗

as 𝑐𝑗𝑡+1 = 𝑋 𝑇 𝜒𝑡𝑗 .

The above claim allows us to compute the updated centroids 𝑐𝑗𝑡+1 using quantum
linear algebra operations. In fact, the state |𝜓𝑡 ⟩ can be written as a weighted
superposition of the characteristic vectors of the clusters.
𝑘 𝑘
|𝐶𝑗 | ⎛ 1 ⎞ |𝐶𝑗 | 𝑡
|𝜓𝑡 ⟩ = ∑ √ ⎜
⎜ ⎟ |𝑗⟩ = ∑ √
∑ |𝑖⟩⎟ |𝜒𝑗 ⟩|𝑗⟩
𝑗=1
𝑁 √|𝐶 | 𝑖∈𝒞𝑗 𝑗=1
𝑁
⎝ 𝑗 ⎠

By measuring the last register, we can sample from the states |𝜒𝑡𝑗 ⟩ for 𝑗 ∈ [𝑘],
with probability proportional to the size of the cluster. We assume here that
all 𝑘 clusters are non-vanishing, in other words they have size Ω(𝑛/𝑘). Given
the ability to create the states |𝜒𝑡𝑗 ⟩ and given that the matrix 𝑉 is stored in
QRAM, we can now perform quantum matrix multiplication by 𝑋 𝑇 to recover an
approximation of the state |𝑋 𝑇 𝜒𝑗 ⟩ = |𝑐𝑗𝑡+1 ⟩ with error 𝜖2 , as stated in theorem
5.11. Note that the error 𝜖2 only appears inside a logarithm. The same theorem
allows us to get an estimate of the norm ∥𝑋 𝑇 𝜒𝑡𝑗 ∥ = ∥𝑐𝑗𝑡+1 ∥ with relative error 𝜖3 .
For this, we also need an estimate of the size of each cluster, namely the norms
∥𝜒𝑗 ∥. We already have this, since the measurements of the last register give us
this estimate, and since the number of measurements made is large compared
to 𝑘 (they depend on 𝑑), the error from this source is negligible compared to
other errors.
The running time of this step is derived from theorem 5.11 where the time to
prepare the state |𝜒𝑡𝑗 ⟩ is the time of Steps 1 and 2. Note that we do not have
to add an extra 𝑘 factor due to the sampling, since we can run the matrix
multiplication procedures in parallel for all 𝑗 so that every time we measure a
random |𝜒𝑡𝑗 ⟩ we perform one more step of the corresponding matrix multiplica-
tion. Assuming that all clusters have size Ω(𝑁 /𝑘) we will have an extra factor
of 𝑂(log 𝑘) in the running time by a standard coupon collector argument. We
2
set the error on the matrix multiplication to be 𝜖2 ≪ 𝑑 𝜖log
4
𝑑 as we need to call
the unitary that builds 𝑐𝑗𝑡+1 for 𝑂( 𝑑 𝜖log2 𝑑 ) times. We will see that this does not
4
increase the runtime of the algorithm, as the dependence of the runtime for
matrix multiplication is logarithmic in the error.

10.2.4 Step 4: Centroid update


In Step 4, we need to go from quantum states corresponding to the centroids,
to a classical description of the centroids in order to perform the update step.
10.2. THE 𝑞-MEANS ALGORITHM 177

For this, we will apply the ℓ2 vector state tomography algorithm, i.e theorem
3.15, on the states |𝑐𝑗𝑡+1 ⟩ that we create in Step 3. Note that for each 𝑗 ∈ [𝑘] we
will need to invoke the unitary that creates the states |𝑐𝑗𝑡+1 ⟩ a total of 𝑂( 𝑑 log
𝜖2
𝑑
)
4
times for achieving ∥|𝑐𝑗 ⟩ − |𝑐𝑗 ⟩∥ < 𝜖4 . Hence, for performing the tomography of
all clusters, we will invoke the unitary 𝑂( 𝑘(log 𝑘)𝑑(log
𝜖24
𝑑)
) times where the 𝑂(𝑘 log 𝑘)
term is the time to get a copy of each centroid state.
The vector state tomography gives us a classical estimate of the unit norm
centroids within error 𝜖4 , that is ∥|𝑐𝑗 ⟩ − |𝑐𝑗 ⟩∥ < 𝜖4 . Using the approximation of
the norms ∥𝑐𝑗 ∥ with relative error 𝜖3 from Step 3, we can combine these estimates
to recover the centroids as vectors. The analysis is described in the following
proposition:
Proposition 10.2. Let 𝜖4 be the error we commit in estimating |𝑐𝑗 ⟩ such that
∥|𝑐𝑗 ⟩ − |𝑐𝑗 ⟩∥ < 𝜖4 , and 𝜖3 the error we commit in the estimating the norms,

| ∥𝑐𝑗 ∥ − ∥𝑐𝑗 ∥| ≤ 𝜖3 ∥𝑐𝑗 ∥. Then ∥𝑐𝑗 − 𝑐𝑗 ∥ ≤ 𝜂(𝜖3 + 𝜖4 ) = 𝜖𝑐𝑒𝑛𝑡𝑟𝑜𝑖𝑑 .

Proof. We can rewrite ∥𝑐𝑗 − 𝑐𝑗 ∥ as ∥∥𝑐𝑗 ∥ |𝑐𝑗 ⟩ − ∥𝑐𝑗 ∥|𝑐𝑗 ⟩∥. It follows from triangle
inequality that:

∥∥𝑐𝑗 ∥|𝑐𝑗 ⟩ − ∥𝑐𝑗 ∥ |𝑐𝑗 ⟩∥ ≤ ∥∥𝑐𝑗 ∥|𝑐𝑗 ⟩ − ∥𝑐𝑗 ∥ |𝑐𝑗 ⟩∥ + ∥∥𝑐𝑗 ∥ |𝑐𝑗 ⟩ − ∥𝑐𝑗 ∥ |𝑐𝑗 ⟩∥

We have the upper bound ∥𝑐𝑗 ∥ ≤ 𝜂. Using the bounds for the error we have
from tomography and norm estimation, we can upper bound the first term by
√ √
𝜂𝜖3 and the second term by 𝜂𝜖4 . The claim follows.

[Link] Tomography on approximately pure states


Let us make a remark about the ability to use theorem 3.15 to perform tomog-
raphy in our case. The updated centroids will be recovered in Step 4 using
the vector state tomography algorithm in theorem 3.15 on the composition of
the unitary that prepares |𝜓𝑡 ⟩ and the unitary that multiplies the first register
of |𝜓𝑡 ⟩ by the matrix 𝑉 𝑇 . The input of the tomography algorithm requires a
unitary 𝑈 such that 𝑈 |0⟩ = |𝑥⟩ for a fixed quantum state |𝑥⟩. However, the
labels ℓ(𝑥𝑖 ) are not deterministic due to errors in distance estimation, hence the
composed unitary 𝑈 as defined above therefore does not produce a fixed pure
state |𝑥⟩. Nevertheless, two different runs of the same unitary returns a quan-
tum state which we can think of a mixed state that is a good approximation of
a pure state. (Remark that in this notes we never discussed nor defined mixed
states, but it’s simple to get an idea of what they are by searching online, or
looking at (Nielsen and Chuang, 2002)$).
We therefore need a procedure that finds labels ℓ(𝑥𝑖 ) that are a deterministic
function of 𝑥𝑖 and the centroids 𝑐𝑗 for 𝑗 ∈ [𝑘]. One solution is to change
the update rule of the 𝛿-𝑘-means algorithm to the following: Let ℓ(𝑥𝑖 ) = 𝑗 if
𝑑(𝑥𝑖 , 𝑐𝑗 ) < 𝑑(𝑥𝑖 , 𝑐𝑗′ ) − 2𝛿 for 𝑗′ ≠ 𝑗 where we discard the points to which no
178 CHAPTER 10. Q-MEANS

label can be assigned. This assignment rule ensures that if the second register is
measured and found to be in state |𝑗⟩, then the first register contains a uniform
superposition of points from cluster 𝑗 that are 𝛿 far from the cluster boundary
(and possibly a few points that are 𝛿 close to the cluster boundary). Note that
this simulates exactly the 𝛿-𝑘-means update rule while discarding some of the
data points close to the cluster boundary. The 𝑘-means centroids are robust
under such perturbations, so we expect this assignment rule to produce good
results in practice.
A better solution is to use consistent phase estimation instead of the usual phase
estimation for the distance estimation step , which can be found in Ta-Shma
(2013); Ambainis (2012b), and we briefly discussed in section 5.1 The distance
estimates are generated by the phase estimation algorithm applied to a certain
unitary in the amplitude estimation step. The usual phase estimation algorithm
does not produce a deterministic answer and instead for each eigenvalue 𝜆 out-
puts with high probability one of two possible estimates 𝜆 such that |𝜆 − 𝜆| ≤ 𝜖.
Instead, here as in some other applications we need the consistent phase estima-
tion algorithm that with high probability outputs a deterministic estimate such
that |𝜆 − 𝜆| ≤ 𝜖.
For what follows, we assume that indeed the state in Equation (10.1) is almost
a pure state, meaning that when we repeat the procedure we get the same state
with very high probability.

10.2.5 Initialization of 𝑞-means++


Before running 𝑘-means, one usually chooses the first 𝑘 centroids by using the
𝑘-means++ technique from (Arthur and Vassilvitskii, 2007). A first centroid is
chosen uniformly at random and we compute its distance to all points of the
dataset. Then we sample one point with a weighted probability distribution
corresponding to their squared distance to the centroid. We repeat the previous
step with this new point as centroid, until 𝑘 centroids have been chosen.
A quantum analogue, 𝑞-means++, can be implemented efficiently using the
distance subroutine, Lemma 5.6. Starting with a random index 𝑖 we compute
the following state in time 𝑂(̃ 𝜖𝜂 ):
1

1 𝑛−1
|𝑖⟩ √ ∑ |𝑗⟩|𝑑(𝑥𝑖 , 𝑥𝑗 )⟩
𝑛 𝑗=0

Where 𝑥𝑖 is the initial centroid. We can then convert the distance register as
amplitudes using a controlled rotation after a simple arithmetic circuit.

1 𝑛−1 𝑑(𝑥𝑖 , 𝑥𝑗 )
|𝑖⟩ √ ∑ |𝑗⟩|𝑑(𝑥𝑖 , 𝑥𝑗 )⟩ ( |0⟩ + 𝛽|1⟩)
𝑛 𝑗=0 2𝜂

Each distance has been normalized by 2𝜂 ≥ 𝑚𝑎𝑥𝑖,𝑗 (𝑑(𝑥𝑖 , 𝑥𝑗 )) to be a valid


amplitude. After undoing the distance computation subroutine in the second
10.3. ANALYSIS 179

register, we perform an amplitude amplification on |0⟩. This creates the state

1 𝑛−1
| + +⟩ ∶= ∑ 𝑑(𝑥𝑖 , 𝑥𝑗 )|𝑗⟩
𝑍 𝑗=0

𝑛−1
where 𝑍 is the normalization factor √∑𝑗=0 𝑑2 (𝑥𝑖 , 𝑥𝑗 ). We can sample a value
𝑗 that will represent the next centroid chosen for iteration 𝑡 = 0. To create the
state |++⟩ we need to perform amplitude amplification, and repeat 𝑂(1/√𝑃 (0))
times the distance estimation procedure, with 𝑃 (0) being the probability of
2
1 𝑑(𝑥𝑖 ,𝑥𝑗 )
measuring |0⟩. Since 𝑃 (0) = 𝑛 (∑ 2𝜂 )

1 2𝜂 2𝜂
= ≤
√𝑃 (0) √ 1 (∑ 𝑑2 (𝑥𝑖 , 𝑥𝑗 ))
2 1
√ 𝑁 ∑ 𝑑2 (𝑥𝑖 , 𝑥𝑗 )
𝑁

̃ 4𝜂2
In the end we repeat 𝑘−1 times this circuit, for a total time of 𝑂(𝑘 ).
𝜖1 √𝔼(𝑑2 (𝑥𝑖 ,𝑥𝑗 ))
In order to be adapt this initialization subroutine with 𝛿-k-means algorithm, it
suffice to pick 𝜖1 < 𝛿/2.

10.3 Analysis
We provide the theorem of the running time and accuracy of the 𝑞-means algo-
rithm.
Theorem 10.2 (q-means iteration). For a data matrix 𝑋 ∈ ℝ𝑛×𝑑 for which
we have quantum access, and parameter 𝛿 > 0, the q-means algorithm with high
probability outputs centroids consistent with the classical 𝛿-𝑘-means algorithm,
in time
1.5
̃ (𝑘𝑑 𝜂 𝜅(𝑋)(𝜇(𝑋) + 𝑘 𝜂 ) + 𝑘2 𝜂 𝜅(𝑉 )𝜇(𝑉 ))
𝑂
𝛿2 𝛿 𝛿2
per iteration.
We prove the theorem in the next two sections.

10.3.1 Error analysis


In this section we determine the error parameters in the different steps of the
quantum algorithm so that the quantum algorithm behaves the same as the
classical 𝛿-𝑘-means. More precisely, we will determine the values of the errors
𝜖1 , 𝜖2 , 𝜖3 , 𝜖4 in terms of 𝛿. In this way, the cluster assignment of all data points
made by the 𝑞-means algorithm is consistent with a classical run of the 𝛿-𝑘-
means algorithm, and also that the centroids computed by the 𝑞-means after
each iteration are again consistent with centroids that can be returned by the
𝛿-𝑘-means algorithm.
180 CHAPTER 10. Q-MEANS

The cluster assignment in 𝑞-means happens in two steps. The first step estimates
the square distances between all points and all centroids. The error in this
procedure is of the form

|𝑑2 (𝑐𝑗 , 𝑥𝑖 ) − 𝑑2 (𝑐𝑗 , 𝑥𝑖 )| < 𝜖1 .

for a point 𝑥𝑖 and a centroid 𝑐𝑗 .


The second step finds the minimum of these distances without adding any error.
For the 𝑞-means to output a cluster assignment consistent with the 𝛿-𝑘-means
algorithm, we require that:

𝛿
∀𝑗 ∈ [𝑘], |𝑑2 (𝑐𝑗 , 𝑥𝑖 ) − 𝑑2 (𝑐𝑗 , 𝑥𝑖 )| ≤
2
which implies that no centroid with distance more than 𝛿 above the minimum
distance can be chosen by the 𝑞-means algorithm as the label. Thus we need to
take 𝜖1 < 𝛿/2.
After the cluster assignment of the 𝑞-means (which happens in superposition),
we update the clusters, by first performing a matrix multiplication to create
the centroid states and estimate their norms, and then a tomography to get
a classical description of the centroids. The error in this part is 𝜖𝑐𝑒𝑛𝑡𝑟𝑜𝑖𝑑𝑠 , as
defined in Claim 10.2, namely:


∥𝑐𝑗 − 𝑐𝑗 ∥ ≤ 𝜖𝑐𝑒𝑛𝑡𝑟𝑜𝑖𝑑 = 𝜂(𝜖3 + 𝜖4 ).

Again, for ensuring that the 𝑞-means is consistent with the classical 𝛿-𝑘-means
algorithm we take 𝜖3 < 4√𝛿 𝜂 and 𝜖4 < 4√𝛿 𝜂 . Note also that we have ignored
the error 𝜖2 that we can easily deal with, since it only appears in a logarithmic
factor in the runtime.

10.3.2 Runtime analysis


As the classical algorithm, the runtime of 𝑞-means depends linearly on the num-
ber of iterations, so here we analyze the cost of a single step. The cost of
tomography for the 𝑘 centroid vectors is 𝑂( 𝑘𝑑 log𝜖 𝑘2 log 𝑑 ) times the cost of prepa-
4
ration of a single centroid state |𝑐𝑗𝑡 ⟩. A single copy of |𝑐𝑗𝑡 ⟩ is prepared applying
the matrix multiplication by 𝑉 𝑇 procedure on the state |𝜒𝑡𝑗 ⟩ obtained using
square distance estimation. The time required for preparing a single copy of
|𝑐𝑗𝑡 ⟩ is 𝑂(𝜅(𝑉 )(𝜇(𝑉 ) + 𝑇𝜒 ) log(1/𝜖2 )) by theorem 5.11 where 𝑇𝜒 is the time for
preparing |𝜒𝑡 ⟩. The time 𝑇 is 𝑂 ̃ ( 𝑘𝜂 log(Δ−1 ) log(𝑛𝑑) ) = 𝑂(
̃ 𝑘𝜂 ) by lemma 5.6.
𝑗 𝜒 𝜖1 𝜖1
The cost of norm estimation for 𝑘 different centroids is independent of the to-
mography cost and is 𝑂( ̃ 𝑘𝑇𝜒 𝜅(𝑉 )𝜇(𝑉 ) ). Combining together all these costs and
𝜖3
suppressing all the logarithmic factors we have a total running time of:
10.3. ANALYSIS 181

̃ (𝑘𝑑 1 𝜅(𝑋)(𝜇(𝑋) + 𝑘 𝜂 ) + 𝑘2 𝜂 𝜅(𝑋)𝜇(𝑋))


𝑂 (10.2)
𝜖24 𝜖1 𝜖3 𝜖1

𝛿
The analysis in the previous section shows that we can take 𝜖1 = 𝛿/2, 𝜖3 = √
4 𝜂
and 𝜖4 = 4√𝛿 𝜂 . Substituting these values in the above running time, it follows
that the running time of the 𝑞-means algorithm is:
1.5
̃ (𝑘𝑑 𝜂 𝜅(𝑉 ) (𝜇(𝑉 ) + 𝑘 𝜂 ) + 𝑘2 𝜂 𝜅(𝑉 )𝜇(𝑉 )) .
𝑂
𝛿 2 𝛿 𝛿2

This completes the proof of the theorem.


A few concluding remarks regarding the running time of 𝑞-means. For dataset
where the number of points is much bigger compared to the other parameters,
the running time for the 𝑞-means algorithm is an improvement compared to the
classical 𝑘-means algorithm. For instance, for most problems in data analysis,
𝑘 is eventually small (< 100). The number of features 𝑑 ≤ 𝑛 in most situations,
and it can eventually be reduced by applying a quantum dimensionality reduc-
tion algorithm first (which have running time polylogarithmic in 𝑑). To sum
up, 𝑞-means has the same output as the classical 𝛿-𝑘-means algorithm (which
approximates 𝑘-means), it conserves the same number of iterations, but has a
running time only polylogarithmic in 𝑛, giving an exponential speedup with
respect to the size of the dataset.
182 CHAPTER 10. Q-MEANS
Chapter 11

Quantum
Expectation-Maximization

In this chapter we discuss the quantum version of Expectation-Maximization


(EM). EM is an iterative algorithm that have been broadly used (and re-
discovered) in many part of machine learning and statistics. As is common
in machine learning literature, we introduce the Expectation-Maximization
algorithm by using it to fit Gaussian mixture models (GMM). As the name
hints, a Gaussian mixture model is a way of describing a probability density
function as a combination of different Gaussian distributions. GMM, and in
general all the mixture models, are a popular generative model in machine
learning.

11.1 Expectation-Maximization for GMM


The intuition behind mixture models is to model complicated distributions by
using a group of simpler (usually uni-modal) distributions. In this setting, the
purpose of the learning algorithm is to model the data by fitting the joint prob-
ability distribution which most likely have generated our samples. It might
not be surprising thinking that, given a sufficiently large number of mixture
components, it is possible to approximate any density defined in ℝ𝑑 (Murphy,
2012). In this section we describe formally GMM, which is a popular mixture
model used to solve unsupervised classification problems. Then we propose the
first quantum algorithm to fit a GMM with a quantum computer. While there
are many classical algorithms that can be used to fit a mixture of Gaussians
(which we detail later), this quantum algorithm resemble as much as possible
Expectation-Maximization: a iterative method to find (local) maxima of max-
imum likelihood and maximum a posteriori optimization problems, especially
used in unsupervised settings.

183
184 CHAPTER 11. QUANTUM EXPECTATION-MAXIMIZATION

Recall that in the unsupervised case, we are given a training set of unlabeled
vectors 𝑣1 ⋯ 𝑣𝑛 ∈ ℝ𝑑 which we represent as rows of a matrix 𝑉 ∈ ℝ𝑛×𝑑 . Let
𝑦𝑖 ∈ [𝑘] one of the 𝑘 possible labels for a point 𝑣𝑖 . We posit that for a GMM
the joint probability distribution of the data 𝑝(𝑣𝑖 , 𝑦𝑖 ) = 𝑝(𝑣𝑖 |𝑦𝑖 )𝑝(𝑦𝑖 ), is defined
as follow: 𝑦𝑖 ∼ Multinomial(𝜃) for 𝜃 ∈ ℝ𝑘−1 , and 𝑝(𝑣𝑖 |𝑦𝑖 = 𝑗) ∼ 𝒩(𝜇𝑗 , Σ𝑗 ). The
𝜃𝑗 are the mixing weights, i.e. the probabilities that 𝑦𝑖 = 𝑗, and 𝒩(𝜇𝑗 , Σ𝑗 ) is the
Gaussian distribution centered in 𝜇𝑗 ∈ ℝ𝑑 with covariance matrix Σ𝑗 ∈ ℝ𝑑×𝑑 .
Note that the variables 𝑦𝑖 are unobserved, and thus are called latent variables.
There is a simple interpretation for this model. We assume the data is created
by first selecting an index 𝑗 ∈ [𝑘] by sampling according to Multinomial(𝜃), and
then a vector 𝑣𝑖 is sampled from 𝒩(𝜇𝑗 , Σ𝑗 ). Fitting a GMM to a dataset reduces
to finding an assignment for the parameters:

𝛾 = (𝜃, 𝜇,⃗ Σ)⃗ = (𝜃, 𝜇1 , ⋯ , 𝜇𝑘 , Σ1 , ⋯ , Σ𝑘 )

that best maximize the log-likelihood (defined in Section 4) for a given dataset.
Note that while a 𝜇𝑗 represents a vector, we define 𝜇⃗ as the vector of vectors
𝜇𝑗 , and the same goes for Σ.⃗ We will now see how the log-likelihood is defined
for a GMM. We use the letter 𝜙 to represent our base distribution, which in this
case is the probability density function of a Gaussian 𝒩(𝜇, Σ):
1 1
𝜙(𝑥|𝜇, Σ) = exp (− (𝑥 − 𝜇)𝑇 Σ−1 (𝑥 − 𝜇)) (11.1)
(2𝜋)𝑑/2 |Σ|1/2 2

With this formulation, a GMM is expressed as:


𝑘
𝑝(𝑣) = ∑ 𝜃𝑗 𝜙(𝑣; 𝜇𝑗 , Σ𝑗 ) (11.2)
𝑗=1

where 𝜃𝑗 are the mixing weights of the multinomial distribution such that
𝑘
∑𝑗=1 𝜃𝑗 = 1. The probability for an observation 𝑣𝑖 to be assigned to the
component 𝑗 is given by:

𝜃𝑗 𝜙(𝑣𝑖 ; 𝜇𝑗 , Σ𝑗 )
𝑟𝑖𝑗 = 𝑝(𝑦𝑖 = 𝑗|𝑣𝑖 ; 𝜃, 𝜇, Σ) = 𝑘
. (11.3)
∑𝑙=1 𝜃𝑙 𝜙(𝑣𝑖 ; 𝜇𝑙 , Σ𝑙 )

This value is called responsibility, and corresponds to the posterior probability


of the sample 𝑖 being assigned label 𝑗 by the current model. More generally,
for any base distribution in the mixture, the responsibility of the 𝑖-th vector in
cluster 𝑗 can be written as (Murphy, 2012):
𝑝(𝑦𝑖 = 𝑗; 𝛾)𝑝(𝑣𝑖 |𝑦𝑖 = 𝑗; 𝛾)
𝑟𝑖𝑗 = 𝑘
(11.4)
∑𝑗′ =1 𝑝(𝑦𝑖 = 𝑗′ ; 𝛾)𝑝(𝑣𝑖 |𝑦𝑖 = 𝑗′ ; 𝛾)
11.2. EXPECTATION-MAXIMIZATION 185

As anticipated, to find the best parameters of our generative model, we maximize


the log-likelihood of the data. To conclude, for GMM, the likelihood is given by
the following formula (Ng, 2012):

𝑛 𝑛 𝑘
ℓ(𝛾; 𝑉 ) = ℓ(𝜃, 𝜇,⃗ Σ;⃗ 𝑉 ) = ∑ log 𝑝(𝑣𝑖 ; 𝜃, 𝜇,⃗ Σ)⃗ = ∑ log ∑ 𝑝(𝑣𝑖 |𝑦𝑖 ; 𝜇,⃗ Σ)𝑝(𝑦
⃗ 𝑖 ; 𝜃)
𝑖=1 𝑖=1 𝑦𝑖 =1
(11.5)
Alas, it is seldom possible to solve maximum likelihood estimation analytically
(i.e. by finding the zeroes of the derivatives of Equation (11.5), and this is one
of those cases. Expectation-Maximization is an iterative algorithm that solves
numerically the optimization problem of ML estimation. To complicate things,
the likelihood function for GMM is not convex, and thus we might find some
local minima (Hastie et al., 2009). Note that the algorithm used to fit GMM
can return a local minimum which might be different than 𝛾 ∗ : the model that
represents the global optimum of the likelihood function.

11.2 Expectation-Maximization
The intuition behind EM is simple. If we were to know the latent variable 𝑦𝑖 ,
then the log-likelihood for GMM would be:

𝑛
ℓ(𝛾; 𝑉 ) = ∑ log 𝑝(𝑣𝑖 | 𝑦𝑖 ; 𝜇,⃗ Σ)⃗ + log 𝑝(𝑦𝑖 ; 𝜃) (11.6)
𝑖=1

This formula can be easily maximized with respect to the parameters 𝜃, 𝜇,⃗ and
Σ.⃗ In the Expectation step we calculate the missing variables 𝑦𝑖 , given a guess
of the parameters (𝜃, 𝜇,⃗ Σ)⃗ of the model. Then, in the Maximization step, we use
the estimate of the latent variables obtained in the Expectation step to update
the estimate of the parameters. While in the Expectation step we calculate a
lower bound on the likelihood, in the Maximization step we maximize it. Since
at each iteration the likelihood can only increase, the algorithm is guaranteed
to converge, albeit possibly to a local optimum (see (Hastie et al., 2009) for
the proof). During the Expectation step all the responsibilities are calculated,
while in the Maximization step we update our estimate on the parameters 𝛾 𝑡+1 =
⃗ , Σ⃗ 𝑡+1 ).
(𝜃𝑡+1 , 𝜇𝑡+1
Again, note that the 𝛾 𝑡+1 might never converge to the global optimum 𝛾 ∗ =
arg max𝛾 ℓ(𝛾; 𝑉 ): since Equation (11.5) is non-convex, any randomized algo-
rithm can get stuck in local minima.
The stopping criterion for GMM is usually a threshold on the increment of
the log-likelihood: if the log-likelihood changes less than a threshold between
two iterations, then the algorithm stops. Notice that, since the value of
186 CHAPTER 11. QUANTUM EXPECTATION-MAXIMIZATION

the log-likelihood significantly depends on the amount of data points in the


training sets, it is often preferable to adopt a scale-free stopping criterion,
which does not depend on the number of samples. For instance, in the
toolkit scikit-learn (Pedregosa et al., 2011) the stopping criterion is given by
a tolerance on the average increment of the log-probability, which is chosen
to be smaller than a certain 𝜖𝜏 , say 10−3 . More precisely, the stopping
criterion is |𝔼[log 𝑝(𝑣𝑖 ; 𝛾 𝑡 )] − 𝔼[log 𝑝(𝑣𝑖 ; 𝛾 𝑡+1 )]| < 𝜖𝜏 which we can estimate as
𝑛 𝑛
| 𝑛1 ∑𝑖=1 log 𝑝(𝑣𝑖 ; 𝛾 𝑡 ) − 𝑛1 ∑𝑖=1 log 𝑝(𝑣𝑖 ; 𝛾 𝑡+1 )| < 𝜖𝜏 .

Figure 11.1: Classical Expectation-Maximization for Gaussian mixture models


11.2. EXPECTATION-MAXIMIZATION 187

11.2.1 Initialization strategies for EM


Unlike k-means clustering, choosing a good set of initial parameters for a mixture
of Gaussian is by no means trivial, and in multivariate context is known that the
solution is problem-dependent. There are plenty of proposed techniques, and
here we describe a few of them. Fortunately, these initialization strategies can
be directly translated into quantum subroutines without impacting the overall
running time of the quantum algorithm.
The simplest technique is called random EM, and consists in selecting initial
points at random from the dataset as centroids, and sample the dataset to
estimate the covariance matrix of the data. Then these estimates are used as
the starting configuration of the model, and we may repeat the random sampling
until we get satisfactory results.
A more standard technique borrows directly the initialization strategy of k-
means++, proposed in (Arthur and Vassilvitskii, 2007), and extends it to make
an initial guess for the covariance matrices and the mixing weights. The initial
guess for the centroids is selected by sampling from a suitable, easy to calculate
distribution. This heuristic works as following: Let 𝑐0 be a randomly selected
point of the dataset, as first centroid. The other 𝑘 − 1 centroids are selected by
selecting a vector 𝑣𝑖 with probability proportional to 𝑑2 (𝑣𝑖 , 𝜇𝑙(𝑣𝑖 ) ), where 𝜇𝑙(𝑣𝑖 )
is the previously selected centroid that is the closest to 𝑣𝑖 in ℓ2 distance. These
centroids are then used as initial centroids for a round of k-means algorithm
to obtain 𝜇01 ⋯ 𝜇0𝑗 . Then, the covariance matrices can be initialized as Σ0𝑗 ∶=
1 𝑇
|𝒞𝑗 | ∑𝑖∈𝒞𝑗 (𝑣𝑖 − 𝜇𝑗 )(𝑣𝑖 − 𝜇𝑗 ) , where 𝒞𝑗 is the set of samples in the training set
that have been assigned to the cluster 𝑗 in the previous round of k-means. The
mixing weights are estimated as 𝒞𝑗 /𝑛. Eventually Σ0𝑗 is regularized to be a PSD
matrix.
There are other possible choices for parameter initialization in EM, for instance,
based on Hierarchical Agglomerative Clustering (HAC) and the CEM algorithm.
In CEM we run one step of EM, but with a so-called classification step between
E and M. The classification step consists in a hard-clustering after computing
the initial conditional probabilities (in the E step). The M step then calculates
the initial guess of the parameters (Celeux and Govaert, 1992). In the small EM
initialization method we run EM with a different choice of initial parameters
using some of the previous strategies. The difference here is that we repeat the
EM algorithm for a few numbers of iterations, and we keep iterating from the
choice of parameters that returned the best partial results. For an overview and
comparison of different initialization techniques, we refer to (Blömer and Bujna,
2013) (Biernacki et al., 2003).

[Link] Special cases of GMM


What we presented in the previous section is the most general model of GMM.
For simple datasets, it is common to assume some restrictions on the covariance
188 CHAPTER 11. QUANTUM EXPECTATION-MAXIMIZATION

matrices of the mixtures. The translation into a quantum version of the model
should be straightforward. We distinguish between these cases:
• Soft k-means. This algorithm is often presented as a generalization of
k-means, but it can actually be seen as special case of EM for GMM -
albeit with a different assignment rule. In soft 𝑘-means, the assignment
function is replaced by a softmax function with stiffness parameter 𝛽. This
𝛽 represents the covariance of the clusters. It is assumed to be equal for
all the clusters, and for all dimensions of the feature space. Gaussian
Mixtures with constant covariance matrix (i.e. Σ𝑗 = 𝛽𝐼 for 𝛽 ∈ ℝ) can
be interpreted as a kind of soft or fuzzy version of k-means clustering.
The probability of a point in the feature space being assigned to a certain
cluster 𝑗 is:
2
𝑒−𝛽‖𝑥𝑖 −𝜇𝑖 ‖
𝑟𝑖𝑗 = 𝑘 2
∑𝑙=1 𝑒−𝛽‖𝑥𝑖 −𝜇𝑙 ‖
where 𝛽 > 0 is the stiffness parameter. This is the case where all the
Gaussians have the same diagonal covariance matrix, which is uniform in
all directions.
• Spherical. In this model, each component has its own covariance matrix,
but the variance is uniform in all the directions, thus reducing the co-
variance matrix to a multiple of the identity matrix (i.e. Σ𝑗 = 𝜎𝑗2 𝐼 for
𝜎𝑗 ∈ ℝ).
• Diagonal. As the name suggests, in this special case the covariance matrix
of the distributions is a diagonal matrix, but different Gaussians might
have different diagonal covariance matrices.
• Tied. In this model, the Gaussians share the same covariance matrix,
without having further restriction on the Gaussian.
• Full. This is the most general case, where each of the components of the
mixture have a different, SDP, covariance matrix.

11.2.2 Dataset assumptions in GMM


We make explicit an assumption on the dataset, namely that all elements of the
mixture contribute proportionally to the total responsibility:

𝑛
∑𝑖=1 𝑟𝑖𝑗
𝑛 = Θ(1) ∀𝑗, 𝑙 ∈ [𝑘] (11.7)
∑𝑖=1 𝑟𝑖𝑙

This is equivalent to assuming that 𝜃𝑗 /𝜃𝑙 = Θ(1) ∀𝑗, 𝑙 ∈ [𝑘]. This resembles the
assumption of “well-clusterability’ ’ in q-means, which we saw in the previous
chapter. The algorithm can be used even in cases where this assumption does
not hold. In this case, the running time will include a factor as in Eq. (11.7)
which for simplicity we have taken as constant in what follows. Note that
classical algorithms would also find it difficult to fit the data in certain cases,
for example when some of the clusters are very small. In fact, it is known (and
11.2. EXPECTATION-MAXIMIZATION 189

not surprising) that if the statistical distance between the probability density
function of two different Gaussian distributions is smaller than 1/2, then we can
not tell for a point 𝑣 from which Gaussian distribution it belongs to, even if we
knew the parameters (Moitra, 2018). Only for convenience in the analysis, we
also assume the dataset as being normalized such that the shortest vector has
2
norm 1 and define 𝜂 ∶= 𝑚𝑎𝑥𝑖 ‖𝑣𝑖 ‖ to be the maximum norm squared of a vector
in the dataset.

[Link] EM and other mixture models


Expectation-Maximization is widely used for fitting mixture models in machine
learning (Murphy, 2012). Most mixture models use a base distribution in the
exponential family: Poisson (Church and Gale, 1995) (when the observations
are a mixture of random counts with a fixed rate of occurrences), Binomial
and Multinomial (when the observations have 2 or multiple possible outcomes,
like answers in a survey or a vote) and log-normal (Dexter and Tanner, 1972),
exponential (when samples have a latent variable that represents a failure of a
certain kind, which is often modeled by the exponential distribution) (Ghitany
et al., 1994), Dirichlet multinomial (Yin and Wang, 2014), and others.
Besides fitting mixture models based on the exponential family, the EM algo-
rithm has several other applications. It has been used to fit mixtures of experts,
mixtures of the student T distribution (which does not belong to the exponen-
tial family, and can be fitted with EM using (Liu and Rubin, 1995)) and for
factor analysis, probit regression, and learning Hidden Markov Models (Murphy,
2012).
Theorem 11.1 (Multivariate mean-value theorem (Rudin et al., 1964)). Let
𝑈 be an open set of ℝ𝑑 . For a differentiable functions 𝑓 ∶ 𝑈 ↦ ℝ it holds that
∀𝑥, 𝑦 ∈ 𝑈 , ∃𝑐 such that 𝑓(𝑥) − 𝑓(𝑦) = ∇𝑓(𝑐) ⋅ (𝑥 − 𝑦).

Proof. Define ℎ ∶ [0, 1] ↦ 𝑈 where ℎ(𝑡) = 𝑥 + 𝑡(𝑦 − 𝑥). We can define a


new function 𝑔(𝑡) ∶= 𝑓 ∘ ℎ = 𝑓(𝑥 + 𝑡(𝑦 − 𝑥)). Note that both functions are
differentiable, and so its their composition. Therefore, we can compute the
derivative of 𝑔 using the chain rule: 𝑔′ = (𝑓 ∘ ℎ)′ = (𝑓 ′ ∘ ℎ)ℎ′ . This gives:

𝑔′ (𝑡) = (∇𝑓(ℎ(𝑡)), ℎ′ (𝑡)) = (𝑓(𝑥 + 𝑡(𝑦 − 𝑎)), 𝑦 − 𝑥)

Because of the one-dimensional Mean Value theorem applied to 𝑔′ (𝑡), we have


that ∃𝑡0 such that 𝑔(1) − 𝑔(0) = 𝑓(𝑦) − 𝑓(𝑥) = 𝑔′ (𝑡0 ) = (𝑓(𝑥 + 𝑡0 (𝑦 − 𝑥)), 𝑦 − 𝑥).
Setting 𝑐 = 𝑥 + 𝑡0 (𝑦 − 𝑥), we have that 𝑓(𝑦) − 𝑓(𝑥) = ∇𝑓(𝑐) ⋅ (𝑦 − 𝑥).

Theorem 11.2 (Componentwise *softmax* function is Lipschitz continuous).


𝑣𝑗
For 𝑑 > 2, let 𝜎𝑗 ∶ ℝ𝑑 ↦ (0, 1) be the softmax function defined as 𝜎𝑗 (𝑣) = 𝑑𝑒 𝑣𝑙 .
∑𝑙=1 𝑒

Then 𝜎𝑗 is Lipschitz continuous, with 𝐾 ≤ 2.
190 CHAPTER 11. QUANTUM EXPECTATION-MAXIMIZATION

Proof. We need to find the 𝐾 such that for all 𝑥, 𝑦 ∈ ℝ𝑑 , we have that
∥𝜎𝑗 (𝑦) − 𝜎𝑗 (𝑥)∥ ≤ 𝐾 ‖𝑦 − 𝑥‖. Observing that 𝜎𝑗 is differentiable and that if we
apply Cauchy-Schwarz to the statement of the mean-value-theorem we derive
that $ �x,y �U, : �c$ such that ‖𝑓(𝑥) − 𝑓(𝑦)‖ ≤ ‖∇𝑓(𝑐)‖𝐹 ‖𝑥 − 𝑦‖. So to show

Lipschitz continuity it is enough to select 𝐾 ≤ ∥∇𝜎𝑗 ∥ = max𝑐∈ℝ𝑑 ∥∇𝜎𝑗 (𝑐)∥.
𝐹
𝑑𝜎𝑗 (𝑣)
The partial derivatives 𝑑𝑣𝑖 are 𝜎𝑗 (𝑣)(1 − 𝜎𝑗 (𝑣)) if 𝑖 = 𝑗 and −𝜎𝑖 (𝑣)𝜎𝑗 (𝑣)
2 𝑑−1
otherwise. So ∥∇𝜎𝑗 ∥ = ∑𝑖=1 (−𝜎(𝑣)𝑖 𝜎𝑗 (𝑣))2 + 𝜎𝑗 (𝑣)2 (1 − 𝜎𝑗 (𝑣))2 ≤
𝐹
𝑑−1 𝑑−1
∑𝑖=1 𝜎(𝑣)𝑖 𝜎𝑗 (𝑣) + 𝜎𝑗 (𝑣)(1 − 𝜎𝑗 (𝑣)) ≤ 𝜎𝑗 (𝑣) ∑𝑖=0
𝜎𝑖 (𝑣) + 1 − 𝜎𝑗 (𝑣) ≤ 2𝜎𝑗 (𝑣) ≤ 2.
√ √
In our case we can deduce that: ∥𝜎𝑗 (𝑦) − 𝜎𝑗 (𝑥)∥ ≤ 2 ‖𝑦 − 𝑥‖ so 𝐾 ≤ 2.

11.3 Quantum Expectation-Maximization for


GMM
In this section, we present a quantum Expectation-Maximization algorithm to
fit a GMM. The algorithm can also be adapted to fit other mixtures models
where the probability distributions belong to the exponential family. As the
GMM is both intuitive and one of the most widely used mixture models, our
results are presented for the GMM case.

[Link] An approximate version of GMM


Here we define an approximate version of GMM, that we fit with QEM algorithm.
The difference between this formalization and the original GMM is simple. Here
we make explicit in the model the approximation error introduced during the
iterations of the training algorithm.
Definition 11.1 (Approximate GMM). Let 𝛾 𝑡 = (𝜃𝑡 , 𝜇𝑡⃗ , Σ⃗ 𝑡 ) = (𝜃𝑡 , 𝜇𝑡1 ⋯ 𝜇𝑡𝑘 , Σ𝑡1 ⋯ Σ𝑡𝑘 )
a model fitted by the standard EM algorithm from 𝛾 0 an initial guess of the
parameters, i.e. 𝛾 𝑡 is the error-free model that standard EM would have
returned after 𝑡 iterations. Starting from the same choice of initial parameters
𝛾 0 , fitting a GMM with the QEM algorithm with Δ = (𝛿𝜃 , 𝛿𝜇 ) means returning
𝑡 𝑡 𝑡
a model 𝛾 𝑡 = (𝜃 , 𝜇⃗ , Σ⃗ ) such that:
𝑡
• ∥𝜃 − 𝜃𝑡 ∥ < 𝛿𝜃 ,
• ∥𝜇𝑗 𝑡 − 𝜇𝑡𝑗 ∥ < 𝛿𝜇 : for all 𝑗 ∈ [𝑘],
𝑡 √
• ∥Σ𝑗 − Σ𝑡𝑗 ∥ ≤ 𝛿𝜇 𝜂 : for all 𝑗 ∈ [𝑘].

[Link] Quantum access to the mixture model


Here we explain how to load into a quantum computer a GMM and a dataset
represented by a matrix 𝑉 . This is needed for a quantum computer to be able
to work with a machine learning model. The definition of quantum access to
other kind of models is analogous. For ease of exposure, we define what does
11.3. QUANTUM EXPECTATION-MAXIMIZATION FOR GMM 191

it means to have quantum access to a GMM and its dataset. This definition is
basically an extension of theorem ??.

Definition 11.2 (Quantum access to a GMM). We say that we have quantum


access to a GMM of a dataset 𝑉 ∈ ℝ𝑛×𝑑 and model parameters 𝜃𝑗 ∈ ℝ, 𝜇𝑗 ∈
ℝ𝑑 , Σ𝑗 ∈ ℝ𝑑×𝑑 for all 𝑗 ∈ [𝑘] if we can perform in time 𝑂(polylog(𝑑)) the following
mappings:

• |𝑗⟩|0⟩ ↦ |𝑗⟩|𝜇𝑗 ⟩,
• |𝑗⟩|𝑖⟩|0⟩ ↦ |𝑗⟩|𝑖⟩|𝜎𝑖𝑗 ⟩ for 𝑖 ∈ [𝑑] where $�_i^{j} $ is the 𝑖-th rows of Σ𝑗 ∈
ℝ𝑑×𝑑 ,
• |𝑖⟩|0⟩ ↦ |𝑖⟩|𝑣𝑖 ⟩ for all 𝑖 ∈ [𝑛],
• |𝑖⟩|0⟩|0⟩ ↦ |𝑖⟩|vec[𝑣𝑖 𝑣𝑖𝑇 ]⟩ = |𝑖⟩|𝑣𝑖 ⟩|𝑣𝑖 ⟩ for 𝑖 ∈ [𝑛],
• |𝑗⟩|0⟩ ↦ |𝑗⟩|𝜃𝑗 ⟩.

Figure 11.2: Classical Expectation-Maximization for Gaussian mixture models


192 CHAPTER 11. QUANTUM EXPECTATION-MAXIMIZATION

[Link] Quantum initialization strategies


For the initialization of 𝛾 0 in the quantum algorithm we can use the same
initialization strategies as in classical machine learning. For instance, we can
use the classical random EM initialization strategy for QEM.
A quantum initialization strategy can also be given using the k-means++
initializion strategy, which we discuss in Chapter 10. It returns 𝑘 initial
guesses for the centroids 𝑐10 ⋯ 𝑐𝑘0 consistent with the classical algorithm in time
2𝜂1.5
(𝑘2 ), where 𝔼(𝑑2 (𝑣𝑖 , 𝑣𝑗 )) is the average squared distance between
𝜖√𝔼(𝑑2 (𝑣𝑖 ,𝑣𝑗 ))

two points of the dataset, and 𝜖 is the tolerance in the distance estimation.
From there, we can perform a full round of q-means algorithm and get an
estimate for 𝜇01 ⋯ 𝜇0𝑘 . With q-means and the new centroids store in the QRAM
we can create the state
1 𝑛
|𝜓0 ⟩ ∶= √ ∑ |𝑖⟩|𝑙(𝑣𝑖 )⟩. (11.8)
𝑛 𝑖=1

Where 𝑙(𝑣𝑖 ) is the label of the closest centroid to the 𝑖-th point. By sampling
𝑆 ∈ 𝑂(𝑑) points from this state we get two things. First, from the frequency 𝑓𝑗
of the second register we can have an guess of 𝜃𝑗0 ← |𝒞𝑗 |/𝑛 ∼ 𝑓𝑗 /𝑆. Then, from
the first register we can estimate Σ0𝑗 ← ∑𝑖∈𝑆 (𝑣𝑖 −𝜇0𝑗 )(𝑣𝑖 −𝜇0𝑗 )𝑇 . Sampling 𝑂(𝑑)
̃
points and creating the state in Equation (11.8) takes time 𝑂(𝑑𝑘𝜂) by theorem
5.6 and the minimum finding procedure, i.e. lemma 5.2.
Techniques illustrated in (Miyahara et al., 2020) can also be used to quantize
the CEM algorithm which needs a hard-clustering step. Among the different
possible approaches, the random and the small EM greatly benefit from a
faster algorithm, as we can spend more time exploring the space of the parame-
ters by starting from different initial seeds, and thus avoid local minima of the
likelihood.

11.3.1 Expectation
In this step of the quantum algorithm we are just showing how to compute
efficiently the responsibilities as a quantum state. First, we compute the re-
sponsibilities in a quantum register, and then we show how to put them as
amplitudes of a quantum state. At each iteration of Quantum Expectation-
Maximization (specifically, in the Expectation step), we assume to have quan-
tum access to the determinant of the covariance matrices. In the next Chapters
we will also detail quantum algorithms for the problem of computing the log-
determinant. From the error analysis we will see that the cost of comping the
log-determinant of the covariance matrices (even with classical algorithms) is
smaller than the cost of the other quantum step, we can discard the cost of com-
puting the log-determinant in the analysis of the quantum algorithms. Thus,
we do not explicitly write the time to compute the determinant from now on
11.3. QUANTUM EXPECTATION-MAXIMIZATION FOR GMM 193

in the algorithm and when we say that we update Σ we include an update on


the estimate of log(det(Σ)) as well. Classical algorithms often depend linearly
on 𝑛𝑛𝑧(Σ)| log(det(Σ))|, which can be upper bounded by 𝑂(𝑑 ̃ 2 ), where 𝑑 is the
dimension of the covariance matrix. Note that it is often the case that GMM is
run with diagonal covariance matrix, thus making the estimation of the deter-
minant trivial.

Lemma 11.1 (Quantum Gaussian Evaluation). Suppose we have stored in the


QRAM a matrix 𝑉 ∈ ℝ𝑛×𝑑 , the centroid 𝜇 ∈ ℝ𝑑 and a SPD covariance matrix
Σ ∈ ℝ𝑑×𝑑 of a multivariate Gaussian distribution 𝜙(𝑣|𝜇, Σ), such that ‖Σ‖ ≤ 1.
Also assume to have an absolute 𝜖1 /2 estimate for log(det(Σ)). Then for 𝜖1 > 0,
there exists a quantum algorithm that with probability 1−𝛾 performs the mapping
𝑈𝐺,𝜖1 ∶ |𝑖⟩|0⟩ → |𝑖⟩|𝑠𝑖 ⟩ such that |𝑠𝑖 − 𝑠𝑖 | < 𝜖1 , where 𝑠𝑖 = − 12 ((𝑣𝑖 − 𝜇)𝑇 Σ−1 (𝑣𝑖 −
𝜇) + 𝑑 log 2𝜋 + log(𝑑𝑒𝑡(Σ))) is the exponent for the Gaussian probability density
function in Equation (11.1). The running time of the algorithm is,

𝜅(Σ)𝜇(Σ) log(1/𝛾)
𝑇𝐺,𝜖1 = 𝑂 ( 𝜂) .
𝜖1

Proof. We use quantum linear algebra and inner product estimation to estimate
the quadratic form (𝑣𝑖 −𝜇)𝑇 Σ−1 (𝑣𝑖 −𝜇) to error 𝜖1 . We decompose the quadratic
form as 𝑣𝑖𝑇 Σ−1 𝑣𝑖 − 2𝑣𝑖𝑇 Σ−1 𝜇 + 𝜇𝑇 Σ−1 𝜇 and separately approximate each term
in the sum to error 𝜖1 /8 using lemma 5.7. The runtime for this operation is
𝑂( 𝜇(Σ)𝜅(Σ)𝜂
𝜖1 ). With this, we obtain an estimate for 12 ((𝑣𝑖 − 𝜇)𝑇 Σ−1 (𝑣𝑖 − 𝜇)
within error 𝜖1 . Recall that (through the algorithm in lemma ?? we also have
an estimate of the log-determinant to error 𝜖1 /2. With these factors, we obtain
an approximation for − 12 ((𝑣𝑖 − 𝜇)𝑇 Σ−1 (𝑣𝑖 − 𝜇) + 𝑑 log 2𝜋 + log(det(Σ))) within
error 𝜖1 .

Using controlled operations it is simple to extend the previous theorem to work


with multiple Gaussians distributions (𝜇𝑗 , Σ𝑗 ). That is, we can control on a
register |𝑗⟩ to do |𝑗⟩|𝑖⟩|0⟩ ↦ |𝑗⟩|𝑖⟩|𝜙(𝑣𝑖 |𝜇𝑗 , Σ𝑗 )⟩. In the next lemma we will see
how to obtain the responsibilities 𝑟𝑖𝑗 using the previous theorem and standard
quantum circuits for doing arithmetic, controlled rotations, and amplitude am-
plification. The lemma is stated in a general way, to be used with any probability
distributions that belong to an exponential family.

Lemma 11.2 (Error in the responsibilities of the exponential family). Let 𝑣𝑖 ∈


ℝ𝑛 be a vector, and let {𝑝(𝑣𝑖 |𝜈𝑗 )}𝑘𝑗=1 be a set of 𝑘 probability distributions in
the exponential family, defined as 𝑝(𝑣𝑖 |𝜈𝑗 ) ∶= ℎ𝑗 (𝑣𝑖 )𝑒𝑥𝑝{𝑜𝑗 (𝜈𝑗 )𝑇 𝑇𝑗 (𝑣𝑖 ) − 𝐴𝑗 (𝜈𝑗 )}.
Then, if we have estimates for √ each exponent with error 𝜖, then we can compute
each 𝑟𝑖𝑗 such that |𝑟𝑖𝑗 − 𝑟𝑖𝑗 | ≤ 2𝑘𝜖 for 𝑗 ∈ [𝑘].

Proof. The proof follows from rewriting the responsibility of Equation (11.3)
194 CHAPTER 11. QUANTUM EXPECTATION-MAXIMIZATION

and (11.4) as:

ℎ𝑗 (𝑣𝑖 ) exp{𝑜𝑗 (𝜈𝑗 )𝑇 𝑇 (𝑣𝑖 ) − 𝐴𝑗 (𝜈𝑗 ) + log 𝜃𝑗 }


𝑟𝑖𝑗 ∶= 𝑘
(11.9)
∑ ℎ𝑙 (𝑣𝑖 ) exp{𝑜𝑙 (𝜈𝑙 )𝑇 𝑇 (𝑣 𝑖) − 𝐴𝑙 (𝜈𝑙 ) + log 𝜃𝑙 }
𝑙=1

In this form, it is clear that the responsibilities can be seen a softmax function,
and we can use theorem 11.2 to bound the error in computing this value. %Note
that in this case the error in log 𝜃𝑗 is also relative, so it will not impact the whole
error in the exponent.
Let 𝑇𝑖 ∈ ℝ𝑘 be the vector of the exponent, that is 𝑡𝑖𝑗 = 𝑜𝑗 (𝜈𝑗 )𝑇 𝑇 (𝑣𝑖 ) − 𝐴𝑗 (𝜈𝑗 ) +
log 𝜃𝑗 . In an analogous way we define 𝑇𝑖 the vector where each component is
the estimate with error 𝜖. The error in the responsibility is defined as |𝑟𝑖𝑗 −
𝑟𝑖𝑗 | = |𝜎𝑗 (𝑇𝑖 ) − 𝜎𝑗 (𝑇𝑖 )|. Because the function 𝜎𝑗 is Lipschitz continuous, as

we proved in theorem √ 11.2 with a Lipschitz constant 𝐾 ≤ 2, we √ have that,
|𝜎𝑗 (𝑇𝑖 ) − 𝜎𝑗 (𝑇𝑖 )| ≤ 2 ∥𝑇𝑖 − 𝑇𝑖 ∥. The result follows as ∥𝑇𝑖 − 𝑇𝑖 ∥ < 𝑘𝜖.
The next lemma provides a quantum algorithm for calculating the responsibilities for th
Lemma 11.3 (Calculating responsibilities). Suppose we have quantum access
to a GMM with parameters 𝛾 𝑡 = (𝜃𝑡 , 𝜇𝑡⃗ , Σ⃗ 𝑡 ). There are quantum algorithms that
can:
• Perform the mapping |𝑖⟩|𝑗⟩|0⟩ ↦ |𝑖⟩|𝑗⟩|𝑟𝑖𝑗 ⟩ such that |𝑟𝑖𝑗 − 𝑟𝑖𝑗 | ≤ 𝜖1 with
probability 1 − 𝛾 in time:

̃ 1.5 × 𝑇
𝑇𝑅1 ,𝜖1 = 𝑂(𝑘 𝐺,𝜖1 )

𝑛
1
• For a given 𝑗 ∈ [𝑘], construct state |𝑅𝑗 ⟩ such that ∥|𝑅𝑗 ⟩ − √𝑍𝑗
∑ 𝑟𝑖𝑗 |𝑖⟩∥ <
𝑖=0
𝑛
2
𝜖1 where 𝑍𝑗 = ∑ 𝑟𝑖𝑗 with high probability in time:
𝑖=0

̃ 2×𝑇
𝑇𝑅2 ,𝜖1 = 𝑂(𝑘 𝑅1 ,𝜖1 )

Proof. For the first statement, we start by recalling the definition of responsibil-
𝜃 𝜙(𝑣 ;𝜇 ,Σ )
ity: 𝑟𝑖𝑗 = 𝑘 𝑗 𝑖 𝑗 𝑗 . With the aid of 𝑈𝐺,𝜖1 of lemma 11.1 we can estimate
∑𝑙=1 𝜃𝑙 𝜙(𝑣𝑖 ;𝜇𝑙 ,Σ𝑙 )
log(𝜙(𝑣𝑖 |𝜇𝑗 , Σ𝑗 )) for all 𝑗 up to additive error 𝜖1 , and then using the current
estimate of 𝜃𝑡 , we can calculate the responsibilities create the state,

1 𝑛 𝑘
√ ∑ |𝑖⟩( ⨂ |𝑗⟩|log(𝜙(𝑣𝑖 |𝜇𝑗 , Σ𝑗 )⟩) ⊗ |𝑟𝑖𝑗 ⟩.
𝑛 𝑖=0 𝑗=1

The estimate 𝑟𝑖𝑗 is computed by evaluating a weighted softmax function with


arguments log(𝜙(𝑣𝑖 |𝜇𝑗 , Σ𝑗 ) for 𝑗 ∈ [𝑘]. The estimates log(𝜙(𝑣𝑖 |𝜇𝑗 , Σ𝑗 ) are then
11.3. QUANTUM EXPECTATION-MAXIMIZATION FOR GMM 195

uncomputed. The runtime of the procedure is given by calling 𝑘 times lemma


11.1 for Gaussian estimation (the runtime for arithmetic operations to calculate
the responsibilities are absorbed).
Let us analyze the error in the estimation of 𝑟𝑖𝑗 . The responsibility 𝑟𝑖𝑗 is a
softmax function with arguments log(𝜙(𝑣𝑖 |𝜇𝑗 , Σ𝑗 )) that are computed up to error

𝜖1 using lemma 11.1. As the softmax function has a Lipschitz constant√ 𝐾≤ 2
by lemma 11.2, we choose precision for lemma 11.1 to be 𝜖1 / 2𝑘 to get the
guarantee |𝑟𝑖𝑗 − 𝑟𝑖𝑗 | ≤ 𝜖1 . Thus, the total cost of this step is 𝑇𝑅1 ,𝜖1 = 𝑘1.5 𝑇𝐺,𝜖1 .
We we see how to encode this information in the amplitudes, as stated in the
second claim of the lemma. We estimate the responsibilities 𝑟𝑖𝑗 to some precision
𝜖 and perform a controlled rotation on an ancillary qubit to obtain,

𝑛
1
√ |𝑗⟩ ∑ |𝑖⟩|𝑟𝑖𝑗 ⟩(𝑟𝑖𝑗 |0⟩ + √1 − 𝑟𝑖𝑗 2 |1⟩). (11.10)
𝑛 𝑖=0

We then undo the circuit on the second register and perform amplitude amplifi-
𝑛
cation on the rightmost auxiliary qubit being |0⟩ to get |𝑅𝑗 ⟩ ∶= ∥𝑅1 ∥ ∑𝑖=0 𝑟𝑖𝑗 |𝑖⟩.
𝑗

𝑛
The runtime for amplitude amplification on this task is 𝑂(𝑇𝑅1 ,𝜖 ⋅ ∥𝑅𝑗 ∥
).

Let us analyze the precision 𝜖 required to prepare |𝑅𝑗 ⟩ such that ∥|𝑅𝑗 ⟩ − |𝑅𝑗 ⟩∥ ≤
𝜖1 . As we have estimates |𝑟𝑖𝑗 − 𝑟𝑖𝑗 | < 𝜖 for all 𝑖, 𝑗, the ℓ2 -norm error ∥𝑅𝑗 − 𝑅𝑗 ∥ =
𝑛 √
√∑𝑖=0 |𝑟𝑖𝑗 − 𝑟𝑖𝑗 |2 < 𝑛𝜖.

Applying Claim D.4, the error for the normalized vector |𝑅𝑗 ⟩ can be bounded as

2𝑛𝜖
∥|𝑅𝑗 ⟩ − |𝑅𝑗 ⟩∥ < ∥𝑅𝑗 ∥
.
By the Cauchy-Schwarz inequality we have that ∥𝑅𝑗 ∥ ≥
𝑛 √ √ √
∑𝑖 𝑟𝑖𝑗

𝑛
. We can use this to obtain a bound ∥𝑅𝑛∥ < ∑ 𝑛𝑟 𝑛 = 𝑂(𝑘), using the
𝑗 𝑖 𝑖𝑗

2𝑛𝜖
dataset assumptions in section 11.2.2. If we choose 𝜖 such that ∥𝑅𝑗 ∥
< 𝜖1 , that
̃ 2×𝑇
is 𝜖 ≤ 𝜖1 /𝑘 then our runtime becomes 𝑇𝑅2 ,𝜖1 ∶= 𝑂(𝑘 𝑅1 ,𝜖1 ).

11.3.2 Maximization
Now we need to get a new estimate for the parameters of our model. This is the
idea: at each iteration we recover the new parameters from the quantum algo-
rithms as quantum states, and then by performing tomography we can update
the QRAM that gives us quantum access to the GMM for the next iteration. In
these sections we will show how.

[Link] Updating mixing weights 𝜃


Lemma 11.4 (Computing mixing weights). We assume quantum access to a
GMM with parameters 𝛾 𝑡 and let 𝛿𝜃 > 0 be a precision parameter. There exists
196 CHAPTER 11. QUANTUM EXPECTATION-MAXIMIZATION

𝑡+1 𝑡+1
an algorithm that estimates 𝜃 ∈ ℝ𝑘 such that ∥𝜃 − 𝜃𝑡+1 ∥ ≤ 𝛿𝜃 in time

𝜅(Σ)𝜇(Σ)
𝑇𝜃 = 𝑂 (𝑘3.5 𝜂1.5 )
𝛿𝜃2

Proof. An estimate of 𝜃𝑗𝑡+1 can be recovered from the following operations. First,
we use lemma 11.3 (part 1) to compute the responsibilities to error 𝜖1 , and then
perform the following mapping, which consists of a controlled rotation on an
auxiliary qubit:

𝑛,𝑘 𝑛,𝑘
1 1
√ ∑ |𝑖⟩|𝑗⟩|𝑟𝑖𝑗 𝑡 ⟩ ↦ √ ∑ |𝑖⟩|𝑗⟩(√𝑟𝑖𝑗 𝑡 |0⟩ + √1 − 𝑟𝑖𝑗 𝑡 |1⟩)
𝑛𝑘 𝑖=1 𝑛𝑘 𝑖=1
𝑗=1 𝑗=1

The previous operation has a cost of 𝑇𝑅1 ,𝜖1 , and the probability of getting |0⟩
𝑛 𝑘
is 𝑝(0) = 1
𝑛𝑘
𝑡
∑𝑖=1 ∑𝑗=1 𝑟𝑖𝑗 = 1
𝑘. Now observe that, by definition, 𝜃𝑗𝑡+1 =
1 𝑛 𝑡
𝑛 ∑𝑖=1 𝑟𝑖𝑗 .

𝑛 𝑛
Let 𝑍𝑗 = ∑𝑖=1 𝑟𝑖𝑗 𝑡 and define state |√𝑅𝑗 ⟩ = ( √𝑍1
∑𝑖=1 √𝑟𝑖𝑗 𝑡 |𝑖⟩) |𝑗⟩. After
𝑗
amplitude amplification on |0⟩ we have the state,

𝑛,𝑘
√ 1
| 𝑅⟩ ∶= √ ∑ √𝑟𝑖𝑗 𝑡 |𝑖⟩|𝑗⟩
𝑛 𝑖=1
𝑗=1
𝑘 𝑛
𝑍𝑗 1
= ∑√ ( ∑ √𝑟𝑖𝑗 𝑡 |𝑖⟩) |𝑗⟩
𝑗=1
𝑛 √𝑍𝑗 𝑖=1
𝑘
𝑡+1
= ∑ √𝜃𝑗 |√𝑅𝑗 ⟩|𝑗⟩. (11.11)
𝑗=1

The probability of obtaining outcome |𝑗⟩ if the second register is measured in


𝑡+1
the standard basis is 𝑝(𝑗) = 𝜃𝑗 . An estimate for 𝜃𝑗𝑡+1 with precision 𝜖 can
be obtained by either sampling the last register, or by performing amplitude
estimation. In this case, we can estimate each of the values 𝜃𝑗𝑡+1 for 𝑗 ∈ [𝑘].
Sampling requires 𝑂(𝜖−2 ) samples to get epsilon accuracy on 𝜃 (by the Chernoff
bounds), but does not incur any dependence on 𝑘. As the number of cluster
𝑘 is relatively small compared to 1/𝜖, √ we chose to do amplitude estimation to
estimate all 𝜃𝑗𝑡+1 for 𝑗 ∈ [𝑘] to error 𝜖/ 𝑘 in time,

𝑘𝑇𝑅1 ,𝜖1
𝑇𝜃 ∶= 𝑂 (𝑘 ⋅ ). (11.12)
𝜖
11.3. QUANTUM EXPECTATION-MAXIMIZATION FOR GMM 197

We analyze the error in this procedure. The error introduced by the estimation
𝑡+1
of responsibility in lemma 11.3 is |𝜃𝑗 − 𝜃𝑗𝑡+1 | = 𝑛1 ∑𝑖 |𝑟𝑖𝑗 𝑡 − 𝑟𝑖𝑗
𝑡
| ≤ 𝜖1 for all
𝑡+1 𝑘
𝑡+1
𝑡+1

𝑗 ∈ [𝑘], pushing the error on the vector 𝜃 ∈ ℝ up to ∥𝜃 − 𝜃 ∥ ≤ 𝑘𝜖1 .

The total error in ℓ2 norm due to amplitude estimation is at most 𝜖 as it estimates


𝑡+1 √
each coordinate of 𝜃𝑗 to error 𝜖/ 𝑘. As the errors sums up additively, we can

use the triangle inequality to bound them. The total error is at most 𝜖+ 𝑘𝜖1 . As
𝑡+1
we require the final error to be upper bounded by ∥𝜃 − 𝜃𝑡+1 ∥ < 𝛿𝜃 , we choose

parameters 𝑘𝜖1 < 𝛿𝜃 /2 ⇒ 𝜖1 < 2𝛿√𝜃𝑘 and 𝜖 < 𝛿𝜃 /2. With these parameters,
𝑇𝑅1 ,𝜖1
the overall running time of the quantum procedure is 𝑇𝜃 = 𝑂(𝑘1.5 𝜖 ) =
1.5
3.5 𝜂 ⋅𝜅2 (Σ)𝜇(Σ)
𝑂 (𝑘 𝛿𝜃2
).

[Link] Updating the centroids 𝜇𝑗


We use quantum linear algebra to transform the uniform superposition of re-
sponsibilities of the 𝑗-th mixture into the new centroid of the 𝑗-th Gaussian.
Let 𝑅𝑗𝑡 ∈ ℝ𝑛 be the vector of responsibilities for a Gaussian 𝑗 at iteration 𝑡. The
following claim relates the vectors 𝑅𝑗𝑡 to the centroids 𝜇𝑡+1
𝑗 .

Lemma 11.5. Let 𝑅𝑗𝑡 ∈ ℝ𝑛 be the vector of responsibilities of the points for the
𝑛 𝑡
∑𝑖=1 𝑟𝑖𝑗 𝑣𝑖 𝑉 𝑇 𝑅𝑗𝑡
𝑡
Gaussian 𝑗 at time 𝑡, i.e. (𝑅𝑗𝑡 )𝑖 = 𝑟𝑖𝑗 . Then 𝜇𝑡+1
𝑗 ← 𝑛
∑𝑖=1 𝑟𝑖𝑗𝑡 = 𝑛𝜃𝑗 .

The proof is straightforward.


Lemma 11.6 (Computing new centroids). We assume we have quantum ac-
cess to a GMM with parameters 𝛾 𝑡 . For a precision parameter 𝛿𝜇 > 0, there
is a quantum algorithm that calculates {𝜇𝑗 𝑡+1 }𝑘𝑗=1 such that for all 𝑗 ∈ [𝑘]
∥𝜇𝑗 𝑡+1 − 𝜇𝑡+1
𝑗 ∥ ≤ 𝛿𝜇 in time

3.5 1.5
̃ ( 𝑘𝑑𝜂𝜅(𝑉 )(𝜇(𝑉 ) + 𝑘
𝑇𝜇 = 𝑂
𝜂 𝜅(Σ)𝜇(Σ))
)
𝛿𝜇3

Proof. A new centroid 𝜇𝑡+1 𝑗 is estimated by first creating an approximation


of the state |𝑅𝑗𝑡 ⟩ up to error 𝜖1 in the ℓ2 -norm using part 2 of lemma 11.3.
Then, we use the quantum linear algebra algorithms in theorem 5.11 to multi-
ply 𝑅𝑗 by 𝑉 𝑇 , and obtain a state |𝜇𝑗 𝑡+1 ⟩ along with an estimate for the norm
∥𝑉 𝑇 𝑅𝑗𝑡 ∥ = ∥𝜇𝑗 𝑡+1 ∥ with error 𝜖3 . The last step of the algorithm consists in es-
timating the unit vector |𝜇𝑗 𝑡+1 ⟩ with precision 𝜖4 , using ℓ2 tomography. The
tomography depends linearly on 𝑑, which we expect to be bigger than the pre-
cision required by the norm estimation. Thus, we assume that the runtime of
the norm estimation is absorbed by the runtime of tomography. We obtain a
̃ (𝑘 𝑑2 ⋅ 𝜅(𝑉 ) (𝜇(𝑉 ) + 𝑇
final runtime of 𝑂 𝜖 4
𝑅2 ,𝜖1 )).
198 CHAPTER 11. QUANTUM EXPECTATION-MAXIMIZATION

We now analyze the total error in the estimation of the new centroids. In order
to satisfy the condition of the robust GMM of definition 11.1, we want the error
on the centroids to be bounded by 𝛿𝜇 . For this, Claim D.3 help us choose the

parameters such that 𝜂(𝜖𝑡𝑜𝑚 + 𝜖𝑛𝑜𝑟𝑚 ) = 𝛿𝜇 . Since the error 𝜖2 for quantum
linear algebra appears as a logarithmic factor in the running time, we can choose
𝜖2 ≪ 𝜖4 without affecting the runtime.

Lemma 11.7 (Computing covariance matrices). We assume we have quantum


access to a GMM with parameters 𝛾 𝑡 . We also have computed estimates 𝜇𝑗 𝑡+1 of
all centroids such that ∥𝜇𝑗 𝑡+1 − 𝜇𝑡+1
𝑗 ∥ ≤ 𝛿𝜇 for precision parameter 𝛿𝜇 > 0. Then,
there exists a quantum algorithm that outputs estimates for the new covariance
𝑡+1 𝑡+1 √
matrices {Σ𝑗 }𝑘𝑗=1 such that ∥Σ𝑡+1 𝑗 − Σ𝑗 ∥ ≤ 𝛿𝜇 𝜂 with high probability, in
𝐹
time,
̃ 𝑘𝑑2 𝜂𝜅(𝑉 )(𝜇(𝑉 ′ ) + 𝜂2.5 𝑘3.5 𝜅(Σ)𝜇(Σ))
𝑇Σ ∶= 𝑂( )
𝛿𝜇3

Proof. It is simple to check, that the update rule of the covariance matrix during
the maximization step can be reduced to (Murphy, 2012) Exercise 11.2.

𝑛 𝑛
∑𝑖=1 𝑟𝑖𝑗 (𝑣𝑖 − 𝜇𝑡+1 𝑡+1 𝑇
𝑗 )(𝑣𝑖 − 𝜇𝑗 ) ∑ 𝑟𝑖𝑗 𝑣𝑖 𝑣𝑖𝑇
Σ𝑡+1
𝑗 ← 𝑛 = 𝑖=1 − 𝜇𝑡+1 𝑡+1 𝑇
𝑗 (𝜇𝑗 )
∑𝑖=1 𝑟𝑖𝑗 𝑛𝜃𝑗
(11.13)
= Σ′𝑗 − 𝜇𝑡+1 𝑡+1 𝑇
𝑗 (𝜇𝑗 ) (11.14)

First, let’s note that we can use the previously obtained estimates of the cen-

troids to compute the outer product 𝜇𝑡+1 𝑡+1 𝑇
𝑗 (𝜇𝑗 ) with error 𝛿𝜇 ‖𝜇‖ ≤ 𝛿𝜇 𝜂. The
error in the estimates of the centroids is 𝜇 = 𝜇+𝑒 where 𝑒 is a vector of norm 𝛿𝜇 .
√ √
Therefore ∥𝜇𝜇𝑇 − 𝜇 𝜇𝑇 ∥ < 2 𝜂𝛿𝜇 + 𝛿𝜇2 ≤ 3 𝜂𝛿𝜇 . Because of this, we allow an

error of 𝜂𝛿𝜇 also for the term Σ′𝑗 . Now we discuss the procedure for estimating
Σ′𝑗 . We estimate |vec[Σ′𝑗 ]⟩ and ∥vec[Σ′𝑗 ]∥. To do it, we start by using quantum
access to the norms and part 1 of lemma 11.3. With them, for a cluster 𝑗, we
start by creating the state |𝑗⟩ √1𝑛 ∑𝑖 |𝑖⟩|𝑟𝑖𝑗 ⟩, Then, we use quantum access to
the norms to store them into another register |𝑗⟩ √1𝑛 ∑𝑖 |𝑖⟩|𝑟𝑖𝑗 ⟩| ‖𝑣𝑖 ‖⟩. Using an
ancilla qubit we can obtain perform a rotation, controlled on the responsibilities
and the norm, and obtain the following state:

1 𝑛 𝑟𝑖𝑗 ‖𝑣𝑖 ‖
|𝑗⟩ √ ∑ |𝑖⟩|𝑟𝑖𝑗 ⟩| ‖𝑣𝑖 ‖⟩ ( √ |0⟩ + 𝛾|1⟩)
𝑛 𝑖 𝜂
We undo the unitary that created the responsibilities in the second register
and the query on the norm on the third register, and we perform amplitude
amplification on the ancilla qubit being zero. The resulting state can be obtained
11.3. QUANTUM EXPECTATION-MAXIMIZATION FOR GMM 199


𝑛𝜂 2 ‖𝑣 ‖2 . Successively, we query the
in time 𝑂(𝑅𝑅1 ,𝜖1 ‖𝑉 ‖ ), where ‖𝑉𝑅 ‖ is √∑𝑖 𝑟𝑖𝑗
𝑅
𝑖
QRAM for the vectors 𝑣𝑖 and we obtain the following state:

1
∑ 𝑟 ‖𝑣 ‖ |𝑖⟩|𝑣𝑖 ⟩ (11.15)
𝑉𝑅 𝑖 𝑖𝑗 𝑖

On which we can apply quantum linear algebra subroutine, multiplying the first
register with the matrix 𝑉 𝑇 . This will lead us to the desired state |Σ′𝑗 ⟩, along
with an estimate of its norm.
𝜅(𝑉 )(𝜇(𝑉 )+𝑇
𝑅2 ,𝜖1 𝑚𝑢𝑙𝑡)) log(1/𝜖 )
As the runtime for the norm estimation 𝜖𝑛𝑜𝑟𝑚𝑠 does not
depend on 𝑑, we consider it smaller than the runtime for performing tomography.
Thus, the runtime for this operation is:

𝑑2 log 𝑑
𝑂( 𝜅(𝑉 )(𝜇(𝑉 ) + 𝑇𝑅2 ,𝜖1 )) log(1/𝜖𝑚𝑢𝑙𝑡 )).
𝜖2𝑡𝑜𝑚


Let’s analyze the error of this procedure. We want a matrix Σ′𝑗 that is 𝜂𝛿𝜇 -

close to the correct one: ∥Σ′𝑗 − Σ′𝑗 ∥ = ∥vec[Σ′𝑗 ] − vec[Σ′𝑗 ]∥ < 𝜂𝛿𝜇 . Again, the
𝐹 2
error due to matrix multiplication can be taken as small as necessary, since is
inside a logarithm. From Claim D.3, we just need to fix the error of tomography

and norm estimation such that 𝜂(𝜖𝑢𝑛𝑖𝑡 + 𝜖𝑛𝑜𝑟𝑚𝑠 ) < 𝜂𝛿𝜇 where we have used 𝜂
as an upper bound on ∥Σ𝑗 ∥ . For the unit vectors, we require ∥|Σ′𝑗 ⟩ − |Σ′𝑗 ⟩∥ ≤
𝐹 √
̂ ̂ ′ ⟩ − |Σ′ ⟩∥ < 𝜖 + 𝜖 ≤ 𝜂𝜖 𝛿 𝜂
∥|Σ′ ⟩ − |Σ
𝑗
′ ⟩∥ + ∥|Σ
𝑗 𝑗 𝑗 4 1 ≤ 𝜇 , where |Σ′ ⟩ is the error
𝑢𝑛𝑖𝑡 2 𝑗
̂
due to tomography and |Σ ′ ⟩ is the error due to the responsibilities in lemma
𝑗 √
𝛿𝜇 / 𝜂
11.3. For this inequality to be true, we choose 𝜖4 = 𝜖1 < 4 .

The same argument applies to estimating the norm ∥Σ′𝑗 ∥ with relative error :
̂ ̂ √
| ∥Σ′𝑗 ∥ − ∥Σ′𝑗 ∥| ≤ |∥Σ′𝑗 ∥ − ∥Σ′𝑗 ∥| + |∥Σ′𝑗 ∥ − ∥Σ′𝑗 ∥ | < 𝜖 + 𝜖1 ≤ 𝛿𝜇 /2 𝜂 (where here 𝜖
is the error of the amplitude estimation step used in theorem √
5.11 and 𝜖1 is the
𝛿 / 𝜂
error in calling lemma 11.3. Again, we choose 𝜖 = 𝜖1 ≤ 𝜇 4 .
Since the tomography is more costly than the amplitude estimation step, we
can disregard the runtime for the norm estimation step. As this operation is
repeated 𝑘 times for the 𝑘 different covariance matrices, the total runtime of the
whole algorithm is given by 𝑂( ̃ 𝑘𝑑2 𝜂𝜅(𝑉 )(𝜇(𝑉 )+𝜂
3
2 3.5
𝑘 𝜅(Σ)𝜇(Σ))
). Let us also recall
𝛿𝜇
that for each of new computed covariance matrices, we use lemma @ref(lemma:
absolute-error-logdet) to compute an estimate for their log-determinant and this
time can be absorbed in the time 𝑇Σ .

[Link] Quantum estimation of log-likelihood


Now we are going to show how it is possible to get an estimate of the log-
likelihood using a quantum procedure. A good estimate of the log-likelihood is
200 CHAPTER 11. QUANTUM EXPECTATION-MAXIMIZATION

crucial, as it is used as stopping criteria for the quantum algorithm. Recall that
the log-likelihood is defined as:
𝑛 𝑛
ℓ(𝛾; 𝑉 ) = ∑ log ∑ 𝜃𝑗 𝜙(𝑣𝑖 ; 𝜇𝑗 , Σ𝑗 ) = ∑ log 𝑝(𝑣𝑖 ; 𝛾)
𝑖=1 𝑗∈[𝑘] 𝑖=1

Classically, we stop to iterate the EM algorithm when |ℓ(𝛾 𝑡 ; 𝑉 )−ℓ(𝛾 𝑡+1 ; 𝑉 )| < 𝑛𝜖,
or equivalently, we can set a tolerance on the average increase of the log of the
probability: |𝔼[log 𝑝(𝑣𝑖 ; 𝛾 𝑡 )] − 𝔼[log 𝑝(𝑣𝑖 ; 𝛾 𝑡+1 )]| < 𝜖. In the quantum algorithm
𝑛
it is more practical to estimate 𝔼[𝑝(𝑣𝑖 ; 𝛾 𝑡 )] = 𝑛1 ∑𝑖=1 𝑝(𝑣𝑖 ; 𝛾). From this we can
estimate an upper bound on the log-likelihood (with the help of the the Jensen
inequality) as:
𝑛 𝑛
𝑛 log 𝔼[𝑝(𝑣𝑖 )] = ∑ log 𝔼[𝑝(𝑣𝑖 )] ≥ ∑ log 𝑝(𝑣𝑖 ) = ℓ(𝛾; 𝑉 )
𝑖=1 𝑖=1
.
Lemma 11.8 (Quantum estimation of likelihood). We assume we have quantum
access to a GMM with parameters 𝛾 𝑡 . For 𝜖𝜏 > 0, there exists a quantum
algorithm that estimates 𝔼[𝑝(𝑣𝑖 ; 𝛾 𝑡 )] with absolute error 𝜖𝜏 in time

̃ (𝑘1.5 𝜂1.5 𝜅(Σ)𝜇(Σ) )


𝑇ℓ = 𝑂
𝜖2𝜏

Proof. We obtain the likelihood from the ability to compute the value of a
Gaussian distribution and quantum arithmetic. Using the mapping of lemma
11.1 with precision 𝜖1 , we can compute 𝜙(𝑣𝑖 |𝜇𝑗 , Σ𝑗 ) for all the Gaussians. We
𝑘−1
can build the state |𝑖⟩ ⨂𝑗=0 |𝑗⟩|𝑝(𝑣𝑖 |𝑗; 𝛾𝑗 )⟩. Then, by knowing 𝜃, and by using
quantum arithmetic we can compute in a register the probability of a point
belonging to the mixture of Gaussian’s: 𝑝(𝑣𝑖 ; 𝛾) = ∑𝑗∈[𝑘] 𝜃𝑗 𝑝(𝑣𝑖 |𝑗; 𝛾) (note that
this operation require undoing the previous steps). for simplicity, we now drop
the notation for the model 𝛾 and write 𝑝(𝑣𝑖 ) instead of 𝑝(𝑣𝑖 ; 𝛾). Doing the
previous calculations in a quantum computer, leads to the creation of the state
|𝑖⟩|𝑝(𝑣𝑖 )⟩. To get an estimate of 𝔼[𝑝(𝑣𝑖 )], we perform the mapping |𝑖⟩|𝑝(𝑣𝑖 )⟩ ↦
|𝑖⟩ (√𝑝(𝑣𝑖 )||0⟩ + √1 − 𝑝(𝑣𝑖 )|1⟩) and estimate 𝑝(|0⟩) ≃ 𝔼[𝑝(𝑣𝑖 )] with amplitude
estimation on the ancilla qubit being zero.
To get a 𝜖𝜏 -estimate of 𝑝(0) we need to decide the precision parameter we
use for estimating 𝑝(𝑣𝑖 |𝑗; 𝛾) and the precision required by amplitude estima-
̂ the
tion. Let 𝑝(0) be the 𝜖1 -error introduced by using lemma 11.1 and 𝑝(0)
error introduced by amplitude estimation. Using triangle inequality we set
̂ < ∥𝑝(0)
∥𝑝(0) − 𝑝(0)∥ ̂ − 𝑝(0)∥ + ∥𝑝(0) − 𝑝(0)∥ < 𝜖 .
𝜏

̂ < 𝜖 , we should set 𝜖 such that |𝑝(0)−𝑝(0)| < 𝜖 /4, and we


To have |𝑝(0)− 𝑝(0)| 𝜏 1 𝜏
set the error in amplitude estimation and in the estimation of the probabilities
11.3. QUANTUM EXPECTATION-MAXIMIZATION FOR GMM 201

to be 𝜖𝜏 /2. The runtime of this procedure is therefore:

̃ (𝑘 ⋅ 𝑇 1 ̃ (𝑘1.5 𝜂1.5 ⋅ 𝜅(Σ)𝜇(Σ) )


𝑂 𝐺,𝜖𝜏 ⋅ )=𝑂
𝜖𝜏 √𝑝(0) 𝜖2𝜏

[Link] Analysis of Quantum Expectation-Maximizaiton


Theorem 11.3 (Quantum Expectation-Maximization for Gaussian mixture
models). We assume we have quantum access to a GMM with parameters 𝛾 𝑡 .
For parameters 𝛿𝜃 , 𝛿𝜇 , 𝜖𝜏 > 0, the running time of one iteration of the Quantum
Expectation-Maximization (QEM) algorithm is

𝑂(𝑇𝜃 + 𝑇𝜇 + 𝑇Σ + 𝑇ℓ ),

for
̃ (𝑘3.5 𝜂1.5 𝜅2 (Σ)𝜇(Σ)
• 𝑇𝜃 = 𝑂 )
𝛿2 𝜃

̃ ( 𝑘𝑑𝜂𝜅(𝑉 )(𝜇(𝑉 )+𝑘3.5


• 𝑇𝜇 = 𝑂 𝜂1.5 𝜅2 (Σ)𝜇(Σ))
)
𝛿3 𝜇
2
̃ 𝑘𝑑 𝜂𝜅2 (𝑉 )(𝜇(𝑉 ′ )+𝜂2 𝑘3.5 𝜅2 (Σ)𝜇(Σ))
• 𝑇Σ = 𝑂( 3
𝛿𝜇 )
̃ (𝑘1.5 𝜂1.5 𝜅2 (Σ)𝜇(Σ)
• 𝑇ℓ = 𝑂 )
𝜖2 𝜏

For the range of parameters of interest, the running time is dominated by 𝑇Σ .


The proof follows directly from the previous lemmas. Note that the cost of the
whole algorithm is given by repeating the Estimation and the Maximization
steps several times, until the threshold on the log-likelihood is reached. Note
also that the expression of the runtime can be simplified from the observation
that the cost of performing tomography on the covariance matrices Σ𝑗 dominates
the cost.
202 CHAPTER 11. QUANTUM EXPECTATION-MAXIMIZATION
Chapter 12

QML on real datasets

In this chapter, we discuss how to have a better idea on the performance of


our algorithms on real dataset. This is very important, as the runtime of the
algorithms we discuss here depends on the characteristics of the dataset, which
might scale badly by increasing the size of the dataset. It’s our duty to see if
this is the case. In the worst case, this might be due for each single dataset that
we analyze. It this section we discuss two main approaches. We could either
start by proving some properties of a dataset that we know is well-suitable to
be analyzed by a certain algorithm. The idea is the following: if (quantum or
classical) data analysis works well for a certain dataset, it might be because the
algorithms that exploits certain structure in the dataset possess. We can exploit
this intuition to prove some properties of the dataset that are expected to be
analyzed by that algorithm. For example, this is the case for section 12.1.1,
where we exploit the “cloud” structure of dataset that we often cluster using
k-means (or q-means).
Secondly, we might just verify experimentally that the scaling of these parame-
ters is favourable (they are small, they don’t grow by increasing the number of
features and the number of samples, and so on..), and that the error introduced
by the quantum procedures won’t perturb the quality of the data anaysis (in
fact we will see that some noise might help regularizing the model, improving
the classification accuracy).

12.1 Theoretical considerations


12.1.1 Modelling well-clusterable datasets
In this section, we define a model for the dataset in order to provide a tight
analysis on the running time of our clustering algorithm. Thanks to this as-
sumption, we can provide tighter bounds for its running time. Recall that for
q-means we consider that the dataset 𝑉 is normalized so that for all 𝑖 ∈ [𝑁 ], we

203
204 CHAPTER 12. QML ON REAL DATASETS

2
have 1 ≤ ‖𝑣𝑖 ‖, and we define the parameter 𝜂 = max𝑖 ‖𝑣𝑖 ‖ . We will also assume
that the number 𝑘 is the “right” number of clusters, meaning that we assume
each cluster has at least some Ω(𝑁 /𝑘) data points.
We now introduce the notion of a well-clusterable dataset. The definition aims to
capture some properties that we can expect from datasets that can be clustered
efficiently using a k-means algorithm. This notion of a well-clusterable dataset
shares some similarity with the assumptions made in (Drineas et al., 2002), but
there are also some differences specific to the clustering problem.
Definition 12.1 (Well-clusterable dataset). A data matrix 𝑉 ∈ ℝ𝑛×𝑑 with rows
𝑣𝑖 ∈ ℝ𝑑 , 𝑖 ∈ [𝑛] is said to be well-clusterable if there exist constants 𝜉, 𝛽 > 0,
𝜆 ∈ [0, 1], 𝜂 ≤ 1, and cluster centroids 𝑐𝑖 for 𝑖 ∈ [𝑘] such that:
• (separation of cluster centroids): $d(c_i, c_j) �� �i,j �[k] $
• (proximity to cluster centroid): At least 𝜆𝑛 points 𝑣𝑖 in the dataset satisfy
𝑑(𝑣𝑖 , 𝑐𝑙(𝑣𝑖 ) ) ≤ 𝛽 where 𝑐𝑙(𝑣𝑖 ) is the centroid nearest to 𝑣𝑖 .
• (Intra-cluster smaller than inter-cluster square distances): The following
inequality is satisfied
√ √
4 𝜂√𝜆𝛽 2 + (1 − 𝜆)4𝜂 ≤ 𝜉 2 − 2 𝜂𝛽.
Intuitively, the assumptions guarantee that most of the data can be easily as-
signed to one of 𝑘 clusters, since these points are close to the centroids, and the
centroids are sufficiently far from each other. The exact inequality comes from
the error analysis, but in spirit it says that 𝜉 2 should be bigger than a quantity
that depends on 𝛽 and the maximum norm 𝜂.
We now show that a well-clusterable dataset has a good rank-𝑘 approximation
where 𝑘 is the number of clusters. This result will later be used for giving tight
upper bounds on the running time of the quantum algorithm for well-clusterable
datasets. As we said, one can easily construct such datasets by picking 𝑘 well
separated vectors to serve as cluster centers and then each point in the cluster
is sampled from a Gaussian distribution with small variance centered on the
centroid of the cluster.
Lemma 12.1. Let 𝑉𝑘 be the optimal 𝑘-rank approximation for a well-clusterable
2 2
data matrix 𝑉 , then ‖𝑉 − 𝑉𝑘 ‖𝐹 ≤ (𝜆𝛽 2 + (1 − 𝜆)4𝜂) ‖𝑉 ‖𝐹 .

Proof. Let 𝑊 ∈ ℝ𝑛×𝑑 be the matrix with row 𝑤𝑖 = 𝑐𝑙(𝑣𝑖 ) , where 𝑐𝑙(𝑣𝑖 ) is the
centroid closest to 𝑣𝑖 . The matrix 𝑊 has rank at most 𝑘 as it has exactly
𝑘 distinct rows. As 𝑉𝑘 is the optimal rank-𝑘 approximation to 𝑉 , we have
2 2 2
‖𝑉 − 𝑉𝑘 ‖𝐹 ≤ ‖𝑉 − 𝑊 ‖𝐹 . It therefore suffices to upper bound ‖𝑉 − 𝑊 ‖𝐹 . Using
the fact that 𝑉 is well-clusterable, we have
2
‖𝑉 − 𝑊 ‖𝐹 = ∑(𝑣𝑖𝑗 − 𝑤𝑖𝑗 )2 = ∑ 𝑑(𝑣𝑖 , 𝑐𝑙(𝑣𝑖 ) )2 ≤ 𝜆𝑛𝛽 2 + (1 − 𝜆)𝑛4𝜂,
𝑖𝑗 𝑖

where we used Definition 12.1 to say that for a 𝜆𝑛 fraction of the points
𝑑(𝑣𝑖 , 𝑐𝑙(𝑣𝑖 ) )2 ≤ 𝛽 2 and for the remaining points 𝑑(𝑣𝑖 , 𝑐𝑙(𝑣𝑖 ) )2 ≤ 4𝜂. Also, as
12.1. THEORETICAL CONSIDERATIONS 205

2
all 𝑣𝑖 have norm at least 1 we have 𝑛 ≤ ‖𝑉 ‖𝐹 , implying that ‖𝑉 − 𝑉𝑘 ‖ ≤
2 2
‖𝑉 − 𝑊 ‖𝐹 ≤ (𝜆𝛽 2 + (1 − 𝜆)4𝜂) ‖𝑉 ‖𝐹 .

The running time of the quantum linear algebra routines for the data matrix
𝑉 in Theorem 5.11 depend on the parameters 𝜇(𝑉 ) and 𝜅(𝑉 ). We establish
bounds on both of these parameters using the fact that 𝑉 is well-clusterable
‖𝑉 ‖𝐹
Lemma 12.2. Let 𝑉 be a well-clusterable data matrix, then 𝜇(𝑉 ) ∶= ‖𝑉 ‖ =

𝑂( 𝑘).

Proof. We show that when we rescale 𝑉 so that ‖𝑉 ‖ = 1, then we have ‖𝑉 ‖𝐹 =



𝑂( 𝑘) for the rescaled matrix. From the triangle inequality we have that
2
‖𝑉 ‖𝐹 ≤ ‖𝑉 − 𝑉𝑘 ‖𝐹 + ‖𝑉𝑘 ‖𝐹 . Using the fact that ‖𝑉𝑘 ‖𝐹 = ∑𝑖∈[𝑘] 𝜎𝑖2 ≤ 𝑘 and
lemma 12.1, we have,

‖𝑉 ‖𝐹 ≤ √(𝜆𝛽 2 + (1 − 𝜆)4𝜂) ‖𝑉 ‖𝐹 + 𝑘

𝑘

Rearranging, we have that ‖𝑉 ‖𝐹 ≤ 1−√(𝜆𝛽2 +(1−𝜆)4𝜂) = 𝑂( 𝑘).

We next show that if we use a condition threshold 𝜅𝜏 (𝑉 ) instead of the true


condition number 𝜅(𝑉 ), that is we consider the matrix 𝑉≥𝜏 = ∑𝜎 ≥𝜏 𝜎𝑖 𝑢𝑖 𝑣𝑖𝑇 by
𝑖
discarding the smaller singular values 𝜎𝑖 < 𝜏 , the resulting matrix remains close
to the original one, i.e. we have that ∥𝑉 − 𝑉≥𝜏 ∥𝐹 is bounded.
Lemma 12.3. Let 𝑉 be a matrix with a rank-𝑘 approximation given by
‖𝑉 − 𝑉𝑘 ‖𝐹 ≤ 𝜖′ ‖𝑉 ‖𝐹 and let 𝜏 = √𝜖𝜏𝑘 ‖𝑉 ‖𝐹 , then ∥𝑉 − 𝑉≥𝜏 ∥𝐹 ≤ (𝜖′ + 𝜖𝜏 ) ‖𝑉 ‖𝐹 .

Proof. Let 𝑙 be the smallest index such that 𝜎𝑙 ≥ 𝜏 , so that we have


∥𝑉 − 𝑉≥𝜏 ∥𝐹 = ‖𝑉 − 𝑉𝑙 ‖𝐹 . We split the argument into two cases depending on
whether 𝑙 is smaller or greater than 𝑘.
• If 𝑙 ≥ 𝑘 then ‖𝑉 − 𝑉𝑙 ‖𝐹 ≤ ‖𝑉 − 𝑉𝑘 ‖𝐹 ≤ 𝜖′ ‖𝑉 ‖𝐹 .
• If 𝑙 < 𝑘 then, ‖𝑉 − 𝑉𝑙 ‖𝐹 ≤ ‖𝑉 − 𝑉𝑘 ‖𝐹 + ‖𝑉𝑘 − 𝑉𝑙 ‖𝐹 ≤ 𝜖′ ‖𝑉 ‖𝐹 +
√∑𝑘𝑖=𝑙+1 𝜎𝑖2 . As each 𝜎𝑖 < 𝜏 and the sum is over at most 𝑘 indices, we
have the upper bound (𝜖′ + 𝜖𝜏 ) ‖𝑉 ‖𝐹 .

The reason the notion of well-clusterable dataset was defined, was to be able to
provide some strong guarantees for the clustering of most points in the dataset.
Note that the clustering problem in the worst case is NP-hard and we only expect
to have good results for datasets that have some good property. Intuitively, we
should only expect 𝑘-means to work when the dataset can actually be clusterd
in 𝑘 clusters. We show next that for a well-clusterable dataset 𝑉 , there is a
constant 𝛿 that can be computed in terms of the parameters in Definition 12.1
such that the 𝛿-𝑘-means clusters correctly most of the data points.
206 CHAPTER 12. QML ON REAL DATASETS

Lemma 12.4. Let 𝑉 be a well-clusterable data matrix. Then, for at least 𝜆𝑛


data points 𝑣𝑖 , we have

min (𝑑2 (𝑣𝑖 , 𝑐𝑗 ) − 𝑑2 (𝑣𝑖 , 𝑐ℓ(𝑖) )) ≥ 𝜉 2 − 2 𝜂𝛽
𝑗≠ℓ(𝑖)


which implies that a 𝛿-𝑘-means algorithm with any 𝛿 < 𝜉 2 − 2 𝜂𝛽 will cluster
these points correctly.

Proof. By Definition 12.1, we know that for a well-clusterable dataset 𝑉 , we


have that 𝑑(𝑣𝑖 , 𝑐𝑙(𝑣𝑖 ) ) ≤ 𝛽 for at least 𝜆𝑛 data points and where 𝑐𝑙(𝑣𝑖 ) is the
centroid closest to 𝑣𝑖 . Further, the distance between each pair of the 𝑘 centroids

satisfies the bounds 2 𝜂 ≥ 𝑑(𝑐𝑖 , 𝑐𝑗 ) ≥ 𝜉. By the triangle inequality, we have
𝑑(𝑣𝑖 , 𝑐𝑗 ) ≥ 𝑑(𝑐𝑗 , 𝑐ℓ(𝑖) ) − 𝑑(𝑣𝑖 , 𝑐ℓ(𝑖) ). Squaring both sides of the inequality and
rearranging,

𝑑2 (𝑣𝑖 , 𝑐𝑗 ) − 𝑑2 (𝑣𝑖 , 𝑐ℓ(𝑖) ) ≥ 𝑑2 (𝑐𝑗 , 𝑐ℓ(𝑖) ) − 2𝑑(𝑐𝑗 , 𝑐ℓ(𝑖) )𝑑(𝑣𝑖 , 𝑐ℓ(𝑖) ))

Substituting the bounds on the distances implied by the well-clusterability as-



sumption, we obtain 𝑑2 (𝑣𝑖 , 𝑐𝑗 ) − 𝑑2 (𝑣𝑖 , 𝑐ℓ(𝑖) ) ≥ 𝜉 2 − 2 𝜂𝛽. This implies that

as long as we pick 𝛿 < 𝜉 2 − 2 𝜂𝛽, these points are assigned to the correct
cluster, since all other centroids are more than 𝛿 further away than the correct
centroid.

12.2 Experiments
The experiments bypassed the construction of the quantum circuit and directly
performed the noisy linear algebraic operations carried out by the quantum
algorithm. The simulations are carried out on datasets that are considered the
standard benchmark of new machine learning algorithms, inserting the same
kind of errors that we expect to have in the real execution on the quantum
hardware. In the experiments, we aim to study the robustness of data analysis to
the noise introduced by the quantum algorithm, study the scaling of the runtime
algorithm on real data and thus understand which datasets can be analyzed
efficiently by quantum computers. The experiments are aimed at finding if the
impact of noise in the quantum algorithms decreases significantly the accuracy
in the data analysis, and if the impact of the error parameters in the runtime
does prevent quantum speedups for large datasets.

12.2.1 Datasets
[Link] MNIST
MNIST (LeCun, 1998) is probably the most used dataset in image classification.
It is a collection of 60000 training plus 10000 testing images of 28 × 28 = 784
pixels. Each image is a black and white handwritten digit between 0 and 9 and
it is paired with a label that specifies the digit. Since the images are black and
12.2. EXPERIMENTS 207

white, they are represented as arrays of 784 values that encode the lightness of
each pixel. The dataset, excluding the labels, can be encoded in a matrix of
size 70000 × 784.

[Link] Fashon-MNIST
Fashion MNIST (Xiao et al., 2017) is a recent dataset for benchmarking in im-
age classification. Like the MNIST, it is a collection of 70000 images composed
of 28 × 28 = 784 pixels. Each image represents a black and white fashion item
among {T-shirt/top, Trouser, Pullover, Dress, Coat, Sandal, Shirt, Sneaker,
Bag, Ankle boot}. Each image is paired with a label that specifies the item
represented in the image. Since the images are black and white, they are rep-
resented as arrays of 784 values that encode the lightness of each pixel. The
dataset, excluding the labels, can be encoded in a matrix of size 70000 × 784.

[Link] CIFAR-10
CIFAR-10 (Krizhevsky et al., 2009) is another widely used dataset for bench-
marking image classification. It contains 60000 colored images of 32 × 32 pixel,
with the values for each of the 3 RGB colors. Each image represents an object
among {airplane, automobile, bird, cat, deer, dog, frog, horse, ship, truck} and
is paired with the appropriate label. When the images are reshaped to unroll the
three channels in a single vector, the resulting size of the dataset is 60000×3072.

[Link] Research Paper


Research Paper (Harun-Ur-Rashid, 2018) is a dataset for text classification,
available on Kaggle. It contains 2507 titles of papers together with the labels of
the venue where they have been published. The labels are {WWW, INFOCOM,
ISCAS, SIGGRAPH, VLDB}. We pre-process the titles to compute a contin-
gency table of 𝑝𝑎𝑝𝑒𝑟𝑠 × 𝑤𝑜𝑟𝑑𝑠: the value of the 𝑖𝑡ℎ − 𝑗𝑡ℎ cell is the number of
times that the 𝑗𝑡ℎ word is contained in the 𝑖𝑡ℎ title. We remove the English
stop-words, the words that appear in only one document, and the words that
appear in more than half the documents. The result is a contingency table of
size 2507 × 2010.

[Link] VoxForge Dataset

12.2.2 q-means
[Link] MNIST pre-processing
From this raw data we first performed some dimensionality reduction processing,
then we normalized the data such that the minimum norm is one. Note that, if
we were doing 𝑞-means with a quantum computer, we could use efficient quan-
tum procedures equivalent to Linear Discriminant Analysis, such as (Kerenidis
and Luongo, 2020), or other quantum dimensionality reduction algorithms like
(Lloyd et al., 2014) (Cong and Duan, 2015).
208 CHAPTER 12. QML ON REAL DATASETS

As preprocessing of the data, we first performed a Principal Component Analysis


(PCA), retaining data projected in a subspace of dimension 40. After normal-
ization, the value of 𝜂 was 8.25 (maximum norm of 2.87), and the condition
number was 4.53. Figure ?? represents the evolution of the accuracy during
the 𝑘-means and 𝛿-𝑘-means for 4 different values of 𝛿. In this numerical ex-
periment, we can see that for values of the parameter 𝜂/𝛿 of order 20, both
𝑘-means and 𝛿-𝑘-means reached a similar, yet low accuracy in the classification
in the same number of steps. It is important to notice that the MNIST dataset,
without other preprocessing than dimensionality reduction, is known not to be
well-clusterable under the 𝑘-means algorithm.

Table 12.1: A sample of results collected from the same experiments as in


Figure ??. Different metrics are presented for the train set and the test set.
ACC: accuracy. HOM: homogeneity. COMP: completeness. V-M: v-measure.
AMI: adjusted mutual information. ARI: adjusted rand index. RMSEC: Root
Mean Square Error of Centroids.

V-
Algo DatasetACC HOM COMPM AMI ARI RMSEC
k-means Train 0.582 0.488 0.523 0.505 0.389 0.488 0
Test 0.592 0.500 0.535 0.517 0.404 0.499 -
𝛿-𝑘-means, 𝛿 = 0.2 Train 0.580 0.488 0.523 0.505 0.387 0.488 0.009
Test 0.591 0.499 0.535 0.516 0.404 0.498 -
𝛿-𝑘-means, 𝛿 = 0.3 Train 0.577 0.481 0.517 0.498 0.379 0.481 0.019
Test 0.589 0.494 0.530 0.511 0.396 0.493 -
𝛿-𝑘-means, 𝛿 = 0.4 Train 0.573 0.464 0.526 0.493 0.377 0.464 0.020
Test 0.585 0.492 0.527 0.509 0.394 0.491 -
𝛿-𝑘-means, 𝛿 = 0.5 Train 0.573 0.459 0.522 0.488 0.371 0.459 0.034
Test 0.584 0.487 0.523 0.505 0.389 0.487 -

12.2.3 QSFA
12.2.4 QEM
In this section, we discuss again Quantum Expectation-Maximization algorithm,
and we present the results of some experiments on real datasets to estimate its
runtime. We will also show some bound on the value of the parameters that
governs it, like 𝜅(Σ), 𝜅(𝑉 ), 𝜇(Σ), 𝜇(𝑉 ), 𝛿𝜃 , and 𝛿𝜇 , and we give heuristic for
dealing with the condition number. As we already have done, we can put a
threshold on the condition number of the matrices Σ𝑗 , by discarding singular
values which are smaller than a certain threshold. This might decrease the
runtime of the algorithm without impacting its performances. This is indeed
done often in classical machine learning models, since discarding the eigenvalues
smaller than a certain threshold might even improve upon the metric under
consideration (i.e. often the accuracy), by acting as a form of regularization
12.2. EXPERIMENTS 209

(look at Section 6.5 of (Murphy, 2012)). This in practice is equivalent to limiting


the eccentricity of the Gaussians. We can do similar considerations for putting
a threshold on the condition number of the dataset 𝜅(𝑉 ). Recall that the value
of the condition number of the matrix 𝑉 is approximately 1/ min({𝜃1 , ⋯ , 𝜃𝑘 } ∪
{𝑑𝑠𝑡 (𝒩(𝜇𝑖 , Σ𝑖 ), 𝒩(𝜇𝑗 , Σ𝑗 ))|𝑖 ≠ 𝑗 ∈ [𝑘]}), where 𝑑𝑠𝑡 is the statistical distance
between two Gaussian distributions (Kalai et al., 2012). We have some choice
in picking the definition for 𝜇: in previous experiments it has been found that
choosing the maximum ℓ1 norm of the rows of 𝑉 lead to values of 𝜇(𝑉 ) around
10 for the MNIST dataset, as we saw on the experiments of QSFA, PCA and
q-means. Because of the way 𝜇 is defined, its value will not increase significantly
as we add vectors to the training set. In case the matrix 𝑉 can be clustered
with high-enough accuracy by distance-based algorithms like k-means, √ it has
been showed that the Frobenius norm of the matrix is proportional to 𝑘, that
is, the rank of the matrix depends on the number of different classes contained
in the data. Given that EM is just a more powerful extension of k-means, we
can rely on similar observations too. Usually, the number of features 𝑑 is much
more than the number of components in the mixture, i.e. 𝑑 ≫ 𝑘, so we expect
𝑑2 to dominate the 𝑘3.5 term in the cost needed to estimate the mixing weights,
thus making 𝑇Σ the leading term in the runtime. We expect this cost to be be
mitigated by using ℓ∞ form of tomography but we defer further experiment for
future research.

As we said, the quantum running time saves the factor that depends on the
number of samples and introduces a number of other parameters. Using our
experimental results we can see that when the number of samples is large enough
one can expect the quantum running time to be faster than the classical one.

To estimate the runtime of the algorithm, we need to gauge the value of the
parameters 𝛿𝜇 and 𝛿𝜃 , such that they are small enough so that the likelihood
is perturbed less than 𝜖𝜏 , but big enough to have a fast algorithm. We have
reasons to believe that on well-clusterable data, the value of these parameters
will be large enough, such as not to impact dramatically the runtime. A quan-
tum version of k-means algorithm has already been simulated on the MNIST
dataset under similar assumptions (Kerenidis et al., 2019a). The experiment
concluded that, for datasets that are expected to be clustered nicely by this
kind of clustering algorithms, the value of the parameters 𝛿𝜇 did not decrease
by increasing the number of samples nor the number of features. There, the
value of 𝛿𝜇 (which in their case was called just 𝛿) has been kept between 0.2 and
0.5, while retaining a classification accuracy comparable to the classical k-means
algorithm. We expect similar behaviour in the GMM case, namely that for large
datasets the impact on the runtime of the errors (𝛿𝜇 , 𝛿𝜃 ) does not cancel out the
exponential gain in the dependence on the number of samples, and we discuss
more about this in the next paragraph. The value of 𝜖𝜏 is usually (for instance
in scikit-learn (Pedregosa et al., 2011) ) chosen to be 10−3 . We will see that
the value of 𝜂 has always been 10 on average, with a maximum of 105 in the
experiments.
210 CHAPTER 12. QML ON REAL DATASETS

12.2.5 QPCA
These experiment are extracted from (Bellante and Zanero, 2022). This section
shows several experiments on the MNIST, Fashion MNIST, CIFAR-10 and Re-
search Papers datasets. In all the experiments, the datasets have been shifted
to row mean 0 and normalized so that 𝜎𝑚𝑎𝑥 ≤ 1.

[Link].1 Explained variance distribution First, we explore the distri-


bution of the factor score ratios in the MNIST, Fashion MNIST, CIFAR-10 and
Research Papers datasets, showing that a small number of singular values is
indeed able to explain a great amount of the variance of the data. For all the
four datasets, we compute the singular values and their factor score ratios and
we plot them. The results of Figure 12.1 show a rapid decrease of the factor
score ratios in all the datasets, confirming the expectations.

(a) MNIST. (b) Fashion MNIST.

(c) CIFAR 10. (d) Research Papers.

Figure 12.1: Explained variance distribution in datasets for machine learning.


In order: MNIST, Fashion MNIST, CIFAR 10, Research Papers.

[Link] Image classification with quantum PCA


To provide the reader with a clearer view of the algorithms in Sections 7.2,
9.1.1 and their use in machine learning, we provide experiments on quantum
PCA for image classification. We perform PCA on the three datasets for image
classification (MNIST, Fashion MNIST and CIFAR 10) and classify them with
a K-Nearest Neighbors. First, we simulate the extraction of the singular values
and the percentage of variance explained by the principal components (top 𝑘
factor score ratios’ sum) using the procedure from Theorem 7.6. Then, we study
the error of the model extraction, using Lemma 9.1, by introducing errors on
the Frobenius norm of the representation to see how this affects the accuracy.
12.2. EXPERIMENTS 211

[Link].1 Estimating the number of principal components We simu-


late Theorem 7.6 to decide the number of principal components needed to retain
0.85 of the total variance. For each dataset, we classically compute the singu-
lar values with an exact classical algorithm and simulate the quantum state
1 𝑟
𝑟 2 ∑𝑖 𝜎𝑖 |𝜎𝑖 ⟩ to emulate the measurement process. After initializing the
√∑𝑗 𝜎𝑗

random object with the correct probabilities, we measure it 𝛾12 = 1000 times
and estimate the factor score ratios with a frequentist approach (i.e., dividing
the number of measurements of each outcome by the total number of measure-
ments). Measuring 1000 times guarantees us an error of at most 𝛾 = 0.03 on
each factor score ratios. To determine the number of principal components to
retain, we sum the factor score ratios until the percentage of explained variance
becomes greater than 0.85. We report the results of this experiments in Table
12.2. We obtain good results for all the datasets, estimating no more than 3
extra principal components than needed.

Table 12.2: Results of the estimation of the number of principal components to


retain. The parameter 𝑘 is the number of components needed to retain at least
𝑝 = 0.85 of the total variance. 𝑝 is computed w.r.t. the estimated 𝑘.

Parameter MNIST F-MNIST CIFAR-10


Estimated 𝑘 62 45 55
Exact 𝑘 59 43 55
Estimated 𝑝 0.8510 0.8510 0.8510
Exact 𝑝 0.8580 0.8543 0.8514
𝛾 0.0316 0.0316 0.0316

The number of principal components can be further refined using Theorem 7.7.
When we increase the percentage of variance to retain, the factor score ratios be-
come smaller and the estimation worsens. When the factor score ratios become
too small to perform efficient sampling, it is possible to establish the threshold
𝜃 for the smaller singular value to retain using Theorems 7.7 and ??. If one is
interested in refining the exact number 𝑘 of principal components, rather than
𝜃, it is possible to obtain it using a combination of the algorithms from The-
orems 7.7, ?? and the quantum counting algorithm (Brassard et al., 2002) in
time that scales with the square root of 𝑘. Once that the number of principal
components has been set, the next step is to use Theorem 7.8 to extract the top
singular vectors. To do so, we can retrieve the threshold 𝜃 from the previous
step by checking the gap between the last singular value to retain and the first
to exclude.

[Link].1.1 Studying the error in the data representation We con-


tinue the experiment by checking how much error in the data representation a
classifier can tolerate. We compute the exact PCA’s representation for the three
212 CHAPTER 12. QML ON REAL DATASETS

datasets and a perform 10-fold Cross-validation error using a k-Nearest Neigh-


bors with 7 neighbors. For each dataset we introduce error in the representation
and check how the accuracy decreases. To simulate the error, we perturb the
exact representation by adding truncated Gaussian error (zero mean and unit
variance, truncated on the interval [ √−𝜉
𝑛𝑚
𝜉
, √𝑛𝑚 ]) to each component of the ma-
trix. The graph in Figure @ref{fig:error-matrix} shows the distribution of the
effective error on 2000 approximation of a matrix 𝐴, such that ‖𝐴 − 𝐴‖ ≤ 0.1.
The distribution is still Gaussian, centered almost at the half of the bound.

Figure 12.2: Introducing some error in the Frobenius norm of a matrix 𝐴. The
error was introduced such that ‖𝐴−𝐴‖ ≤ 0.01. The figure shows the distribution
of the error over 2000 measurements.

The results show a reasonable tolerance of the errors, we report them in two
set of figures. Figure 12.3 shows the drop of accuracy in classification as the
error bound increases. Figure 12.4 shows the trend of the accuracy against the
effective error of the approximation.

(a) MNIST. (b) Fashion MNIST. (c) CIFAR 10.

Figure 12.3: Classification accuracy of 7-Nearest Neighbor on three machine


learning datasets after PCA’s dimensionality reduction. The drop in accuracy
is plotted with respect to the bound on the Frobenius norm of the difference
between the exact data representation and its approximation. In order: MNIST,
Fashion MNIST, CIFAR 10.

[Link].2 Analyzing the run-time parameters As discussed in Section


̃ (( 12 + √𝑘𝑧 2 ) 𝜇(𝐴) ), where 𝐴 ∈
9.1.1, the model extraction’s run-time is 𝑂 𝛾 𝜃 𝑝𝛿 𝜖
12.2. EXPERIMENTS 213

(a) MNIST. (b) Fashion MNIST. (c) CIFAR 10.

Figure 12.4: Classification accuracy of 7-Nearest Neighbor on three machine


learning datasets after PCA’s dimensionality reduction. The drop in accuracy
is plotted with respect to the effective Frobenius norm of the difference between
the exact data representation and its approximation. In order: MNIST, Fashion
MNIST, CIFAR 10.

ℝ𝑛×𝑚 is PCA’s input matrix, 𝜇(𝐴) is a parameter bounded by min(‖𝐴‖𝐹 , ‖𝐴‖∞ ),


𝑘 is the number of principal components retained, 𝜃 is the value of the last sin-
gular value retained, 𝛾 is the precision to estimate the factor score ratios, 𝜖
bounds the absolute error on the estimation of the singular values, 𝛿 bounds
the ℓ2 norm of the distance between the singular vectors and their approxima-
tion, and 𝑧 is either 𝑛, 𝑚 depending on whether we extract the left singular
vectors, to compute the classical representation, or the right ones, to retrieve
the model and allow for further quantum/classical computation. This run-time
can be further lowered using Theorem ?? if we are not interested in the fac-
tor score ratios. The aim of this paragraph is to show how to determine the
run-time parameters for a specific dataset. We enrich the parameters of Table
12.2 with the ones in Table 12.3 and we discuss how to compute them. From
the previous paragraphs it should be clear how to determine 𝑘, 𝜃, 𝛾 and 𝑝, and

it is worth noticing again that 1/ 𝑝 ≃ 1. To bound 𝜇(𝐴) we have computed
‖𝐴‖𝐹 and ‖𝐴‖∞ . To compute the parameter 𝜖 we have considered two situa-
tions: we need to allow for a correct ordering of the singular values; we need
to allow for a correct thresholding. We refer to the first as the ordering 𝜖 and
to the second as the thresholding 𝜖. To compute the first one it is sufficient to
check the smallest gap between the first 𝑘 singular values of the dataset. For
the last one, one should check the difference between the last retained singu-
lar value and the first that is excluded. It follows that the thresholding 𝜖 is
always smaller than the ordering 𝜖. For sake of completeness, we have run ex-
periments to check how the Coupon Collector’s problem changes as 𝜖 increases.
Recall that in the proof of Theorem @ref(thm:top-k_sv_extraction) we use that
𝑘 𝑘
1
𝑘 𝜎2
∑𝑖 𝜎𝜎𝑖 |𝑢𝑖 ⟩|𝑣𝑖 ⟩|𝜎𝑖 ⟩ ∼ √1𝑘 ∑𝑖 |𝑢𝑖 ⟩|𝑣𝑖 ⟩|𝜎𝑖 ⟩ to say that the number of mea-
𝑖 𝑖
√∑𝑖
𝜎2
𝑖
surements needed to observe all the singular values is 𝑂(𝑘 log(𝑘)), and this is
true only if 𝜖 is small enough to let the singular values distribute uniformly. We
observe that the thresholding 𝜖 always satisfy the Coupon Collector’s scaling,
and we have plotted the results of our tests in Figure 12.5.
214 CHAPTER 12. QML ON REAL DATASETS

(a) MNIST. (b) Fashion MNIST. (c) CIFAR 10.

Figure 12.5: Number of measurements needed to obtain all the 𝑘 singular values
𝑘
from the quantum state 1
𝑟 2
∑𝑖 𝜎𝜎𝑖 |𝜎𝑖 ⟩, where ‖𝜎𝑖 − 𝜎𝑖 ‖ ≤ 𝜖, as 𝜖 increases.
√∑𝑖 𝜎𝑖 𝑖

The benchmark line is 𝑘 log2.4 (𝑘). In order: MNIST, Fashion MNIST, CIFAR
10.


Furthermore, we have computed 𝛿 by using the fact that ‖𝐴 − 𝐴‖ ≤ 𝑘(𝜖 + 𝛿)
(Lemma 9.1). By inverting the equation and considering the thresholding 𝜖 we
have computed an estimate for 𝛿. In particular, we have fixed ‖𝐴 − 𝐴‖ to the
biggest value in our experiments so that the accuracy doesn’t drop more than
1%.

Since we have considered the values of the effective errors instead of the bounds,
our estimates are pessimistic.

Table 12.3: Run-time parameters.

Parameter MNIST F-MNIST CIFAR-10


Ordr. 𝜖 0.0003 0.0003 0.0002
Thrs. 𝜖 0.0030 0.0009 0.0006
‖𝐴‖𝐹 3.2032 1.8551 1.8540
‖𝐴‖∞ 0.3730 0.3207 0.8710
𝜃 0.1564 0.0776 0.0746
𝛿 0.1124 0.0106 0.0340

These results show that Theorem 7.6, 7.7 and ?? can already provide speed-ups
on datasets as small as the MNIST. Even though their speed-up is not expo-
nential, they still run sub-linearly on the number of elements of the matrix
even though all the elements are taken into account during the computation,
offering a polynomial speed-up with respect to their traditional classical coun-
terparts. On the other hand, Theorem 7.8 requires bigger datasets. On big
low-rank datasets that maintain a good distribution of singular values, these
algorithms are expected to show their full speed-up. As a final remark, note
that the parameters have similar orders of magnitude.
12.2. EXPERIMENTS 215

[Link].3 Projecting the quantum data in the new quantum


feature space To end with, we have tested the value of 𝛼 (Defini-
tion 9.1, Lemma 9.3) for the MNIST dataset, fixing 𝜀 = 0 and try-
ing 𝑝 ∈ {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9}. We have observed that
𝛼 = 0.96 ± 0.02, confirming that the run-time of Corollary 9.1 can be assumed
constant for the majority of the data points of a PCA-representable dataset.
216 CHAPTER 12. QML ON REAL DATASETS
Chapter 13

Quantum algorithms for


graph problems

In this chapter we are going to discuss quantum algorithms for graph theoretical
problems. Initial focus of this chapter revolves around the work of (Dürr et al.,
2006), which investigated the query complexity of problems like MINIMUM
SPANNING TREE, CONNECTIVITY, STRONG CONNECTIVITY, and SIN-
GLE SOURCE SHORTEST PATH. Classically, these problems can be solved
efficiently i.e. in polynomial number of queries to the graph. In this chapter, we
will see how to decrease the query complexity of the quantum algorithm further,
by applying in a shrewd way amplitude amplification and related algorithms.
More specifically, in the work of (Dürr et al., 2006), they used three different
versions of the Grover’s algorithm. In particular, we state a slightly improved
version here, with a quadratic improvement also in the runtime dependence on
the probability of failure.
Theorem 13.1 (Grover’s search algorithm, version of (Buhrman et al., 1999)).
Let 𝑁 = 2𝑛 for 𝑛 > 0. Given quantum oracle access 𝑂𝑥 ∶ |𝑖⟩ ↦ |𝑖⟩|𝑥𝑖 ⟩ to a
vector 𝑥 ∈ [𝑘]𝑁 (for a fixed 𝑘) and access to an oracle 𝑂𝑓 |𝑥⟩ = (−1)𝑓(𝑥) |𝑥⟩
for a function 𝑓 ∶ [𝑘] ↦ {0, 1}, If 𝑚 is the number of elements of the vector 𝑥
that are evaluated to 1 (called marked elements), there is a quantum algorithm
that succeed with probability greater than 1 − 𝛿 and finds an index of a marked
element using 𝑂𝑥 only 𝑂(√𝑁 /𝑚 log(1/𝛿)) times.
In fact, note that the “standard” version of bounding the probability of failure of
a quantum or classical randomized algorithm consist in repeating the algorithm
a certain number of time, and use the “powering lemma” C.1. This will result
in an increase of the runtime that is logarithmic in 𝛿. This version of Grover’s
algorithm achieves a quadratic speedup in the failure probability.
Further discussions of some of the quantum algorithms for graphs can also be

217
218 CHAPTER 13. QUANTUM ALGORITHMS FOR GRAPH PROBLEMS

found in (Dürr et al., 2006) and also in (Dörn, 2008).


As usual, we assume two different access to the graph: the “adjacecny matrix
model” and the “adjacency array” (or list) model.
• In the adjacecy matrix model we assume to have query access to the entries
of an adjacecny matrix of a graph, as in definition 3.12.
• In the adjacency list model we assume to have query access to the an
oracle that tells us the number of adjacent nodes, and an oracle that gives
us the index of the adjacent nodes, as in 3.13. Note that sometimes this
goes under the name “adjacency array”, as in the quantum case we don’t
have to go through the whole list of adjacent nodes, but we can index
them as an array.

13.1 Connectivity
The problem of connectivity, as stated below can be seen as a special case of
them minimum spanning tree problem, where all edges of 𝐺 carries equal weight.
Definition 13.1 (GRAPH CONNECTIVITY problem). Given an undirected
graph 𝐺 = (𝑉 , 𝐸), decide if 𝐺 is connected.
The following algorithm has first been proposed in (Dürr et al., 2006), and
reelaborated in (Dörn, 2008).

Figure 13.1: Algorithm for graph connectivity of undirected graph in the ad-
jacecy model

Theorem 13.2 (Quantum algorithm for graph conectivity (adjacency matrix


model)). Assume that 𝑈𝐴 is a unitary that gives you query access to the adja-
cency matrix 𝑀 of an undirected graph 𝐺 = (𝑉 , 𝐸). Then, deciding if a graph
̃ 3/2 ). In particular,
is connected has an expected number of queries to 𝑈𝐴 of 𝑂(𝑛
13.1. CONNECTIVITY 219

if the graph is connected, algorithm in figure 13.1 returns a spanning tree for 𝐺
with probability greater than 2/3.

Proof. The whole algorithm tries to build a spanning tree for the graph. If
we succeed, then the graph is connected. The algorithm start by creating a
data structure that holds 𝑛 different connected components, one for each vertex.
Then, we construct a spanning tree by finding an edge that connects any two of
the connected components.
Initialize the algorithm with an empty edge set 𝐴 for the spanning tree 𝑇 =
(𝑉 , 𝐴). We use theorem 13.1 on the operator 𝑈𝐴 and the oracle 𝑈𝑓𝑇 . As usual,
𝑈𝐴 is defined as 𝑈𝐴 ∶ |𝑖, 𝑗, 𝑐⟩ ↦ |𝑖, 𝑗, 𝑐 ⊕ 𝐴𝑖𝑗 ⟩. We ecapsulate into the oracle
𝑈𝑓𝑇 the data structure that stores the connected components, so we can have a
unitary implementing the function 𝑓𝑇 ∶ 𝐸 ↦ {0, 1}:

1 if 𝑐(𝑇 ∪ 𝑒) < 𝑐(𝑇 )


𝑓𝑇 (𝑒) {
0 otherwise

Where 𝑐(𝐺) is the number of connected components of the graph 𝐺. It is basi-


cally a unitary that checks if a given edge has endpoints of 2 different connected
component. Note that 𝑈𝑓𝑇 needs to compare a given edge with a whole list of
edges that are currently in the list of connected components. Note that in order
to work, this oracle should compare a given edge with the list of edges that are
part of the spanning tree 𝑇 . The spanning tree can grow up to size 𝑂(𝑛), so
the depth of the oracle is at worst 𝑂(𝑛) (up to a polylogarithmic factors).
The runtime analysis is concluded by noting that we need to repeat the search
procedure of theorem 13.1 up to 𝑛 times (because when we obtain 𝑛 nodes in the
MST we stop the algorithm). Suppose that the graph is connected. The main
loop of the algorithm is repeated exactly 𝑛 − 1 times, and each search withint
the loop can be done in 𝑂(√𝑛2 /𝑘), where 𝑘 is the number of valid solutions to
the search problem. These solutions correspond to the edges 𝑒 of 𝐺 that are
linking any two connected components. It is simple to observe that at the first
iteration we have at least 𝑘 = 𝑛 − 1 solutions (i.e. any edge is a good solution),
and the number of solutions decreases at each iteration. The number of queries
to the oracle is:

𝑛 𝑛
𝑛2 1
∑√ = 𝑛∑ √
𝑘=2
(𝑘 − 1) 𝑘=2 𝑘 −1
With Cauchy-Schwartz we can see that:

1/2 1/2
𝑛 𝑛−1 √ 𝑛−1 √
1 1 1 1
∑√ = ∑ √ ≤ 𝑛 − 1 (∑ ) = 𝑛 − 1 (𝛾 + log(𝑛 − 1) + )
𝑘=2 𝑘 − 1 𝑘=1 𝑘 𝑘=1
𝑘 2(𝑛 − 1)
220 CHAPTER 13. QUANTUM ALGORITHMS FOR GRAPH PROBLEMS

where 𝛾 is the Bonferroni constant, and we just interpret the second norm as
a truncated Harmonic series approximated by Taylor expansion. Thus, overall
we get
𝑛 1/2
𝑛2 √ 1
∑√ ≤ 𝑛 𝑛 − 1 (𝛾 + log(𝑛 − 1) + ) = 𝑂(𝑛1.5 log(𝑛))
𝑘=2
𝑘 − 1 2(𝑛 − 1)

If the graph is not connected, at some point we will not be able to find any new
edges, and the procedure of theorem 13.1 will fail (we can repeat this procedure
a certain number of times to be sure that there are indeed no more valid edges,
leveraging the powering lemma, i.e. lemma C.1).
We need to set the failure probability of each run of theorem 13.1. It is simple
to check that if we want the probability of failure to be bounded by 2/3 we need
1
to se the probability of failure for a single run of the algorithm as 𝛿 ≥ 3𝑛 . This
is relatively simple to obatin from the union bound (see exercise C.2).

Exercise 13.1 (Improve bound of number of queries). Can you show that
𝑛 𝑛 2
∑𝑘=2 √ (𝑘−1) = 𝑂(𝑛3/2 ), i.e. without the polylogarithmic factor log(𝑛). Or can
you prove that it is not possible to remove it? Hint.
For the array model, we report the theorem of (Dürr et al., 2006).
Theorem 13.3 (Quantum algorithm for graph conectivity (array model)). As-
sume that 𝑈𝐴 is a unitary that gives you query access to the array model of
an undirected graph 𝐺 = (𝑉 , 𝐸). Then, deciding if a graph is connected has an
expected number of queries to 𝑈𝑀 of 𝑂(𝑛). In particular, algorithm 13.1 returns
a spanning tree for 𝐺 if 𝐺 is connected, otherwise runs forever.

13.2 Summary of results


A summary of the query complexities is stated below.

Problem Adj. Matrix Array


3/2

Minimum Spanning 𝑂(𝑛 ) 𝑂( 𝑛𝑚)
Tree
Connectivity 𝑂(𝑛3/2 ) 𝑂(𝑛)

Strong Connectivity 𝑂(𝑛3/2 ) Ω( 𝑛𝑚),
𝑂(√𝑛𝑚𝑙𝑜𝑔(𝑛))

Single Sourced Shortest Ω(𝑛3/2 ), 𝑂(𝑛3/2 𝑙𝑜𝑔2 (𝑛)) Ω( √𝑛𝑚𝑙𝑜𝑔2 (𝑛)),
Path 𝑂( 𝑛𝑚)
Chapter 14

Lower bounds on query


complexity of quantum
algorithms

Contributors: Trong Duong


We have discussed about several important quantum algorithms. A large portion
of them is query-based, i.e. the input is given as a quantum black box 𝑂 ∶
|x⟩|𝑦⟩ ↦ |x⟩|𝑦 ⊕ 𝑓(𝑥)⟩. In that setting, query complexity plays a key role in
determining the advantage and limitation of an algorithm. This chapter will
discuss how to obtain a lower bound on query complexity, i.e. the minimal
number of queries an algorithm needs to make for a desired output (probably
up to some error bound). In particular, we are going to look into Polynomial
method and Adversary method, along with some simple applications.

14.1 Polynomial method


The goal of a quantum query algorithm usually involves determining entirely
or partially a function 𝑓 ∶ {0, 1}𝑛 → {0, 1} given via an oracle 𝑂𝑓 ∶ 𝑂𝑓 |x, 𝑎⟩ =
|x, 𝑎 ⊕ 𝑦⟩, where 𝑦 ∈ {0, 1} is the evaluation of 𝑓 at the input x ∈ {0, 1}𝑛 .
The oracle basically swaps |x, 0⟩ and |x, 1⟩ when 𝑦 = 1, and does nothing when
𝑦 = 0. For a general superposition of |𝜓⟩ = ∑𝑖∈[𝑁] 𝛼𝑖,0 (x)|𝑖, 0⟩ + 𝛼𝑖,1 (x)|𝑖, 1⟩,
where 𝛼𝑖,𝑎 (x) is an 𝑁 -variate polynomial in terms of 𝑥𝑖 ’s, the degree of 𝛼𝑖,𝑎 (x)
is increased by 𝑂𝑓 by at most 1.

𝑂𝑓 |𝜓⟩ = ∑ [(1 − 𝑦𝑖 )𝛼𝑖,0 (x) + 𝑦𝑖 𝛼x,1 (x)] |𝑖, 0⟩+[𝑦𝑖 𝛼𝑖,0 (x) + (1 − 𝑦𝑖 )𝛼𝑖,1 (x)] |𝑖, 1⟩
𝑖∈[𝑁]

221
222CHAPTER 14. LOWER BOUNDS ON QUERY COMPLEXITY OF QUANTUM ALGORITHMS

A quantum algorithm typically calls an interleaved chain of unitary operators


and the oracles. Those unitary operators do not depend of x, so 𝑂𝑓 ’s are the
only contributors to any increase in the degree of 𝛼𝑖,𝑎 (x), with an increase of at
most 1 for each call to the oracle.
The following lemmas come as consequences of the preceeding observation and
the fact that 𝑦𝑖2 = 𝑦𝑖 .
Lemma 14.1 (Degree of amplitude polynomials). Suppose a quantum query
algorithm makes 𝑇 call to 𝑂𝑓 . Then the amplitude of every basis state is a
multilinear polynomial in terms of 𝑥𝑖 ’s of degree at most 𝑇 .
In a decision problem, one define acceptance rate 𝑝(𝑥) as the probability of ob-
taining the ancilla in state 1 at the final measurement. In particular. 𝑝(𝑥) =
∑𝑖∈[𝑁] |𝛼𝑖,1 |2 . By the previous lemma, one can bound the degree of the accep-
tance rate as a polynomial.
Lemma 14.2 (Degree of acceptance polynomials). Acceptance rate of the algo-
rithm is a multilinear polynomial in 𝑥𝑖 ’s of degree at most 2𝑇 .
For an error-bounded algorithm that computes 𝑓 with error at most 𝜀, the
acceptance polynomial 𝑝(x) is called an approximating polynomial of 𝑓 if

∀x ∈ {0, 1}𝑛 , |𝑝(x) − 𝑓(x)| ≤ 𝜀


As a result, if we can show a approximating polynomial of 𝑓 has degree at least
𝑑, then every quantum algorithm that computes 𝑓 with error at most 𝜀 must
make at least 𝑑/2 queries to the oracle. In practice we typically choose 𝜀 = 1/3.
To shed light on the use of polynomial method, we shall look into one of its partic-
ular applications when 𝑓(x) is symmetric, i.e. 𝑓 only depends on the Hamming
weight |x|, which the number of bits 1 in x. The value of such 𝑓 is invari-
ant under permutations of (𝑥1 , 𝑥2 , … , 𝑥𝑛 ). Suppose we have an approximating
polynomial 𝑝 of 𝑓, consider the average 𝑝̄ of 𝑝 over all input permutations 𝜋(x).

1
𝑝(x)
̄ = ∑ 𝑝(𝑥𝜋(1) , 𝑥𝜋(2) , … , 𝑥𝜋(𝑛) )
𝑁 ! 𝜋∈𝑆
𝑛

A nice property of this symmetrized polynomial is that it is a uni-variate poly-


nomial in |𝑥| that approximates 𝑓. Moreover, the uni-variate polynomial has a
degree 𝑑 ≤ deg(𝑝). To see why this is the case, we observe that
𝑝(x)
̄ = 𝑐0 + 𝑐1 𝑄1 + 𝑐2 𝑄2 + ⋯ + 𝑐𝑑 𝑄𝑑 , where 𝑄1 = 𝑥1 + 𝑥2 + ⋯ + 𝑥𝑛 , 𝑄2 =
𝑥1 𝑥2 + ⋯ + 𝑥1 𝑥𝑛 + 𝑥2 𝑥1 + ⋯ + 𝑥𝑛 𝑥𝑛−1 , etc. Consider

𝑄𝑗 = ∑ ∏ 𝑥𝑖
𝑆⊂[𝑁] 𝑖∈𝑆
|𝑆|=𝑗
14.1. POLYNOMIAL METHOD 223

If 𝑗 > |𝑥|, each product within the representation of 𝑄𝑗 is equal to zero, so


𝑄𝑗 = 0. If 𝑗 ≤ |𝑥|, there are exactly (|𝑥|
𝑗 ) nonzero products within 𝑄𝑗 . Those
nonzero products equal 1, so 𝑄𝑗 = (|𝑥|
𝑗 ). Therefore the symmetrized polynomial
is
|𝑥| |𝑥|
𝑝(x)
̄ = 𝑐0 + 𝑐1 ( ) + ⋯ + 𝑐𝑑 ( ) = 𝑟(|𝑥|)
1 𝑑
Also, since 𝑝 approximates 𝑓 that only depends on |x|, the sum over all in-
put permutations 𝑝̄ also approximates 𝑓. From all of the above, one has
deg(𝑝)̄ ≤ deg(𝑝) ≤ 2𝑇 . The best lower bound for 𝑇 can be obtained if we
find the smallest-degree 𝑝.̄ Sometimes it is not easy to access to the degree of
the symmetrized polynomial without having the explicit form of the initial ap-
proximating polynomial. Rather, we can relax the lower bound for 𝑇 relying on
the smallest-degree 𝑝. The following powerful theorem characterizes the degree
of the smallest-degree approximating polynomial.
Theorem 14.1 (Paturi theorem (Paturi, 1992)). Suppose 𝑓 is a non-constant
symmetric boolean function on {0,1}^n and 𝑝 is some approximating polynomial
of 𝑓.
Let 𝑓𝑘 ≡ 𝑓(x) when |x| = 𝑘, and Γ(𝑓) ≡ min{|2𝑘 − 𝑛 + 1| ∶ 𝑓𝑘 ≠ 𝑓𝑘+1 for
0 ≤ 𝑘 ≤ 𝑛 − 1}.
Then min deg(𝑝) ∈ Θ(√𝑛(𝑛 − Γ(𝑓)))
A simple example is the black-box PARITY function 𝑓(x) = 𝑥1 ⊕ 𝑥2 ⊕ ⋯ ⊕ 𝑥𝑛 .
Symmetrizing 𝑓 induces a zero-error polynomial 𝑟(𝑥) such that

1, 𝑘 is even
𝑟(𝑘) = {
0, 𝑘 is odd

Note that 𝑟(𝑥) changes direction at least 𝑛 times, so deg(𝑟) ≥ 𝑛. Note that, for
PARITY function, we have Γ(𝑓) = 1 and min deg(𝑝) ∈ Θ(𝑛). So 𝑟(𝑥) offers the
optimal lower bound. Thus the computation of 𝑓 requires at least 𝑛/2 queries.
According to this, Deutsch’s algorithm is the optimal algorithm even in no-error
case for 𝑛 = 2.
We will look at another example of OR function. One way to learn the function
from the corresponding oracle is using the Grover’s algorithm. If the input has
at least one 𝑥𝑖 = 1, the algorithm
√ can find some index 𝑗 such that 𝑥𝑗 = 1
with high probability using Θ( 𝑛) queries.√ As a result, one can compute the
OR function with bounded error with Θ( 𝑛) queries. √ This result agrees with
Paturi’s theorem with Γ(𝑓) = 𝑛−1 and min deg(𝑝) ∈ Θ( 𝑛). We can also prove
the minimum number of query calls required independently: Computing the
symmetric OR function with error ≤ 1/3 induces a uni-variate approximating
polynomial 𝑟 such that

𝑟(0) ∈ [0, 1/3] and 𝑟(𝑘) ∈ [2/3, 1] ∀𝑘 ∈ {1, 2, … , 𝑛}


224CHAPTER 14. LOWER BOUNDS ON QUERY COMPLEXITY OF QUANTUM ALGORITHMS

A bound for derivatives of a polynomial can be obtained as a function of its


degree according to the Markov brothers’ inequality, whose statement is given
as follows:
Theorem 14.2 (Markov brothers’ inequality (Markov, 1890)). Given a polyno-
mial 𝑝 of degree 𝑑 such that |𝑝(𝑥)| ≤ 𝐿 for 𝑥 ∈ [𝑎, 𝑏]. Then within the domain,
the first derivative of 𝑝 is bounded.
2𝑑2 𝐿
|𝑝′ (𝑥)| ≤
𝑏−𝑎
2
Applying the inequality to 𝑟, one have |𝑟′ (𝑥)| ≤ 2𝑑𝑛 . On the other hand, 𝑟′ (𝑥) ≥
1/3 at some
√ point between 0 and 1 by the Mean Value Theorem. Hence, 𝑇 ≥
𝑑/2 ≥ Ω( 𝑛) that gives the same lower bound for number of queries required
as the previous method.
However, a similar quadratic speedup is not feasible for an exact algorithm for
OR function. Assume such an algorithm exists, then it induces 𝑟(0) = 0 and
𝑟(𝑘) = 1, 𝑘 ∈ {1, 2, … , 𝑛}. The univariate polynomial 𝑟 then has to change
direction at least 𝑛 − 1 times to satisfy the constraint, making its degree at least
𝑛. Thus 𝑇 ≥ 𝑛/2, so the exact algorithm cannot achieve a quadratic speedup.

14.2 Quantum adversary method


Consider a decision problem given by a function 𝑓 ∶ {0, 1}𝑛 → {0, 1}. An input
w = (𝑤1 , … , 𝑤𝑛 ) ∈ {0, 1}𝑛 to the function can be accessed via a phase oracle
𝑂w ∶ |𝑖⟩ ↦ (−1)𝑤𝑖 |𝑖⟩. This type of oracle can be obtained from the general

oracle 𝑂w ∶ |𝑖⟩|𝑎⟩ ↦ |𝑖⟩|𝑎 ⊕ 𝑔(𝑖)⟩ by setting the ancilla state |𝑎⟩ = |−⟩ and
𝑔(𝑖) = 𝑤𝑖 . This trick is often referred as phase kickback.

|𝑖⟩ ( |0⟩−|1⟩

2
) ↦ |𝑖⟩ ( |𝑤𝑖 ⟩−|1⊕𝑤

2
𝑖⟩
)
|𝑖⟩ ( |0⟩−|1⟩

2
), 𝑤𝑖 = 0
= { |1⟩−|0⟩ (14.1)
|𝑖⟩ ( √2 ) , 𝑤𝑖 = 1
= (−1)𝑤𝑖 |𝑖⟩ ( |0⟩−|1⟩

2
)

Our goal is to determine 𝑓(x) with high probability, say at least 2/3, for a
given x using as few 𝑂x queries as possible. An error-bounded algorithm must
accept any x ∈ 𝑓 −1 (0) with probability ≤ 1/3 and accept any y ∈ 𝑓 −1 (1) with
probability ≥ 2/3.
For an arbitrary input w, a general algorithm can be formulated as a sequence
𝑈𝑇 𝑂w 𝑈𝑇 −1 𝑂w … 𝑂w 𝑈1 𝑂w 𝑈0
𝑡
Denote |𝜓w ⟩ be the state of the system after the 𝑡-th query to the oracle. Let
x ∈ 𝑋 ≡ {x|𝑓(x) = 0} = 𝑓 −1 (0) and y ∈ 𝑌 = 𝑓 −1 (1). Define the progress
14.2. QUANTUM ADVERSARY METHOD 225

function of x and y as the inner product of their corresponding quantum state


though the time period ⟨𝜓x𝑡 |𝜓y𝑡 ⟩. Define the progress measure over a subset 𝑅
of 𝑋 × 𝑌 as

𝑆(𝑡) = ∑ |⟨𝜓x𝑡 |𝜓y𝑡 ⟩|


(𝑥,𝑦)∈𝑅

Observe that ⟨𝜓x0 |𝜓y0 ⟩ = 1 as the initial states for all inputs are necessarily the
same. Also, non-oracle unitary operators 𝑈𝑖 do not alter ⟨𝜓x𝑡 |𝜓y𝑡 ⟩. One can
show |⟨𝜓x𝑇 |𝜓y𝑇 ⟩| ≤ 17
18 for an error-bounded algorithm. The proof is based on an
inequality between total variation distance and 𝐿2 norm distance.
Definition 14.1 (Total variation distance). The total variation between two
probability distributions 𝑃 and 𝑄 over a countable sample space Ω is given by

𝑑(𝑃 , 𝑄) ≡ sup𝐴⊆Ω |𝑃 (𝐴) − 𝑄(𝐴)|


1
= 2 ∑𝜔∈Ω |𝑃 (𝜔) − 𝑄(𝜔)|

In the context of quantum measurement, the decision problem involves a 2-


outcome measurement at time 𝑡 = 𝑇 . The probability of obtaining the outcome
𝑚 ∈ {0, 1} by a measurement of quantum states 𝜙 and 𝜏 are |𝜙𝑚 |2 and |𝜏𝑚 |2
respectively.

1 1
2 ∑𝑚 ||𝜙𝑚 |2 − |𝜏𝑚 |2 | = 2 ∑𝑚 ||𝜙𝑚 | − |𝜏𝑚 || ⋅ ||𝜙𝑚 | + |𝜏𝑚 ||
1
≤ 2∑𝑚 |𝜙𝑚 − 𝜏𝑚 | ⋅ ||𝜙𝑚 | + |𝜏𝑚 ||
1 2
≤ 2 √∑𝑚 |𝜙𝑚 − 𝜏𝑚 |2 √∑𝑚 (|𝜙𝑚 | + |𝜏𝑚 |)
≤ √∑𝑚 |𝜙𝑚 − 𝜏𝑚 |2 = ‖𝜙 − 𝜏 ‖2

The first and second inequality come as a result of triangle inequality and
Cauchy-Schwarz inequality respective. The third inequality comes from (𝑎 +
𝑏)2 ≤ 2(𝑎2 + 𝑏2 ) and the fact that ∑𝑚 |𝜙𝑚 |2 = ∑𝑚 |𝜏𝑚 |2 = 1. Consider
an error-bounded algorithm with tolerance of 1/3, i.e. |⟨1|𝜓x𝑇 ⟩|2 < 1/3 and
|⟨1|𝜓y𝑇 ⟩|2 ≥ 2/3. The total variation distance, and therefore ‖𝜓x𝑇 − 𝜓y𝑇 ‖2 , is at
least 1/3. Notice that the 𝐿2 -norm distance between two states can be written
in terms of their inner product

‖𝜓x𝑇 − 𝜓y𝑇 ‖22 = ⟨𝜓x𝑇 − 𝜓y𝑇 |𝜓x𝑇 − 𝜓y𝑇 ⟩ = 2 − 2ℜ⟨𝜓x𝑇 |𝜓y𝑇 ⟩. (14.2)

We can assume that ⟨𝜓𝑥𝑇 |𝜓𝑦𝑇 ⟩ is real, otherwise multiply |𝜓𝑦𝑇 ⟩ by some scalar of
norm 1 to make the inner product real. Then it follows that |⟨𝜓𝑥𝑇 |𝜓𝑦𝑇 ⟩| ≤ 17/18.
Intuitively, as the inner product is bounded above, the measurement statistics
can distinguish x ∈ 𝑓 −1 (0) and y ∈ 𝑓 −1 (1).
226CHAPTER 14. LOWER BOUNDS ON QUERY COMPLEXITY OF QUANTUM ALGORITHMS

However we should rather look at more than a fixed pair x, y to obtain a mean-
ingful result. This suggests us to look at some particular subset 𝑅 ⊆ 𝑋 × 𝑌 .
Observe that the progress measure before and after the algorithm are 𝑆(0) = |𝑅|
and 𝑆(𝑇 ) ≤ 17 18 |𝑅|. So, if one can come up with an upper bound Δ for
|𝑆(𝑡) − 𝑆(𝑡 − 1)|, then the number of queries needed is 𝑇 ≥ |𝑆(𝑇 ) − 𝑆(0)|/Δ =
|𝑅|/18Δ. We prove the following theorem based on that idea.
Theorem 14.3 (Basic Adversary Method (Ambainis, 2002)). Let 𝑓 be a de-
cision problem, 𝑋 ⊆ 𝑓 −1 (0), 𝑌 ⊆ 𝑓 −1 (1), and a binary relation 𝑅 ⊆ 𝑋 × 𝑌 .
Suppose that
1. ∀x ∈ 𝑋, there are at least 𝑚0 distinct y ∈ 𝑌 such that (x, y) ∈ 𝑅
2. ∀y ∈ 𝑌 , there are at least 𝑚1 distinct x ∈ 𝑋 such that (x, y) ∈ 𝑅
3. ∀x ∈ 𝑋 and ∀𝑖 ∈ {0, 1, … , 𝑛}, there are at most 𝑙0 distinct y ∈ 𝑌 such
that 𝑥𝑖 ≠ 𝑦𝑖 and (x, y) ∈ 𝑅
4. ∀y ∈ 𝑌 and ∀𝑖 ∈ {0, 1, … , 𝑛}, there are at most 𝑙1 distinct x ∈ 𝑋 such
that 𝑥𝑖 ≠ 𝑦𝑖 and (x, y) ∈ 𝑅.

Then the quantum query complexity of 𝑓 is Ω√ 𝑚𝑙0 𝑚


𝑙
1
0 1

The following proof is modified from a proof for the case 𝑙0 = 𝑙1 = 1 given in
the lecture note (O’Donnell, 2015).
For each (x, y) ∈ 𝑅, let 𝐽xy = {(𝑗1 , 𝑗2 , … , 𝑗𝑘 )|𝑥𝑗1 ≠ 𝑦𝑗1 , 𝑥𝑗2 ≠ 𝑦𝑗2 , … , 𝑥𝑗𝑘 ≠ 𝑦𝑗𝑘 }.
From the first assumption, |𝑅| ≥ 𝑚0 |𝑋|. The quantum states corresponding to
the initial inputs right before they pass through the 𝑡-th oracle can be repre-
sented by

|𝜓x𝑡−1 ⟩ = ∑ 𝑎𝑖 |𝑖⟩ ⊗ |𝜙𝑖 ⟩ (14.3)


𝑖

|𝜓y𝑡−1 ⟩ = ∑ 𝑏𝑖 |𝑖⟩ ⊗ |𝜒𝑖 ⟩ (14.4)


𝑖

⇒ ⟨𝜓x𝑡−1 |𝜓y𝑡−1 ⟩ = ∑ 𝑎∗𝑖 𝑏𝑖 ⟨𝜙𝑖 |𝜒𝑖 ⟩ (14.5)


𝑖

When the states pass through the 𝑡-th oracle, it flips the sign on each 𝑎𝑖 , 𝑏𝑖
whenever 𝑥𝑖 = 1 or 𝑦𝑖 = 1 respectively. The overall effect on the inner product
is flipping the sign of the coefficient corresponding to ⟨𝜙𝑖 |𝜒𝑖 ⟩ when 𝑥𝑖 ≠ 𝑦𝑖 . We
can express the inner product at time 𝑡 as follows

⟨𝜓x𝑡 |𝜓y𝑡 ⟩ = ∑ 𝑎∗𝑖 𝑏𝑖 ⟨𝜙𝑖 |𝜒𝑖 ⟩ − ∑ 𝑎∗𝑗 𝑏𝑗 ⟨𝜙𝑖 |𝜒𝑖 ⟩


𝑖∉𝐽xy 𝑗∈𝐽xy

The change in the inner product at two successive time is


14.2. QUANTUM ADVERSARY METHOD 227

⟨𝜓x𝑡 |𝜓y𝑡 ⟩ − ⟨𝜓x𝑡−1 |𝜓y𝑡−1 ⟩ = 2 ∑ 𝑎∗𝑖 𝑏𝑖 ⟨𝜙𝑖 |𝜒𝑖 ⟩


𝑗∈𝐽xy

|𝑆(𝑡) − 𝑆(𝑡 − 1)| = ∣∑(x,y)∈𝑅 |⟨𝜓x𝑡 |𝜓y𝑡 ⟩| − ∑(x,y)∈𝑅 |⟨𝜓x𝑡−1 |𝜓y𝑡−1 ⟩|∣
≤ ∑(x,y)∈𝑅 ∣⟨𝜓x𝑡 |𝜓y𝑡 ⟩ − ⟨𝜓x𝑡−1 |𝜓y𝑡−1 ⟩∣
= ∑(x,y)∈𝑅 ∣2 ∑𝑗∈𝐽 𝑎∗𝑗(x,y) 𝑏𝑗(x,y) ⟨𝜙𝑖 |𝜒𝑖 ⟩∣
xy

≤ ∑(x,y)∈𝑅 ∑𝑗∈𝐽 2 ∣𝑎∗𝑗(x,y) 𝑏𝑗(x,y) ∣


xy
2 2
≤ ∑(x,y)∈𝑅 ∑𝑗∈𝐽 √𝑚0 𝑙1
𝑚 𝑙 ∣𝑎𝑗(x,y) ∣ +
√𝑚1 𝑙0
𝑚 𝑙 ∣𝑏𝑗(x,y) ∣
xy 1 0 0 1

The last line comes from the simple inequality |𝑎|2 + |𝑏|2 ≥ 2|𝑎𝑏|. Consider the
first summand in the expression above.

2
∑(x,y)∈𝑅 ∑𝑗∈𝐽 √𝑚0 𝑙1
𝑚 𝑙 ∣𝑎𝑗(x,y) ∣ = √𝑚0 𝑙1
𝑚 𝑙 ∑x∈𝑋 ∑𝑖∈[𝑁] ∑ y∈𝑌 |𝑎𝑖(x,y) |
2
xy 1 0 1 0
𝑦𝑖 ≠𝑥𝑖
≤ √𝑚0 𝑙1
𝑚 𝑙 ∑x∈𝑋 𝑙0
1 0

≤ √𝑚0 𝑙1 |𝑅|
𝑚1 𝑙0 𝑚0 𝑙0 = √ 𝑚𝑙0 𝑙𝑚1 |𝑅|
0 1

The second line comes from the third assumption and the fact that
∑𝑖∈[𝑁] |𝑎𝑖(x,y) |2 = 1 for every (x, y) ∈ 𝑅. We can also derive the same
bound for the second summand. The upper bound for |𝑆(𝑡) − 𝑆(𝑡 − 1)| is
Δ = 2√ 𝑚𝑙0 𝑙𝑚1 |𝑅|. Hence 𝑇 ≥ |𝑅|
18Δ ∈ Ω (√ 𝑚𝑙0 𝑚
𝑙 ), which is the conclusion of
1
0 1 0 1

the theorem.
We revisit two examples of PARITY and OR functions and show the adversary
method and the polynomial method give the same lower bound. Recall from
the√Polynomial method that one needs at least 𝑛/2 queries for PARITY and
Θ( 𝑛) for OR. Let’s see if the same result can be obtained with the Adversary
method. The PARITY function 𝑓 maps binary strings with odd Hamming
weight to 1 and even Hamming weight to 0. Let 𝑋 = 𝑓 −1 (0), 𝑌 = 𝑓 −1 (1), and
𝑅 = {(x, y)|𝑑(x, y) = 1}. It not difficult to see that 𝑚0 = 𝑚1 = 𝑛, 𝑙0 = 𝑙1 = 1
so that the function requires Ω(𝑛) queries. The OR function 𝑔 maps only the
all-zero sequence to 0 and other inputs to 1. Let 𝑋 = {00 … 00} = 𝑔−1 (0) and
−1
𝑌 = {y|y contains exactly one bit 1} ⊂ √ 𝑔 (1). Then, 𝑚0 = 𝑛, 𝑚1 = 1, 𝑙0 =
𝑙1 = 1, so we have a lower bound of Ω( 𝑛).
228CHAPTER 14. LOWER BOUNDS ON QUERY COMPLEXITY OF QUANTUM ALGORITHMS
Part III

Everything else

229
Chapter 15

Selected works on quantum


algorithms

This is a work in progress, as the vast majority of works are not present here,
yet. Obviously, feel free to write at “scinawa [at] luongo . pro” for suggestions,
or open an issue on github. Please understand that the aim of this section if to
select relevant quantum algorithms. Special interested is devoted to works that
can be applied for data analysis or used as other subroutines for other QML
algorithms.

2022
• An efficient quantum algorithm for lattice problems achieving subexpo-
nential approximation factor #algo #crypto
• Improved quantum algorithms for linear and nonlinear differential equa-
tions #algo
• New Quantum Algorithms for Computing Quantum Entropies and Dis-
tances #algo
• Quantum machine learning with subspace states #algo
• A quantum algorithm for solving eigenproblem of the Laplacian matrix of
a fully connected graph #algo
• Quantum State Preparation with Optimal Circuit Depth: Implementa-
tions and Applications #algo, #theory
• Quantum Meets Fine-Grained Complexity: Sublinear Time Quantum Al-
gorithms for String Problems #algo
• Two-level Quantum Walkers on Directed Graphs II: An Application to
qRAM #algo
• Memory Compression with Quantum Random-Access Gates
• Mean estimation when you have the source code; or, quantum Monte Carlo
methods

231
232 CHAPTER 15. SELECTED WORKS ON QUANTUM ALGORITHMS

• Exact and efficient Lanczos method on a quantum computer


• On establishing learning separations between classical and quantum ma-
chine learning with classical data
• Matching Triangles and Triangle Collection: Hardness based on a Weak
Quantum Conjecture
• Partition Function Estimation: Quantum and Quantum-Inspired Algo-
rithms
• A Faster Quantum Algorithm for Semidefinite Programming via Robust
IPM Framework
• Quantum Subroutine Composition #algo
• Complexity-Theoretic Limitations on Quantum Algorithms for Topologi-
cal Data Analysis #theory
• Quantum Algorithms for Sampling Log-Concave Distributions and Esti-
mating Normalizing Constants #algo
• Quantum divide and conquer

2021
• Information-theoretic bounds on quantum advantage in machine learning
#theory
• Noisy intermediate-scale quantum (NISQ) algorithms #review,
#variational A massive review on the state-of-the-art quantum al-
gorithms for NISQ architectures. It highlights the limitations, but also
the wins of the variational paradigm.
• Parallel Quantum Algorithm for Hamiltonian Simulation #algo
• Quantum Perceptron Revisited: Computational-Statistical Tradeoffs
#algo
• Lower bounds for monotone arithmetic circuits via communication com-
plexity #theory
• Fast algorithm for quantum polar decomposition, pretty-goodmeasurements,
and the Procrustes problem #algo
• Quantum Algorithms based on the Block-Encoding Framework for Matrix
Functions by Contour Integrals #algo
• Classical and Quantum Algorithms for Orthogonal Neural Networks #algo
• Quantum Semi Non-negative Matrix Factorization #algo
• Quantum Algorithms based on the Block-Encoding Framework for Matrix
Functions by Contour Integrals
• Quantum Alphatron #algo
• Quantum SubGaussian Mean Estimator #algo
• A randomized quantum algorithm for statistical phase estimation #algo
• Near-Optimal Quantum Algorithms for String Problems #algo
• Quantum Algorithms and Lower Bounds for Linear Regression with Norm
Constraints #algo
• Dequantizing the Quantum Singular Value Transformation: Hardness and
Applications to Quantum Chemistry and the Quantum PCP Conjecture
#algo
233

• A randomized quantum algorithm for statistical phase estimation #algo


• Nearly Optimal Quantum Algorithm for Estimating Multiple Expectation
Values #algo
• Quantum Algorithms for Reinforcement Learning with a Generative
Model #algo #qrl #qmc
• Quantum Monte-Carlo Integration: The Full Advantage in Minimal Cir-
cuit Depth #algo #qmc
• Near-Optimal Quantum Algorithms for Multivariate Mean Estimation
#algo #qmc
• Quantum algorithms for multivariate Monte Carlo estimation #algo #qmc
• Quantum Sub-Gaussian Mean Estimator #algo #qmc
• Quantum algorithm for stochastic optimal stopping problems #qfinance
#algo
• Quantum Machine Learning For Classical Data #thesis
• Quantum algorithms for anomaly detection using amplitude estimation
#algo
• Two-level Quantum Walkers on Directed Graphs I: Universal Quantum
Computing #algo
• Quantum algorithms for learning a hidden graph and beyond #algo
• Asymptotically Optimal Circuit Depth for Quantum State Preparation
and General Unitary Synthesis

2020
• Variational Quantum Algorithms #review
• Circuit-centric Quantum Classifier #variational
• Quantum polar decomposition algorithm #algo
• The power of quantum neural networks #variational
• Robust quantum minimum finding with an application to hypothesis se-
lection #algo
• Quantum exploration algorithms for multi-armed bandits #algo
• Sublinear classical and quantum algorithms for general matrix games
#algo

2019
• Quantum Language Processing #NLP
• A Quantum Search Decoder for Natural Language Processing #NLP
• Quantum and Classical Algorithms for Approximate Submodular Func-
tion Minimization #algo
• Quantum algorithms for zero-sum games #algo
• Practical implementation of a quantum backtracking algorithm
#experiment
• Quantum speedup of branch-and-bound algorithms #algo
• The Quantum Version Of Classification Decision Tree Constructing Algo-
rithm C5.0 #algo
234 CHAPTER 15. SELECTED WORKS ON QUANTUM ALGORITHMS

• Sublinear quantum algorithms for training linear and kernel-based classi-


fiers #algo
• Quantum Algorithms for Classical Probability Distributions #algo #qmc

2018
• Continuous-variable quantum neural networks A work presented at
TQC2018 that exploit deep similarities between the mathematical
formulation of NN and photinics
• Classification with quantum neural networks on near term processors
#variational
• Artificial Quantum Neural Network: quantum neurons, logical elements
and tests of convolutional nets. A new approach to qnn ø/. This skips
complitely the unitary and gate based quantum computation Also here
the model is mean to be trained by classical optimization.
• Optimizing quantum optimization algorithmsvia faster quantum gradient
computation #algo
• Quantum Statistical Inference #phdthesis, #algo A PhD thesis on QML
and other aspects of quantum information. With focus on Gaussian
Processes, Quantum Bayesian Deep Learning (and other resources about
causality and correlations..).
• Troubling Trends in Machine Learning Scholarship #opinion-paper Is a
self-autocritic of the ML community on the way they are doing science
now. I think this might be relevant as well for the QML practicioner.
• Quantum machine learning for data scientits #review #tutorial This is
a very nice review of some of the most known qml algorithms.
• Quantum algorithm implementations for beginners #review #tutorial
• Quantum linear systems algorithms: a primer #review
• Quantum singular value transformation and beyond: exponential improve-
ments for quantum matrix arithmetics #algo
• The power of block-encoded matrix powers: improved regression tech-
niques via faster Hamiltonian simulation #algo
• Applying quantum algorithms to constraint satisfaction problems
#resource-estimation
• Quantum Chebyshev’s Inequality and Applications #qmc
• From linear combination of quantum states to Grover’s searching algo-
rithm

2017
• Implementing a distance based classifier with a quantum interference cir-
cuit #algo
• Quantum SDP solvers: Large speed-ups, optimality, and applications to
quantum learning #algo
• Quantum machine learning for quantum anomaly detection #algo Here
the authors used previous technique to perform anomaly detection. Basi-
235

cally they project the data on the 1-dimensional subspace of the covariance
matrix of the data. In this way anomalies are supposed to lie furhter away
from the rest of the dataset.
• Quantum machine learning: a classical perspective: #review #quantum
learning theory
• Quantum Neuron: an elementary building block for machine learning on
quantum computers
• Quantum speedup of Monte Carlo methods #algo
• Improved quantum backtracking algorithms using effective resistance es-
timates #algo

2016
• Quantum Discriminant Analysis for Dimensionality Reduction and Clas-
sification #algo
• An efficient quantum algorithm for spectral estimation #algo
• Quantum Recommendation Systems #algo

2015
• Advances in quantum machine learning #implementations, #review It
cover things up to 2015, so here you can find descriptions of Neural
Networks, Bayesian Networks, HHL, PCA, Quantum Nearest Centroid,
Quantum k-Nearest Neighbour, and others. -Quantum walk speedup of
backtracking algorithms #algo
• Quantum algorithms for topological and geometric analysis of data #algo

2014
• Quantum Algorithms for Nearest-Neighbor Methods for Supervised and
Unsupervised Learning #algo
• Quantum support vector machine for big data classification #algo This
was one of the first example on how to use HHL-like algorithms in order
to get something useful out of them.
• Improved Quantum Algorithm for Triangle Finding via Combinatorial Ar-
guments #algo
• Fixed-point quantum search with an optimal number of queries #algo
• Quantum Principal Component Analysis #algo

2013
• Quantum algorithms for supervised and unsupervised machine learning
#algo
• Exponential improvement in precision for simulating sparse Hamiltonians
#algo
236 CHAPTER 15. SELECTED WORKS ON QUANTUM ALGORITHMS

2010
• Variable time amplitude amplification and a faster quantum algorithm for
solving systems of linear equations #algo
• Any and-or formula of size 𝑛 can be evaluated in time 𝑛1/2+𝑜(1) on a
quantum computer

2009
• Quantum algorithms for linear systems of equations #algo

2007
• A Quantum Algorithm for the Hamiltonian NAND Tree

2005
• Fast quantum algorithm for numerical gradient estimation #algo

1999
• The quantum query complexity of approximating the median and related
statistics #algo

1996
• A fast quantum mechanical algorithm for estimating the median #algo
Chapter 16

Solutions to exercises

237
238 CHAPTER 16. SOLUTIONS TO EXERCISES
Appendix A

Math and linear algebra

A.1 Norms, distances, trace, inequalities


Take a look at this, and this.
1 𝑧
Just remember that for a complez number 𝑧, 𝑧𝑧 = 𝑎2 + 𝑏2 = |𝑧|2 , and 𝑧 = 𝑧𝑧 ,
and the conjugation is the mapping 𝑧 = (𝑎 + 𝑖𝑏) ↦ 𝑧 = (𝑎 − 𝑖𝑏).
Definition A.1 (Inner product). A function 𝑓 ∶ 𝐴 × 𝐵 ↦ ℂ is called an inner
product (𝑎, 𝑏) ↦ 𝑧 if:
• (𝑎, 𝑏 + 𝑐) = (𝑎, 𝑏) + (𝑎, 𝑐) (and respectively for (𝑎 + 𝑐, 𝑏) )
• (𝑎, 𝛼𝑏) = 𝛼(𝑎, 𝑏)
Definition A.2 (Norm). A function 𝑓 ∶ ℝ𝑑 ↦ ℝ is called a norm if:
• ‖𝑥‖ ≥ 0∀𝑥 ∈ ℝ𝑑 , also ‖𝑥‖ = 0 iff 𝑥 = 0 (positive definiteness)
• ‖𝛼𝑥‖ = 𝛼‖𝑥‖∀𝑥 ∈ ℝ𝑑 and ∀𝛼 ∈ ℝ (positively homogeneous)
• ‖𝑥‖ − ‖𝑦‖ ≤ ‖𝑥 + 𝑦‖ ≤ ‖𝑥‖ + ‖𝑦‖ (triangle inequality).
Note that along with triangle inequality you might also need to know the reverse
triangle inequality
The triangle inequality is basically the subadditivity property of the norm. It
is simople to see that norms are not linear operators.
Theorem A.1 (Cauchy(-Bunyakovsky)-Schwarz).

|(𝑥, 𝑦)| ≤ ‖𝑥‖‖𝑦‖

Proof. Note that by taking the square on both sides we get: (𝑥, 𝑦)2 ≤ (𝑥, 𝑥)(𝑦, 𝑦).
Substituting (𝑥, 𝑦) = ‖𝑥‖‖𝑦‖𝑐𝑜𝑠(𝜃), we get:

|‖𝑥‖2 ‖𝑦‖2 𝑐𝑜𝑠2 (𝜃)| ≤ (𝑥, 𝑥)(𝑦, 𝑦)

239
240 APPENDIX A. MATH AND LINEAR ALGEBRA

The inequality follows from noting that |𝑐𝑜𝑠(𝜃)| is always ≤ 1.

Remark. It is simple to see - using Cauchy-Schwarz - that for a vector 𝑥 we


have that: √
‖𝑥‖1 ≤ 𝑛‖𝑥‖2

We will use the following matrix norms:


• ‖𝐴‖0 as the number of non-zero elements of the matrix 𝐴,
𝑛
• ‖𝐴‖1 = max ∑𝑖=0 |𝑎𝑖𝑗 | is the maximum among the sum of the absolute
1≤𝑗≤𝑛
value along the columns of the matrix,
• ‖𝐴‖2 = ‖𝐴‖ = 𝜎1 is the biggest singular value of the matrix,
𝑛
• ‖𝐴‖∞ = max ∑𝑗=0 |𝑎𝑖𝑗 | is the maximum among the sum of the absolute
1≤𝑖≤𝑚
values along the rows of the matrix,
• ‖𝐴‖max is the maximal element of the matrix in absolute value.
• ‖𝐴‖𝐹 is the Frobenius norm of the matrix, defined as √∑𝑖𝑗 𝑎2𝑖𝑗

Note that for symmetric matrices, ‖𝐴‖∞ = ‖𝐴‖1 .


Exercise A.1 (bound error on product of matrices). Suppose that ‖𝐴 − 𝐴‖𝐹 ≤
𝑇
𝜖‖𝐴‖𝐹 . Bound ‖𝐴𝑇 𝐴 − 𝐴 𝐴‖𝐹
Definition A.3 (Distance). A function 𝑓 ∶ ℝ𝑑 × ℝ𝑑 ↦ ℝ is called a distance if:
• 𝑑(𝑥, 𝑦) ≥ 0
• 𝑑(𝑥, 𝑦) = 0 iif 𝑥 = 𝑦
• 𝑑(𝑥, 𝑦) = 𝑑(𝑦, 𝑥)
• 𝑑(𝑥, 𝑧) ≤ 𝑑(𝑥, 𝑦) + 𝑑(𝑦, 𝑧)
Definition A.4 (Convex and concave function). A function 𝑓 defined on a
convex vector space 𝐷 is said to be concave if, ∀𝜆 ∈ [0, 1], and ∀𝑥, 𝑦 ∈ 𝐷:

𝑓 ((1 − 𝛼)𝑥 + 𝛼𝑦) ≥ (1 − 𝛼)𝑓(𝑥) + 𝛼𝑓(𝑦)


Conversely, a function 𝑓 defined on a convex vector space 𝐷 is said to be convex
if, ∀𝜆 ∈ [0, 1], and ∀𝑥, 𝑦 ∈ 𝐷:

𝑓 ((1 − 𝛼)𝑥 + 𝛼𝑦) ≤ (1 − 𝛼)𝑓(𝑥) + 𝛼𝑓(𝑦)

A.1.0.1 Properties of the trace operator


• 𝑇 𝑟[𝐴 + 𝐵] = 𝑇 𝑟[𝐴] + 𝑇 𝑟[𝐵]
• 𝑇 𝑟[𝐴 ⊗ 𝐵] = 𝑇 𝑟[𝐴]𝑇 𝑟[𝐵]
• 𝑇 𝑟1 [𝐴 ⊗ 𝐵] = 𝑇 𝑟[𝐴]𝐵
• 𝑇 𝑟[|𝑎⟩⟨𝑏|] = ⟨𝑎|𝑏⟩
• 𝑇 𝑟[𝐴𝐵] = ⟨𝐴, 𝐵⟩
where inner product between matrices is basically defined pointwise as ∑𝑖𝑗 𝑎𝑖𝑗 𝑏𝑖𝑗
A.1. NORMS, DISTANCES, TRACE, INEQUALITIES 241

Exercise A.2. Can you show that the last identity is true?

A.1.0.2 Properties of tensor product

Given two liner maps 𝑉1 ∶ 𝑊1 ↦ 𝑉1 and 𝑉2 ∶ 𝑊2 ↦ 𝑉2 we define the tensor


product as the linear map:

𝑉1 ⊗ 𝑉 2 ∶ 𝑉 1 ⊗ 𝑉 2 ↦ 𝑊 1 ⊗ 𝑊 2

• 𝛼𝑣 ⊗ 𝑤 = 𝑣 ⊗ 𝛼𝑤 = 𝛼(𝑣 ⊗ 𝑤)
• (𝑣1 + 𝑣2 ) ⊗ 𝑤 = (𝑣1 ⊗ 𝑤) + (𝑣2 ⊗ 𝑤) (and the symmetric of it)
• |𝜓1 ⟩⟨𝜙1 | ⊗ |𝜓2 ⟩⟨𝜙2 | = |𝜓1 ⟩|𝜓2 ⟩ ⊗ ⟨𝜙1 |⟨𝜙2 |

When a basis is decided for representing linear maps between vector spaces, the
tensor product becomes the Kroeneker product.
242 APPENDIX A. MATH AND LINEAR ALGEBRA
A.1. NORMS, DISTANCES, TRACE, INEQUALITIES 243

A.1.0.3 Useful inequalities


244 APPENDIX A. MATH AND LINEAR ALGEBRA

Theorem A.2 (Binomial theorem).


𝑛
𝑛
(𝑎 + 𝑏)𝑛 = ∑ ( )𝑎𝑘 𝑏𝑛−𝑘
𝑘=0
𝑘

A.2 Linear algebra


A.2.1 Eigenvalues, eigenvectors and eigendecomposition
of a matrix
Real matrices are important tools in Machine Learning as they allow to comfort-
ably represent data and describe the operations to perform during an algorithm.
Eigenvectors and eigenvalues are fundamental linear algebra concepts that pro-
vide important information about a matrix.
Definition A.5 (Eigenvalues and Eigenvectors (Section 6.1 page 289 from
(Strang, 2016) )). Let 𝐴 be a ℝ𝑛×𝑛 square matrix, 𝑞 ∈ ℝ𝑛 a non-zero vector and
𝜆 a scalar. If the following equation is satisfied

𝐴𝑞 = 𝜆𝑞,

then 𝑞 is said to be an eigenvector of matrix 𝐴 and 𝜆 is its associated eigenvalue.


To have a geometric insight into what eigenvectors and eigenvalues are, we can
think of any matrix as a linear transformation in the ℝ𝑛 space. Under this
light, we can say that the eigenvectors of a matrix are those vectors of the space
that, after the transformation, lie on their original direction and only get their
magnitude scaled by a certain factor: the eigenvalue.
The eigenvalues reveal interesting properties of a matrix. For example, the trace
of a matrix (i.e. the sum of the element along the main diagonal of a square
matrix) is the sum of its eigenvalues
𝑛
𝑇 𝑟[𝐴] = ∑ 𝜆𝑖 ,
𝑖

and its determinant is equal to the product of the eigenvalues (Section 6.1 page
294 from (Strang, 2016))
𝑛
𝑑𝑒𝑡(𝐴) = ∏ 𝜆𝑖 .
𝑖

Moreover, a matrix 𝐴 with eigenvalues {𝜆1 , ..., 𝜆𝑘 } has an inverse only if all the
eigenvalues are not zero. The inverse has eigenvalues { 𝜆1 , ..., 𝜆1 }.
1 𝑘

Generally, one eigenvalue can be associated with multiple eigenvectors. There


might be a set of vectors 𝐸(𝜆) ⊆ ℝ𝑛 such that for all those vectors 𝑞 ∈ 𝐸(𝜆) ∶
𝐴𝑞 = 𝜆𝑞. That is why for each eigenvalue we talk about an eigenspace.
A.2. LINEAR ALGEBRA 245

Definition A.6 (Eigenspace (Definition 7.1.5 page 108 (Manara et al., 2007) )).
Let 𝐴 be a ℝ𝑛×𝑛 square matrix and 𝜆 be an eigenvalue of 𝐴. The eigenspace of
𝐴 related to 𝜆 is the space defined over the set of vectors 𝐸(𝜆) = {𝑥 ∶ 𝐴𝑥 = 𝜆𝑥}.
For each eigenspace, through the Gram-Schmidt procedure, starting from lin-
early independent vectors it is possible to identify a set of orthogonal eigenvec-
tors that constitute a basis for the space. The basis that spans the space where
all the eigenvectors of a matrix lie is called eigenbasis.
Definition A.7 (Eigenbasis). A basis for the space where all the eigenvectors
of a matrix lie is called eigenbasis.
An important result is that vectors in different eigenspaces are linearly indepen-
dent.
Lemma A.1 (Linear independence of eigenvectors (Lemma 7.2.3 page 112 from
(Manara et al., 2007) )). The set of vectors obtained by the union of the bases
of the eigenspaces of a matrix is linearly independent.
This means that if the sum of the dimensions of the eigenspaces ∑𝑖 𝑑𝑖𝑚(𝐸(𝜆𝑖 ))
equals 𝑛, it is possible to find 𝑛 eigenvectors of 𝐴 that form a basis for the ℝ𝑛
space. If that is the case, each vector that lies in ℝ𝑛 can be written as a linear
combination of the eigenvectors of 𝐴. Interestingly, matrices that have 𝑛 linearly
independent eigenvectors can be decomposed in terms of their eigenvalues and
eigenvectors.
Theorem A.3 (Eigendecomposition or Diagonalization). (Strang, 2016, Sec-
tion 6.2 page 304) Let 𝐴 ∈ ℝ𝑛×𝑛 be a square matrix with 𝑛 linearly independent
eigenvectors. Then, it is possible to decompose the matrix as

𝐴 = 𝑄Λ𝑄−1 .

Where 𝑄 ∈ ℝ𝑛×𝑛 is an square matrix and Λ ∈ ℝ𝑛×𝑛 is a diagonal matrix. In


particular, each 𝑖𝑡ℎ column of 𝑄 is an eigenvector of 𝐴 and the 𝑖𝑡ℎ entry of Λ
is its associated eigenvalue.
The matrices that can be eigendecomposed are also said diagonalizable, as in
practice the theorem above states that such matrices are similar to diagonal
matrices. Unfortunately, not all the square matrices have enough independent
eigenvectors to be diagonalized. The Spectral Theorem provides us with a set
of matrices that can always be eigendecomposed.
Theorem A.4 (Spectral theorem). (Strang, 2016, Spectral Theorem page 339)
Every symmetric matrix is diagonalizable 𝐴 = 𝑄Λ𝑄−1 . Furthermore, its eigen-
values are real and it is possible to choose the columns of 𝑄 so that it is an
orthogonal matrix.
Recall that a matrix 𝑄 is said to be orthogonal if 𝑄𝑄𝑇 = 𝑄𝑇 𝑄 = 𝕀, therefore
𝑄−1 = 𝑄𝑇 . The Spectral theorem, together with the fact that matrices like
𝐴𝑇 𝐴 and 𝐴𝐴𝑇 are symmetric, will come in handy in later discussions.
246 APPENDIX A. MATH AND LINEAR ALGEBRA

Being able to eigendecompose a matrix allows performing some computations


faster than otherwise. Some examples of operations that gain speed-ups from the
eigendecomposed representation are matrix inversion and matrix exponentiation.
Indeed, if we have a matrix 𝐴 = 𝑄Λ𝑄−1 its inverse can be computed as 𝐴−1 =
𝑄Λ−1 𝑄−1 where Λ−1 = 𝑑𝑖𝑎𝑔([ 𝜆1 , ... 𝜆1 ]). It is easy to check that this matrix is
1 𝑛
the inverse of 𝐴:

𝐴𝐴−1 = (𝑄Λ𝑄−1 )(𝑄Λ−1 𝑄−1 ) = 𝑄ΛΛ−1 𝑄−1 = 𝑄𝑄−1 = 𝕀

𝐴−1 𝐴 = (𝑄Λ−1 𝑄−1 )(𝑄Λ𝑄−1 ) = 𝑄Λ−1 Λ𝑄−1 = 𝑄𝑄−1 = 𝕀.


At the same time, the eigendecomposition of a matrix allows performing matrix
exponentiation much faster than through the usual matrix multiplication. In
fact, it is true that 𝐴𝑝 = 𝑄Λ𝑝 𝑄−1 . For instance,

𝐴3 = (𝑄Λ𝑄−1 )(𝑄Λ𝑄−1 )(𝑄Λ𝑄−1 ) = 𝑄Λ(𝑄−1 𝑄)Λ(𝑄−1 𝑄)Λ𝑄−1 = 𝑄ΛΛΛ𝑄−1 = 𝑄Λ3 𝑄−1 .

Computing big matrix powers such as 𝐴100 , with its eigendecomposed represen-
tation, only takes two matrix multiplications instead of a hundred.
Traditionally, the computational effort of performing the eigendecomposition of
a ℝ𝑛×𝑛 matrix is in the order of 𝑂(𝑛3 ) and may become prohibitive for large
matrices (Partridge and Calvo, 1997).

A.2.2 Singular value decomposition


Eigenvalues and eigenvectors can be computed only on square matrices. More-
over, not all matrices can be eigendecomposed. For this reason, we introduce
the concepts of singular values and singular vectors, that are closely related to
the ones of eigenvalues and eigenvectors, and offer a decomposition for all the
kind of matrices.
Theorem A.5 (Singular Value Decomposition (Sections 7.1, 7.2 from [@linear-
algebragilbert). )] (Strang, 2016, Sections 7.1, 7.2) Any matrix 𝐴 ∈ ℝ𝑛×𝑛 can
be decomposed as
𝐴 = 𝑈 Σ𝑉 𝑇
where 𝑈 ∈ ℝ𝑛×𝑟 and 𝑉 ∈ ℝ𝑚×𝑟 are orthogonal matrices and Σ ∈ ℝ𝑟×𝑟 is
a diagonal matrix. In particular, each 𝑖𝑡ℎ column of 𝑈 and 𝑉 are respectively
called left and right singular vectors of 𝐴 and the 𝑖𝑡ℎ entry of Σ is their associated
singular value. Furthermore, 𝑟 is a natural number smaller then 𝑚 and 𝑛.
Another (equivaloent) definition of SVD is the following:

Σ 0
𝐴 = (𝑈 , 𝑈0 ) ( ) (𝑉 , 𝑉0 )𝑇 .
0 0

The matrix Σ is a diagonal matrix with Σ𝑖𝑖 = 𝜎𝑖 being the singular values
(which we assume to be sorted 𝜎1 ≥ ⋯ ≥ 𝜎𝑛 ).
A.2. LINEAR ALGEBRA 247

The matrices (𝑈 , 𝑈0 ) and (𝑉 , 𝑉0 ) are unitary matrices, which contain a basis


for the column and the row space (respectively 𝑈 and 𝑉 ) and the left null-space
and right null-space (respectively 𝑈0 and 𝑉0 ). Oftentimes, it is simpler to define
the SVD of a matrix by simply discarding the left and right null spaces, as
𝐴 = 𝑈 Σ𝑉 𝑇 , where 𝑈 , 𝑉 are orthogonal matrices and Σ ∈ ℝ𝑟×𝑟 is a diagonal
matrix with real elements, as we did in Theorem A.5.
Similarly to how eigenvalues and eigenvectors have been defined previously, for
each pair of left-right singular vector, and the associated singular value, the
following equation stands:
𝐴𝑣 = 𝜎𝑢.

If we consider the Singular Value Decomposition (SVD) under a geometric per-


spective, we can see any linear transformation as the result of a rotation, a
scaling, and another rotation. Indeed, if we compute the product between a
matrix 𝐴 ∈ ℝ𝑛×𝑚 and a vector 𝑥 ∈ ℝ𝑚

𝐴𝑥 = 𝑈 Σ𝑉 𝑇 𝑥 = (𝑈 (Σ(𝑉 𝑇 𝑥))).

𝑈 and 𝑉 𝑇 , being orthogonal matrices, only rotate the vector without changing
its magnitude, while Σ, being a diagonal matrix, alters its length.
It is interesting to note that the singular values of 𝐴 - denoted as {𝜎1 , ..., 𝜎𝑟 } - are
the square roots {√𝜆1 , ..., √𝜆𝑟 } of the eigenvalues of 𝐴𝐴𝑇 (or 𝐴𝑇 𝐴) and that
the left and right singular vectors of 𝐴 - denoted as {𝑢1 , ..., 𝑢𝑟 } and {𝑣1 , ..., 𝑣𝑟 }
- are respectively the eigenvectors of 𝐴𝐴𝑇 and 𝐴𝑇 𝐴.
The fact that each matrix can be decomposed in terms of its singular vectors
and singular values, as in the theorem above, makes the relationship between
singular values - singular vectors of a matrix and eigenvalues - eigenvectors of
its products with the transpose clearer:

𝐴𝐴𝑇 = (𝑈 Σ𝑉 𝑇 )(𝑈 Σ𝑉 𝑇 )𝑇 = 𝑈 Σ𝑉 𝑇 𝑉 Σ𝑈 𝑇 = 𝑈 Σ2 𝑈 𝑇 ;

𝐴𝑇 𝐴 = (𝑈 Σ𝑉 𝑇 )𝑇 (𝑈 Σ𝑉 𝑇 ) = 𝑉 Σ𝑈 𝑇 𝑈 Σ𝑉 𝑇 = 𝑉 Σ2 𝑉 𝑇 .

Note that the matrices 𝐴𝐴𝑇 and 𝐴𝑇 𝐴 are symmetric matrices and so, for the
Spectral theorem, we can always find an eigendecomposition. Moreover, note
that they have positive eigenvalues: being the square roots of real positive
eigenvalues, the singular values of a real matrix are always real positive numbers.
As the left and right singular vectors are eigenvectors of symmetric matrices,
they can be chosen to be orthogonal as well. In particular, the left singular
vectors of a matrix span the row space of the matrix, and the right singular
vectors span the column space.
Definition A.8 (Column (row) Space (Definition 8.1 page 192 [@schlesinger).
)] (Schlesinger, 2011, Definition 8.1 page 192) Let 𝐴 be a ℝ𝑛×𝑚 matrix. The
column (row) space of 𝐴 is the space spanned by the column (row) vectors of
248 APPENDIX A. MATH AND LINEAR ALGEBRA

𝐴. Its dimension is equal to the number of linearly independent columns (rows)


of 𝐴.
The number 𝑟 of singular values and singular vectors of a matrix is its rank.
Definition A.9 (Rank of a matrix (Definition 8.3, Proposition 8.4 page 193-194
from [@schlesinger). ) ] The rank of a matrix is the number of linearly indepen-
dent rows/columns of the matrix. If the matrix belongs to the ℝ𝑛×𝑚 space, the
rank is less or equal than 𝑚𝑖𝑛(𝑛, 𝑚). A matrix is said to be full rank if its rank
is equal to 𝑚𝑖𝑛(𝑛, 𝑚).
The dimension of the null-space is the number of linearly-dependent columns.
𝑘
For a rank 𝑘 matrix, the Moore-Penrose pseudo-inverse is defined as ∑𝑖 𝜎1 𝑢𝑖 𝑣𝑖𝑇 .
𝑖
Another relevant property of SVD is that the nonzero singular values and the
corresponding singular vectors are the nonzero eigenvalues and eigenvectors of
0 𝐴
the matrix ( 𝑇 ):
𝐴 0

0 𝐴 𝑢 𝑢
( 𝑇 ) ( 𝑖 ) . = 𝑠𝑖 ( 𝑖 )
𝐴 0 𝑣𝑖 𝑣𝑖

With 𝑠(𝐴) or simply with 𝑠 we denote the sparsity, that is, the maximum number
of non-zero elements of the rows.

A.2.3 Singular vectors for data representation


Singular values and singular vectors provide important information about ma-
trices and allow to speed up certain kind of calculations. Many data analysis
algorithms, such as Principal Component Analysis, Correspondence Analysis,
and Latent Semantic Analysis that will be further investigated in the following
sections, are based on the singular value decomposition of a matrix.
To begin with, the SVD representation of a matrix allows us to better un-
derstand some matrix norms, like the spectral norm and the Frobenius norm
(Strang, 2016).
Definition A.10 (l2 (or Spectral) norm). Let 𝐴 ∈ ℝ𝑛×𝑚 be a matrix. The 𝑙2
norm of 𝐴 is defined as ‖𝐴‖2 = 𝑚𝑎𝑥𝑥 ‖𝐴𝑥‖
‖𝑥‖ .

It is pretty easy to see that ‖𝐴‖2 = 𝜎𝑚𝑎𝑥 , where 𝜎𝑚𝑎𝑥 is the greatest singular
value of 𝐴. In particular, if we consider again the matrix 𝐴 = 𝑈 Σ𝑉 𝑇 as a
linear transformation, we see that 𝑈 and 𝑉 𝑇 only rotate vectors ||𝑈 𝑥|| = ||𝑥||,
||𝑉 𝑥|| = ||𝑥|| while Σ changes their magnitude ||Σ𝑥|| ≤ 𝜎𝑚𝑎𝑥 ||𝑥||. For this
reason, the 𝑙2 Norm of a matrix is also referred to as the Spectral Norm. During
the rest of the work we will also use the notation ||𝐴|| to refer to the Spectral
Norm.
Another important matrix norm that benefits from SVD is the Frobenius norm,
defined in the following way.
A.2. LINEAR ALGEBRA 249

Definition A.11 (Frobenius norm). Let 𝐴 ∈ ℝ𝑛×𝑚 be a matrix. The Frobenius


𝑛 𝑚
norm of 𝐴 is defined as ‖𝐴‖𝐹 = √∑𝑖 ∑𝑗 𝑎2𝑖𝑗 .

It can be shown that also this norm is related to the singular values. ::: {.propo-
sition} The Frobenius norm of a matrix 𝐴 ∈ ℝ𝑛×𝑚 is equal to the square root
of the sum of squares of its singular values.
𝑟
‖𝐴‖𝐹 = √∑ 𝜎𝑖2
𝑖

:::

Proof.

√ 𝑛 𝑛
||𝐴||𝐹 = √∑ ∑ 𝑎2𝑖𝑗 = √𝑇 𝑟[𝐴𝐴𝑇 ] = √𝑇 𝑟[(𝑈 Σ𝑉 𝑇 )(𝑈 Σ𝑉 )𝑇 ] =
⎷ 𝑖 𝑗
𝑛
√𝑇 𝑟[𝑈 Σ𝑉 𝑇 𝑉 Σ𝑈 𝑇 ] = √𝑇 𝑟[𝑈 ΣΣ𝑈 𝑇 ] = √𝑇 𝑟[𝑈 Σ2 𝑈 𝑇 ] = √∑ 𝜎2
𝑖=1

From the cyclic property of the trace 𝑇 𝑟[𝐴𝐵] = 𝑇 𝑟[𝐵𝐴] it follows that
𝑇 𝑟[𝑈 Σ2 𝑈 𝑇 ] = 𝑇 𝑟[𝑈 𝑇 𝑈 Σ2 ] = 𝑇 𝑟[Σ2 ], which is the sum of the squares of the
𝑛
singular values ∑𝑖=1 𝜎2 .

Another interesting result about the SVD of a matrix is known as the Eckart–
Young–Mirsky theorem. ::: {.theorem #eckart-young-mirsky name=“Best F-
Norm Low Rank Approximation”} Eckart and Young (1936)? Let 𝐴 ∈ ℝ𝑛×𝑚
be a matrix of rank 𝑟 and singular value decomposition 𝐴 = 𝑈 Σ𝑉 𝑇 . The
matrix 𝐴(𝑘) = 𝑈 (𝑘) Σ(𝑘) 𝑉 (𝑘)𝑇 of rank 𝑘 ≤ 𝑟, obtained by zeroing the smallest
𝑟 − 𝑘 singular values of 𝐴, is the best rank-k approximation of 𝐴. Equivalently,
𝐴𝑘 = 𝑎𝑟𝑔𝑚𝑖𝑛𝐵∶𝑟𝑎𝑛𝑘(𝐵)=𝑘 (‖𝐴 − 𝐵‖𝐹 ). Furthermore, 𝑚𝑖𝑛𝐵∶𝑟𝑎𝑛𝑘(𝐵)=𝑘 (‖𝐴 − 𝐵‖𝐹 ) =
𝑟
√∑𝑖=𝑘+1 𝜎𝑖 . :::

To get a clearer understanding of this result, we could rewrite 𝐴 = 𝑈 Σ𝑉 𝑇 =


𝑟
∑𝑖 𝜎𝑖 𝑢𝑖 𝑣𝑖𝑇 and notice that matrix 𝐴 is the sum of 𝑟 matrices 𝑢𝑖 𝑣𝑖𝑇 each scaled
by a scalar 𝜎𝑖 .
In practice, SVD decomposes matrix 𝐴 in matrices of rank one, ordered by
importance according to the magnitude of the singular values: the smaller the 𝜎𝑖 ,
the smaller is the contribution that the rank-1 matrix gives to the reconstruction
of 𝐴. When the smallest singular values are set to 0, we still reconstruct a big
part of the original matrix, and in practical cases, we will see that matrices can
be approximated with a relatively small number of singular values.
Unfortunately though, calculating the singular vectors and singular values of
a matrix is a computationally intensive task. Indeed, for a matrix 𝐴 ∈ ℝ𝑛×𝑚
250 APPENDIX A. MATH AND LINEAR ALGEBRA

the cost of the exact SVD is 𝑂 (𝑚𝑖𝑛(𝑛2 𝑚, 𝑛𝑚2 )). Recently, there have been
developed approximate methods that compute the Eckart-Young-Mirsky ap-
proximations of matrices in time 𝑂(𝑘𝑛𝑚), where k is the rank of the output
matrix (Partridge and Calvo, 1997), or in times that scale super-linearly on the
desired rank and one dimension of the input matrix ??.

A.3 Useful theorems around linear algebra


• Gershgorin circle theorem
• Perron-Frobenius theorem
• Sherman-Morrison formula

A.4 Inequalities
From here.
Theorem A.6 (Bernoulli inequalities).
• Bernoulli inequality: for ∀𝑛 ∈ ℕ, 𝑥 ≥ −1

(1 + 𝑥)𝑛 ≥ 1 + 𝑛𝑥

(Reader, check what happens if 𝑛 even or odd!)


• Generalized bernoully inequality: ∀𝑟 ∈ ℝ ≥ 1 or 𝑟 ≤ 0, and 𝑥 ≥ −1

(1 + 𝑥)𝑟 ≥ 1 + 𝑟𝑥

. For 0 ≤ 𝑟 ≤ 1,
(1 + 𝑥)𝑟 ≤ 1 + 𝑟𝑥

• Related inequality: for any 𝑥, 𝑟 ∈ ℝ, and 𝑟 > 0 >:

(1 + 𝑥)𝑟 ≤ 𝑒𝑟𝑥

Theorem A.7 (Jensen inequality). Let 𝑋 be a random variable with 𝔼|𝑋| ≤ ∞


and 𝑔 ∶ ℝ → ℝ a real continious convex function. Then

𝑔(𝔼[𝑋]) ≤ 𝔼[𝑔(𝑋)].

A mnemonic trick to remember the difference between convex and concave.


ConvEX ends with EX, as the word EXponential, which is convex.
Theorem A.8 (Ljapunov’s inequality). For any real 0 ≤ 𝑝 ≤ 𝑞 and any real
random variable, ‖𝑋‖𝑝 ≤ ‖𝑋‖𝑞 .
A.5. TRIGONOMETRY 251

1 1
Theorem A.9 (Hölder’s inequality). Let 𝑝, 𝑞 > 1 that satisfy 𝑝 + 𝑞 = 1. If
‖𝑋‖𝑝 ≤ ∞ and ‖𝑋‖𝑞 then

̇
𝔼[|𝑋𝑌 |] ≤ ‖𝑋‖𝑝 ‖𝑋‖ 𝑞.

Theorem A.10 (Minkowski’s inequality). Let 𝑝 > 1, ‖𝑋‖𝑝 ≤ ∞ and ‖𝑌 ‖𝑝 ≤ ∞.


Then:
‖𝑋 + 𝑌 ‖𝑝 ≤ ‖𝑋‖𝑝 + ‖𝑌 ‖𝑝 .

A.5 Trigonometry
Always have in mind the following Taylor expansion:
Theorem A.11 (Taylor expansion of exponential function).

𝑥𝑘
𝑒𝑥 = ∑
𝑘=0
𝑘!

Note that this series is convergent for all 𝑥


From that, it is easy to derive that:

𝑒±𝑖𝑥 = 𝑐𝑜𝑠(𝑥) ± 𝑖𝑠𝑖𝑛(𝑥)

Theorem A.12 (Nunzio’s version of Euler’s identity). For 𝜏 = 2𝜋,

𝑒𝑖𝜏 = 1

Because of this, we can rewrite sin and cos as:


𝑖𝑥 −𝑖𝑥
• cos(𝑥) = 𝑒 +𝑒 2
𝑖𝑥 −𝑖𝑥
• sin(𝑥) = 𝑒 −𝑒2𝑖

Note that we can do a similar thing of A.11 for matrices. In this case, we define
the exponential of a matrix via it’s Taylor expansion:


𝐴𝑘
𝑒𝐴 = ∑
𝑘=0
𝑘!
The matrix exponential has the following nice properties (Walter, 2018):

• (𝑒𝐴 )† = 𝑒𝐴
• 𝑒𝐴⊗𝐼 = 𝑒𝐴 ⊗ 𝐼
• if [𝐴, 𝐵] = 0, then 𝑒𝐴 𝑒𝐵 = 𝑒𝐴+𝐵 .
• 𝑈 𝑒𝐴 𝑈 † = 𝑒𝑈𝐴𝑈†
• 𝑑𝑒𝑡(𝑒𝐴 ) = 𝑒𝑇 𝑟[𝐴]
252 APPENDIX A. MATH AND LINEAR ALGEBRA

A.5.0.1 Useful equalities in trigonometry


• sin(𝑎) cos(𝑏) = 12 (sin(𝑎 + 𝑏) + sin(𝑎 − 𝑏)) = 1/2(sin(𝑎 + 𝑏) − sin(𝑏 − 𝑎))
• 2 cos 𝑥 cos 𝑦 = cos(𝑥 + 𝑦) + cos(𝑥 − 𝑦)
Exercise A.3. Derive an expression for cos(𝑎 + 𝑏).

Proof. Recall that 𝑒𝑖𝑥 = 𝑐𝑜𝑠(𝑥) + 𝑖𝑠𝑖𝑛(𝑥),

𝑒𝑖(𝐴+𝐵) = 𝑐𝑜𝑠(𝑎 + 𝑏) + 𝑖𝑠𝑖𝑛(𝑎 + 𝑏) = 𝑒𝑖𝐴 𝑒𝑖𝐵 = (𝑐𝑜𝑠(𝑎) + 𝑖𝑠𝑖𝑛(𝑎))(𝑐𝑜𝑠(𝑏) + 𝑖𝑠𝑖𝑛(𝑏))

𝑐𝑜𝑠(𝑎+𝑏)+𝑖𝑠𝑖𝑛(𝑎+𝑏) = 𝑐𝑜𝑠(𝑎)𝑐𝑜𝑠(𝑏)+𝑐𝑜𝑠(𝑎)+𝑖𝑠𝑖𝑛(𝑏)+𝑖𝑠𝑖𝑛(𝑎)𝑐𝑜𝑠(𝑏)−𝑠𝑖𝑛(𝑏)𝑠𝑖𝑛(𝑎)
𝑐𝑜𝑠(𝑎+𝑏)+𝑖𝑠𝑖𝑛(𝑎+𝑏) = 𝑐𝑜𝑠(𝑎)𝑐𝑜𝑠(𝑏)+𝑐𝑜𝑠(𝑎)𝑖𝑠𝑖𝑛(𝑏)+𝑖𝑠𝑖𝑛(𝑎)𝑐𝑜𝑠(𝑏)−𝑠𝑖𝑛(𝑏)𝑠𝑖𝑛(𝑎)
From this, it follows
Appendix B

Series

253
254 APPENDIX B. SERIES
Appendix C

Probability

C.1 Measure theory


Definition C.1 (Sigma algebra). Let Ω be a set, and Σ be a subset of the power
set of Ω (or equivalently a collection of subsets of 𝑋). Then Σ is a 𝜎-algebra if:
• ∅ ∈ Σ,
• Σ is closed under countable union,
• ∀𝑆 ∈ Σ, 𝑆 ∈ Σ.
Observe that thanks to de Morgan’s law, we can equivalently define the sigma
algebra to be closed under countable intersection. Oftentimes, it’s common to
conflate Σ and (Ω, Σ), and call both 𝜎-algebra.
Definition C.2 (Measurable space). Let Ω be a set, and Σ a 𝜎-algebra. The
tuple (Ω, Σ) is a measurable space (or Borel space).
Definition C.3 (Measurable function). Let (Ω, Σ), and (𝑌 , 𝑇 ) two different
measurable space. A function 𝑓 ∶ Ω ↦ 𝑌 is said to be measurable if for every
𝐸 ∈ 𝑇:
𝑓 −1 (𝐸) ∶= {𝑥 ∈ Ω|𝑓(𝑥) ∈ 𝐸} ∈ Σ

A measurable function is a function between the underlying sets of two mea-


surable spaces that preserves the structure of the spaces: the preimage of any
measurable set is measurable. This is in direct analogy to the definition that a
continuous function between topological spaces preserves the topological struc-
ture: the preimage of any open set is open.
Definition C.4 (Continious function). Let (𝑋, 𝕏), (𝑌 , 𝕐) two topological
spaces. Let 𝑓 be a function between two topological spaces 𝑓 ∶ 𝑋 ↦ 𝑌 is said
to be continious if the inverse image of every open subset of 𝑌 is open in 𝑋. In
other words, if 𝑉 ∈ 𝕐, then its inverse image 𝑓 −1 (𝑉 ) ∈ 𝕏

255
256 APPENDIX C. PROBABILITY

Definition C.5 (Measure space). The tuple (Ω, Σ, ℙ) is a measure space if:
• (Ω, Σ) is a measurable space.
• 𝜇(𝐸) is a measure on (Ω, Σ):
– 𝜇 ∶ Σ ↦ ℝ + {−∞, +∞}
– non-negativity: 𝜇(𝐸) ≥ 0∀𝐸 ∈ Σ
– Null empty set 𝜇(∅) = 0
– Coutable additivity (or 𝜎-additivity): for all countable collections
{𝐸𝑘 }∞𝑘=1 of pariwise disjoint sets in Σ,

𝜇 (∪∞
𝑘=1 𝐸𝑘 ) = ∑ 𝜇(𝐸𝑘 )
𝑘=1

Definition C.6 (Probability space). The tuple (Ω, Σ, ℙ) is a probability space


if:
• (Ω, Σ) is a 𝜎-algebra (Ω is the set of outcomes of the experiment, and Σ
is the set of events)
• ℙ is a measurable function:
– ℙ ∶ Σ ↦ [0, 1]
– Null empty set.
– 𝜇 is countably additive.
• ℙ(Ω) = 1
I.e. a probability space is a measure space where the measurable function on Ω
is 1.
Definition C.7 (Complete probability space). For 𝐵 ⊂ Σ s.t. ℙ(𝐵) = 0, a
(Ω, Σ, ℙ) probability space is complete if ∀𝐴 ⊂ 𝐵, 𝐴 ∈ Σ.
Definition C.8 (Equivalence between probability measures). Let (Ω, Σ, ℙ), (Ω, Σ, ℚ)
two probability space with the same Ω and Σ. We say that ℙ and ℚ are equiv-
alent iif for every 𝐴 ∈ Σ, ℙ(𝐴) = 0 ⇔ ℚ(𝐴) = 0.
It basically means that the two measures agree on the possible and impossible
events (even if it is pretty strange to call them equivalent).
Definition C.9 (Random variable). A (real-valued) random variable on a prob-
ability space (Ω, Σ, ℙ) is a measurable function 𝑋 ∶ Ω ↦ ℝ.
Remember that, for a list of numbers 𝑥1 , 𝑥𝑛 ,
• The mode can be defined as arg min𝑥 ∑𝑖 |𝑥𝑖 − 𝑥|0
• The median can be defined as arg min𝑥 ∑𝑖 |𝑥𝑖 − 𝑥|1
• The mean can be defined as arg min𝑥 ∑𝑖 |𝑥𝑖 − 𝑥|2 .

C.1.0.1 Union bound


The union bound is used to show that the probability of union (i.e. at least one
of them happens) of a finite or countable set of events is less than or equal to
the sum of the probabilities of the events.
C.1. MEASURE THEORY 257

Theorem C.1 (Union bound). ∀ events 𝐴1 … 𝐴𝑛 ∈ Σ:


𝑛
𝑃 (∪𝑛𝑖=1 𝐴𝑖 ) ≤ ∑ 𝑃 (𝐴𝑖 )
𝑖=1

Exercise C.1. In Erdős–Rényi graphs 𝐺(𝑛, 𝑝), (that is, a graph with 𝑛 nodes
with probability 𝑝 that each of the two nodes are connected). We define the
event 𝐵𝑛 as the event where a graph 𝐺(𝑛, 𝑝) has at least one isolated node.
Show that 𝑃 (𝐵𝑛 ) ≤ 𝑛(1 − 𝑝)𝑛−1 .

Proof. Let 𝐴𝑖 , 𝑖 ∈ [𝑛] the event that node 𝑖 is isoldated. Its probability, from
the definition of 𝐺(𝑛, 𝑝) is (1 − 𝑝)𝑛−1 , because there might be an edge with
probability 𝑝 with other 𝑛 − 1 nods. From this, applying directly the union
bonund we obtain an upper bound on the probability that there is at least one
isoldated node is in the graph:
𝑃 (𝐵𝑛 ) = 𝑃 (∪𝑛𝑖=1 𝐴𝑖 ) ≤ ∑ 𝑃 (𝐴𝑖 ) ≤ 𝑛𝑃 (𝐴𝑖 ) = 𝑛(1 − 𝑝)𝑛−1
𝑖

Exercise C.2. Suppose we run 4 times a randomized algorithm, with success


probability 1 − 𝛿. Can you bound the probability that we never fail using the
union bound?

Proof. Let 𝑓𝑖 the event that we fail running our algorithm at time 𝑖. We know
that the failure probability 𝑓𝑖 is 𝛿 for all 𝑖 ∈ [4]. Thanks to the union bound we
4
can bound the probability that we fail at least once: 𝑃 (∪𝑘𝑖 𝑓𝑖 ) ≤ ∑𝑖 𝛿 = 4𝛿. It
follows that the have 4 success in a row is lower bounded by 1 − 4𝛿.
Note that we could have also bypassed the union bound and compute this quan-
tity analitically, as the probability of getting 4 success in a row would be (1−𝛿)4 ,
which we can compute with the binomial theorem A.2.

Definition C.10 (Variance).


Var(𝑋) = E [(𝑋 − E[𝑋])2 ] (C.1)
= E [𝑋 2 − 2𝑋 E[𝑋] + E[𝑋]2 ] (C.2)
= E [𝑋 2 ] − 2 E[𝑋] E[𝑋] + E[𝑋]2 (C.3)
2 2
= E [𝑋 ] − E[𝑋] (C.4)

Exercise C.3. How can we express the variance as expectation of quantum


states? What quantum algorithm might we run to estimate the variance of a
random variable 𝑀 ?
⟨𝜓|𝑀 2 |𝜓⟩ − (⟨𝜓|𝑀 |𝜓⟩)2
Discuss.
258 APPENDIX C. PROBABILITY

Definition C.11 (Exponential Family [@murphy2012machine). ]


A probability density function or probability mass function 𝑝(𝑣|𝜈) for 𝑣 =
(𝑣1 , ⋯ , 𝑣𝑚 ) ∈ 𝒱𝑚 , where 𝒱 ⊆ ℝ, is a 𝜎-algebra over a set 𝑋 𝜈 ∈ ℝ𝑝 is said
to be in the exponential family if it can be written as:

𝑝(𝑣|𝜈) ∶= ℎ(𝑣) exp{𝑜(𝜈)𝑇 𝑇 (𝑣) − 𝐴(𝜈)}

where:
• 𝜈 ∈ ℝ𝑝 is called the canonical or natural parameter of the family,
• 𝑜(𝜈) is a function of 𝜈 (which often is just the identity function),
• 𝑇 (𝑣) is the vector of sufficient statistics: a function that holds all the
information the data 𝑣 holds with respect to the unknown parameters,
• 𝐴(𝜈) is the cumulant generating function, or log-partition function, which
acts as a normalization factor,
• ℎ(𝑣) > 0 is the base measure which is a non-informative prior and de-facto
is scaling constant.

C.1.0.2 Bias-variance tradeoff


Here is a nice reference to understand the bias-variance tradeoff

C.1.1 Boosting probabilities with “median lemma” (or


powering lemma )
In this section we discuss the following, widely known result in CS. It’s used not
only in writing algorithms, but also in complexity theory.
Lemma C.1 (Powering lemma [@jerrum1986random). ] Let 𝒜 be a quantum
or classical algorithm which aims to estimate some quantity 𝜇, and whose output
𝜇̃ satisfies |𝜇 − 𝜇|̃ ≤ 𝜖 except with probability 𝛾, for some fixed 𝛾 ≤ 1/2. Then,
for any 𝛾 > 0 it suffices to repeat 𝒜 𝑂(log 1/𝛿) times and take the median to
obtain an estimate which is accurate to within 𝜖 with probability at least 1 − 𝛿.

C.2 Markov chains


Useful resources: here, here.
Definition C.12 (Markov chain (Serfozo, 2009)). Let (𝑋𝑡 )𝑡∈𝐼 be a stochastic
process defined over a probability space (Ω, Σ, ℙ), for a countable set 𝐼, where
𝑋𝑡 are random variables on a set 𝒮 (called state space). Then (𝑋𝑡 )𝑡∈𝐼 is a
Markov chain if, for any 𝑗 ∈ 𝒮 and 𝑡 ≥ 0, it holds that

ℙ[𝑋𝑡+1 = 𝑗|𝑋0 , 𝑋1 , … 𝑋𝑡 ] = ℙ[𝑋𝑡+1 = 𝑗|𝑋𝑡 ]

and for all 𝑗, 𝑖 ∈ 𝒮, it holds that

ℙ[𝑋𝑡+1 = 𝑗|𝑋𝑡 = 𝑖] = 𝑝𝑖𝑗


C.3. DISTRIBUTIONS 259

, where 𝑝𝑖𝑗 is the transition probability for the Markov chain to go from state 𝑖
to state 𝑗.
Less formally, a Markov chain is a stochastic process with the Markov property,
for which we can just use a matrix 𝑃 to identify its transition probability. Most
of the time, we will discretize the state space 𝒮, so we can label elements of 𝒮
with integers 𝑖 ∈ [|𝒮|]. This fact will allow us to conflate the (push-forward)
measure 𝒫 on 𝒮 and the matrix 𝑃 .
A state 𝑗 is said to be accessible from 𝑖 (written as 𝑖 ↦ 𝑗) if 𝑃𝑖𝑗𝑡 > 0 for some 𝑡,
where 𝑃 𝑡 is the 𝑡-th power of the transition matrix 𝑃 . A communication class is
an equivalence releation between states (relatively simple to prove) where two
states 𝑗, 𝑖 are said to communicate if they are mutually accessible.
Definition C.13 (Irreducible markov chain). A Markov Chain (𝑋𝑡 )𝑡∈𝐼 is irre-
ducible if and only if
𝑡
• there exist some integer 𝑡 ∈ 𝐼 such that 𝑝𝑖𝑗 > 0 for all 𝑖, 𝑗 ∈ 𝒮 there exist
some integer 𝑡 ∈ 𝐼 such that 𝑃 [𝑋𝑡 = 𝑗|𝑋0 = 𝑖] > 0, for all 𝑖, 𝑗 ∈ 𝒮
• there is only one communication class.
The previous conditions are equivalent.
In terms of random walks, irreducibility means that: if the graph is undirected,
the graph is has only one connected component (i.e. is connected), and if the
graph is directed, the graph is strongly connected.

C.3 Distributions
This is a beautiful guide that shows you how to draw samples from a probability
distribution.
• Binomial distribution

C.4 Concentration inequalities


Take a look at this and this. Also recall that the Union bound was presented in
the section dedicated for probability theory, i.e. Theorem C.1.

C.4.1 Markov inequality


The Markov inequality is an upper bound for the probability that a non-negative
function of a random variable, that is greater than or equal to a positive constant.
Especially in analysis, people refer to it as Chebyshev’s inequality (sometimes,
calling it the first Chebyshev inequality, while referring to the “usual” Cheby-
shev’s inequality as the second Chebyshev inequality or Bienaymé–Chebyshev
inequality).
260 APPENDIX C. PROBABILITY

Theorem C.2 (Markov inequality). For all non-negative random variable, and
𝑎 > 0, we have that:
• 𝑃 𝑟(𝑋 ≥ 𝑎) ≤ 𝐸[𝑋]
𝑎
1
• 𝑃 𝑟(𝑋 ≥ 𝑎𝐸[𝑋]) ≤ 𝑎

Proof. Observe that :

𝐸[𝑋] = 𝑃 (𝑋 < 𝑎) ⋅ 𝐸[𝑋|𝑋 < 𝑎] + 𝑃 (𝑋 > 𝑎) ⋅ 𝐸[𝑋|𝑋 > 𝑎]

As both of these expected values are bigger than zero, (using the nonnegativity
hypothesis) we have that

̇
𝐸[𝑋] ≥ 𝑃 (𝑋 > 𝑎)𝐸[𝑋|𝑋 > 𝑎]

Now is easy to observe that 𝐸[𝑋|𝑋 > 𝑎] is at least 𝑎, and by rearranging we


obtain that:
𝐸[𝑋]
≥ 𝑃 (𝑋 > 𝑎)
𝑎

The second statement of the theorem follows from substitution, i.e. setting 𝑏 =
𝑎𝐸[𝑋] and using the previous statement on 𝑃 𝑟(𝑋 ≥ 𝑏).

A very useful corollary of Markov inequality is the following.


Theorem C.3 (Corollary of Markov inequality). Let 𝑓 be a monotone increas-
ing (or noll) function on a space 𝐼, and define the random variable on 𝑌 .

𝐸[𝑓(𝑌 )]
𝑃 (𝑌 ≥ 𝑏) ≤
𝑓(𝑏)

C.4.2 Chebyshev inequality


This inequality tells us about the probability of finding the random variable 𝑋
away from the mean 𝔼[𝑋] is bounded by the variance of 𝑋.
Theorem C.4 (Chebyshev inequality). Let 𝑋 be a random variable with finite
mean 𝜇 and variance 𝜎. For 𝜖 > 0:

𝜎2
𝑃 𝑟[|𝑋 − 𝔼[𝑋]| ≥ 𝜖] ≤
𝜖2

Moreover, if 𝑘 = 𝜖/𝜎 we can replace 𝜖 with 𝑘𝜎 and obtain:

1
𝑃 𝑟[|𝑋 − 𝔼[𝑋]| ≥ 𝑘𝜎] ≤
𝑘2
C.4. CONCENTRATION INEQUALITIES 261

Proof. Observe that (𝑋 − 𝜇)2 is a non-negative random variable. Therefore,

𝑃 (|𝑋 − 𝜇| ≥ 𝜖) = 𝑃 ((𝑋 − 𝜇)2 ≥ 𝜖2 )

Now since (𝑋 − 𝜇)2 is a non-negative random variable, we can apply Markov


inequality to get :

𝐸[(𝑋 − 𝜇)2 ]
𝑃 (|𝑋 − 𝜇| ≥ 𝜖) = 𝑃 ((𝑋 − 𝜇)2 ≥ 𝜖2 ) ≤
𝜖2

[𝑉 𝑎𝑟(𝑋)]
(|𝑋 − 𝜇| ≥ 𝜖) = 𝑃 ((𝑋 − 𝜇)2 ≥ 𝜖2 ) ≤
𝜖2

It is very useful to see what happen when we define a new random variable 𝑌
as the sample mean of 𝑋1 … 𝑋𝑛 other random variables (iid) indipendent and
𝑛
identically distributed: 𝑌 = 𝑛1 ∑𝑖 𝑋𝑖 . The expected value of 𝑌 is the same as
the expected value of 𝑋, but the variance is now linearly smaller in the number
of samples:

1 𝑛
𝐸[𝑌 ] = ∑ 𝐸[𝑋𝑖 ] = 𝔼[𝑋𝑖 ] for any 𝑖
𝑛 𝑖

1 𝑛 𝑉 𝑎𝑟[𝑋𝑖 ]
𝑉 𝑎𝑟[𝑌 ] = 2
∑ Var[𝑋𝑖 ] = for any 𝑖
𝑛 𝑖 𝑛

This allows us to obtain the following bound:


1 𝑛
Theorem C.5 (Chebyshev inequality for sample mean). Let 𝑌 = 𝑛 ∑𝑖 𝑋𝑖 .
Then,

𝜎2
𝑃 𝑟[|𝑌 − 𝐸[𝑌 ]| ≥ 𝜖] ≤
𝑛𝜖2

C.4.3 Weak Law of large numbers


Theorem C.6 (Weak Law of large numbers). Let 𝑋1 , 𝑋2 , … , 𝑋𝑛 be i.i.d random
variables with a finite expected value 𝔼[𝑋𝑖 ] = 𝜇 ≤ ∞, and let 𝑋 be the average
1 𝑛
𝑛 ∑𝑖 𝑋𝑖 . Then, for any 𝜖 > 0, we have that:

lim 𝑃 (|𝑋 − 𝜇| ≥ 𝜖) = 0
𝑛→+∞

𝜎2
Proof. We know that 𝐸[𝑋] = 𝜇 and 𝑉 𝑎𝑟(𝑋) = 𝑛 . By Chebyshev Inequality
for the sample mean (Theorem C.5):
262 APPENDIX C. PROBABILITY

𝑉 𝑎𝑟(𝑋) 𝜎2
𝑃 (|𝑋 − 𝜇| > 𝜖) ≤ =
𝜖2 𝑛𝜖2

𝜎2
Trivially, lim𝑛→∞ 𝑛𝜖2 = 0, concluding the proof.

C.4.4 Strong Law of Large Numbers


Theorem C.7 ((Strong) Law of large numbers). Let 𝑋1 , 𝑋2 , 𝑋3 , … , 𝑋𝑛 be i.i.d
𝑛
random variables with mean 𝜇. Let 𝑋 = ∑𝑖=1 𝑋𝑖 be the sample mean. Then,
𝑋 converges almost surely to 𝜇:

𝑃 ( lim 𝑋 𝑛 = 𝜇) = 1
𝑥→−∞

Remark. The SLLN implies WLLN but not vice-versa.

C.4.5 Chernoff bound


From here and here, here, and here
We focus on a restricted class of random variables, i.e. the case when our random
variable is obtained as the sum of indipendent other random variables. Central
limit theorem says that, as 𝑛 → ∞, the value 𝑋−𝜇 𝜎 approaches the standard
normal distribution 𝑁 (0, 1). Hoewver, it does not tell any information on the
rate of convergence.
𝑛
Theorem C.8 (Chernoff bound). Let 𝑋 = ∑𝑖 𝑋𝑖 where 𝑋𝑖 = 1 with probability
𝑝𝑖 and 𝑋𝑖 = 0 with probability (1 − 𝑝𝑖 ), and all 𝑋𝑖 are independent. Let
𝑛
𝜇 = 𝐸[𝑋] = ∑𝑖 𝑝𝑖 . Then:
2
𝛿
• Upper tail: 𝑃 (𝑋 ≥ (1 + 𝛿)𝜇) ≤ 𝑒− 2+𝛿 𝜇 for all 𝛿 > 0
𝜇𝛿2 /2
• Lower tail: 𝑃 (𝑋 ≤ (1 − 𝛿)𝜇) ≤ 𝑒 for all 0 ≤ 𝛿 ≤ 1
You can find a nice proof here.
Theorem C.9 (Chernoff bound). Suppose 𝑋1 , … , 𝑋𝑡 are independent random
variables taking values in {0, 1}. Let 𝑀𝑡 = (𝑋1 + … 𝑋𝑡 )/𝑡 denote their average
value. Then for any 0 < 𝜖 < 1,
𝑡𝜇𝜖2
• (Multiplicative) 𝑃 𝑟[𝑀𝑡 − 𝜇 ≤ −𝜖𝜇] ≤ exp− 2 and 𝑃 𝑟[𝑀𝑡 − 𝜇 ≥ 𝜖𝜇] ≤
2
− 𝑡𝜇𝜖
exp 3
2 2
• (Additive) 𝑃 𝑟[𝑀𝑡 − 𝜇 ≤ −𝜖] ≤ 𝑒𝑥𝑝−2𝑡𝜖 and 𝑃 𝑟[𝑀𝑡 − 𝜇 ≥ 𝜖] ≤ exp−2𝑡𝜖
Remark. Trick: if our random variables are not between 0 and 1, we can define
𝑌𝑖 = 𝑋𝑖 /𝑚𝑎𝑥(𝑋𝑖 )
C.4. CONCENTRATION INEQUALITIES 263

C.4.6 Hoeffding inequality


Lemma C.2 (Hoeffding inequality). Let 𝑋1 , … , 𝑋𝑘 be independent random
variables bounded by the interval [𝑎, 𝑏]. Define the empirical mean of these
variables by 𝑋 = 𝑘1 (𝑋1 + ⋯ + 𝑋𝑘 ), then

2𝑘𝜖2
𝑃 𝑟(|𝑋 − 𝔼[𝑋]| ≤ 𝜖) ≥ 1 − 2 exp (− ).
𝑏−𝑎

Consequently, if 𝑘 ≥ (𝑏 − 𝑎)𝜖−2 log(2/𝜂), then 𝑋 provides an 𝜖-approximation of


𝔼[𝑋] with probability at least 1 − 𝜂.
Exercise C.4. Suppose the number of red lights Alex encounters each day to
work is on average 4.8 (according to historical trips to work). Alex really will
be late if he encounters 8 or more red lights. Let 𝑋 be the number of lights he
gets on a given day.
1. Give a bound for 𝑃 (𝑋 ≥ 8) using Markov’s inequality.
2. Give a bound for 𝑃 (𝑋 ≥ 8) using Chebyshev’s inequality, if we also assume
𝑉 𝑎𝑟(𝑋) = 2.88.
3. Give a bound for 𝑃 (𝑋 ≥ 8) using the Chernoff bound. Assume that 𝑋 ∼
𝐵𝑖𝑛(12, 0.4) - that there are 12 traffic lights, and each is independently
red with probability 0.4.
4. Compute 𝑃 (𝑋 ≥ 8) exactly using the assumption from the previous part.
5. Compare the three bounds and their assumptions.

Proof. We apply all the inequalities learned in this section and discuss them at
the end.
1. Since 𝑋 is nonnegative and we know its expectation, we can apply
Markov’s inequality:

𝔼[𝑋] 4.8
𝑃 (𝑋 ≥ 8) ≤ = = 0.6
8 8

2. Since we know 𝑋’𝑠 variance, we can apply Chebyshevs inequality after


some manipulation. We have to do this to match the form required:

𝑃 (𝑋 ≥ 8) ≤ 𝑃 (𝑋 ≥ 8) + 𝑃 (𝑋 ≤ 1.6) = 𝑃 (|𝑋 − 4.8| ≥ 3.2)

The reason we chose 𝑋 ≤ 1.6 is so it looks like 𝑃 (|𝑋 − | ≥ 𝛼). Now,


applying Chebyshev’s gives:

𝑉 𝑎𝑟(𝑋) 2.88
≤ = = 0.28125
3.22 3.22

3. Actually, 𝑋 ∼ 𝐵𝑖𝑛(12, 0.4) also has 𝐸[𝑋] = 𝑛𝑝 = 4.8 and 𝑉 𝑎𝑟(𝑋) =


𝑛𝑝(1 − 𝑝) = 2.88 (what a coincidence). The Chernoff bound requires
264 APPENDIX C. PROBABILITY

something of the form 𝑃 (𝑋 ≥ (1 + 𝛿)𝜇), so we first need to solve for


𝛿 ∶ (1 + 𝛿)4.8 = 8 so that 𝛿 = 2/3. Now,
2
2 − 2 4.8
𝑃 (𝑋 ≥ 8) = 𝑃 (𝑋 ≥ (1 + ).4.8) ≤ 𝑒𝑥𝑝( 3 ) ≈ 0.4991
3 3

4. The exact probabiltity can be found summing the Binomial probability


mass function:
1
12
𝑃 (𝑋 ≥ 8) = ∑ 2( )0.4𝑘 0.6(12−𝑘) ≈ 0.0573
𝑘=8
𝑘

5. Usually the bounds are tighter as we move down the list Markov, Cheby-
shev, Chernoff. But in this case Chebyshev’s gave us the tightest bound,
even after being weakened by including some additional 𝑃 (𝑋 ≤ 1.6). Cher-
noff bounds will typically be better for farther tails - 8 isn’t considered too
far from the mean 4.8. It’s also important to note that we found out more
information progressively - we can’t blindly apply all these inequalities
every time. We need to make sure the conditions are satisfied.
Remarkably, note that even our best bound of 0.28125 was 5 − 6 times larger
than the true probability of 0.0573.
Appendix D

Error propagation and


approximation

This part is based on many different sources, like (Hogan, 2006), (Ku et al.,
1966). In the following, let 𝐴 be the quantity that we want to estimate, and 𝐴
our estimate. We have the definition of absolute error and relative error.
Definition D.1 (Absolute error).

|𝐴 − 𝐴| = 𝜖𝐴𝑏𝑠

Definition D.2 (Relative error).

|𝐴 − 𝐴|
= 𝜖𝑅
𝐴
or equivalently
𝐴(1 − 𝜖𝑅 ) ≤ 𝐴 ≤ 𝐴(1 + 𝜖𝑅 )

Thus observe that:


• If (and only if) |𝐴| < 1, then, 𝜖𝐴𝑏𝑠 ≤ 𝜖𝑅
• If (and only if) |𝐴| > 1, then, 𝜖𝐴𝑏𝑠 ≥ 𝜖𝑅
We will study the relation between the two errors, often leveraging the trick
setting 𝜖𝐴𝑏𝑠 = 𝜖𝑅 𝐴. Oftentimes, we would like to move from a relative to
absolute precision, or vice versa.

D.[Link] From absolute to relative precision Suppose that we have an


algorithm that in time 𝑂(𝑓( 𝜖 1 )) gives us |𝐴 − 𝐴| ≤ 𝜖𝐴𝑏𝑠 for 𝜖𝐴𝑏𝑠 ∈ (0, 1] and
𝐴𝑏𝑠
we want a relative error 𝜖𝑅 > 0:

265
266 APPENDIX D. ERROR PROPAGATION AND APPROXIMATION

• If |𝐴| < 1, then we want to obtain an error 𝜖𝐴𝑏𝑠 such that 𝜖𝐴𝑏𝑠 = 𝜖𝑅 𝐴.
For this, we need to have a lower bound 𝜆−1 on 𝐴. If we have it, we can
just set 𝜖𝐴𝑏𝑠 = 𝜖𝑅 𝜆−1 and run our algorithm in time 𝑂(𝑓( 𝜖 𝜆 ))
𝐴𝑏𝑠

• If |𝐴| > 1, If we want a relative error 𝜖𝑅 , then by running the algorithm


with 𝜖𝐴𝑏𝑠 = 𝜖𝑅 we have already a relative error bound, as |𝐴−𝐴|𝐴 ≤ |𝐴 −
𝐴| ≤ 𝜖𝐴𝑏𝑠 Note that we 𝜖𝐴𝑏𝑠 is meant to stay ∈ (0, 1] as it wouldn’t make
sense to have a runtime of 𝑂( 𝜖 1 ) for 𝜖𝑎𝑏𝑠 > 1.
𝑎𝑏𝑠

Exercise D.1. Are there cases of algorithms with 𝜖𝑎𝑏𝑠 > 1? Does it make
sense? Can you make examples?

D.[Link] From relative to absolute precision If we have an algorithm


that in time 𝑂(𝑓( 𝜖1 )) gives us |𝐴 − 𝐴| ≤ 𝐴𝜖𝑅 and we want an absolute 𝜖𝐴𝑏𝑠 :
𝑅

• IF 𝐴 ≤ 1, we could just call the algorithm with error 𝜖𝑅 = 𝜖𝐴𝑏𝑠 , and thus
obtain
|𝐴 − 𝐴| ≤ 𝜖𝑅 𝐴 ⇒ |𝐴 − 𝐴| ≤ 𝜖𝑅 = 𝜖𝐴𝑏𝑠 ,
as the absolute error is an upper bound of the relative error. Note that
the runtime of the algorithm might (should!) depend on the quantity 𝐴
that we want to estimate, so we could improve upon this, by trying to not
pay a price that depends on 𝐴 in the runtime.
• IF 𝐴 > 1,
|𝐴 − 𝐴| ≤ 𝜖𝑅 𝐴
we want
𝜖𝐴𝑏𝑠
|𝐴 − 𝐴| ≤ 𝜖𝐴𝑏𝑠 by setting 𝜖𝑅 =
𝐴
By running algorithm 𝒜 with error 𝜖′ = 𝐴𝜖 , i.e. we run it once with
𝜖𝑅 = 1/4 error, and than. We run it again with the improved 𝜖𝑅 = 𝜆1 ,
and we have a runtime of 𝑂(f( 𝜖𝐴
−1 )).

Example D.1. Amplitude estimation output a scalar 0 ≤ 𝑝̃ ≤ 1 which equal


1
some probability 𝑝, such that |𝑝 − 𝑝|̃ ≤ 𝜖𝑝 in time 𝑂 ( 𝜖𝑝 ). We have directly an
absolute error of 𝜖 in this estimate (which we will rarely use, as oftenwe would
like to multiply this estimate, so that the error scales proportionately).
–> –> –>
–> –> –> –> –> –>

D.0.1 Propagation of error in functions of one variable


Check this, this, this, and (Hogan, 2006).
–>
–> –> –> –> –> –> –> –> –>
267

–>

–>

–> –> –>

–>

–> –> –>

–>

–>

–>

–> –> –> –> –>

–> –> –> –>

–> –> –> –> –> –> –>

–>

–> –> –> –> –>

–> –>

–> –> –> –> –>

–> –> –>

–> –> –> –> –>

–>

–> –> –> –> –>

–>

–>

–> –> –>

Lemma D.1 ((Hamoudi et al., 2020)). Let 𝑎̃ be an estimate of 𝑎 > 0 such that
|𝑎̃ − 𝑎| ≤ 𝜖𝑎 𝑎. with 𝜖𝑎 ∈ (0, 1). Similarly, let 𝑏̃ be an estimate of 𝑏 > 0 and
𝜖𝑏 ∈ (0, 1) such that |𝑏̃ − 𝑏| ≤ 𝜖𝑏 𝑏. Then the ratio 𝑎/𝑏 is estimated to relative
error ∣ 𝑎𝑏̃ ̃ − 𝑎𝑏 ∣ ≤ ( 𝜖1−𝜖
𝑎 +𝜖𝑏
) 𝑎𝑏 .
𝑏

The proof comes directly from their work ::: {.proof} Note that 𝑏 − 𝑏̃ ≤ |𝑏̃ − 𝑏| ≤
𝜖𝑏 𝑏, so as we said before, deduce 1𝑏̃ ≤ 𝑏(1−𝜖
1
).
𝑏
268 APPENDIX D. ERROR PROPAGATION AND APPROXIMATION

Now we can combine the previous observation:

𝑎̃ 𝑎 𝑎𝑏̃ − 𝑎𝑏̃ 𝑎𝑏̃ − 𝑎𝑏 + 𝑎𝑏 − 𝑎𝑏̃ 𝑎 ̃ − 𝑎 𝑎 𝑏 − 𝑏̃


∣ − ∣ =∣ ∣=∣ ∣=∣ + ∣ (D.1)
𝑏̃ 𝑏 𝑏𝑏̃ 𝑏𝑏̃ 𝑏̃ 𝑏̃ 𝑏
𝑎̃ − 𝑎 𝑎 𝑏 − 𝑏̃ 𝜖 𝑎 + 𝜖𝑏 𝑎 𝑎 𝜖𝑎 + 𝜖 𝑏
≤∣ ∣+ ∣ ∣≤ 𝑎 ≤ . (D.2)
̃𝑏 ̃𝑏 𝑏 ̃𝑏 𝑏 (1 − 𝜖𝑏 )

:::
–>
–> –> –>
–> –> –>

D.1 Useful quantum subroutines and folklore


results
We will often make use of a tool developed in (Wiebe et al., 2018). It is standard
technique in classical computer science to boost the success probability of a
randomized algorithm by repeating it and computing some statistics in the
results. For the case of quantum algorithms, in high level, we take multiple
copies of the output of the amplitude estimation procedure, compute the median,
and reverse the circuit in order to get rid of the garbage.
Lemma D.2 (Median evaluation [@wiebe2018quantum). ] Let 𝒰 be a unitary
operation that maps
√ √
𝒰 ∶ |0⊗𝑛 ⟩ ↦ 𝑎|𝑥, 1⟩ + 1 − 𝑎|𝐺, 0⟩

for some 1/2 < 𝑎 ≤ 1 in time 𝑇 . Then there exists a quantum algorithm that,
for any Δ > 0 and√for any 1/2 < 𝑎0 ≤ 𝑎, produces a state |Ψ⟩ such that
‖|Ψ⟩ − |0⊗𝑛𝐿 ⟩|𝑥⟩‖ ≤ 2Δ for some integer 𝐿, in time

ln(1/Δ)
2𝑇 ⌈ 2⌉.
2 (|𝑎0 | − 12 )

We will report here some simple statements from literature which now are folk-
lore.
Lemma D.3 ([@kerenidis2019qmeans). ] Let 𝜖𝑏 be the error we commit in
estimating |𝑐⟩ such that ‖|𝑐⟩ − |𝑐⟩‖ < 𝜖𝑏 , and 𝜖𝑎 the error we commit in the

estimating the norms, | ‖𝑐‖ − ‖𝑐‖| ≤ 𝜖𝑎 ‖𝑐‖. Then ‖𝑐 − 𝑐‖ ≤ 𝜂(𝜖𝑎 + 𝜖𝑏 ).
Lemma D.4 ([@kerenidis2017quantumsquares). ] Let 𝜃 be the angle between
vectors

𝑥, 𝑦, and assume that 𝜃 < 𝜋/2. Then, ‖𝑥 − 𝑦‖ ≤ 𝜖 implies ‖|𝑥⟩ − |𝑦⟩‖ ≤
2𝜖
‖𝑥‖ . Where |𝑥⟩ and |𝑦⟩ are two unit vectors in ℓ2 norm.
Appendix E

Approximation theory

In this section we collect some polynomial approximation of useful functions


that can be used in your quantum algorithms. As we learned in Section 5.4.3,
in order to obtain efficient quantum algorithms we often need a low-degree poly-
nomial approximation of certain functions. This is an interesting link between
approximation theory (where it’s relatively easy to obtain some lower bounds)
and quantum algorithms. We will start by recalling an important tool in ap-
proximation theory.
Chebyshev polynomials play an important role in approximation theory (see,
for example, (Iske, 2018)).
Definition E.1 (Chebyshev polynomial). For 𝑛 ∈ ℕ0 , the Chebyshev polyno-
mial 𝑇𝑛 of degree 𝑛 is the function defined on the interval [−1, 1] by

𝑇𝑛 (𝑥) ∶= cos(𝑛 arccos(𝑥)).

E.1 Polynomial approximation of log(𝑥)


Lemma E.1 (Polynomial approximations of logarithm (Gilyén and Li, 2019)).
Let 𝛽 ∈ (0, 1], 𝜖 ∈ (0, 1/6]. Then there exists a polynomial 𝑆 ̃ of degree
̃ log (𝑥)
𝑂( 𝛽1 log( 1𝜖 )) such that |𝑆(𝑥) − 3 log 𝑏(2/𝛽) | ≤ 𝜖 for all 𝑥 ∈ [𝛽, 1] and base 𝑏 ∈ ℕ,
𝑏

and for all 𝑥 ∈ [−1, 1] 1/2 ≤ 𝑆(𝑥) ̃ ̃


= 𝑆(−𝑥) ≤ 1/2.

E.2 Polynomial approximation of 1/𝑥


We are going to approximate 1/𝑥 using Chebychev polynomial, with some ad-
ditional tricks, which will be used to decrease the degree of the polynomial
approximation. As

269
270 APPENDIX E. APPROXIMATION THEORY

The function 1/𝑥 has an essential discontinuity in 𝑥 = 0 since

1 1
lim = −∞ and lim = +∞.
𝑥→0− 𝑥 𝑥→0+ 𝑥

In this section we will follow (Childs et al., 2017) and show that 1/𝑥 can be
approximated arbitrarily closely on the set [−1, −𝛿] ∪ [𝛿, 1], where 0 < 𝛿 < 1,
by a linear combination of Chebyshev polynomials. We start by approximating
1/𝑥 with the following function:

(1 − (1 − 𝑥2 )𝑏 )/𝑥, if 𝑥 ∈ ℝ ∖ {0}
𝑔𝑏 (𝑥) ∶= { (E.1)
0, if 𝑥 = 0

where 𝑏 > 0 is a positive constant.


Lemma E.2. The function (E.1) is continuous in ℝ.

Proof. We need to show the continuity of 𝑔𝑏 in 𝑥 = 0. This follows by an


application of L’Hôpital’s rule:

1 − (1 − 𝑥2 )𝑏 2𝑏𝑥(1 − 𝑥2 )𝑏−1
lim = lim = 0 = 𝑔𝑏 (0).
𝑥→0 𝑥 𝑥→0 1

The following lemma shows that 𝑔𝑏 approximates 1/𝑥 arbitrarily closely on the
set [−1, −𝛿] ∪ [𝛿, 1], 0 < 𝛿 < 1, if 𝑏 is large enough.
Lemma E.3. Let 𝜖 > 0 and 0 < 𝛿 < 1. If 𝑏 ≥ max{1, 𝛿 −2 log(1/(𝜖𝛿))}, then
|𝑔𝑏 (𝑥) − 1/𝑥| < 𝜖 for all 𝑥 ∈ [−1, −𝛿] ∪ [𝛿, 1].

Proof. From the inequality 𝑒𝑎 ≥ 1 + 𝑎, 𝑎 ∈ ℝ, and 𝑏 > 1 it follows with 𝑎 ∶= −𝛿 2


2
(1 − 𝛿 2 )𝑏 ≤ 𝑒−𝛿 𝑏 .

Therefore, for 𝑥 ∈ [−1, −𝛿] ∪ [𝛿, 1] we have


2
1 (1 − 𝑥2 )𝑏 (1 − 𝛿 2 )𝑏 𝑒−𝛿 𝑏
∣𝑔𝑏 (𝑥) − ∣= ≤ ≤ ≤ 𝜖.
𝑥 |𝑥| 𝛿 𝛿

The following lemma shows that 𝑔𝑚 , 𝑚 ∈ ℕ, is on the interval [−1, 1] equal to


a linear combination of Chebyshev polynomials of degree at most 2𝑚 − 1.
E.2. POLYNOMIAL APPROXIMATION OF 1/𝑥 271

Lemma E.4. Let 𝑚 ∈ ℕ be a positive integer. Then,

𝑚−1 𝑚 2𝑚
𝑛
∑𝑘=𝑛+1 (𝑚+𝑘 )
𝑔𝑚 (𝑥) = 4 ∑ (−1) ( ) 𝑇2𝑛+1 (𝑥) (E.2)
𝑛=0
22𝑚

for all 𝑥 ∈ [−1, 1].

Proof. For 𝑥 = 0 the equality (E.2) follows from the definitions of Chebyshev
polynomials and 𝑔𝑚 . We are left with the task to prove

𝑚−1 2𝑚 𝑚
1 − (1 − 𝑥2 )𝑚 ∑ (𝑚+𝑘 )
= 4 ∑ (−1)𝑛 ( 𝑘=𝑛+1
2𝑚
) 𝑇2𝑛+1 (𝑥)
𝑥 𝑛=0
2

for all 𝑥 ∈ [−1, 1] ∖ {0}. Choose 𝜃 ∈ ℝ such that 𝑥 = cos(𝜃). Because sin2 (𝜃) +
cos2 (𝜃) = 1 and 𝑇𝑛 (cos(𝜃)) = cos(𝑛𝜃), we need to prove that

𝑚−1 𝑚 2𝑚
2𝑚 𝑛
∑𝑘=𝑛+1 (𝑚+𝑘 )
1 − sin (𝜃) = 4 ∑ (−1) ( ) cos((2𝑛 + 1)𝜃) cos(𝜃), (E.3)
𝑛=0
22𝑚

where in the previous equation we moved cos(𝜃) from the denominator of the
l.h.s. to the r.h.s..
In order to complete the proof we can proceed in two different ways. Either we
will write the left and right side of Equation (E.3) respectively in the form

𝑚 𝑚
∑ 𝑎𝑗 cos(2𝑗𝜃) and ∑ 𝑏𝑗 cos(2𝑗𝜃), (E.4)
𝑗=0 𝑗=0

and, finally, verify that 𝑎𝑗 = 𝑏𝑗 for all 𝑗 ∈ {0, … , 𝑚}. This approach follows the
original proof of (Childs et al., 2017). Another way is to just convert the l.h.s.
of Equation (E.3) so it matches the coefficients of the r.h.s. We will start with
the second approach, as it is the canonical one, but we discuss the second one
later, as it is the one presented in the original proof.
Using the binomial formula for complex numbers 𝑎, 𝑏 ∈ ℂ and 𝑝 ∈ ℕ0 , which is
stated in Theorem A.6

𝑝
𝑝
(𝑎 + 𝑏)𝑝 = ∑ ( )𝑎𝑝−𝑗 𝑏𝑗 ,
𝑗=0
𝑗

we obtain a nice expansion of the sin(𝜃)2𝑚 as:


272 APPENDIX E. APPROXIMATION THEORY

2𝑚
𝑒𝑖𝜃 − 𝑒−𝑖𝜃
sin2𝑚 (𝜃) = ( )
2𝑖
2𝑚
1 2𝑚
= ∑ ( )(−𝑒−𝑖𝜃 )2𝑚−𝑗 (𝑒𝑖𝜃 )𝑗
22𝑚 𝑖2𝑚 𝑗=0 𝑗

(−1)𝑚 2𝑚 2𝑚
= ∑ ( )(−1)𝑗 𝑒𝑖(2𝑗−2𝑚)𝜃
22𝑚 𝑗=0 𝑗

1 2𝑚 (−1)𝑚 𝑚−1 2𝑚 2𝑚
= 2𝑚
( ) + 2𝑚
∑ (( )(−1)𝑗 𝑒𝑖(2𝑗−2𝑚)𝜃 + ( )(−1)2𝑚−𝑗 𝑒−𝑖(2𝑗−2𝑚)𝜃 )
2 𝑚 2 𝑗=0
𝑗 2𝑚 − 𝑗

1 2𝑚 2 𝑚−1 2𝑚 𝑚−𝑗 𝑒
𝑖(2𝑗−2𝑚)𝜃
+ 𝑒−𝑖(2𝑗−2𝑚)𝜃
= ( ) + ∑ ( )(−1)
22𝑚 𝑚 22𝑚 𝑗=0 𝑗 2

1 2𝑚 2 𝑚−1 2𝑚
= ( ) + 2𝑚 ∑ ( )(−1)𝑚−𝑗 cos(2(𝑗 − 𝑚)𝜃).
22𝑚 𝑚 2 𝑗=0
𝑗

To give more context on some of the steps in the previous series of equations,
we have done the following:
• we wrote the sin using the euler formula.
• we used the binomial theorem
• we used that (−1)𝑗 = (−1)2𝑚−𝑗 to factor out the minus sign
• we exploited the symmetry of the binomial, and removed the middle term
1 2𝑚
( 22𝑚 ( 𝑚 )) from the summation.
• we collect back the (−1)𝑚 in the summation
• we used again Euler formula (multiplying and dividing everything by 2)
to obtain a cos in the summation.
Thus, we have

1 2𝑚 2 𝑚−1 2𝑚
1 − sin2𝑚 (𝜃) = (1 − 2𝑚
( )) + 2𝑚
∑ (−1)𝑚−𝑗−1 ( ) cos(2(𝑗 − 𝑚)𝜃).
2 𝑚 2 𝑗=0
𝑗
(E.5)
Note that we factored the − sign in the third term in the exponent of the (−1)
factor. Now we perform a substitution, and set 𝑘 = 𝑚 − 𝑗. Recall that cosine
is an even function, and thus cos(2(𝑗 − 𝑚)𝜃) = cos(2(𝑚 − 𝑗)𝜃) = cos(2𝑘𝜃). Also
recalling again the symmetry of the binomial coefficients, i.e. (2𝑚 2𝑚
𝑗 ) = (2𝑚−𝑗) =
2𝑚
(𝑚+𝑘 ), we can rewrite our function as:

1 2𝑚 2 𝑚 2𝑚
1 − sin2𝑚 (𝜃) = 1 − ( ) + ∑( )(−1)𝑘−1 cos(2𝑘𝜃) . (E.6)
22𝑚 𝑚 22𝑚 𝑘=1 𝑚 + 𝑘
E.2. POLYNOMIAL APPROXIMATION OF 1/𝑥 273

Note also that because of the substition step, now we have the index of 𝑘 that
2𝑚
goes from 1 to 𝑚. Now we have a first trick: 22𝑚 = (1 + 1)2𝑚 = ∑𝑖=0 (2𝑚
𝑖 ).This
allows to rewrite the first two terms of the summation as:

1 2𝑚 22𝑚 − (2𝑚
𝑚) 1 𝑚 2𝑚 2𝑚 2 𝑚 2𝑚
1− ( ) = = ∑ (( ) + ( )) = ∑( ).
22𝑚 𝑚 22𝑚 22𝑚 𝑘=1 𝑚+𝑘 𝑚−𝑘 22𝑚 𝑘=1 𝑚 + 𝑘
(E.7)
2𝑚
Where we used the fact that (2𝑚 2𝑚
𝑚 ) is the central term in ∑𝑖=0 ( 𝑖 ), and its
2𝑚
symmetry again. Thus, the whole equation can be rewritten by factoring (𝑚+𝑘)
as:

𝑚
2 2𝑚 2 𝑚 2𝑚
1 − sin2𝑚 (𝜃) = ∑( ) + 2𝑚 ∑ ( )(−1)𝑘−1 cos(2𝑘𝜃) (E.8)
22𝑚 𝑘=1
𝑚 + 𝑘 2 𝑘=1
𝑚 + 𝑘
𝑚
2 2𝑚
=1 − sin2𝑚 (𝜃) = ∑( ) × (1 + (−1)𝑘−1 cos(2𝑘𝜃)) ,
22𝑚 𝑘=1
𝑚+𝑘
(E.9)

Now we rewrite the last factor as a telescoping sum as:


𝑘−1
1 + (−1)𝑘−1 cos(2𝑘𝜃) = ∑(−1)𝑛 (cos(2𝜃(𝑛 + 1)) + cos(2𝜃𝑛)) . (E.10)
𝑛=0

Now, we want to obtain a product of cosines, as Equation (E.3), we use the


standard formula (Section A.5.0.1) of cos(𝑥 + 𝑦) + cos(𝑥 − 𝑦) = 2 cos(𝑥) cos(𝑦).
Specifically, we set 𝑥 + 𝑦 = 2𝜃(𝑛 + 1) and 𝑥 − 𝑦 = 2𝜃𝑛, so we obtain the value
of 𝑥 = (2𝑛 + 1)𝜃 and 𝑦 = 𝜃. Thanks to these two passages we can rewrite

𝑚 𝑘−1
2 2𝑚
1 − sin2𝑚 (𝜃) = ∑( ) × (2 ∑(−1)𝑛 cos((2𝑛 + 1)𝜃) cos 𝜃) . (E.11)
22𝑚 𝑘=1
𝑚+𝑘 𝑛=0

We need one more step to obtain the coefficients of the Chebychev polynomial
from the previous equation, which is a simple change in the order of the sum-
mations. To be very explicit, we are just using the following observation:
𝑚 𝑘−1 𝑚 𝑘−1 𝑚−1 𝑚
∑ 𝑓𝑘 (∑ 𝑐𝑛 ) = ∑ ∑ 𝑓𝑘 𝑐𝑛 = ∑ 𝑐𝑛 ( ∑ 𝑓𝑘 ).
𝑘=1 𝑛=0 𝑘=1 𝑛=0 𝑛=1 𝑘=𝑛+1

Thus, we obtain
274 APPENDIX E. APPROXIMATION THEORY

𝑚−1 𝑚
4 2𝑚
1−sin2𝑚 (𝜃) = ∑ ((−1)𝑛 ( ∑ ( )) cos((2𝑛+1)𝜃) cos(𝜃)). (E.12)
22𝑚 𝑛=0 𝑘=𝑛+1
𝑚+𝑘

The proof ends here, but for completeness, we report the other approach here.
We can start by comparing comparing the first equation of (E.4) with (E.5), we
obtain the following formulas for 𝑎𝑗 :

1 2𝑚
1 − 22𝑚 ( 𝑚 ), if 𝑗 = 0
𝑎𝑗 = { 𝑗−1 2 2𝑚
(−1) 22𝑚 (𝑚−𝑗 ), if 𝑗 ∈ {1, … , 𝑚}.

Using the trigonometric identity 2 cos(𝜃1 ) cos(𝜃2 ) = cos(𝜃1 − 𝜃2 ) + cos(𝜃1 + 𝜃2 ),


the right side of (E.3) simplifies to
𝑚−1 𝑚 2𝑚
𝑛
∑𝑘=𝑛+1 (𝑚+𝑘)
2 ∑ (−1) ( ) (cos((2𝑛 + 2)𝜃) + cos((2𝑛)𝜃)). (E.13)
𝑛=0
22𝑚

Comparing the second equation of (E.4) with (E.13), we obtain the following
formulas for 𝑏𝑘 :
𝑚 𝑚 𝑚
2 2𝑚 1 2𝑚 2𝑚
𝑏0 = ∑( ) = 2𝑚 (∑ ( ) + ∑( ))
22𝑚 𝑘=1
𝑚 + 𝑘 2 𝑘=1
𝑚 + 𝑘 𝑘=1
𝑚 +𝑘
𝑚 2𝑚
1 2𝑚 2𝑚
= (∑ ( ) + ∑ ( ))
22𝑚 𝑘=1
𝑚−𝑘 𝑘=𝑚+1
𝑘
𝑚−1 2𝑚
1 2𝑚 2𝑚
= (∑ ( ) + ∑ ( ))
22𝑚 𝑘=0
𝑘 𝑘=𝑚+1
𝑘
2𝑚
1 2𝑚 2𝑚
= (∑ ( ) − ( ))
22𝑚 𝑘=0
𝑘 𝑚
1 2𝑚
=1− ( ),
22𝑚 𝑚

and, for 𝑗 ∈ {1, … , 𝑚 − 1},


𝑚 𝑚
2 2𝑚 2 2𝑚
𝑏𝑗 = (−1)𝑗−1 ∑ ( ) + 2𝑚 (−1)𝑗 ∑ ( )
22𝑚 𝑙=𝑗
𝑚 + 𝑙 2 𝑙=𝑗+1
𝑚 +𝑙
2 2𝑚
= (−1)𝑗−1 ( )
22𝑚 𝑚+𝑗
2 2𝑚
= 2𝑚 (−1)𝑗−1 ( ),
2 𝑚−𝑗
E.2. POLYNOMIAL APPROXIMATION OF 1/𝑥 275

and, for 𝑗 = 𝑚,
1 2𝑚 (−1)𝑚−1
𝑏𝑚 = (−1)𝑚−1 ( ) = .
22𝑚 2𝑚 22𝑚
Thus, 𝑎𝑗 = 𝑏𝑗 for all 𝑗 ∈ {0, … , 𝑚}.

Although 𝑔𝑚 is the sum of 𝑚 Chebyshev polynomials, the following lemma


shows that for 𝑚 large enough the sum can be truncated while still remaining
close to 𝑔𝑚 .
Lemma E.5. Let 0 < 𝜖 < 1 and 𝑚 ∈ ℕ ∩ [2, ∞[. Set 𝑘0 ∶= min{𝑚 −
1, ⌊√3𝑚 log(4(𝑚 − 1)/𝜖)⌋}. Then,

𝑘0 𝑚 2𝑚
∑𝑘=𝑛+1 (𝑚+𝑘)
∣𝑔𝑚 (𝑥) − 4 ∑(−1)𝑛 ( ) 𝑇2𝑛+1 (𝑥)∣ ≤ 𝜖 (E.14)
𝑛=0
22𝑚

for all 𝑥 ∈ [−1, 1].

Proof. If 𝑘0 = 𝑚 − 1 then we know from Lemma E.4 that the left side of
Inequality (E.14) is 0. Next, assume 𝑘0 < 𝑚 − 1. Consider a random variable 𝑋
that follows the binomial distribution with parameters 2𝑚 and 1/2. It is very
simple to see that the expected value of this random variable is just 𝑚. The
probability of getting at least 𝑚 + 𝑛 + 1, 𝑛 < 𝑚, successes in 2𝑚 independent
Bernoulli trials is given by

𝑚
1 2𝑚
Pr(𝑋 ≥ 𝑚 + 𝑛 + 1) = ∑ ( ).
22𝑚 𝑘=𝑛+1
𝑚+𝑘
On the other hand, the Chernoff bound of Theorem C.8 gives
𝑘+1 −((𝑘+1)/𝑚)2 𝑚 𝑘2
Pr(𝑋 ≥ 𝑚 + 𝑘 + 1) = Pr (𝑋 ≥ (1 + ) 𝑚) ≤ 𝑒 2+(𝑘+1)/𝑚 ≤ 𝑒− 3𝑚 .
𝑚

Therefore, we have

𝑘0 𝑚 2𝑚 𝑚−1 𝑚 2𝑚
𝑛
∑𝑘=𝑛+1 (𝑚+𝑘) ∑𝑘=𝑛+1 (𝑚+𝑘)
∣𝑔𝑚 (𝑥) − 4 ∑(−1) ( ) 𝑇2𝑛+1 (𝑥)∣ = ∣4 ∑ ( ) 𝑇2𝑛+1 (𝑥)∣
𝑛=0
22𝑚 𝑛=𝑘0 +1
22𝑚
𝑚−1
𝑘2
≤ ∣4 ∑ 𝑒− 3𝑚 𝑇2𝑛+1 (𝑥)∣
𝑛=𝑘0 +1
𝑘2
0
≤ 4(𝑚 − 1)𝑒− 3𝑚
≤ 𝜖,
where we used the fact the 𝑇2𝑛+1 (𝑥)| ≤ 1 for 𝑥 ∈ [−1, 1].
276 APPENDIX E. APPROXIMATION THEORY

We are now ready to state the main result of this section that expresses the
fact that the function 1/𝑥 can be approximated arbitrarily closely by linear
combination of Chebyshev polynomials with a minimal number of terms.
Corollary E.1 (Low degree polynomial approximation of 1/x). Let 0 < 𝜖 < 1
and 0 < 𝛿 < 1. Set 𝑚 ∶= ⌈𝛿 −2 log(2/(𝜖𝛿))⌉ and 𝑘0 ∶= 0 if 𝑚 = 1 or 𝑘0 ∶=
min{𝑚 − 1, ⌊√3𝑚 log(8(𝑚 − 1)/𝜖)⌋} otherwise. Then,
𝑘0 𝑚
2𝑚
1 𝑛
∑𝑘=𝑛+1 (𝑚+𝑘 )
∣ − 4 ∑(−1) ( 2𝑚
) 𝑇2𝑛+1 (𝑥)∣ ≤ 𝜖 (E.15)
𝑥 𝑛=0
2

for all 𝑥 ∈ [−1, −𝛿] ∪ [𝛿, 1].

Proof. This is an immediate consequence of Lemmas E.3, E.4, and E.5.


2 2𝑚
Interestingly, there is another way of obtaining the decomposition of 1−(1−𝑥
𝑥
)

with Chebychev polynomials, which is more akin to the canonical way one would
approach the problem, so we report it here as an exercise, as it might be more
mathematically challenging to solve than what we presented before.
Exercise E.1. Can you prove Lemma E.4 using the orthogonality of Chebychev
polynomials?

Proof. We give just a hint for the proof.


1
𝑥 = ∑ 𝑎𝑛 𝑇𝑛 (𝑥) (E.16)
(1 − 𝑥2 )2𝑚 𝑛=0

what we want is an explicit expression for 𝑎𝑛 , so we exploit the orthogonality of


1
Chebychev polynomials (which are orthogonal under the measure 𝜇(𝑥) = √1−𝑥 2

on the interval [1, 1], i.e. we have:

1 ⎧0 𝑖𝑓𝑛 ≠ 𝑚,
d𝑥 {
∫ 𝑇𝑛 (𝑥) 𝑇𝑚 (𝑥) √ = ⎨𝜋 𝑖𝑓𝑛 = 𝑚 = 0, (E.17)
−1 1 − 𝑥2 {𝜋
⎩2 𝑖𝑓𝑛 = 𝑚 ≠ 0.

Therefore, multiplying by a polynomial 𝑇𝑙 (𝑥) and the measure 𝜇(𝑥) on both


sides, we can read

1 1 ∞ ∞
1 − (1 − 𝑥2 )2𝑚 𝑇𝑙 (𝑥) 𝑇 𝑇 𝜋 𝜋
∫ √ = ∫ ∑ 𝑎𝑛 √ 𝑛 𝑙 = ∑ 𝑎𝑛 𝑑𝑥 = 𝑎𝑛 .
−1 𝑥 1−𝑥 2
−1 𝑛=0 1−𝑥 2
𝑛=0
2 2
(E.18)
The task now is to compute the integral on the l.h.s..
E.3. POLYNOMIAL APPROXIMATION OF OTHER FUNCTIONS 277

E.3 Polynomial approximation of other func-


tions
278 APPENDIX E. APPROXIMATION THEORY
Appendix F

Contributions and
acknowledgements

Hello! I am Alessandro Luongo, and these are my first lecture notes in quantum
algorithms! They spurred out from my old blog, back in 2016/2017. Then, they
took a more concrete form out of my Ph.D. thesis (which I made at IRIF with
the support of Atos, which I thank), and now are in this extended form with
the hope to serve the future researchers in QML. While I strive to be as precise
as the lecture notes of Ronald de Wolf and Andrew Childs, I know this work is
still far from the level of quality I aspire to. If you want to give me any feedback,
feel free to write me at “scinawa - at - luongo - dot - pro”. Or contact me on
Twitter.

Ciao, Ale.

Core team

This work has been made possible only thanks to the help of the team of the
Open-Source project of [Link]:

• Armando ‘ikiga1’ Bellante

279
280 APPENDIX F. CONTRIBUTIONS AND ACKNOWLEDGEMENTS

• Hue Jun Hao Alexander

Contributors
The contributors to the project are:
• Patrick Rebentrost
• Yassine Hamoudi
• Martin Plávala
• Trong Duong
• Filippo Miatto
• Jinge Bao
• Michele Vischi
• Samantha Buck
• Adrian Lee
• Ethan Hansen
• Lei Fan
• Giacomo De Leva
• Pablo Rotondo
• João Doriguello
• Avhijit_Nair
• Marco Caselli
Funding
This website is supported by:
• [Link].
• Centre for Quantum Technologies
Suppliers
A big thanks to:
• 42LF for the legal support,
• Lorenzo Gecchelin for the graphics.
F.1. LICENSE AND CITATION 281

In sparse order, I would like to thank Dong Ping Zhang, Mehdi Mhalla , Simon
Perdrix, Tommaso Fontana, and Nicola Vitucci for the initial help with the
previous version of this project, and the helpful words of encouragement.

F.1 License and citation


The website [Link] by Alessandro Luongo is licensed under CC
BY-NC-SA 4.0
@misc{quantumalgorithms,
title={Quantum algorithms for data analysis},
author={Luongo, Alessandro},
url={[Link]
year={2020}
}

The CSS style file comes from here.

F.2 Cookie Policy


The website [Link] (the “Website”) uses cookies for
the following purposes: allowing online authentication, monitoring sessions and
memorising information on specific configurations of users accessing the server.
This document sets out detailed information on the use of cookies and similar
technology, how they are used by the Website and how to manage them. Visitors
are able to configure their own browsers so that they are alerted to the use of
cookies or they may otherwise refuse them. Browser acceptance of cookies can
be disabled by changing your settings.

F.2.0.1 DEFINITIONS
Cookies are small strings of text (letters or numbers) that allow a web server to
memorise browser information that can be used during the same session (session
cookies) or at a later stage, even days later (persistent cookies). Cookies are
memorised in accordance with the user settings by the individual browser on
the device being used (computer, tablet, smartphone).

F.2.0.2 TYPES OF COOKIES


There are different categories of cookies and each has its own characteristics and
uses:
• Technical cookies: this type of cookie is essential for a website to function
properly and they are only used to the extent required for the transmission
of communications over an electronic communication network, or to the ex-
tent strictly necessary for the supplier of an information service explicitly
requested by the subscriber or by the user to supply that service;
282 APPENDIX F. CONTRIBUTIONS AND ACKNOWLEDGEMENTS

• Analytical cookies: this type of cookie is used to anonymously collect


and analyse the traffic to and use of a website. Without identifying the
user, they make it possible for example, to detect whether said user has
subsequently accessed the website. They also make it possible to monitor
the system and enhance the services and user experience. These cookies
may be disabled without affecting the functioning of a website.
• Profiling cookies: these are persistent cookies used to identify (anony-
mously and not) user preferences and to enhance the navigation experi-
ence.
• Third-party cookies (analytical and/or profiling): these are generated by
companies other than the actual website and integrated into a website’s
pages, for example Google widgets (such as Google Maps) or social plugins
(Facebook, Twitter, LinkedIn, Google+, etc.). The management of infor-
mation that is collected by a “third party” is regulated by the relevant
privacy statement, which you are requested to read. For ease of reference,
they are indicated in the links set out below.

F.2.0.3 TYPES OF COOKIES USED


The Website uses the following type of cookies:
• Third-party analytical cookies: Google Analytics, a web traffic analysis
service provided by Google Inc. (“Google”), which makes it possible to
access and analyse detailed statistics on website visitors. The Google
Analytics service has been designed to use pre-anonymised data so as to
conceal the last part of the visitor’s IP address. For further information,
please see [Link] Users may
disable Google Analytics by installing on their browser the opt-out add-
on tool provided by Google (please see [Link]
gaoptout)

F.2.0.4 DURATION
Some cookies (called session cookies) remain active until a user closes their
browser. Other cookies (called persistent cookies) “survive” the closure of the
browser and are available in subsequent user visits. Their duration is set by the
server when they are created: in some cases, there is a set expiry date whereas
in other cases their duration is unlimited. However, they may always be deleted
using browser settings. The majority of the cookies we use are persistent and
expire 2 years from the date when they are downloaded onto the Visitor’s device.

F.2.0.5 MANAGEMENT
Visitors may accept or refuse cookies via their browser settings. Content may
be accessed even if cookies are completely disabled and disabling “third–party
technical” cookies will not prevent a visitor from using a website. It could
however adversely impact the User’s experience (insofar as it is not possible
F.2. COOKIE POLICY 283

to memorise their data for future use). Settings can be changed for different
websites and/or website applications. Moreover, the leading browsers allow
users to change their settings depending on the type of cookie:
• Firefox: [Link]
• Internet Explorer: [Link]
windows-internet-explorer-delete-manage-cookies
• Chrome: [Link]
• Opera: [Link]
• Safari for Mac: [Link]
IT&locale=it_IT
• Safari for iOS: [Link]
Third parties are hereby informed that the use of this policy, even partial, for
other websites shall be subject to sanctions by the Italian Data Protection Au-
thority. This page may be accessed via the link set out in the footer of all the
website’s pages, pursuant to Article 122(2) of Legislative Decree 196/2003 and
the simplified process for privacy information and the acquisition of consent to
the use of cookies published on the Italian Official Journal no. 126 of 3 June
2014 and the relevant register of measures 229 dated 8 May 2014.
284 APPENDIX F. CONTRIBUTIONS AND ACKNOWLEDGEMENTS
Appendix G

References

285
286 APPENDIX G. REFERENCES
Bibliography

Aaronson, S. and Rall, P. (2020). Quantum approximate counting, simplified.


In Symposium on Simplicity in Algorithms, pages 24–32. SIAM.

Aharonov, D. and Touati, Y. (2018). Quantum circuit depth lower bounds for
homological codes. arXiv preprint arXiv:1810.03912.

Ahmadi, H. and Chiang, C.-F. (2010). Quantum phase estimation with arbitrary
constant-precision phase shift operators. arXiv preprint arXiv:1012.4727.

Allcock, J., Bao, J., Doriguello, J. F., Luongo, A., and Santha, M. (2023).
Constant-depth circuits for uniformly controlled gates and boolean functions
with application to quantum memory circuits.

Ambainis, A. (2002). Quantum lower bounds by quantum arguments. Journal


of Computer and System Sciences, 64(4):750–767.

Ambainis, A. (2007). Quantum walk algorithm for element distinctness. SIAM


Journal on Computing, 37(1):210–239.

Ambainis, A. (2012a). Variable time amplitude amplification and a faster quan-


tum algorithm for solving systems of linear equations 29th int. In Symp.
Theoretical Aspects of Computer Science (STACS 2012), volume 14, pages
636–47.

Ambainis, A. (2012b). Variable time amplitude amplification and quantum


algorithms for linear algebra problems. In STACS’12 (29th Symposium on
Theoretical Aspects of Computer Science), volume 14, pages 636–647. LIPIcs.

Ambainis, A., Buhrman, H., Leijnse, K., Patro, S., and Speelman, F. (2022).
Matching triangles and triangle collection: Hardness based on a weak quan-
tum conjecture. arXiv preprint arXiv:2207.11068.

An, D. and Lin, L. (2022). Quantum linear system solver based on time-optimal
adiabatic quantum computing and quantum approximate optimization algo-
rithm. ACM Transactions on Quantum Computing, 3(2):1–28.

Andrew, C. (2017). Lecture notes on quantum algorithms.

287
288 BIBLIOGRAPHY

Araujo, I. F., Park, D. K., Petruccione, F., and da Silva, A. J. (2021). A divide-
and-conquer algorithm for quantum state preparation. Scientific Reports,
11(1):6329.

Arrazola, J. M., Delgado, A., Bardhan, B. R., and Lloyd, S. (2020). Quantum-
inspired algorithms in practice. Quantum, 4:307.

Arthur, D. and Vassilvitskii, S. (2006). How slow is the k-means method? In


Proceedings of the twenty-second annual symposium on Computational geom-
etry, pages 144–153. ACM.

Arthur, D. and Vassilvitskii, S. (2007). k-means++: The advantages of care-


ful seeding. In Proceedings of the eighteenth annual ACM-SIAM symposium
on Discrete algorithms, pages 1027–1035. Society for Industrial and Applied
Mathematics.

Arunachalam, S., Gheorghiu, V., Jochym-O’Connor, T., Mosca, M., and Srini-
vasan, P. V. (2015). On the robustness of bucket brigade quantum ram. New
Journal of Physics, 17(12):123010.

Babbush, R., Gidney, C., Berry, D. W., Wiebe, N., McClean, J., Paler, A.,
Fowler, A., and Neven, H. (2018). Encoding electronic spectra in quantum
circuits with linear t complexity. Physical Review X, 8(4):041015.

Bausch, J. (2022). Fast black-box quantum state preparation. Quantum, 6:773.

Bausch, J., Subramanian, S., and Piddock, S. (2021). A quantum search decoder
for natural language processing. Quantum Machine Intelligence, 3(1):1–24.

Beals, R., Brierley, S., Gray, O., Harrow, A. W., Kutin, S., Linden, N., Shep-
herd, D., and Stather, M. (2013). Efficient distributed quantum computing.
Proceedings of the Royal Society A: Mathematical, Physical and Engineering
Sciences, 469(2153):20120686.

Bellante, A. and Zanero, S. (2022). Quantum matching pursuit: A quantum


algorithm for sparse representations. Physical Review A, 105(2):022414.

Bergholm, V., Vartiainen, J. J., Möttönen, M., and Salomaa, M. M. (2005).


Quantum circuits with uniformly controlled one-qubit gates. Phys. Rev. A,
71:052330.

Berkes, P. (2005). Pattern Recognition with Slow Feature Analysis. Cognitive


Sciences EPrint Archive (CogPrints), 4104.

Berkes, P. and Wiskott, L. (2005). Slow feature analysis yields a rich repertoire
of complex cell properties. Journal of Vision, 5(6).

Bernstein, D. J., Jeffery, S., Lange, T., and Meurer, A. (2013). Quantum
algorithms for the subset-sum problem. In International Workshop on Post-
Quantum Cryptography, pages 16–33. Springer.
BIBLIOGRAPHY 289

Berry, D. W., Childs, A. M., Cleve, R., Kothari, R., and Somma, R. D. (2015a).
Simulating hamiltonian dynamics with a truncated taylor series. Physical
review letters, 114(9):090502.
Berry, D. W., Childs, A. M., and Kothari, R. (2015b). Hamiltonian simulation
with nearly optimal dependence on all parameters. In 2015 IEEE 56th Annual
Symposium on Foundations of Computer Science, pages 792–809. IEEE.
Biernacki, C., Celeux, G., and Govaert, G. (2003). Choosing starting values for
the EM algorithm for getting the highest likelihood in multivariate gaussian
mixture models. Computational Statistics & Data Analysis, 41(3-4):561–575.
Blaschke, T. and Wiskott, L. (2004). Independent slow feature analysis and
nonlinear blind source separation. In International Conference on Independent
Component Analysis and Signal Separation, pages 742–749. Springer.
Blömer, J. and Bujna, K. (2013). Simple methods for initializing the EM algo-
rithm for gaussian mixture models. CoRR.
Borga, M., Landelius, T., and Knutsson, H. (1997). A unified approach to pca,
pls, mlr and cca. Linköping University, Department of Electrical Engineering.
Boyer, M., Brassard, G., Høyer, P., and Tapp, A. (1998). Tight bounds on
quantum searching. Fortschritte der Physik: Progress of Physics, 46(4-5):493–
505.
Brassard, G., Dupuis, F., Gambs, S., and Tapp, A. (2011). An optimal quantum
algorithm to approximate the mean and its application for approximating
the median of a set of points over an arbitrary distance. arXiv preprint
arXiv:1106.4267.
Brassard, G., Hoyer, P., Mosca, M., and Tapp, A. (2002). Quantum amplitude
amplification and estimation. Contemporary Mathematics, 305:53–74.
Buhrman, H., Cleve, R., de Wolf, R., and Zalka, C. (1999). Bounds for small-
error and zero-error quantum algorithms. In 40th Annual Symposium on Foun-
dations of Computer Science (Cat. No. 99CB37039), pages 358–368. IEEE.
Buhrman, H., Cleve, R., Watrous, J., and de Wolf, R. (2001a). Quantum
fingerprinting. Physical Review Letters, 87(16):167902.
Buhrman, H., Folkertsma, M., Loff, B., and Neumann, N. M. (2023a).
State preparation by shallow circuits using feed forward. arXiv preprint
arXiv:2307.14840.
Buhrman, H., Folkertsma, M., Loff, B., and Neumann, N. M. P. (2023b).
State preparation by shallow circuits using feed forward. arXiv preprint
arXiv:2307.14840.
Buhrman, H., Loff, B., Patro, S., and Speelman, F. (2022). Memory compression
with quantum random-access gates. arXiv preprint arXiv:2203.05599.
290 BIBLIOGRAPHY

Buhrman, H., Tromp, J., and Vitányi, P. (2001b). Time and space bounds for
reversible simulation. In International Colloquium on Automata, Languages,
and Programming, pages 1017–1027. Springer.
Cade, C. and Montanaro, A. (2017). The quantum complexity of computing
schatten 𝑝-norms. arXiv preprint arXiv:1706.09279.
Camps, D., Lin, L., Van Beeumen, R., and Yang, C. (2024). Explicit quantum
circuits for block encodings of certain sparse matrices. SIAM Journal on
Matrix Analysis and Applications, 45(1):801–827.
Celeux, G. and Govaert, G. (1992). A classification EM algorithm for cluster-
ing and two stochastic versions. Computational statistics & Data analysis,
14(3):315–332.
Chakrabarti, S., Krishnakumar, R., Mazzola, G., Stamatopoulos, N., Woerner,
S., and Zeng, W. J. (2021). A threshold for quantum advantage in derivative
pricing. Quantum, 5:463.
Chakraborty, S., Gilyén, A., and Jeffery, S. (2019). The power of block-encoded
matrix powers: Improved regression techniques via faster hamiltonian simu-
lation. In 46th International Colloquium on Automata, Languages, and Pro-
gramming (ICALP 2019). Schloss Dagstuhl-Leibniz-Zentrum fuer Informatik.
Chakraborty, S., Morolia, A., and Peduri, A. (2022). Quantum regularized least
squares. arXiv preprint arXiv:2206.13143.
Childs, A. M., Kothari, R., and Somma, R. D. (2015). Quantum linear systems
algorithm with exponentially improved dependence on precision.
Childs, A. M., Kothari, R., and Somma, R. D. (2017). Quantum Algorithm
for Systems of Linear Equations with Exponentially Improved Dependence
on Precision. SIAM Journal on Computing, 46(6):1920–1950.
Childs, A. M. and Wiebe, N. (2012). Hamiltonian simulation using linear com-
binations of unitary operations. arXiv preprint arXiv:1202.5822.
Church, K. W. and Gale, W. A. (1995). Poisson mixtures. Natural Language
Engineering, 1(2):163–190.
Cong, I. and Duan, L. (2015). Quantum discriminant analysis for dimensionality
reduction and classification. arXiv preprint arXiv:1510.00113.
Costa, P., An, D., Sanders, Y. R., Su, Y., Babbush, R., and Berry, D. W. (2021).
Optimal scaling quantum linear systems solver via discrete adiabatic theorem.
arXiv preprint arXiv:2111.08152.
Cuccaro, S. A., Draper, T. G., Kutin, S. A., and Moulton, D. P. (2004). A new
quantum ripple-carry addition circuit. arXiv preprint quant-ph/0410184.
De Bie, T., Cristianini, N., and Rosipal, R. (2005). Eigenproblems in pattern
recognition. In Handbook of Geometric Computing, pages 129–167. Springer.
BIBLIOGRAPHY 291

de Brugière, T. G. (2020). Methods for optimizing the synthesis of quantum


circuits. PhD thesis, Université Paris-Saclay.
de Veras, T. M., da Silva, L. D., and da Silva, A. J. (2022). Double sparse
quantum state preparation. Quantum Information Processing, 21(6):204.
de Wolf, R. (2019). Quantum computing: Lecture notes. arXiv:1907.09415.
Deerwester, S., Dumais, S. T., Furnas, G. W., Landauer, T. K., and Harshman,
R. (1990). Indexing by latent semantic analysis. Journal of the American
society for information science, 41(6):391–407.
Dervovic, D., Herbster, M., Mountney, P., Severini, S., Usher, N., and Wossnig,
L. (2018). Quantum linear systems algorithms: a primer. arXiv preprint
arXiv:1802.08227.
Deutsch, D. and Jozsa, R. (1992). Rapid solution of problems by quantum com-
putation. Proceedings of the Royal Society of London. Series A: Mathematical
and Physical Sciences, 439(1907):553–558.
Dexter, A. and Tanner, D. (1972). Packing densities of mixtures of spheres with
log-normal size distributions. Nature physical science, 238(80):31.
Di Matteo, O., Gheorghiu, V., and Mosca, M. (2020). Fault-tolerant resource es-
timation of quantum random-access memories. IEEE Transactions on Quan-
tum Engineering, 1:1–13.
Doriguello, J. F., Giapitzakis, G., Luongo, A., and Morolia, A. (2024). On the
practicality of quantum sieving algorithms for the shortest vector problem.
arXiv preprint arXiv:2410.13759.
Doriguello, J. F., Luongo, A., Bao, J., Rebentrost, P., and Santha, M. (2022).
Quantum algorithm for stochastic optimal stopping problems with applica-
tions in finance. Schloss Dagstuhl – Leibniz-Zentrum für Informatik.
Dörn, S. (2008). Quantum complexity of graph and algebraic problems. PhD
thesis, Universität Ulm.
Drineas, P., Kerenidis, I., and Raghavan, P. (2002). Competitive recommenda-
tion systems. In Proceedings of the thiry-fourth annual ACM symposium on
Theory of computing, pages 82–90. ACM.
Duan, B., Yuan, J., Yu, C.-H., Huang, J., and Hsieh, C.-Y. (2020). A survey
on hhl algorithm: From theory to application in quantum machine learning.
Physics Letters A, 384(24):126595.
Dürr, C., Heiligman, M., Høyer, P., and Mhalla, M. (2004). Quantum query
complexity of some graph problems *.
Dürr, C., Heiligman, M., HOyer, P., and Mhalla, M. (2006). Quantum query
complexity of some graph problems. SIAM Journal on Computing, 35(6):1310–
1328.
292 BIBLIOGRAPHY

Durr, C. and Hoyer, P. (1996). A quantum algorithm for finding the minimum.
arXiv preprint quant-ph/9607014.
Eckart, C. and Young, G. (1936). The approximation of one matrix by another
of lower rank. Psychometrika, 1(3):211–218.

Escalante-B, A. N. and Wiskott, L. (2012). Slow feature analysis: Perspectives


for technical applications of a versatile learning algorithm. KI-Künstliche
Intelligenz, 26(4):341–348.
Ghitany, M., Maller, R. A., and Zhou, S. (1994). Exponential mixture models
with long-term survivors and covariates. Journal of multivariate Analysis,
49(2):218–241.

Ghojogh, B., Karray, F., and Crowley, M. (2019). Eigenvalue and generalized
eigenvalue problems: Tutorial. arXiv preprint arXiv:1903.11240.
Gidney, C. (2018). Halving the cost of quantum addition. Quantum, 2:74.
Gidney, C. and Ekerå, M. (2021). How to factor 2048 bit rsa integers in 8 hours
using 20 million noisy qubits. Quantum, 5:433.
Gilyén, A. and Li, T. (2019). Distributional property testing in a quantum
world. arXiv preprint arXiv:1902.00814.
Gilyén, A., Su, Y., Low, G. H., and Wiebe, N. (2019). Quantum singular value
transformation and beyond: exponential improvements for quantum matrix
arithmetics. In Proceedings of the 51st Annual ACM SIGACT Symposium on
Theory of Computing, pages 193–204.
Giovannetti, V., Lloyd, S., and Maccone, L. (2008a). Architectures for a quan-
tum random access memory. Physical Review A, 78(5):052310.

Giovannetti, V., Lloyd, S., and Maccone, L. (2008b). Quantum random access
memory. Physical review letters, 100(16):160501.
Gleinig, N. and Hoefler, T. (2021). An efficient algorithm for sparse quantum
state preparation. In 2021 58th ACM/IEEE Design Automation Conference
(DAC), pages 433–438. IEEE.

Gosset, D., Kothari, R., and Wu, K. (2024). Quantum state preparation with
optimal t-count. arXiv preprint arXiv:2411.04790.
Greenacre, M. J. (1984). Theory and applications of correspondence analysis.
Gribling, S., Kerenidis, I., and Szilágyi, D. (2021). Improving quantum
linear system solvers via a gradient descent perspective. arXiv preprint
arXiv:2109.04248.
Grinko, D., Gacon, J., Zoufal, C., and Woerner, S. (2019). Iterative quantum
amplitude estimation. arXiv preprint arXiv:1912.05559.
BIBLIOGRAPHY 293

Grover, L. and Rudolph, T. (2002). Creating superpositions that correspond


to efficiently integrable probability distributions. arXiv preprint quant-
ph/0208112.
Grover, L. K. (2000). Synthesis of quantum superpositions by quantum compu-
tation. Physical review letters, 85(6):1334.
Grover, L. K. (2005). Fixed-point quantum search. Physical Review Letters,
95(15):150501.
Gu, X., Liu, C., and Wang, S. (2013). Supervised Slow Feature Analysis for
Face Recognition. pages 178–184.
Gur, T., Hsieh, M.-H., and Subramanian, S. (2021). Sublinear quantum algo-
rithms for estimating von neumann entropy. arXiv preprint arXiv:2111.11139.
Gyurik, C., Cade, C., and Dunjko, V. (2020). Towards quantum advantage for
topological data analysis. arXiv preprint arXiv:2005.02607.
Hamoudi, Y. and Magniez, F. (2018). Quantum chebyshev’s inequality and
applications. arXiv preprint arXiv:1807.06456.
Hamoudi, Y., Ray, M., Rebentrost, P., Santha, M., Wang, X., and Yang, S.
(2020). Quantum algorithms for hedging and the sparsitron. arXiv preprint
arXiv:2002.06003.
Hann, C. T. (2021). Practicality of Quantum Random Access Memory. PhD
thesis, Yale University.
Hann, C. T., Lee, G., Girvin, S., and Jiang, L. (2021). Resilience of quantum
random access memory to generic noise. PRX Quantum, 2(2):020311.
Harrow, A. W., Hassidim, A., and Lloyd, S. (2009). Quantum Algorithm for
Linear Systems of Equations. Physical Review Letters, 103(15):150502.
Harun-Ur-Rashid (2018). Research paper dataset.
Hastie, T., Tibshirani, R., and Friedman, J. (2009). The Elements of Statistical
Learning, volume 1 of Springer Series in Statistics. Springer New York, New
York, NY.
Heinrich, S. (2002). Quantum summation with an application to integration.
Journal of Complexity, 18(1):1–50.
Herbert, S. (2021). No quantum speedup with grover-rudolph state preparation
for quantum monte carlo integration. Physical Review E, 103(6):063302.
Hogan, R. (2006). How to combine errors.
Holmes, A. and Matsuura, A. Y. (2020). Efficient quantum circuits for accurate
state preparation of smooth, differentiable functions. In 2020 IEEE Inter-
national Conference on Quantum Computing and Engineering (QCE), pages
169–179. IEEE.
294 BIBLIOGRAPHY

Hsu, H., Salamatian, S., and Calmon, F. P. (2019). Correspondence analysis


using neural networks. In The 22nd International Conference on Artificial
Intelligence and Statistics, pages 2671–2680.
Huang, H.-Y., Bharti, K., and Rebentrost, P. (2019). Near-term quantum algo-
rithms for linear systems of equations. arXiv preprint arXiv:1909.07344.
Iske, A. (2018). Approximation Theory and Algorithms for Data Analysis.
Springer.
Jeffery, S. (2014). Frameworks for quantum algorithms.
Kalai, A. T., Moitra, A., and Valiant, G. (2012). Disentangling gaussians. Com-
munications of the ACM, 55(2):113–120.
Kapoor, A., Wiebe, N., and Svore, K. (2016). Quantum perceptron models. In
Advances in Neural Information Processing Systems, pages 3999–4007.
Kennedy, T. (2016). Chapter2: Basics of direct Monte Carlo.
Kerenidis, I., Landman, J., Luongo, A., and Prakash, A. (2019a). q-means: A
quantum algorithm for unsupervised machine learning. In Advances in Neural
Information Processing Systems, pages 4136–4146.
Kerenidis, I., Landman, J., and Prakash, A. (2019b). Quantum algorithms for
deep convolutional neural networks. arXiv preprint arXiv:1911.01117.
Kerenidis, I. and Luongo, A. (2020). Classification of the mnist data set with
quantum slow feature analysis. Physical Review A, 101(6):062327.
Kerenidis, I. and Prakash, A. (2017). Quantum recommendation systems. Pro-
ceedings of the 8th Innovations in Theoretical Computer Science Conference.
Kerenidis, I. and Prakash, A. (2018). A quantum interior point method for LPs
and SDPs. arXiv:1808.09266.
Kerenidis, I. and Prakash, A. (2020). Quantum gradient descent for linear
systems and least squares. Physical Review A, 101(2):022316.
Kitaev, A. Y. (1996). Quantum measurements and the abelian stabilizer prob-
lem. In Electronic Colloq. on Computational Complexity.
Krishnakumar, R., Soeken, M., Roetteler, M., and Zeng, W. (2022). Aq#
implementation of a quantum lookup table for quantum arithmetic functions.
In 2022 IEEE/ACM Third International Workshop on Quantum Computing
Software (QCS), pages 75–82. IEEE.
Krizhevsky, A. et al. (2009). Learning multiple layers of features from tiny
images.
Ku, H. H. et al. (1966). Notes on the use of propagation of error formulas.
Journal of Research of the National Bureau of Standards, 70(4):263–273.
BIBLIOGRAPHY 295

Kuperberg, G. (2011). Another subexponential-time quantum algorithm for the


dihedral hidden subgroup problem. arXiv preprint arXiv:1112.3333.
LeCun, Y. (1998). The mnist database of handwritten digits. [Link] lecun.
com/exdb/mnist/.

Lin, L. and Tong, Y. (2020). Optimal polynomial based quantum eigenstate


filtering with application to solving quantum linear systems. Quantum, 4:361.
Litinski, D. and Nickerson, N. (2022). Active volume: An architecture for
efficient fault-tolerant quantum computers with limited non-local connections.
arXiv preprint arXiv:2211.15465.

Liu, C. and Rubin, D. B. (1995). ML estimation of the t distribution using EM


and its extensions, ECM and ECME. Statistica Sinica, pages 19–39.
Lloyd, S. (1982). Least squares quantization in pcm. IEEE transactions on
information theory, 28(2):129–137.
Lloyd, S., Mohseni, M., and Rebentrost, P. (2013). Quantum principal compo-
nent analysis. Nature Physics, 10(9):631–633.
Lloyd, S., Mohseni, M., and Rebentrost, P. (2014). Quantum principal compo-
nent analysis. Nature Physics, 10(9):631.
Low, G. H. and Chuang, I. L. (2017). Hamiltonian simulation by uniform spec-
tral amplification. arXiv preprint arXiv:1707.05391.
Low, G. H. and Chuang, I. L. (2019). Hamiltonian simulation by qubitization.
Quantum, 3:163.
Low, G. H., Kliuchnikov, V., and Schaeffer, L. (2018). Trading t-gates for
dirty qubits in state preparation and unitary synthesis. arXiv preprint
arXiv:1812.00954.
Luongo, A., Miti, A. M., Narasimhachar, V., and Sireesh, A. (2024).
Measurement-based uncomputation of quantum circuits for modular arith-
metic. arXiv preprint arXiv:2407.20167.
Manara, M., Perotti, A., and Scapellato, R. (2007). Geometria e algebra lineare.
Esculapio.
Markov (1890). On a question by d. i. mendeleev. Zap. Imp. Akad. Nauk. St.
Petersburg.
Mathur, N., Landman, J., Li, Y. Y., Strahm, M., Kazdaghli, S., Prakash, A.,
and Kerenidis, I. (2022). Medical image classification via quantum neural
networks.
McArdle, S., Gilyén, A., and Berta, M. (2022). Quantum state preparation
without coherent arithmetic. arXiv preprint arXiv:2210.14892.
296 BIBLIOGRAPHY

Metger, T. and Yuen, H. (2023). stateqip= statepspace. In 2023 IEEE 64th


Annual Symposium on Foundations of Computer Science (FOCS), pages 1349–
1356. IEEE.
Mitchell, T. M. et al. (1997). Machine learning.
Miyahara, H., Aihara, K., and Lechner, W. (2020). Quantum expectation-
maximization algorithm. Physical Review A, 101(1):012326.
Moitra, A. (2018). Algorithmic aspects of machine learning. Cambridge Univer-
sity Press.
Montanaro, A. (2015). Quantum speedup of monte carlo methods. Proceedings
of the Royal Society A: Mathematical, Physical and Engineering Sciences,
471(2181):20150301.
Moosa, M., Watts, T. W., Chen, Y., Sarma, A., and McMahon, P. L. (2023).
Linear-depth quantum circuits for loading fourier approximations of arbitrary
functions. Quantum Science and Technology, 9(1):015002.
Mori, H., Mitarai, K., and Fujii, K. (2024). Efficient state preparation for
multivariate monte carlo simulation. arXiv preprint arXiv:2409.07336.
Murphy, K. P. (2012). Machine learning: a probabilistic perspective. MIT press.
Nannicini, G. (2019). Fast quantum subroutines for the simplex method. arXiv
preprint arXiv:1910.10649.
Ng, A. (2012). Cs229 lecture notes - machine learning. Lecture notes CS229
Stanford.
Nielsen, M. A. and Chuang, I. (2002). Quantum computation and quantum
information.
O’Donnell, R. and Wright, J. (2016). Efficient quantum tomography. In Pro-
ceedings of the forty-eighth annual ACM symposium on Theory of Computing,
pages 899–912.
Otterbach, J., Manenti, R., Alidoust, N., Bestwick, A., Block, M., Bloom,
B., Caldwell, S., Didier, N., Fried, E. S., Hong, S., et al. (2017). Unsu-
pervised machine learning on a hybrid quantum computer. arXiv preprint
arXiv:1712.05771.
O’Donnell, R. (2015). Lecture 13: Lower bounds using the adversary method.
Partridge, M. and Calvo, R. (1997). Fast dimensionality reduction and simple
pca. Intelligent data analysis, 2(3):292–298.
Paturi, R. (1992). On the degree of polynomials that approximate symmetric
boolean functions (preliminary version). In Proceedings of the Twenty-Fourth
Annual ACM Symposium on Theory of Computing, STOC ’92, page 468–474,
New York, NY, USA. Association for Computing Machinery.
BIBLIOGRAPHY 297

Pedregosa, F., Varoquaux, G., Gramfort, A., Michel, V., Thirion, B., Grisel, O.,
Blondel, M., Prettenhofer, P., Weiss, R., Dubourg, V., Vanderplas, J., Pas-
sos, A., Cournapeau, D., Brucher, M., Perrot, M., and Duchesnay, E. (2011).
Scikit-learn: Machine learning in Python. Journal of Machine Learning Re-
search, 12:2825–2830.
Plesch, M. and Brukner, v. (2011). Quantum-state preparation with universal
gate decompositions. Phys. Rev. A, 83:032302.
Prakash, A. (2014). Quantum Algorithms for Linear Algebra and Machine
Learning. PhD thesis, EECS Department, University of California, Berkeley.
Rattew, A. G. and Koczor, B. (2022). Preparing arbitrary continuous func-
tions in quantum registers with logarithmic complexity. arXiv preprint
arXiv:2205.00519.
Rebentrost, P., Gupt, B., and Bromley, T. R. (2018). Quantum computa-
tional finance: Monte carlo pricing of financial derivatives. Physical Review
A, 98(2):022321.
Rebentrost, P. and Lloyd, S. (2018). Quantum computational finance: quan-
tum algorithm for portfolio optimization. arXiv preprint arXiv:1811.03975,
98(4):042308.
Rebentrost, P., Santha, M., and Yang, S. (2021). Quantum alphatron. arXiv
preprint arXiv:2108.11670.
Rosenkranz, M., Brunner, E., Marin-Sanchez, G., Fitzpatrick, N., Dilkes, S.,
Tang, Y., Kikuchi, Y., and Benedetti, M. (2024). Quantum state preparation
for multivariate functions. arXiv preprint arXiv:2405.21058.
Rosenthal, G. (2021). Query and depth upper bounds for quantum unitaries
via Grover search. arXiv preprint arXiv:2111.07992.
Rosenthal, G. (2024). Efficient quantum state synthesis with one query. In Pro-
ceedings of the 2024 Annual ACM-SIAM Symposium on Discrete Algorithms
(SODA), pages 2508–2534.
Rosenthal, G. and Yuen, H. (2021). Interactive proofs for synthesizing quantum
states and unitaries. arXiv preprint arXiv:2108.07192.
Rudin, W. et al. (1964). Principles of mathematical analysis, volume 3. McGraw-
hill New York.
Sanders, Y. R., Low, G. H., Scherer, A., and Berry, D. W. (2019). Black-
box quantum state preparation without arithmetic. Physical review letters,
122(2):020502.
Schlesinger, E. (2011). Algebra lineare e geometria. Zanichelli.
Schmitt, B., Mozafari, F., Meuli, G., Riener, H., and De Micheli, G. (2021).
From boolean functions to quantum circuits: A scalable quantum compilation
298 BIBLIOGRAPHY

flow in c++. In 2021 Design, Automation & Test in Europe Conference &
Exhibition (DATE), pages 1044–1049. IEEE.

Schuld, M. and Petruccione, F. (2018). Supervised learning with quantum com-


puters, volume 17. Springer.

Schuld, M. and Petruccione, F. (2021). Machine Learning with Quantum Com-


puters. Quantum Science and Technology. Springer International Publishing.

Schuld, M., Sinayskiy, I., and Petruccione, F. (2015). An introduction to quan-


tum machine learning. Contemporary Physics, 56(2):172–185.

Serfozo, R. (2009). Basics of applied stochastic processes. Springer Science &


Business Media.

Shende, V. V., Bullock, S. S., and Markov, I. L. (2006). Synthesis of quantum-


logic circuits. IEEE Transactions on Computer-Aided Design of Integrated
Circuits and Systems, 25(6):1000–1010.

Shende, V. V., Markov, I. L., and Bullock, S. S. (2004). Minimal universal two-
qubit controlled-not-based circuits. Physical Review A—Atomic, Molecular,
and Optical Physics, 69(6):062321.

Soeken, M., Riener, H., Haaswijk, W., Testa, E., Schmitt, B., Meuli, G., Moza-
fari, F., and De Micheli, G. (2018). The epfl logic synthesis libraries. arXiv
preprint arXiv:1805.05121.

Sprekeler, H. and Wiskott, L. (2008). Understanding Slow Feature Analysis:


A Mathematical Framework. Cognitive Sciences EPrint Archive (CogPrints),
6223.

Strang, G. (2016). Introduction to linear algebra. Wellesley - Cambridge Press.

Subaşı, Y., Somma, R. D., and Orsucci, D. (2019). Quantum algorithms for sys-
tems of linear equations inspired by adiabatic quantum computing. Physical
review letters, 122(6):060504.

Subramanian, S., Brierley, S., and Jozsa, R. (2019). Implementing smooth


functions of a hermitian matrix on a quantum computer. Journal of Physics
Communications, 3(6):065002.

Sun, L., Jia, K., Chan, T.-H., Fang, Y., Wang, G., and Yan, S. (2014). Dl-sfa:
deeply-learned slow feature analysis for action recognition. In Proceedings of
the IEEE Conference on Computer Vision and Pattern Recognition, pages
2625–2632.

Sun, X., Tian, G., Yang, S., Yuan, P., and Zhang, S. (2023). Asymptotically
optimal circuit depth for quantum state preparation and general unitary syn-
thesis. IEEE Transactions on Computer-Aided Design of Integrated Circuits
and Systems, 42(10):3301–3314.
BIBLIOGRAPHY 299

Ta-Shma, A. (2013). Inverting well conditioned matrices in quantum logspace.


In Proceedings of the forty-fifth annual ACM symposium on Theory of com-
puting, pages 881–890.
Tang, E. (2018). Quantum-inspired classical algorithms for principal component
analysis and supervised clustering. arXiv preprint arXiv:1811.00414.
van Apeldoorn, J., Gilyén, A., Gribling, S., and de Wolf, R. (2020). Quantum
sdp-solvers: Better upper and lower bounds. Quantum, 4:230.
Walter, M. (2018). Symmetry and quantum information.
Wiebe, N., Kapoor, A., and Svore, K. M. (2018). Quantum nearest-neighbor
algorithms for machine learning. Quantum information and computation, 15.
Wiskott, L., Berkes, P., Franzius, M., Sprekeler, H., and Wilbert, N. (2011).
Slow feature analysis. Scholarpedia, 6(4):5282. revision #137965.
Wiskott Laurenz and Wiskott, L. (1999). Learning invariance manifolds. Neu-
rocomputing, 26-27:925–932.
Wocjan, P., Chiang, C.-F., Nagaj, D., and Abeyesinghe, A. (2009). Quan-
tum algorithm for approximating partition functions. Physical Review A,
80(2):022340.
Xiao, H., Rasul, K., and Vollgraf, R. (2017). Fashion-mnist: a novel im-
age dataset for benchmarking machine learning algorithms. arXiv preprint
[Link]/1708.07747.
Yin, J. and Wang, J. (2014). A dirichlet multinomial mixture model-based
approach for short text clustering. In Proceedings of the 20th ACM SIGKDD
international conference on Knowledge discovery and data mining, pages 233–
242. ACM.
Yoder, T. J., Low, G. H., and Chuang, I. L. (2014). Fixed-point quantum search
with an optimal number of queries. Physical review letters, 113(21):210501.
Yu, C.-H., Gao, F., Lin, S., and Wang, J. (2019). Quantum data compression by
principal component analysis. Quantum Information Processing, 18(8):249.
Yuan, P. and Zhang, S. (2023). Optimal (controlled) quantum state prepara-
tion and improved unitary synthesis by quantum circuits with any number of
ancillary qubits. Quantum, 7:956.
Zhang, K., Hsieh, M.-H., Liu, L., and Tao, D. (2020). Efficient state read-out
for quantum machine learning algorithms. arXiv preprint arXiv:2004.06421.
Zhang, X.-M., Li, T., and Yuan, X. (2022). Quantum state preparation with
optimal circuit depth: Implementations and applications. arXiv preprint
arXiv:2201.11495.
Zhang, X.-M., Yung, M.-H., and Yuan, X. (2021). Low-depth quantum state
preparation. Phys. Rev. Res., 3:043200.
300 BIBLIOGRAPHY

Zhang, Z., Wang, Q., and Ying, M. (2024). Parallel quantum algorithm for
hamiltonian simulation. Quantum, 8:1228.
Zhang Zhang and Dacheng Tao (2012). Slow Feature Analysis for Human Ac-
tion Recognition. IEEE Transactions on Pattern Analysis and Machine In-
telligence, 34(3):436–450.
Zhao, L., Pérez-Delgado, C. A., and Fitzsimons, J. F. (2016). Fast graph oper-
ations in quantum computation. Physical Review A, 93(3).
Zhao, Z., Fitzsimons, J. K., Rebentrost, P., Dunjko, V., and Fitzsimons, J. F.
(2021). Smooth input preparation for quantum and quantum-inspired machine
learning. Quantum Machine Intelligence, 3(1):14.
Zhu, S., Sundaram, A., and Low, G. H. (2024). Unified architecture for a
quantum lookup table. arXiv preprint arXiv:2406.18030.

Common questions

Powered by AI

Defining quantum access to a Gaussian Mixture Model involves preparing quantum states that encapsulate the model parameters and data points. This access enables quantum algorithms to perform operations like expectation-maximization more efficiently, leveraging parallel processing to manage and manipulate large datasets effectively .

Quantum estimation of singular values and vectors utilizes parameters δ, ε, and θ to control the precision and threshold for significant values. Algorithms perform these estimations by efficiently accessing the matrix and applying techniques like SVD to extract singular components with unit vectors, ensuring results meet specified precision criteria .

Quantum algorithms achieve a quadratic improvement in query complexity using amplitude amplification techniques, which reduce the number of oracle queries to ̃O(√N) for a given function f: {0, 1}^n ↦ [0, 1]. This is achieved by assuming oracle access to the function's values, allowing the algorithm to enhance the probability of desired outcomes efficiently .

Reducing the Toffoli count in quantum circuits, crucial for managing circuit depth and error rates, faces challenges due to the inherent complexity of Boolean operations within quantum circuits. Recent advancements propose optimization techniques and circuit design strategies that lower the Toffoli count by using fewer control operations and incorporating hybrid architectures to maintain efficiency .

Quantum arithmetic enables efficient estimation of log-likelihood by allowing precise computation of Gaussian densities and their probabilities, encapsulated in a quantum state. This approach significantly impacts computation by enabling faster convergence to the stopping criteria in algorithms like Expectation-Maximization, leveraging quantum parallelism for complex calculations .

Quantum algorithms address the challenge of sparse matrices by using a 'sparse access' model, allowing efficient query access to matrix entries without requiring quantum random access memory (QRAM). This model benefits quantum computing by enabling efficient circuit implementations for encoding sparse structures, which are common in quantum physics and computing .

Oracle synthesis is a specific case of quantum circuit synthesis, which involves constructing quantum circuits to implement oracle functions, including reversible and non-reversible Boolean functions. This area is significant in quantum computing research because the efficiency and complexity of quantum algorithms often depend on the effectiveness of implementing oracles within quantum circuits .

Quantum initialization for Gaussian Mixture Models uses strategies similar to classical methods, such as random initialization or k-means++ adaptations, but with quantum efficiency. Quantum operations involve mapping data into quantum states and computing responsibilities using quantum arithmetic, potentially reducing computational overhead while maintaining accuracy .

Amplitude encoding, a method of preparing quantum states, presents lower bounds on circuit complexity, necessitating Ω(2^n) for size and Ω(n) for depth when using arbitrarily many ancilla qubits. Recent results refine the necessary depth to Ω(max{n, 4n n+m}), where m is the number of ancilla qubits, showing that certain algorithms can achieve these bounds .

Quantum circuits for vector data access balance depth and space through the use of multiplexer circuits, which perform controlled operations to write data into the target register. These circuits are linear in depth relative to the vector's length but minimize space requirements by eliminating ancilla qubits, thus illustrating a trade-off between circuit depth and space utilization .

You might also like