scieee AI-readable full text Open interactive document viewer

Classes of Quantum Complexity

Lobillo Olmedo, Javier

Abstract

This work aims to ensure a digital functioning of the world of trading cards that we are already familiar with. For this purpose, a significant portion of the functions associated with trading cards has been transferred to the application, such as acquiring or exchanging them. The developed functions are comprehensive, starting with organized storage by collections. With this feature, users will be able to track which cars from a collection they possess and which ones they are missing. As a result, users can search for collections to subscribe to and begin collecting. The method for obtaining new cards is based on exchanges with other users or purchasing packs. These packs offer 3 cards from the selected collection and can be bought using coins that can be earned by answering questions correctly. Everything related to the cards and collections is created, modified, or deleted by the creators, who have their own panel to interact with their creations. The application is designed to be used in a web browser on our computer, developed using HTML/PHP, and with an SQL database.

Full text

Classes of Quantum Complexity. Clases de complejidad cuántica. Bachelor’s thesis in Computer Science Double major in Computer Science and Mathematics Facultad de Informatica Universidad Complutense de Madrid Year 2022-2023 Javier Lobillo Olmedo Supervised by Alberto Antonio del Barrio García and Angelo Lucia Contents Acknowledgements v Abstract vii Resumen ix Introduction xi I A model for Quantum Mechanics 1 I.1 Bra-Ket and state space . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 II Classical and quantum circuits 5 II.1 ClassicalCircuits............................... 5 II.2 QuantumCircuits .............................. 14 III Shor’s Algorithm 25 III.1 Some Quantum Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . 25 III.2Periodicity .................................. 31 III.3 Factoring as period finding . . . . . . . . . . . . . . . . . . . . . . . . . . 38 IV Real World Implementations 43 IV.1 Shor’s Algorithm implementation . . . . . . . . . . . . . . . . . . . . . . 43 IV.2QFTimplementation............................. 46 Results 55 iii Acknowledgements To my mother, and to those who are not here either, for taking care of me everyday. To my tutors, Alberto and Ángelo, for their patience and guidance. To Sergio, my friend and partner in many adventures throughout these years in university. To my family and friends, for supporting me and loving me. v Abstract This bachelor’s thesis is about quantum complexity classes, which are the quantum analogues of classical complexity classes. We start by introducing the basic mathematical concepts that support quantum computing, such as the bra-ket notation, the state space, and the quantum gates. Then, in the second chapter, we study some classical complexity theory, such as classical complexity classes and the P vs NP problem. Afterwards, we introduce the quantum complexity classes, and we study the relationship between them and the classical complexity ones, specially the relationship between BPP, BQP and PSPACE. We see that one is contained in the next one. In the third chapter we study some quantum algorithms, such as Deutsch’s algorithm, Simon’s algorithm, and Shor’s algorithm. We show apparent differences between the classical and the quantum world, such as the fact that quantum computers can solve the factoring problem in polynomial time, while classical computers are not known to be able to do so. Finally, in the fourth chapter, we implement Shor’s algorithm in several quantum simulators, and we study how it works in practice, comparing the different backends. Additionally, we implement the quantum Fourier transform and run it in different real quantum backends. Keywords: Quantum Computing, Quantum Algorithms, Complexity Theory, BPP, BQP, QFT, Shor’s Algorithm. vii Resumen Este trabajo de fin de grado trata sobre las clases de complejidad cuántica, que son el análogo cuántico de las clases de complejidad clásica. Empezamos en el primer capítulo introduciendo los conceptos matemáticos básicos que sustentan la computación cuántica, como la notación bra-ket, el espacio de estados y las puertas cuánticas. Después, en el segundo capítulo, estudiamos algo de teoría de complejidad clásica, como las clases de complejidad clásicas y el problema P vs NP. Después introducimos las clases de complejidad cuánticas, y estudiamos la relación entre ellas y las clases de complejidad clásicas, especialmente la relación entre BPP, BQP y PSPACE, viendo que una está contenida en la siguiente. En el tercer capítulo estudiamos algunos algoritmos cuánticos, como el algoritmo de Deutsch, el algoritmo de Simon y el algoritmo de Shor. Mostramos diferencias aparentes entre el mundo clásico y el mundo cuántico, como el hecho de que los ordenadores cuánticos pueden resolver el problema de factorización de un numero natural en tiempo polinomial, mientras que los ordenadores clásicos no se sabe que puedan hacerlo. Finalmente, en el cuarto capítulo, logramos implementar el algoritmo de Shor en varios simuladores cuánticos, y estudiamos cómo funciona en la práctica, comparando los diferentes backends. Además, implementamos la transformada cuántica de Fourier y la ejecutamos en varios ordenadores cuánticos reales. Palabras clave: Computación Cuántica, Algoritmos Cuánticos, BPP, BQP, Teoría de la Complejidad, QFT, Algoritmo de Shor. ix 2 I.1. Bra-Ket and state space Definition I.1.4. Aray is an equivalence class of vectors defined by the next equivalence relation: |x⟩∼|y⟩if and only if |x⟩=α|y⟩for some α∈Cwith α= 0. We will choose a representative of the equivalence class, x, such that ⟨x|x⟩= 1. Now, the state space that we will consider as a model for quantum computation will be the set of all rays in Cn, or projective Hilbert space. Definition I.1.5. Astate is a normalized ray in a Hilbert space. It is important to note that the overall phase of a state is irrelevant: |x⟩and eiθ |x⟩ describe the same state, where θ∈Rand |eiθ|= 1. Definition I.1.6. Aqubit is an isolated quantum system with a two-dimensional state space. We wil usually fix an orthonormal basis {|0⟩,|1⟩} for the state space of a qubit. Therefore, a state of a qubit is of the form |ψ⟩=α|0⟩+β|1⟩with α, β ∈Cand |α|2+|β|2= 1. Now that we have defined an n-dimensional Hilbert space, and we have our small elements, called qubits, from which we will build our larger Hilbert spaces, we need to provide a way of constructing this larger systems from our smaller bricks. Proposición I.1.7. Let H1, H2be two Hilbert spaces with orthonormal bases {|ui⟩}i∈Iand {|vj⟩}j∈Jrespectively. Then, H1⊗H2is a Hilbert space with orthonormal basis {|ui⟩ ⊗ |vj⟩}(i,j)∈I×J. Once we have found ourselves in a projective Hilbert space, we will need ways to operate inside it. This is done through unitary operators, which will act as the gates of our quantum circuits. Definition I.1.8. Aunitary operator Uon a Hilbert space His a linear operator or matrix U:H→Hsuch that U†U=UU†I, where U†is the adjoint of U, and Iis the identity operator. The reason we use unitary operators is that they preserve the norm of the vectors, and therefore they take representatives of the rays (of norm 1) to representatives of rays. Proposición I.1.9. Let H1, H2be two Hilbert spaces with orthonormal bases {|ui⟩}i∈Iand {|vj⟩}j∈Jrespectively, and let U1and U2be unitary operators on H1and H2respectively. Then, U1⊗U2is a unitary operator on H1⊗H2given by U1⊗U2(|ui⟩⊗|vj⟩) = U1|ui⟩⊗U2|vj⟩. In addition, if we write the matrices like U1= (uij), then the matrix representation of U1⊗U2is given by U1⊗U2= (uijU2). I. A model for Quantum Mechanics 3 Lastly, we need to define what a measurement is. This is the way we will extract information from our quantum system. Definition I.1.10. We say that the computational measurement of a quantum state system of dimension N= 2nwith state |ψ⟩= N−1 X i=0 αi|i⟩, is a discrete random variable such that P(X=|i⟩) = |αi|2. Now we should mention some unitary operators that will be useful for us in the future. Definition I.1.11. The Hadamard gate is the unitary operator on a qubit given by H=1 √21 1 1−1. Definition I.1.12. The controlled-not gate is the unitary operator on two qubits given by CNOT =    1 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0     . Definition I.1.13. The SWAP gate is the unitary operator on two qubits given by SWAP =    1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1     . Definition I.1.14. The Pauli-X gate is the unitary operator on a qubit given by X=0 1 1 0. The Pauli-Y gate is the unitary operator on a qubit given by Y=0−i i0. The Pauli-Z gate is the unitary operator on a qubit given by Z=1 0 0−1. Chapter II Classical and quantum circuits In this chapter we will precise our model of quantum computing, we will point out some basic properties for the model, and afterwards we will investigate the power of the model. In order to do so in the second part of the chapter, we have to begin, in the first chapter, with the study of what a classical computer does. This chapter is based on the fifth chapter of [5]. II.1 Classical Circuits We start with the definition of a classical computer focusing on what it does. Later in the subsection this will translate this to what it is in terms of circuits. Universal gates Definition II.1.1. A (deterministic) classical computer evaluates a function f:{0,1}n→ {0,1}m, which takes n-bits of input and produces m-bits of output. A function with an m-bit output can be seen as a function with mfunctions with a 1-bit output. Therefore, we can assume that m= 1. This produces the following definition: Definition II.1.2. A Boolean function is a function f:{0,1}n→ {0,1}, which takes n-bits of input and produces 1-bit of output. We may think of one Boolean functions as a binary string of length 2n, where each bit is the output f(x)of the function for one of the 2npossible inputs x. It is clear that there are 22ndifferent Boolean functions of nvariables, which is a very large number. For example, for n= 5 there are 225= 232 = 4,294,967,296 different Boolean functions. 5 6 II.1. Classical Circuits Definition II.1.3. We say that a Boolean function faccepts an n-bit string xif f(x)=1, and rejects xif f(x)=0. Therefore we may regard a Boolean function as the subset Σcontaining all the accepted strings. The evaluation of a Boolean function fcan be reduced to a sequence of simple logical operations. To see how, we denote the n-bit strings accepted by fas Σ = x(1), x(2), x(3), . . ., and note that for a given x(a)we can define a function f(a):{0,1}n→ {0,1}, x 7→ (1if x=x(a) 0otherwise, which accepts only x(a). Then we can write fas f(x) = f(1)(x)∨f(2)(x)∨f(3)(x)∨. . . , where ∨denotes the logical OR operation. In binary arithmetic, the OR operation may be represented x∨y=x+y−x·y, which has the value 0if xand yare both 0, and 1otherwise. Now, we consider the evaluation of f(a). We may express the n-bit string x(a)as x(a)=x(a) n−1x(a) n−2. . . x(a) 1x(a) 0. If x(a)= 11 . . . 1, we may simply write f(a)(x) = xn−1∧xn−2∧···∧x1∧x0, where ∧denotes the logical AND operation. In binary arithmetic, the AND operation is the product x∧y=x·y. If x(a)has a 0in the i-th position, we may apply the NOT (¬) operation to the i-th bit of x, and then write f(a)as the same expression as above. In binary arithmetic, the NOT operation is the subtraction ¬x= 1 −x. For example f(a)(x) = . . . (¬x3)∧x2∧(¬x1)∧x0, if x(a)=. . . 0101. We have now constructed the function fform three elementary logical operations: NOT, AND and OR. The expression we obtained is denoted the disjunctive normal form of f. Of course, we have implicitly used another operation INPUT(xi) which inputs the i-th bit of x. II. Classical and quantum circuits 7 Now we are ready to transform the definition of a function to that of a circuit model for classical computation. A computation is a finite sequence of elementary operations, acircuit, applied to a specify input. Each operation is called a gate. The result of the computation is the final value of the remaining bits after the last gate has been applied. For a Boolean function, there is only one output bit. A circuit can be seen as a directed acyclic graph, where each node is a gate and the directed edges represent the flow of bits throughout the circuit, with the direction specifying the order in which the gates are applied. Finally, we say that the gate set {NOT, AND, OR, INPUT} is universal for classical computation, which means that any function may be computed by building a circuit from only these gates. It is a remarkable fact that any arbitrary computation can be performed using such simple building blocks. Most functions require large circuits Our previous DNF construction shows that any Boolean function can be evaluated with no more that 2nOR gates, n2nAND gates, n2nNOT gates and n2nINPUT gates, with a total of (3n+ 1)2ngates. Although some Boolean functions can be computed with a smaller number of gates, it is clear that most functions require an exponentially large (in n) number of gates. How many circuits are there with Ggates acting on a n-bit input? Considering the gate set from which we constructed the DNF, we will also allow imputing of a constant bit (either 0or 1) as an input. Therefore there are n+ 5 different gates: AND, OR, NOT, INPUT(0), INPUT(1) and INPUT(xi) for i= 0,1, . . . , n −1. Each two-bit gate acts on a pair of bits which are outputs of previous gates, and there are G such gates, so this pair can be chosen in fewer that G2ways. Therefore, the total number of size-Gcircuits is at most Ncircuit(G)≤((n+ 5)G2)G. If we take G=c2n 2nwhere cis a constant independent of n, then log2Ncircuit(G)≤G(log2(n+ 5) + 2 log2G) = c2n1 + 1 2nlog2c2(n+ 5) 4n2≤c2n, where the second inequality holds for nsufficiently large. Comparing with the number of Boolean functions, Nfunction(n) = 22n, we see that log2Ncircuit(G) Nfunction(n)≤c2n−2n= (c−1)2n, for nsufficiently large. Therefore, for any c < 1, the number of circuits is smaller than the number of functions by a huge factor. Although we did this analysis for one particular 8 II.1. Classical Circuits universal gate set, the result would have not been very different for any other universal gate set. We conclude that for any ε > 0then most Boolean functions require circuits of size at least (1 −ε)2n 2ngates. The circuit size is so large because most functions have no structure that can be exploited to construct a more compact circuit. We basically cannot do much better than consulting a “look-up table” of the function values for all possible inputs, which is essentially what the DNF construction does. Circuit complexity So far we have only considered a computation that acts on a fixed input (consisting of n bits), but we may also consider families of circuits that act on inputs of different lengths. Circuit families provide a useful scheme for analyzing and classifying the complexity of computations, a scheme that will have a natural generalization to quantum computation. Boolean functions arise naturally in the study of computational complexity. A Boolean function fis said to encode the solution to a “decision problem” - the function examines the input and returns 1if the answer is “yes” and 0if the answer is “no”. Often what might not be stated colloquially as a decision problem can be reformulated as one. For example, the function that defines the FACTORING problem is f(x, y) = (1if integer xhas a factor zsuch that 1< z < y, 0otherwise. Knowing f(x, y)for all xand yis equivalent to knowing the complete factorization of x. Another example of a decision problem is the HAMILTONIAN PATH problem: let the input be an l-vertex graph, represented by its l×ladjacency matrix (a 1in the i, j entry means that there is an edge between vertices iand j). The function is f(x) = (1if the graph has a Hamiltonian path, 0otherwise. A Hamiltonian path is a path that visits each vertex exactly once. For the FACTORING problem the size of the input is the number of bits needed to represent the integers xand y, while for the HAMILTONIAN PATH problem the size of the input is the number of bits needed to represent the adjacency matrix. Therefore each problem really defines a family of Boolean functions with variable input size. We denote such a function family as f:{0,1}∗→ {0,1}, where {0,1}∗is the set of all finite bit strings. When xis an n-bit string, by writing f(x) we mean the Boolean function in the family that corresponds to the input size n. The set Lof strings accepted by a function family f L={x∈ {0,1}∗:f(x)=1}, II. Classical and quantum circuits 9 is called a language. We can quantify the hardness of a problem by stating how the computational resources required to solve it scale with the size of the input n. In the circuit model of computation, it is natural to use the number of gates as a measure of the computational resources required. Alternatively we could be interested in how much time it takes to do the computation if many gates can be executed in parallel; the depth of the circuit is the number of time steps required, assuming that gates acting on distinct bits can be executed in parallel (that is, the depth is the maximum length of a directed path from the input to the output of the circuit). The width of the circuit is the maximum number of gates that in any one time step, and quantifies the storage space required to do the computation. We want to divide the decision problems in two classes: easy and hard. However it is not possible to give a precise definition of what easy and hard should be. We will consider decision problems with variable input size and we will examine how the size of the circuit that solves the problem scales with the input size. If we use the scaling behavior of a circuit family to characterize the complexity of a problem, there is a subtlety that we must address. It would be cheating to hide the difficulty of the problem in the design of the circuit. Therefore we should restrict attention to circuit families that have acceptable “uniformity” properties - it must be “easy” to construct the circuit with n+ 1 bits of input once we have constructed the circuit with an n-bit input. Associated with a family of functions {fn}(where fnhas n-bit input) is a family of circuits {Cn}where Cnis a circuit that computes fn. Definition II.1.4. We say that a circuit family {Cn}is polynomial-size uniform if the size |Cn|of the circuit Cngrows with nno faster than a power of n, |Cn| ≤ poly(n), where poly denotes a polynomial. Then we naturally define: Definition II.1.5. Pis the set of decision problems that can be solved by a polynomial-size uniform circuit family. Now, the natural choice is to define problems in Pas “easy” and problems not in Pas “hard”. Notice that Cncomputes fn(x)for every possible n-bit input x, and therefore, if a decision problem is in Pwe can find the answer to the problem even for the “worst-case” input using a circuit of size no greater than poly(n). As noted before, we implicitly assume that the circuit family is “uniform” so that the design of the circuit can itself be solved by a polynomial-time algorithm. Under this assumption, solvability in polynomial time by a circuit family is equivalent to solvability in polynomial time by a universal Turing machine. Of course, to determine the size of a circuit that computes fn, we must know what the elementary components of the circuit are. Fortunately, though, it turns out that the precise choice of elementary components does not matter. We can use any universal set of gates 10 II.1. Classical Circuits to efficiently simulate any other universal set of gates, as long as the gate set is finite and each gate act on a constant number of bits. The way of distinguishing between easy and hard problems might seem rather arbitrary. If |Cn| ∼ n1000 we might consider the problem to be intractable in practice, even though it is in P. On the other hand, if |Cn| ∼ nlog log log nwe might consider the problem to be easy in practice, although the scaling is “superpolynomial”. Furthermore, even if |Cn|scales like a modest power of n, the constant factor in front of the power might be so large that the circuit is too big to be practical. Nevertheless, such pathological cases are rare, and the distinction between easy and hard problems is useful in practice. Of particular interest are decision problems that can be answered by providing an example of a solution that is easy to check. For example, given xand y < x, it is hard (in the worst case) to determine if xhas a factor less than y, but if we are given a factor z < y of x, it is easy to check that zis indeed a factor of x. Similarly it is hard to find a Hamiltonian path in a graph, but if we are given a Hamiltonian path, it is easy to check that it is indeed a Hamiltonian path. The concept of a problem that is hard to solve but a given solution can be easily checked is formalized as follows: Definition II.1.6. A language Lis in the class NP if and only if there is a polynomial-size verifier V(x, y)such that: (1) If x∈L, then there exists ysuch that V(x, y)=1(completeness). (2) If x /∈L, then for all y,V(x, y)=0(soundness). The verifier Vis the uniform circuit family that decides L. Completeness means that if xis in the language, then there is a “witness” ysuch that the verifier accepts the input if the witness is provided. Soundness means that if xis not in the language, then no matter what witness is provided, the verifier rejects the input. It is immplicit that the witness is of polynomial length since the verifier has a polynomial number of gates, including input gates. NP stands for “nondeterministic polynomial time”, name which is used for historical reasons. The name comes from the fact that the verifier Vcan be thought of as a nondeterministic Turing machine that guesses the witness yand then checks that it is correct in polynomial time. It is easy to see that P⊆NP. If Lis in P, then there is a polynomial-size circuit C that decides Lwithout any witness whatsoever. Nevertheless, there are problems in NP that are not known to be in P. Naturally arises the conjecture upon which the much of the field of complexity theory is based: Conjecture: P=NP. If this conjecture was false, that is if P=NP, that would mean that we could easily find a solution for any problem whose solutions are easy to verify. For example, we could discover all mathematical theorems which have short proofs. If P=NP, then our computers would II. Classical and quantum circuits 11 never achieve such power and the mere existence of a succint proof for a statement would not ensure that we could find it in any reasonable amount of time. An important example of a Boolean problem that is in NP but not known to be in Pis CIRCUIT-SAT. In this problem, the input is a Boolean circuit Cand the question is whether there is an input xsuch that C(x)=1. The problem is in NP because if the answer is yes, then we can provide the input xas a witness which can be easily checked as the circuit C is of polynomial size. The problem is not known to be in Pbecause we do not know how to find the input xin polynomial time. In this case, the function to be evaluated is f(C) = (1if there exists xsuch that C(x)=1, 0otherwise. The problem CIRCUIT-SAT is particularly important because if we have a machine that solves CIRCUIT-SAT in polynomial time, then we can use it to solve any problem in NP in polynomial time. We say that every problem in NP us (efficiently) reducible to CIRCUITSAT. More generally, we say that problem Breduces to problem Aif a machine that solves Acan be used to solve Bas well. Definition II.1.7. If Aand Bare Boolean function families, then Breduces to Aif there is a function family R, computed by polynomial-size circuits, such that B(x) = A(R(x)) for all x. What this definition says, in other words, is that Baccepts xif and only if Aaccepts R(x). In particular, then, if we have a polynomial-size circuit family that solves A, we can hook Aup with Rto obtain a polynomial-size circuit family that solves B. Thus, any problem Bcan be effectively reduced to CIRCUIT-SAT. This reduction is possible because problem Bpossesses a polynomial-size verifier V(x, y)which accepts xif and only if a valid witness yexists, satisfying V(x, y)=1. To clarify, for each fixed x, the question of whether such a witness yexists becomes an instance of CIRCUIT-SAT. Consequently, the existence of a poly-size circuit family capable of solving CIRCUIT-SAT would also imply the ability to solve problem Bby utilizing the same circuit family. Definition II.1.8. We say a problem A∈NP is NP-complete if every problem in NP reduces to A. With the above definition, we can say that CIRCUIT-SAT is NP-complete. The NP- complete problems are the “hardest” problems in NP in the sense that if we can solve any one of them in polynomial time, then we can solve every NP problem in polynomial time. Furthermore, to show that any problem is NP-complete, it suffices to show that it is in NP and that it reduces to any other NP-complete problem. In fact, if Cis any problem in NP and Bis NP-complete, then there is a polynomial-size reduction Rsuch that C(x) = B(R(x)), and if Bis reductible to Athen there is another polynomial-size reduction R′such that B(y) = A(R′(y)). Hence C(x) = A(R′(R(x))) and, since the composition of two polynomial-size circuits is also polynomial-size, we see that an arbitrary problem Cin NP reduces to A, and therefore Ais NP-complete. NP-completeness is a useful concept 18 II.2. Quantum Circuits The errors cause the actual state of the quantum computer to wander away from the ideal state. How far does it wander? After one step, the ideal state would be |φ1⟩=U1|φ0⟩, But if the actual transformation ˆ U1where applied instead, the state would be ˆ U1|φ0⟩=U1|φ0⟩+|E⟩1=|φ1⟩+|E1⟩, where |E1⟩= ( ˆ U1−U1)|φ0⟩, is an unnormalized vector. Although we could also suppose that the initial state deviates from |φ0⟩by some small error vector which contributes an aditional error to the computation that does not depend on the circuit size, we will ignore this possibility for we are trying to understand how the error scales with the circuit size. Now if ˆ Utdenotes the actual gate applied at step t,|ˆφt⟩the actual state of the computer after step t, and |φt⟩the ideal state, then we have |ˆφt⟩=Ut|φt−1⟩+ ( ˆ Ut−Ut)|φt−1⟩+ˆ Ut(|ˆφt−1⟩−|φt−1⟩) =|φt⟩+|Et⟩+ˆ Ut(|ˆφt−1⟩−|φt−1⟩), where |Et⟩= ( ˆ Ut−Ut)|φt−1⟩. Hence we have |ˆφ2⟩=ˆ U2|ˆφ1⟩=|φ2⟩+|E2⟩+ˆ U2|E1⟩, |ˆφ3⟩=ˆ U3|ˆφ2⟩=|φ3⟩+|E3⟩+ˆ U3|E2⟩+ˆ U3ˆ U2|E1⟩, and so on. We can see that after Tsteps we obtain |ˆφT⟩=|φT⟩+|ET⟩+ˆ UT|ET−1⟩+ˆ UTˆ UT−1|ET−2⟩ +···+ˆ UTˆ UT−1. . . ˆ U2|E1⟩. Therefore we have expressed the difference between |ˆφT⟩and |φT⟩as a sum of T remainder terms. The worst case error is obtained when the remainder terms are all lined up in the same direction, so that the errors add up. Therefore we conclude that ∥|ˆφT⟩−|φT⟩∥ ≤ ∥|ET⟩∥+∥|ET−1⟩∥+···+∥|E1⟩∥, where the norm of than unitary matrix is 1. Let ∥A∥sup denote the sup norm of the matrix A, that is, the maximum of the eigenvalues of √A†A. We then have ∥|Et⟩∥ =∥(ˆ Ut−Ut)|φt−1⟩∥ ≤ ∥ˆ Ut−Ut∥sup, since ∥|φt−1⟩∥ = 1. Now suppose that, for each value of t, the error in our quantum gate is bounded by ∥ˆ Ut−Ut∥sup ≤ϵ;(II.1) II. Classical and quantum circuits 19 then, after Tsteps, the error in the final state is bounded by ∥|ˆφT⟩−|φT⟩∥ ≤ Tϵ. (II.2) In this sense, the accumulated error in the state grows linearly with the length of the computation. The distance bounded in (II.1) can equivalently be expressed as ∥Wt−I∥sup, where Wt=U† tˆ Ut. Since Wtis unitary, its eigenvalues have unit modulus, and each one of them is a phase eiθt, and the corresponding eigenvalue of Wt−Ihas modulus |eiθt−1|= (2 −2 cos θ)1/2, so that (II.1) is the requirement that each eigenvalue satisfies cos θt>1−ϵ2 2. or |θt|< ϵ for ϵ≪1. The origin of equation (II.2) is clear. In each time step, |ˆφt⟩is rotated by an angle of order ϵat worst, and the distance between te vector increases by at most of order ϵ. How much accuracy is good enough? In the final step of our computation, we perform an orthogonal measurement, and the probability of obtaining outcome a, in the ideal case, is pa=|⟨a|φT⟩|2. Because of the error, the actual probability is ˆpa=|⟨a|ˆφT⟩|2. It can be proven, although we will not do so here, that the L1distance between the ideal and actual probabilities is bounded by 1 2∥ˆp−p∥1=1 2X a|ˆpa−pa| ≤ ∥|ˆφT⟩−|φT⟩∥ ≤ Tϵ. (II.3) Therefore, if we keep Tϵ fixed and small as Tincreases, the error in the probability of the outcome will be fixed and small. If we use a quantum computer to solve a decision problem, we want the actual quantum circuit to get the right answer with probability 1 2+ˆ δ, where ˆ δ > 0. If the ideal quantum circuit has Tgates and success probability 1 2+δwhere δ > 0, then eq. (II.3) shows that ˆ δ is also positive provided ϵ < δ/T. We should be able to solve hard problems using quantum computers as long as we can improve the accuracy of the gates linearly with the circuit size. This is still a demanding requirement, since performing very accurate quantum gates is a daunting challenge for the hardware builder. Fortunately, we will be able to show, using the theory of quantum fault tolerance, that physical gates with constant accuracy (independent of T) suffice to achieve logical gates acting on encoded quantum states with accuracy improving like 1/T, as is required for truly scalable quantum computing. 20 II.2. Quantum Circuits BQP ⊂PSPACE A randomized classical computer can simulate any quantum computer if we grant the classical computer enough time and storage size. But how much memory does the classical computer require? Naively, since the simulation of an n-qubit circuit involves manipulating matrices of size 2n, it may seem that we need an amount of memory space exponential in n. However, we will now show that the classical simulation of a quantum computer can be done to acceptable accuracy (although very slowly indeed) in polynomial space. This means that the quantum class BQP is contained in the class PSPACE of problems that can be solved with polynomial space on a classical computer. The primary objective of the randomized classical simulation is to generate samples from a probability distribution that closely approximates the distribution of measurement outcomes for the given quantum circuit. Remarkably, our classical simulation goes beyond mere sampling, as it tackles an even more challenging task – estimating the probability p(a) for each potential outcome aof the final measurement, which can be expressed p(a) = |⟨a|U|0⟩|2, where U=UTUT−1. . . U1, is a product of Tquantum gates. Each Ui, acting on the nqubits, can be represented by a2n×2nunitary matrix, characterized by the complex matrix elements ⟨y|Ut|x⟩, where x, y ∈ {0,1,...,2n−1}. Writing out the matrix multiplication explicitly we have ⟨a|U|0⟩=X {xt:t=1,...,T−1}⟨a|UT|xT−1⟩⟨xT−1|UT−1|xT−2⟩. . . ⟨x1|U1|0⟩.(II.4) Eq. (II.4) is a sort of “path integral” representation of the quantum computation - the probability amplitude for the final outcome ais expressed as a coherent sum of amplitudes for each of a vast number 2n(T−1) of possible computational paths that begin at 0and terminate at aafter Tsteps. Our classical simulator is to add up the 2n(T−1) complex numbers in eq. (II.4) to compute ⟨a|U|0⟩. The first problem we face is that finite size classical circuits do integer arithmetic, while the matrix elements ⟨y|UT|x⟩need not be rational numbers. The classical simulator must therefore settle for an approximate calculation to reasonable accuracy. Each term in the sum is a product of Tcomplex factors, and there are 2n(T−1) terms in the sum. The accumulated error in the sum is therefore small if we express the matrix elements to an accuracy of mbits, where mis a large number compared to nT log T. Therefore we can replace each complex matrix element by pairs of signed integers - the binary expansions, each of length m, of the real and imaginary parts. Our simulator will need to compute each term in the sum (II.4) and accumulate a total of all the terms. However, each addition requires only a modest amount of scratch space, II. Classical and quantum circuits 21 and furthermore, since we only need to storage the accumulated sum to an accuracy of m bits, not much space is needed to sum all the terms, even though there are exponentially many of them. Therefore it only remains to consider the evaluation of a typical term in the sum, a product of Tmatrix elements. In order to do this, we will need a classical circuit that computes ⟨y|Ut|x⟩; this circuit receives the 2n-bit input (x, y), and outputs the 2m-bit approximation to the complex matrix element. Given a circuit that performs this function, it will be easy to build a circuit that multiplies the complex numbers together without using much space. This task would be difficult if Utwere an arbitrary 2n×2nunitary matrix. However, we can exploit the properties that we demanded of our quantum gate set - the gates from a discrete set, and each gate acts on a bounded number of qubits. Because there are a fixed finite number of gates, there are only a fixed number of gate subroutines that our simulator needs to be able to call. And because each gate acts on a few qubits, nearly all of its matrix elements vanish (when nis large), and the value ⟨y|Ut|x⟩can be computed to the required accuracy by a simple circuit requiring only a small amount of memory. For example, in the case of a single qubit acting on the first qubit, we have ⟨yn−1. . . y1y0|Ut|xn−1. . . x1x0⟩= 0 if yn−1. . . y1=xn−1. . . x1. A simple circuit can compare x1with y1,x2with y2, and so on, and if any of the bits disagree, the circuit outputs 0. In the event of an equality, the circuit outputs one of the four complex numbers ⟨y0|Ut|x0⟩, to mbits of accuracy. A simple classical circuit can encode the 8mbits of this 2×2 complex-valued matrix. Similarly, a simple circuit, requiring only space polynomial in m, can evaluate the matrix elements of any gate of fixed size. We conclude then, that a classical computer with memory space scaling like nT log T can simulate a quantum circuit with Tgates acting on nqubits. If we wished to consider quantum circuits with superpolynomial size T, we would need a lot of memory, but for quantum circuit families with size polynomial in n, a polynomial amount of memory suffices. We have therefore proved that BQP is contained in PSPACE. But it is also evident that the simulation is not efficient, as it requires exponential time, because we need to evaluate the sum of 2n(T−1) complex terms (where each term in the sum is a product of Tcomplex numbers). Though most of these terms are zero, we still need to evaluate an exponential number of nonvanishing terms. Most unitary transformations require large quantum circuits We saw that any given Boolean function can be computed by an exponential size classical circuit, and also that exponential size circuits are required to compute most functions. What are the corresponding statements about unitary transformations and quantum circuits? 22 II.2. Quantum Circuits We will not discuss how large a quantum circuit suffices to compute a given unitary transformation, focusing instead on showing that quantum circuits with exponential size are necessary to compute most unitary transformations. The question about quantum circuits is different than the corresponding question about classical circuits, because there is a finite set of Boolean functions action on nbits, but there is a continuum of unitary transformations acting on nqubits. Since the quantum circuits are countable (if the quantum computer’s gate set is finite), and the unitary transformations are not, we cannot reach arbitrary unitaries with finite-size circuits. We will be satisfied to accurately approximate an arbitrary unitary. As noted in our discussion of quantum circuit accuracy, to ensure that we have a good approximation in the L1norm to the probability distribution for any measurement performed after applying a unitary transformation, it suffices for the actual unitary ˜ Uto be close to the ideal unitary Uin the sup norm. Therefore we will say that ˜ Uis δ-close to Uif ∥˜ U−U∥sup ≤δ. How large should the circuit size Tbe if we want to approximate any arbitrary n-qubit unitary to accuracy δ? If we consider balls of radius δ(in the sup norm) centered at each unitary achieved by some circuit with Tgates, then the balls should cover the unitary group U(N), where N= 2n. The number Nballs of balls needed satisfies Nballs ≥Vol(U(N)) Vol(δ−ball), where Vol(U(N)) is the volume of the unitary group U(N)with respect to the sup norm and Vol(δ−ball)is the volume of a ball of radius δ. The geometry of U(N)is actually curved, but we may safely approximate it by a flat space and ignore that subtlety - all we need to know is that U(N)contains a ball centered at the identity with a small but constant redius C(independent of N). Ignoring the curvature, because U(N)has real dimension N2, the volume of this ball (a lower bound on the volume of U(N)) is ΩN2CN2, where ΩN2 denotes the volume of a unit ball in flat space; likewise, the volume of a δ-ball is ΩN2δN2. Therefore we have that Nballs ≥C δN2 . On the other hand, if our universal gate set contains a constant number Gof quantum gates (independent of n), and each gate act on no more than kqubits, where kis a constant, then the number of ways to choose the quantum gate at step tis at most Gn k= poly(n). Therefore the number NTof quantum circuits with Tgates acting on n-qubits is at most (poly(n))T. We conclude that if we want to reach every element of U(N)to accuracy δwith circuits of size T, hence NT≥Nballs, then we must have T≥22nlog(C/δ) log(poly(n)), i.e. the circuit size must be exponential in n. With polynomial-size quantum circuits, we can II. Classical and quantum circuits 23 achieve a good approximation to unitaries that occupy only an exponentially small fraction of the volume of U(N). Reaching any desired quantum state by applying a suitable quantum circuit to a fixed initial (e.g., product) state is easier than reaching any desired unitary, but still hard, because the volume of the 2n-dimensional n-qubit Hilbert space is exponential in n. Therefore, circuits with size exponential are required. Future quantum engineers will know the joy of exploring Hilbert space, but no matter how powerful their technology, most quantum states will remain forever out of reach. Chapter III Shor’s Algorithm The main goal of this chapter is to introduce and explain the algorithm Peter Shor presented to the world in [9]. This chapter is based on the sixth chapter of [5]. III.1 Some Quantum Algorithms Although we are not able to prove that BPP ⊊BQP, there are three approaches that we can take to study the differences between the capabilities of classical and quantum computers: (1) Nonexponential speedup. We can find quantum algorithms that are faster than the best classical algorithm, but not exponentially faster. These algorithms shed no light on the conventional classification of complexity. However they do demonstrate a type of separation between tasks that classical and quantum computers can perform. For example, we can mention Grover’s quantum speedup of the search of an unsorted data base, as can be studied in [4]. (2) “Relativized” exponential speedup. We can consider the problem of analyzing the contents of a “quantum black box”. This is a device that performs an a priori unknown unitary transformation on an input state. We can prepare said input for the box, and we can measure the output, but we cannot see inside the box. Our task is to find what the box does. It is possible to prove that quantum black boxes, or oracles, exist with this property. By feeding quantum superpositions to the box, one can learn what is inside with an exponential speedup, relative to how long it would take if we were only allowed classical inputs. We could say BQP ⊇BPP relative to the oracle. For example, we can mention Simon’s exponential quantum speedup for finding the period of a 2-to-1 function. (3) Exponential speedup for “aparently” hard problems. We can exhibit a quantum algorithm that solves a problem in polynomial time, where the problem appears to be hard for classical computers, so that it is strongly suspected (though not proven) that the problem is not in BPP. For example, we can mention Shor’s exponential quantum speedup for factoring integers. 25 26 III.1. Some Quantum Algorithms Deutsch’s problem We will discuss examples for each of the three approaches. But first, we will introduce a simple problem that will be useful for illustrating the power of quantum computation. Deutsch’s algorithm for distinguishing between constant and balanced functions f:{0,1} → {0,1}. We are presented with a quantum black box that computes f(x); that is, it enacts the two-qubit unitary transformation Uf:|x⟩|y⟩→|x⟩|y⊕f(x)⟩, which flips the second qubit if and only if f(x) = 1. Our mission is to determine whether f(0) = f(1) or not. If we are restricted to the “classical” inputs |0⟩and |1⟩, we need to access the box twice (x= 0 and x= 1) to get the answer. However if we are allowed to input a coherent superposition of these “classical” states, then one is enough. The quantum circuit that solves the problem is: Figure III.1: Circuit for Deutsch’s problem Here Hdenotes the Hadamard transform H:|x⟩ 7→ 1 √2X y (−1)xy |y⟩, or H:|0⟩ 7→ 1 √2(|0⟩+|1⟩), |1⟩ 7→ 1 √2(|0⟩−|1⟩), that is, His the 2×2matrix H: 1 √2 1 √2 1 √2−1 √2!. The circuit takes the input |0⟩|1⟩to |0⟩|1⟩ 7→ 1 2(|0⟩+|1⟩)(|0⟩−|1⟩) 7→ 1 2(−1)f(0) |0⟩+ (−1)f(1) |1⟩(|0⟩−|1⟩) 7→ 1 2(−1)f(0) + (−1)f(1)|0⟩ +(−1)f(0) −(−1)f(1)|1⟩1 √2(|0⟩−|1⟩). III. Shor’s Algorithm 27 Then when we measure the first qubit, we find the outcome |0⟩with probability one if f(0) = f(1) (constant function) and the outcome |1⟩the probability one if f(0) =f(1) (balanced function). A quantum computer enjoys an advantage over a classical computer because it can use quantum parallelism. Because we input a superposition of |0⟩and |1⟩, the output is sensitive to both the values of f(0) and f(1), even though we ran the box just once. Deutsch-Jozsa problem Now we will consider some generalizations of Deutsch’s problem as was exposed in [3]. We will continue to assume that we are to analyze a quantum oracle. However, in the hope of learning something about complexity, we will imagine that we have a family of oracles, with variable input size. We are interested in how the time needed to find out what is inside the box scales with the size of the input (where “time” is measured by how many times we query the box). In the Deutsch-Jozsa problem we are presented with a quantum oracle that computes a function taking nbits to 1, f:{0,1}n→ {0,1}, and we have in good authority that fis either constant (f(x) = c∀x) or balanced (f(x) = 0 for exactly half of the inputs). Our mission is to determine which of the two cases holds. In fact we can solve this problem also with a single query to the back box, using the same circuit as for Deutch’s problem, but with ninput qubits instead of just one. We note that if we apply nHadamard gates in parallel to nqubits, H(n)=H⊗H⊗···⊗H, then the n-qubit state transforms as H(n):|x⟩ 7→ n Y i=1   1 √2X yi={0,1} (−1)xiyi|yi⟩ ≡1 √2n 2n−1 X y=0 (−1)x·y|y⟩, where x, y represent n-bit strings and x·yis the bitwise inner product modulo 2or AND x·y= (x1∧y1)⊕(x2∧y2)⊕···⊕(xn∧yn). Acting on the input |0⟩n|1⟩, the action of the circuit is |0⟩n|1⟩ 7→ 1 √2n 2n−1 X x=0 |x⟩!1 √2(|0⟩−|1⟩) 7→ 1 √2n 2n−1 X x=0 (−1)f(x)|x⟩!1 √2(|0⟩−|1⟩) 7→ 1 2n 2n−1 X x=0 2n−1 X y=0 (−1)f(x)(−1)x·y|y⟩!1 √2(|0⟩−|1⟩). (III.1) 34 III.2. Periodicity More generally we may sum the geometric series A−1 X j=0 eiθj =eiAθ −1 eiθ −1,(III.4) using θy=2πyr mod N N. There are precisely rvalues of yin {0,1, . . . , N −1}such that −r 2≤yr mod N≤r 2.(III.5) To see this, imagine marking the multiples of rand Non a number line ranging from 0to rN −1. For each multiple of N, there is a multiple of rno more than distance r/2 away. For each of these values, the corresponding θysatisfies −πr n≤θy≤πr n. Now, since A−1<N r, for these values of θyall of the terms in the sum over jin eq. (III.4) lie in the same half-plane of the complex plane, so that the terms interfere constructively and the sum is substantial. We know that |1−eiAθ|≤|θ|, because the straight-line distance from the origin is less than the arc length along the circle, and for A|θ| ≤ πwe have |1−eiAθ| ≥ 2A|θ| π, because we can see that this distance is a convex function. We actually have A < N r+ 1, and hence Aθy< π(1 + r N)but by applying the above bound to  ei(A−1)θ−1 eiθ −1+ei(A−1)θ≥ ei(A−1)θ−1 eiθ −1−1, we can still conclude that  ei(A−1)θ−1 eiθ −1≥2(A−1)|θ| π|θ|−1 = 2A π−(1 + 2 π). Ignoring a possible correction of order 2/A then, we find that P(y)≥4 π21 r, III. Shor’s Algorithm 35 for each of the rvalues that satisfy eq. (III.5). Thus, with a probability of, at least, 4/π2, the measured value of ywill satisfy kN r−1 2≤y≤kN r+1 2, or k r−1 2N≤y N≤k r+1 2N, where k∈ {0,1, . . . , r−1}. The output of the computation is reasonably likely to be within distance 1/2of an integer multiple of N/r. Suppose that we know that r < M ≪N. Thus, we know that N/r is a rational number with a denominator smaller than M. Two distinct rational numbers with denominators less than Mcannot be closer than 1/M2. Thus, if we measure yto be within distance 1/2from an integer multiple of N/r, then there is a unique value of k/r (with r < M) determined by y/N, provided that N≥M2. This value of k/r can be efficiently extracted from the measured y/N by continued fractions. Now, with probability exceeding 4/π2, we have found a value of k/r where Kis selected from {0,1, . . . , r−1}. It is reasonably likely that kand rare relatively prime, so that we have succeeded in finding r. With a query of the oracle, we may check whether f(x) = f(x+r). But if gcd(k, r)= 1, we have found only a factor r1of r. In the case where we do not initially succeed in finding rusing the quantum algorithm, we have various strategies to improve the chances of success. For instance, we can test nearby values of ysince the measured value might be close to the range −r/2≤yr mod N≤r/2, but not precisely within it. Additionally, trying a few multiples of r(the value of gcd(k, r), if not 1, is probably not large) can also help refine our result. If the above attempts do not yield the desired factor r, we can resort to repeating the quantum circuit to obtain a new value k′/r with a probability exceeding 4/π2. At this point, k′might share a common factor with r, leading us to determine another factor r2 of r. However, it is reasonably likely that gcd(k, k′)=1, in which case we can compute r= lcm(r1, r2). We can estimate the probability that randomly selected kand k′are relatively prime. Since a prime number pdivides a fraction 1/p of all integers, the probability that pdivides both kand k′is 1/p2. Conversely, kand k′are relatively prime if no prime divides both k and k′. Thus, the probability that kand k′are relatively prime is given by: P(k, k′coprime) = Y pprime 1−1 p2=1 ζ(2) =6 π2≈0.61, where ζis the Riemann zeta function. Hence, after some constant number of repetitions of the algorithm, the probability of success in finding rbecomes significantly high, thanks to the repeated trials and the likelihood of kand k′being relatively prime. This makes the quantum algorithm a promising approach for factoring large numbers efficiently. 36 III.2. Periodicity From FFT to QFT Now let’s consider the implementation of the quantum Fourier transform. The Fourier transform X x f(x)|x⟩ 7→ X y 1 √NX x e2πixy/N f(x)!|y⟩, is a multiplication by an N×Nunitary matrix. In said matrix, the (x, y)matrix element is (e2πi/N )xy. Naively, this transforms requires O(N2)elementary operations. However there is a well-known and very useful classical procedure that reduces the number of operations to O(Nlog N). Assuming N= 2n, we start by expressing xand yin binary as x=xn−1·2n−1+xn−2·2n−2+···+x0, y =yn−1·2n−1+yn−2·2n−2+···+y0. In the product of xand ywe may discard any terms containing nor more powers of 2, as there is no contribution to e2πixy/N from such terms. Thus, we may write xy 2n≡yn−1(.x0) + yn−2(.x1x0) + ···+y0(.xn−1. . . x0),(III.6) where the factors in parentheses are binary expressions; e.g. .x2x1x0=x2·2−1+x1·2−2+x0·2−3. We can now evaluate ˜ f(x) = 1 √NX y e2πixy/N f(y), for each of the 2nvalues of x. However the sum over yfactors into nsums over yk= 0,1, which can be done sequentially in a time of order n. With quantum parallelism, we can do far better. From eq. (III.6) we obtain QFT :|x⟩ 7→ 1 √NX y e2πixy/N |y⟩ 7→ 1 √2n(|0⟩+e2πi(.x0)|1⟩)(|0⟩+e2πi(.x1x0)|1⟩) . . . (|0⟩+e2πi(.xn−1...x0)|1⟩). The QFT takes each computational basis state to an unentangled state of nqubits; thus it is reasonable to anticipate that it can be efficiently implemented. Indeed, let’s consider the case n= 3. We can readily see that the circuit Figure III.2: Circuit for the QFT. III. Shor’s Algorithm 37 does the job. Note that the order of the bits has been reversed in the output. Each Hadamard gate acts as H:|xk⟩ 7→ 1 √2(|0⟩+e2πi(.xk)|1⟩). The other contributions to the relative phase of |0⟩and |1⟩in the k-th qubit are provided by the two-qubit conditional rotations, where Rd=1 0 0eπi/2d, and d= (k−j)is the “distance” between the qubits. In the case n= 3, the QFT is constructed from three Hgates and three controlled-R gates. In general, the QFT is constructed from nHgates and n 2=n(n−1)/2controlled Rgates. A two-qubit gate is applied to each pair of qubits, again with controlled relative phase π/2d, where dis the distance between the qubits. Thus the circuit family that implements the QFT has a size of order log(N)2. We can further reduce the circuit complexity to linear in log(N)by accepting an implementation with fixed accuracy. The two-qubit gates acting on distant qubits contribute only exponentially small phases, allowing us to drop gates acting on pairs of qubits separated by more than mqubits. Consequently, each term in equation (III.6) is replaced by an approximation with mbits of accuracy. The resulting error in xy/2nis no worse than n2−m, enabling us to achieve an accuracy of εin xy/2nwith m≥log(n/ε). By retaining only the gates acting on qubit pairs with distances smaller than m, the circuit size becomes of order mn ∼mlog(n/ε). In fact, if we plan to measure in the computational basis immediately after the Quantum Fourier Transform (QFT), there are further simplifications we can exploit. Notably, there is no need to apply any two-qubit gates at all. The controlled-Rdgate exhibits a symmetric action on the two qubits: it acts trivially on states |00⟩,|01⟩, and |10⟩, while modifying the phase of state |11⟩by eiθd. Consequently, we can interchange the control and target bits without affecting the gate’s action. With this change, our circuit for the 3-qubit QFT becomes: Figure III.3: Circuit for the QFT, with interchange. Once we have measured |y0⟩, we know the value of the controlled bit in the controlled- R1gate that acted on the first two qubits. Therefore, we will obtain the same probability 38 III.3. Factoring as period finding distribution of measurement outcomes if, instead of applying the controlled-R1and then measuring, we instead measure y0first and only then apply (R1)y0to the next qubit, conditioned on the outcome of the measurement of the first qubit. Similarly we can replace the controlled-R1and controlled-R2acting on the third qubit by the single qubit rotation (R2)y0(R1)y1, that is, a rotation with relative phase π(.y1y0), after the values of y0and y1have been measured. Altogether then, if we are going to measure after performing the QFT, only nHadamard gates and n−1single qubit rotations are required. The circuit size for the QFT is remarkably simple. However, we should note that, however interesting these results are, such simplifications are currently very far of being implemented. Such rotation gates are constructed from the primitive ones that the corresponding backend has. And this is not expected to change in a long time. III.3 Factoring as period finding What does the factoring problem have to do with periodicity? There is a well-known randomized reduction of factoring to determining the period of a function. Although this reduction is not directly related to quantum computing, we will discuss it here for the completeness of this work, and because the prospect of using a quantum computer to factor large numbers has generated so much excitement. Suppose that we want to find a factor of the n-bit number N. Select pseudo-randomly a < N and compute the Euclidean algorithm, which has cost O(log(N)3)in order to get gcd(a, N). If gcd(a, N)= 1, then we have found a factor of N. Let’s study the case in which gcd(a, N) = 1. We know that the numbers which are coprime to Nform a group under multiplication modulo N. Therefore, ahas an order r, which is the smallest positive integer such that ar≡1 mod N. The order ris the period of the function fN,a(x) = axmod N. As we have seen, the period of a function can be found efficiently using the QFT. Thus, if we can compute fN,a(x)efficiently, we can find the order rof aefficiently. Computing fN,a may look difficult at first, since the exponent xcan be very large. However, we can use the binary representation of xto compute fN,a efficiently. We can write xas x=xm−1·2m−1+xm−2·2m−2+···+x1·2 + x0, III. Shor’s Algorithm 39 and we have axmod N= (a2m−1)xm−1·(a2m−2)xm−2···(a2)x1·ax0mod N. Each a2jcan be computed efficiently by a classical computer using repeated squaring: a2jmod N=(aif j= 0 (a2j−1)2mod Nif j > 0. So only m−1classical multiplications mod Nare required to assemble a table of all a2j’s. The computation of axmod Nis accomplished by multiplying together the relevant entries from the table. This process requires a maximum of m−1 mod Nmultiplications, with each multiplication necessitating at most an order of (log(N))2operations. As r < N, selecting m∼2 log Nprovides a reasonable chance of finding r. Consequently, the total cost of computing fN,a is approximately (log(N))3. This analysis highlights the efficiency of the algorithm and its polynomial complexity in terms of log(N). Schematically, the circuit has the form: Figure III.4: Circuit for calculating fN,a(x). Multiplication by a2jis performed if the control qubit xjis 1. Let’s suppose now that we have found the period rof fN,a. If ris even, then we have N|ar−1=(ar/2−1)(ar/2+ 1). We know that Ndoes not divide ar−1, since if it did, the order of awould be smaller than r/2. Thus, if it is also the case that Ndoes not divide ar/2+ 1, or ar/2=−1 mod N, then Nmust have a nontrivial common factor with each of ar/2±1. Therefore, we gcd(N, ar/2+ 1) = 1 is a nontrivial factor of Nand we are done. We see that, once we have found r, we succeed in factoring Nunless either ris odd or ris even and ar/2≡ −1 mod N. How likely is success? Let’s suppose that Nis a product of two prime factors p=q, which is actually the least favorable case. N=pq. 40 III.3. Factoring as period finding For each a < pq, there exist a1< p and a2< q such that a≡a1mod p, a≡a2mod q. Choosing a random a < N is, therefore, equivalent to choosing two random numbers a1< p and a2< q. Now let r1and r2be the orders of a1and a2modulo pand q, respectively. The Chinese Remainder theorem tells us that solving ar≡1 mod Nis equivalent to ar1≡1 mod p, ar2≡1 mod q. Therefore, r= lcm(r1, r2). If r1and r2are both odd, then so is rand we lose. However, if either r1or r2is even, then ris even and we have a chance of success. If ar1/2≡ −1 mod p, ar2/2≡ −1 mod q, (III.7) then we have ar/2≡ −1 mod Nand we lose. Otherwise, if either ar/2≡ −1 mod p, ar/2≡1 mod q, (III.8) or ar/2≡1 mod p ar/2≡ −1 mod q, (III.9) then ar/2≡ −1 mod Nand we succeed. Suppose that r1= 2s1r′ 1, r2= 2s2r′ 2, where r′ 1and r′ 2are odd and s1> s2. Then r= lcm(r1, r2) = 2r2·integer, so that ar/2≡1 mod qand eq. (III.8) is satisfied and we win. Analogously, s2> s1implies that eq. (III.9) is satisfied and we win as well. But if s1=s2, then r=r1·odd =r2·odd′so that eq. (III.7) is satisfied and we lose. Therefore it all comes down to: for s1=s2we lose and for s1=s2we win. What is the probability of s1=s2? We know that the multiplicative group Z∗ pis cyclic of order p−1 and has a generator element. Suppose that p−1 = 2k·c, where cis odd, and consider the orders of all the elements of the group. For brevity, we will discuss only the case k= 1, which is the least favourable case for us. Then if bis a generator of Z∗ p, the even powers of bhave odd order, and the odd powers of bhave order 2·odd. In this case, then, r= 2t·odd III. Shor’s Algorithm 41 where t∈ {0,1}, each occurring with equal probability. Therefore, if p, q are both of this unfavorable form, and a1and a2are chosen at random, then the probability of s1=s2is 1/2. Hence, once we found r, the probability of finding a factor is, at least 1/2, if Nis a product of two primes. If Nhas more than two prime factors, the probability of success is even higher. The method fails if Nis a prime power, but prime powers can be efficiently factored by other methods. Chapter IV Real World Implementations This last chapter will be divided in two sections. In the first section, we will discuss the current state of the art of quantum computing, implementing Shor’s algorithm to factorize a number and running it in three different simulators. In this part we will study how long it takes right now to factor a number using Shor’s algorithm and the size of the numbers we will be able to factorize. In the second section, we will implement the Quantum Fourier Transform in a real quantum computer, and we will discuss the results obtained. We will study the noise of the current open-source IBM quantum computers. IV.1 Shor’s Algorithm implementation As we have previously proven, there is a time-efficient way to factorize a number using a quantum computer. On the other hand, we do not know any polynomial time algorithm to factorize a number using a classical computer. In this chapter, we will implement Shor’s algorithm and run it in three quantum computer simulators made by IBM Quantum using the Qiskit environment. A good and useful textbook and tutorial can be found in [6] and [7]. We have based our code in the implementation by Qiskit at [8]. This guide implements the algorithm using n+ 4 qubits. This means that, in order to implement the algorithm to factor the number 15 as the guide does, we would need 8qubits. We have chosen a simulator instead of a real quantum computer because there is not any decent size opensource quantum computer available yet. In fact, none of them offer more than 7qubits. A lot of progress need to be made in this matter. However, this will do the job as a proof of concept. Simulators Our goal will be to observe the different time performances of the three simulators and try to understand why they are the way they are. The three simulator we will use are: •simulator_statevector: This simulator computes the wavefunction of the qubit’s 43 50 IV.2. QFT implementation Executions and results Once we have the code, we need to decide the number of qubits we want to use, as well as the bound for the rotations in the second implementation. However, our aim is to study how the noise affects the QFT, so we have decided to take a statistical approach in order to study this phenomenon. We have decided to execute the QFT for nqubits, with nranging from 3to 7, both included. Also, we have chosen the bound for the rotations in the second implementation to be 1≤m≤n−2. This is because if the bound is n−1or higher, the bounded circuit will end up being the generic circuit. Each execution was repeated 8000 times, and the results were stored in different diagrams, as mentioned before. We can observe, as expected, that the execution on the simulator is perfect in the sense that it shows no error at all. All the runs in this backend provide the result 0, which is the expected one. Because of this, we will only show the results obtained for the generic QFT for 3qubits in the simulator, as they are exactly the same as the results obtained for the other number of qubits. This is shown in figure IV.3. However, when we work with the real quantum computer, we start to see how the noise affects the results. Two examples of histograms of this type are the figures IV.4 and IV.5. In order to show how noise affects in all studied cases, we present the following table with the results obtained for each possible QFT implementation and each quantum backend. In the columns we present what percentage of times the result 0was obtained and what position does the result 0occupy in the probability distribution of measurement results. In the rows we present the different backends used, as well as the number of qubits used and the bound for the bounded QFT. Figure IV.3: Simulator_Statevector: generic QFT for 3qubits in the simulator. IV. Real World Implementations 51 Figure IV.4: IBMQ_Jakarta: generic QFT for 3qubits in IBMQ_Jakarta. Figure IV.5: IBMQ_Nairobi: generic QFT for 3qubits in IBMQ_Nairobi. 52 IV.2. QFT implementation Backend Percentage Position Q= 3 IBM_Lagos 86.58% 1 IBM_Nairobi 80.51% 1 IBM_Perth 79.21% 1 IBMQ_Jakarta 86.2% 1 Q= 3, B = 1 IBM_Lagos 90.25% 1 IBM_Nairobi 85.96% 1 IBM_Perth 84.39% 1 IBMQ_Jakarta 90.74% 1 Q= 4 IBM_Lagos 48.21% 1 IBM_Nairobi 48.59% 1 IBM_Perth 45.01% 1 IBMQ_Jakarta 58.18% 1 Q= 4, B = 1 IBM_Lagos 81.84% 1 IBM_Nairobi 64.15% 1 IBM_Perth 66.36% 1 IBMQ_Jakarta 83.04% 1 Q= 4, B = 2 IBM_Lagos 71.46% 1 IBM_Nairobi 39.49% 1 IBM_Perth 52.96% 1 IBMQ_Jakarta 67.65% 1 Q= 5 IBM_Lagos 11.35% 3 IBM_Nairobi 8.55% 4 IBM_Perth 21.6% 2 IBMQ_Jakarta 32.05% 1 Q= 5, B = 1 IBM_Lagos 61.79% 1 IBM_Nairobi 69.5% 1 IBM_Perth 47.56% 1 IBMQ_Jakarta 68.0% 1 Q= 5, B = 2 IBM_Lagos 25.28% 1 IBM_Nairobi 34.56% 1 IBM_Perth 24.68% 1 IBMQ_Jakarta 41.1% 1 Backend Percentage Position Q= 5, B = 3 IBM_Lagos 6.2% 5 IBM_Nairobi 8.74% 4 IBM_Perth 8.66% 3 IBMQ_Jakarta 30.4% 1 Q= 6 IBM_Lagos 2.8% 11 IBM_Nairobi 2.69% 14 IBM_Perth 2.33% 17 IBMQ_Jakarta 5.96% 2 Q= 6, B = 1 IBM_Lagos 20.66% 2 IBM_Nairobi 42.91% 1 IBM_Perth 28.94% 1 IBMQ_Jakarta 51.65% 1 Q= 6, B = 2 IBM_Lagos 10.73% 2 IBM_Nairobi 6.73% 4 IBM_Perth 6.53% 4 IBMQ_Jakarta 18.39% 1 Q= 6, B = 3 IBM_Lagos 2.03% 25 IBM_Nairobi 9.65% 2 IBM_Perth 4.96% 2 IBMQ_Jakarta 7.24% 2 Q= 6, B = 4 IBM_Lagos 2.23% 16 IBM_Nairobi 3.18% 10 IBM_Perth 2.91% 6 IBMQ_Jakarta 9.35% 2 Q= 7 IBM_Lagos 1.24% 31 IBM_Nairobi 2.7% 1 IBM_Perth 1.74% 6 IBMQ_Jakarta 1.43% 27 Q= 7, B = 1 IBM_Lagos 7.38% 4 IBM_Nairobi 22.51% 1 IBM_Perth 19.94% 1 IBMQ_Jakarta 40.19% 1 IV. Real World Implementations 53 Backend Percentage Position Q= 7, B = 2 IBM_Lagos 3.25% 9 IBM_Nairobi 5.23% 4 IBM_Perth 2.21% 10 IBMQ_Jakarta 7.53% 2 Q= 7, B = 3 IBM_Lagos 1.95% 15 IBM_Nairobi 7.29% 1 IBM_Perth 2.93% 7 IBMQ_Jakarta 4.3% 5 Q= 7, B = 4 IBM_Lagos 1.1% 37 IBM_Nairobi 3.33% 2 IBM_Perth 2.46% 7 IBMQ_Jakarta 2.24% 7 Q= 7, B = 5 IBM_Lagos 1.46% 18 IBM_Nairobi 2.34% 4 IBM_Perth 2.19% 2 IBMQ_Jakarta 1.89% 15 Table IV.3: Results for the different qubits, bound and backend choices. All results can be seen in the following link: https://github.com/JaviLobillo/TFG_ Quantum_Complexity/tree/main/Results Nonetheless we can interpret the results obtained in a more general way. All main points in this regard are: •First and most important, we can see that the noise is so high right now that it is not useful to work with real quantum computers yet. Many advancements in the building of quantum computing are coming and they will be welcome in order to change the current statu quo. •IBMQ_Jakarta seems to be the most accurate backend for most of the cases, although it is still not even near to be accurate enough to be useful. However, the fact that it is the most accurate seems somehow counter-intuitive because, although all four quantum backends share the same Falcon r5.11H type architecture, IBMQ_Jakarta has the least quantum value with a value of 16, compared to the other’s value of 32. These, and other parameters, can be seen in Table IV.2. This would mean that IBMQ_Jakarta should be less accurate, and we see it is not the case. However, when we work with such inaccurate machines, the fact that one has more or less accuracy can be difficult to attribute to a particular reason, beyond general lack of accuracy. Furthermore, these performance measures lose reliability when we consider, 54 IV.2. QFT implementation for example, the fact that the quantum computers need to be continuously calibrated, so the larger the time from last calibration induces larger accuracy loss. Also, not every circuit uses the resources in the same way, so accuracy parameters can vary from circuit to circuit (the QFT being just one of the possible ones). •We can see that the more qubits we use, the more noise we get. This is because the more qubits we use, the more gates we need to apply, and hence the more noise we get. This problem becomes even more important as the right result is not even the most probable one for most of the 5qubits (or more) implementations. •Using the bounded QFT instead of the generic one reduces the noise significantly. This is because the bounded QFT uses less gates than the generic one, and hence the noise is reduced. This might be counter-intuitive, as theoretically this would be a less accurate implementation of the QFT. A bound value of 1and 2makes the 5qubit QFT to accurate enough as to make the right result of 0the most probable again for all backends. Backend IBM_Lagos IBM_Perth IBM_Nairobi IBMQ_Jakarta Processor type Falcon r5.11H Falcon r5.11H Falcon r5.11H Falcon r5.11H Qubits 7 7 7 7 QV 32 32 32 16 CLOPS 2.7K 2.9K 2.6K 2.4K Median T1 113.19 µs 174.07 µs 101.23 µs 124.11 µs Median T2 60.61 µs 86.27 µs 62.52 µs 39.66 µs Table IV.4: Parameters for the different backends. The table contains the main physical parameters that differentiate the four quantum backends. QV means Quantum Value and CLOPS stands for Circuit Layer Operations Per Second. Median T1 and median T2 are also included. T1 is the relaxation time, the time it takes to decay and lose its amplitude value. T2 is the dephasing time, the time it takes to lose the phase coherence. As we mentioned before, one could think that IBMQ_Jakarta ought to be the worst performing backend, and experimental results tell us otherwise. Results and conclusions This Bachelor’s thesis has presented itself as an opportunity to better understand the new world which has been presented to us in the last few years, that is, the world of quantum computing. The best way we can try to understand this world is by first having a background research on its theoretical bases and then try to work in a more practical way with what it can offer. And that is exactly how this work was conducted. The first chapter was dedicated to the theoretical background of quantum computing. We have seen how quantum mechanics can be used to perform computations in a different way than the classical one. We have seen as well how the qubit is the quantum equivalent of the classical bit, and how the quantum gates are the quantum equivalent of the classical gates. Finally we have seen how the quantum gates can be represented by unitary matrices. This approach has provided a mental structure to understand the quantum circuits and algorithms that we would study later on. This mental structure was necessary as the beginner quantum computing student is not expected to think in terms of this structure as fluidly as he does in terms of classical computing. In the second chapter we provided the basis for understanding how classical and quantum circuits work. This base is critical as all complexity theory that came in the third chapter is based on circuit design and size rather than time complexity. We got to categorize the complexity of a problem in terms of the complexity of the circuits that solve it, both in the classical and quantum case. We have related the complexity of a problem to the complexity of the circuits that solve it. Also we have seen how we can relate the depth of a circuit to the time complexity of the problem it solves. We got to explicitly differenciate easy problems from hard problems, which is crucial to understand the importance of quantum computing. Finally we got to relate quantum and classical complexity classes. In the third chapter we have seen the main results of quantum computing. We have seen how we can use quantum circuits to solve problems in constant time that would take linear time to solve classically, although as both cases are considered to be easy, this was only to introduce Simon’s and Shor’s algorithms. Shor’s algorithm, which uses the quantum Fourier transform, is the most important quantum algorithm to date, as it provides a polynomial time algorithm to factorize numbers, which is a problem that is believed to be hard classically. If the factoring problem is confirmed to be classically hard, this would mean that we have found a problem that can be solved in polynomial time using a quantum computer but not using a classical one. We have seen that the whole structure of the work leads us to understand one of the 55 56 IV.2. QFT implementation reasons why quantum computing is so important, which is that it can solve problems that are believed to be hard classically in polynomial time. The whole thesis works constructively, giving all the bricks necessary, in order to build the understanding of the reader to the point where he can understand how important Shor’s algorithm and quantum computing is. Chapter four of the project focuses on two distinct proofs of concept. The first proof of concept involves the implementation of Shor’s algorithm within a quantum simulator. While this approach offers the advantage of testing the main algorithm discussed in this work, it’s worth noting that a simulation does not reflect the algorithm’s true efficiency. The second proof of concept centers around the implementation of the quantum Fourier transform, a crucial component of Shor’s algorithm. Unlike the first implementation, this one is executed on real quantum computers. Its primary purpose is to analyze how noise influences the results. Consequently, this second approach offers valuable insights into the current state of quantum computing technology. Bibliography [1] S. Aaronson. Introduction to Quantum Information Science Lecture Notes, 2018. Online PDF at https://www.scottaaronson.com/qclec.pdf. [2] E. Bernstein and U. Vazirani. Quantum complexity theory. SIAM Journal on Computing, 26(5):1411–1473, 1997. [3] D. Deutsch and R. Jozsa. Rapid solutions of problems by quantum computation. Royal Society, 439(1907), 1992. [4] L. K. Grover. A fast quantum mechanical algorithm for database search. In Proceedings of the Twenty-Eighth Annual ACM Symposium on Theory of Computing, STOC ’96, page 212–219, New York, NY, USA, 1996. Association for Computing Machinery. [5] J. Preskill. Lecture Notes for Physics 219: Quantum Computation, 1997-2022. Online PDF at http://theory.caltech.edu/~preskill/ph219/index.html#lecture. [6] Qiskit. Qiskit Textbook, 2023. https://qiskit.org/learn. [7] Qiskit. Qiskit Tutorials, 2023. https://qiskit.org/documentation/tutorials. html. [8] Qiskit. Shor’s Algorithm, 2023. https://learn.qiskit.org/course/ ch-algorithms/shors-algorithm. [9] P. W. Shor. Polynomial time algorithms for prime factorization and discrete logarithms on a quantum computer. SIAM J. Sci. Statist. Comput., 26:1484, 1997. [10] D. R. Simon. On the power of quantum computation. SIAM Journal on Computing, 26(5):1474–1483, 1997. 57