Quantum Algorithms for Data Analysis
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
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
10 q-means 171
10.1 The k-means algorithm . . . . . . . . . . . . . . . . . . . . . . . . 171
10.2 The 𝑞-means algorithm . . . . . . . . . . . . . . . . . . . . . . . . 173
10.3 Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
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
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
13
Chapter 2
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.
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:
𝜓(𝑡 + 𝜖) − 𝜓(𝑡)
= −𝑖𝐻𝜓(𝑡).
𝜖
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:
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:
𝑀𝑚 |𝜓⟩
†
√⟨𝜓|𝑀𝑚 𝑀𝑚 |𝜓⟩
𝑀 = ∑ 𝑚𝑃𝑚
𝑚
2.2. AXIOMS OF QUANTUM MECHANICS 19
• 𝑃𝑚 is positive definite
• 𝑃𝑚 is Hermitian
• ∑𝑚 𝑃𝑚 = 𝐼
• (𝑃𝑚 )(𝑃𝑛 ) = 𝛿𝑚𝑛 (𝑃𝑚 ) are orthogonal projections.
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:
𝐸(𝑀 ) = ∑ 𝑝(𝑚)𝑚
𝑚
= ∑ 𝑚⟨𝜓|𝑃𝑚 |𝜓⟩
𝑚
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.
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.
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
̃ ( 1 ) = 𝑂 ( 1 log(1/𝜖) log(1/𝛿))
𝑂 (2.4)
𝜖,𝛿
𝜖 𝜖
𝑈𝑇 𝑂𝑥 𝑈𝑇 −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
• 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.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.
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
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?
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
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.
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
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
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)
𝑖=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.
1 𝑁−1
|𝑥⟩ = ∑ 𝑥 |𝑖⟩ = ‖𝑥‖−1 𝑥, (3.3)
‖𝑥‖ 𝑖=0 𝑖
𝑛
1
|𝑋⟩ = ∑ ‖𝑥(𝑖)‖|𝑖⟩|𝑥(𝑖)⟩ (3.4)
√∑𝑛 ‖𝑥(𝑖)‖2 𝑖=1
𝑖=1
𝑛,𝑑
1
|𝑋⟩ = ∑ 𝑋𝑖𝑗 |𝑖⟩|𝑗⟩, (3.5)
𝑛,𝑑
√∑𝑖,𝑗=1 |𝑋𝑖𝑗 |2 𝑖,𝑗=1
𝐴 .
𝑈𝐴 = ( ). (3.7)
. .
𝑛
|𝑥⟩ = ∏ 𝜎𝛼𝑖 (𝑥𝑖 )|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.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.
1 𝑛
|𝑥⟩ = ∑ 𝑥 |𝑒 ⟩, (3.10)
||𝑥|| 𝑖=1 𝑖 𝑖
where, for some integer 𝑖, the states 𝑒𝑖 take the form 𝑒𝑖 = 0𝑖−1 10𝑛−𝑖 .
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)
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.
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
𝑘
∏(U𝑖 )→𝐼𝑖 (3.12)
𝑖=1
Input |ψ⟩I
⊗poly(log n)
Workspace |0⟩W
Address |i⟩A
Target |b⟩T
⊗poly(n)
Ancillae |0⟩Aux
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.
|𝑖⟩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
|𝑖⟩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.
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)
≤𝑚
(𝑡)
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
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.
𝑈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
• |𝑖, 𝑙⟩ ↦ |𝑖, 𝑙, 𝜈(𝑖, 𝑙)⟩, 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
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.
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).
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
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.
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].
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.
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/𝜖))
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.
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.
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:
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
(𝑚) (𝑚)
𝑥𝑖+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 𝑒𝑖𝜃
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.
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)
𝜋 𝜋 𝜋 𝜋
|𝜙⟩ = 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:
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 𝑂( 𝑁 ).
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
‖𝑋‖ ∑𝑖,𝑗 𝑥𝑖𝑗 |𝑖, 𝑗⟩.
𝐹
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 𝐴
𝐴=[ ]. (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
𝑟𝑖𝑗 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:
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.
†
𝑈𝑀 = (𝑈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
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/𝑝𝑜𝑙𝑦(𝑑)).
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.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/𝑝𝑜𝑙𝑦(𝑑)).
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
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 + 𝛿)𝜃].
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.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
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.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)
• 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 − 𝑇 𝑁𝑅
𝐹𝑃 + 𝑇𝑁
A useful toolbox
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.
√𝑝(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 𝑛
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:
𝑁−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
√
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),
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
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
√1
√
any operator that satisfies 𝑉 |0⊗𝑚 ⟩ ∶= 𝛼
∑𝑖 𝛼𝑖 |𝑖⟩, where 𝛼 ∶= ∑𝑖 𝛼𝑖 . Then
𝑊 ∶= 𝑉 † 𝑈 𝑉 satisfies
1 ⊗𝑚
𝑊 |0⊗𝑚 ⟩|𝜓⟩ = |0 ⟩𝑀 |𝜓⟩ + |Ψ⟂ ⟩ (5.3)
𝛼
for all states |𝜓⟩, where 𝑈 ∶= ∑𝑖 |𝑖⟩⟨𝑖| ⊗ 𝑈𝑖 and (|0⊗𝑚 ⟩⟨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 .
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
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
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.
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
|𝜙𝑖𝑗 ⟩ ∶= |𝑖⟩|𝑗⟩ √ (|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
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
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).
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
|𝑖⟩|𝑗⟩|𝑤𝑖𝑇 𝐴𝑣𝑖 ⟩.
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
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
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
𝑧max Γ𝑧
𝐼= , (5.13)
𝑢max Γ𝑢
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
‖𝑧‖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.
𝑑
|𝜓(𝑡)⟩ = 𝐻(𝑡)|𝜓(𝑡)⟩
𝑑𝑡
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
109
Chapter 6
Quantum perceptron
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)
111
112 CHAPTER 6. QUANTUM PERCEPTRON
𝑛
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
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:
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.
𝑦(𝑖) 𝑞 ⊤ 𝑥(𝑖)
𝛾 = max min . (6.5)
𝑚
𝑞∈ℝ 𝑖∈[𝑛] ‖𝑞‖‖𝑥(𝑖) ‖
It naturally follows that a dataset is linearly separable if and only if its margin
is different from 0.
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 𝑈 .
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
𝑤(𝑗) . 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𝜖 )).
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.
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.
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(𝑟).
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 𝑂 𝜖 𝜂 𝑝
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
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 factor score ratios 𝜆(𝑖) , such that ‖𝜆(𝑖) − 𝜆 ‖ ≤ 𝛾, with high probability;
124 CHAPTER 7. SVE-BASED QUANTUM ALGORITHMS
̃
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
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.
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 𝑖 𝜎𝑖
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
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
𝑗!
ℓ 𝑗 ℓ 𝑗
̃ = ∑ (−𝑖𝑊 ) = 𝑉 ∑ (−𝑖Σ) 𝑉 𝑇
𝑈
𝑗=0
𝑗! 𝑗=0
𝑗!
∞ ℓ ∞ ∞ ∞
̃∥ (−𝑖𝑊 )𝑗 (−𝑖𝑊 )𝑗 (−𝑖𝑊 )𝑗 (−𝑖𝑊 )𝑗 1
∥𝑈 − 𝑈 ≤ ‖∑ −∑ ‖≤‖ ∑ ‖≤ ∑ ‖ ‖≤ ∑
𝑗=0
𝑗! 𝑗=0
𝑗! 𝑗=ℓ+1
𝑗! 𝑗=ℓ+1
𝑗! 𝑗=ℓ+1
𝑗!
∞
1
≤ ∑ 𝑗−1
≤ 2−ℓ+1
𝑗=ℓ+1
2
𝑙
1 −𝑖𝑗
∑ |𝑗⟩|𝑥⟩
√𝑁𝑙 𝑗=0 𝑗!
𝑙
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
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
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
/𝜖 ).
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
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
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
133
134 CHAPTER 8. QUANTUM ALGORITHMS FOR MONTE CARLO
1 𝑁
𝜇𝑁
̃ = ∑𝑋 . (8.2)
𝑁 𝑖=1 𝑖
1 𝑁
𝜇𝑁
̃ = ∑ 𝑋 → 𝜇, (𝑎.𝑠), (8.3)
𝑁 𝑖=1 𝑖
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
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
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:
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:
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
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)
𝐷 𝐷
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 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
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.
𝑑𝑆𝑡 = 𝑆𝑡 𝛼 𝑑𝑡 + 𝑆𝑡 𝜎 𝑑𝑊𝑡
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:
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:
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.
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)
|𝑗⟩|𝑣(𝑗)⟩
̃ → |𝑗⟩|𝑣(𝑗)⟩(
̃ √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
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 𝜈 + 𝜖.
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 𝑡𝑙
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:
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:
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
153
154 CHAPTER 9. DIMENSIONALITY REDUCTION
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: ||𝜎𝑖 𝑢𝑖 − 𝜎𝑖 𝑢𝑖 ||.
⎷ 𝑖 𝑗 ⎷ 𝑗
√ 𝑘 √
√ 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:
√ √
∥‖𝐴‖𝑈 Σ − ||𝐴||𝑈 Σ∥𝐹 ≤ 𝑘‖𝐴‖(𝜖 + 𝛿), ∥‖𝐴‖𝑉 Σ − ‖𝐴‖𝑉 Σ∥𝐹 ≤ 𝑘‖𝐴‖(𝜖 + 𝛿).
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 ‖𝑎𝑖 ‖.
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.
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.
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 𝜃
).
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 .
𝜎𝑖 𝑖 𝜎𝑖 𝑖 𝜎𝑖 𝜃 − 𝜃𝜖 𝜎𝑖 𝜎𝑖 𝜃 − 𝜃𝜖 𝜃 𝜃 − 𝜃𝜖
√ 𝑘 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
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.
1 𝐾 2
Δ(𝑦𝑗 ) = ∑ ∑ (𝑔𝑗 (𝑥𝑠 ) − 𝑔𝑗 (𝑥𝑡 ))
𝑎 𝑘=1 𝑠,𝑡∈𝑇
𝑘
𝑠<𝑡
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
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 ]
𝑤𝑗𝑇 𝐴𝑤𝑗
Δ(𝑦𝑗 ) = , (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].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.
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.
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
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 )
𝛿𝜃
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
q-means
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.
1 𝑛 1 𝑛
√ ∑ |𝑖⟩ ⊗𝑗∈[𝑘] (|𝑗⟩|0⟩) ↦ √ ∑ |𝑖⟩ ⊗𝑗∈[𝑘] (|𝑗⟩|𝑑2 (𝑥𝑖 , 𝑐𝑗 )⟩),
𝑛 𝑖=1 𝑛 𝑖=1
174 CHAPTER 10. Q-MEANS
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 𝜂.
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
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.
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.
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.
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𝜂
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.
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 (𝑐𝑗 , 𝑥𝑖 )| ≤
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.
𝛿
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
Quantum
Expectation-Maximization
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:
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
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 𝜃𝑙 𝜙(𝑣𝑖 ; 𝜇𝑙 , Σ𝑙 )
𝑛 𝑛 𝑘
ℓ(𝛾; 𝑉 ) = ℓ(𝜃, 𝜇,⃗ Σ;⃗ 𝑉 ) = ∑ 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
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.
𝑛
∑𝑖=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.
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.
it means to have quantum access to a GMM and its dataset. This definition is
basically an extension of theorem ??.
• |𝑗⟩|0⟩ ↦ |𝑗⟩|𝜇𝑗 ⟩,
• |𝑗⟩|𝑖⟩|0⟩ ↦ |𝑗⟩|𝑖⟩|𝜎𝑖𝑗 ⟩ for 𝑖 ∈ [𝑑] where $�_i^{j} $ is the 𝑖-th rows of Σ𝑗 ∈
ℝ𝑑×𝑑 ,
• |𝑖⟩|0⟩ ↦ |𝑖⟩|𝑣𝑖 ⟩ for all 𝑖 ∈ [𝑛],
• |𝑖⟩|0⟩|0⟩ ↦ |𝑖⟩|vec[𝑣𝑖 𝑣𝑖𝑇 ]⟩ = |𝑖⟩|𝑣𝑖 ⟩|𝑣𝑖 ⟩ for 𝑖 ∈ [𝑛],
• |𝑗⟩|0⟩ ↦ |𝑗⟩|𝜃𝑗 ⟩.
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
𝜅(Σ)𝜇(Σ) 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 .
Proof. The proof follows from rewriting the responsibility of Equation (11.3)
194 CHAPTER 11. QUANTUM EXPECTATION-MAXIMIZATION
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
𝑛
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.
𝑡+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
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 .
Lemma 11.5. Let 𝑅𝑗𝑡 ∈ ℝ𝑛 be the vector of responsibilities of the points for the
𝑛 𝑡
∑𝑖=1 𝑟𝑖𝑗 𝑣𝑖 𝑉 𝑇 𝑅𝑗𝑡
𝑡
Gaussian 𝑗 at time 𝑡, i.e. (𝑅𝑗𝑡 )𝑖 = 𝑟𝑖𝑗 . Then 𝜇𝑡+1
𝑗 ← 𝑛
∑𝑖=1 𝑟𝑖𝑗𝑡 = 𝑛𝜃𝑗 .
3.5 1.5
̃ ( 𝑘𝑑𝜂𝜅(𝑉 )(𝜇(𝑉 ) + 𝑘
𝑇𝜇 = 𝑂
𝜂 𝜅(Σ)𝜇(Σ))
)
𝛿𝜇3
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.
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 𝑇Σ .
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
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)∥ < 𝜖 .
𝜏
𝑂(𝑇𝜃 + 𝑇𝜇 + 𝑇Σ + 𝑇ℓ ),
for
̃ (𝑘3.5 𝜂1.5 𝜅2 (Σ)𝜇(Σ)
• 𝑇𝜃 = 𝑂 )
𝛿2 𝜃
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 𝜇(𝑉 ) ∶= ‖𝑉 ‖ =
√
𝑂( 𝑘).
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
√
which implies that a 𝛿-𝑘-means algorithm with any 𝛿 < 𝜉 2 − 2 𝜂𝛽 will cluster
these points correctly.
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.
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
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
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.
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.
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.
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.
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.
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
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
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
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}:
𝑛 𝑛
𝑛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.
𝑂𝑓 |𝜓⟩ = ∑ [(1 − 𝑦𝑖 )𝛼𝑖,0 (x) + 𝑦𝑖 𝛼x,1 (x)] |𝑖, 0⟩+[𝑦𝑖 𝛼𝑖,0 (x) + (1 − 𝑦𝑖 )𝛼𝑖,1 (x)] |𝑖, 1⟩
𝑖∈[𝑁]
221
222CHAPTER 14. LOWER BOUNDS ON QUERY COMPLEXITY OF QUANTUM ALGORITHMS
1
𝑝(x)
̄ = ∑ 𝑝(𝑥𝜋(1) , 𝑥𝜋(2) , … , 𝑥𝜋(𝑛) )
𝑁 ! 𝜋∈𝑆
𝑛
𝑄𝑗 = ∑ ∏ 𝑥𝑖
𝑆⊂[𝑁] 𝑖∈𝑆
|𝑆|=𝑗
14.1. POLYNOMIAL METHOD 223
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⟩−|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
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
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) ∈ 𝑅.
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
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
|𝑆(𝑡) − 𝑆(𝑡 − 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
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
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
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
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
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
Proof. Note that by taking the square on both sides we get: (𝑥, 𝑦)2 ≤ (𝑥, 𝑥)(𝑦, 𝑦).
Substituting (𝑥, 𝑦) = ‖𝑥‖‖𝑦‖𝑐𝑜𝑠(𝜃), we get:
239
240 APPENDIX A. MATH AND LINEAR ALGEBRA
Exercise A.2. Can you show that the last identity is true?
𝑉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
𝐴𝑞 = 𝜆𝑞,
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 𝑘
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 .
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).
Σ 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
𝐴𝑥 = 𝑈 Σ𝑉 𝑇 𝑥 = (𝑈 (Σ(𝑉 𝑇 𝑥))).
𝑈 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
0 𝐴 𝑢 𝑢
( 𝑇 ) ( 𝑖 ) . = 𝑠𝑖 ( 𝑖 )
𝐴 0 𝑣𝑖 𝑣𝑖
With 𝑠(𝐴) or simply with 𝑠 we denote the sparsity, that is, the maximum number
of non-zero elements of the rows.
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
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 𝜎𝑖 . :::
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.4 Inequalities
From here.
Theorem A.6 (Bernoulli inequalities).
• Bernoulli inequality: for ∀𝑛 ∈ ℕ, 𝑥 ≥ −1
(1 + 𝑥)𝑛 ≥ 1 + 𝑛𝑥
(1 + 𝑥)𝑟 ≥ 1 + 𝑟𝑥
. For 0 ≤ 𝑟 ≤ 1,
(1 + 𝑥)𝑟 ≤ 1 + 𝑟𝑥
(1 + 𝑥)𝑟 ≤ 𝑒𝑟𝑥
𝑔(𝔼[𝑋]) ≤ 𝔼[𝑔(𝑋)].
1 1
Theorem A.9 (Hölder’s inequality). Let 𝑝, 𝑞 > 1 that satisfy 𝑝 + 𝑞 = 1. If
‖𝑋‖𝑝 ≤ ∞ and ‖𝑋‖𝑞 then
̇
𝔼[|𝑋𝑌 |] ≤ ‖𝑋‖𝑝 ‖𝑋‖ 𝑞.
A.5 Trigonometry
Always have in mind the following Taylor expansion:
Theorem A.11 (Taylor expansion of exponential function).
∞
𝑥𝑘
𝑒𝑥 = ∑
𝑘=0
𝑘!
𝑒𝑖𝜏 = 1
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
𝑐𝑜𝑠(𝑎+𝑏)+𝑖𝑠𝑖𝑛(𝑎+𝑏) = 𝑐𝑜𝑠(𝑎)𝑐𝑜𝑠(𝑏)+𝑐𝑜𝑠(𝑎)+𝑖𝑠𝑖𝑛(𝑏)+𝑖𝑠𝑖𝑛(𝑎)𝑐𝑜𝑠(𝑏)−𝑠𝑖𝑛(𝑏)𝑠𝑖𝑛(𝑎)
𝑐𝑜𝑠(𝑎+𝑏)+𝑖𝑠𝑖𝑛(𝑎+𝑏) = 𝑐𝑜𝑠(𝑎)𝑐𝑜𝑠(𝑏)+𝑐𝑜𝑠(𝑎)𝑖𝑠𝑖𝑛(𝑏)+𝑖𝑠𝑖𝑛(𝑎)𝑐𝑜𝑠(𝑏)−𝑠𝑖𝑛(𝑏)𝑠𝑖𝑛(𝑎)
From this, it follows
Appendix B
Series
253
254 APPENDIX B. SERIES
Appendix C
Probability
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
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
𝑖
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.
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.
, 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
•
Theorem C.2 (Markov inequality). For all non-negative random variable, and
𝑎 > 0, we have that:
• 𝑃 𝑟(𝑋 ≥ 𝑎) ≤ 𝐸[𝑋]
𝑎
1
• 𝑃 𝑟(𝑋 ≥ 𝑎𝐸[𝑋]) ≤ 𝑎
As both of these expected values are bigger than zero, (using the nonnegativity
hypothesis) we have that
̇
𝐸[𝑋] ≥ 𝑃 (𝑋 > 𝑎)𝐸[𝑋|𝑋 > 𝑎]
The second statement of the theorem follows from substitution, i.e. setting 𝑏 =
𝑎𝐸[𝑋] and using the previous statement on 𝑃 𝑟(𝑋 ≥ 𝑏).
𝐸[𝑓(𝑌 )]
𝑃 (𝑌 ≥ 𝑏) ≤
𝑓(𝑏)
𝜎2
𝑃 𝑟[|𝑋 − 𝔼[𝑋]| ≥ 𝜖] ≤
𝜖2
1
𝑃 𝑟[|𝑋 − 𝔼[𝑋]| ≥ 𝑘𝜎] ≤
𝑘2
C.4. CONCENTRATION INEQUALITIES 261
𝐸[(𝑋 − 𝜇)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 𝑖
𝑛 𝑖 𝑛
𝜎2
𝑃 𝑟[|𝑌 − 𝐸[𝑌 ]| ≥ 𝜖] ≤
𝑛𝜖2
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.
𝑃 ( lim 𝑋 𝑛 = 𝜇) = 1
𝑥→−∞
2𝑘𝜖2
𝑃 𝑟(|𝑋 − 𝔼[𝑋]| ≤ 𝜖) ≥ 1 − 2 exp (− ).
𝑏−𝑎
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.88
≤ = = 0.28125
3.22 3.22
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
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).
|𝐴 − 𝐴| = 𝜖𝐴𝑏𝑠
|𝐴 − 𝐴|
= 𝜖𝑅
𝐴
or equivalently
𝐴(1 − 𝜖𝑅 ) ≤ 𝐴 ≤ 𝐴(1 + 𝜖𝑅 )
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 𝑂(𝑓( 𝜖 𝜆 ))
𝐴𝑏𝑠
Exercise D.1. Are there cases of algorithms with 𝜖𝑎𝑏𝑠 > 1? Does it make
sense? Can you make examples?
• 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 )).
–>
–>
–>
–>
–>
–>
–>
–> –>
–>
–>
–>
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
:::
–>
–> –> –>
–> –> –>
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
269
270 APPENDIX E. APPROXIMATION THEORY
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
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].
𝑚−1 𝑚 2𝑚
𝑛
∑𝑘=𝑛+1 (𝑚+𝑘 )
𝑔𝑚 (𝑥) = 4 ∑ (−1) ( ) 𝑇2𝑛+1 (𝑥) (E.2)
𝑛=0
22𝑚
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
𝑗
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)
𝑚 𝑘−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, … , 𝑚}.
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 2𝑚 (−1)𝑚−1
𝑏𝑚 = (−1)𝑚−1 ( ) = .
22𝑚 2𝑚 22𝑚
Thus, 𝑎𝑗 = 𝑏𝑗 for all 𝑗 ∈ {0, … , 𝑚}.
𝑘0 𝑚 2𝑚
∑𝑘=𝑛+1 (𝑚+𝑘)
∣𝑔𝑚 (𝑥) − 4 ∑(−1)𝑛 ( ) 𝑇2𝑛+1 (𝑥)∣ ≤ 𝜖 (E.14)
𝑛=0
22𝑚
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
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?
∞
1
𝑥 = ∑ 𝑎𝑛 𝑇𝑛 (𝑥) (E.16)
(1 − 𝑥2 )2𝑚 𝑛=0
1 ⎧0 𝑖𝑓𝑛 ≠ 𝑚,
d𝑥 {
∫ 𝑇𝑛 (𝑥) 𝑇𝑚 (𝑥) √ = ⎨𝜋 𝑖𝑓𝑛 = 𝑚 = 0, (E.17)
−1 1 − 𝑥2 {𝜋
⎩2 𝑖𝑓𝑛 = 𝑚 ≠ 0.
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
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]:
279
280 APPENDIX F. CONTRIBUTIONS AND ACKNOWLEDGEMENTS
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.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.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
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., 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.
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.
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., 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.
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
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.
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
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.
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.
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.
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
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.
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 .