PROC. 28th INTERNATIONAL CONFERENCE ON MICROELECTRONICS (MIEL 2012), NIŠ, SERBIA, 13-16 MAY, 2012 Quantum Computers: Registers, Gates and Algorithms Paul Isaac Hagouel and Ioannis G. Karafyllidis Abstract - Quantum computing is a process that incorporates interacting physical systems that represent quantum bits and quantum gates. We present the quantum bit (qubit), the quantum register and the quantum gates. The qubit is described as a vector in a two-dimensional Hilbert space and the quantum register, which comprises a number of qubits, as a vector in a multidimensional Hilbert space. Quantum gates are Hilbert space operators that rotate the qubit or the quantum register vectors. Quantum computations are modeled and described using a quantum circuit model. We also present a quantum computer simulator based on the circuit model of quantum computation. In this model quantum computations and quantum algorithms are represented by circuits, which comprise quantum gates and quantum registers. The well-known Deutsch’s algorithm is described and the corresponding quantum circuit is presented. Possible applications of quantum computers are be presented and discussed. is the probability of measuring each one of the possible quantum register basis states and the phase of each state at each computation step. We will also present a quantum computer simulator based on the circuit model of quantum computation [14]. In this model quantum computations and quantum algorithms are represented by circuits, which comprise quantum gates and quantum registers. This simulator has been used for the visualization of the quantum Fourier transform [15], the study of cellular quantum computer architecture [16], the simulation of entanglement generation and variation in quantum computations [17], and the definition and evolution of quantum cellular automata [18]. The complete simulator comprises a graphical user interface used for entering the inputs, which are the initial states of the qubits that form a quantum register and the quantum gates applied at each computation step. The quantum computation is visualized using two graphical outputs showing the probability of measuring each one of the possible quantum register basis states and the phase of each state at each computation step. The well-known Deutsch’s algorithm was the first algorithm that showed that a quantum computer can outperform a classical one. The problem posed by Deutsch is: “Given a binary function f(x) find out if the function is constant ( i.e. f(0)=f(1) ) or balanced ( i.e. f(0) ≠ f(1) ) by performing the minimum number of computations.” On a classical computer one has to compute the value of f(x) twice and compare the results, but, as Deutsch showed, on a quantum computer one computation is enough [19]. This algorithm will be described and the corresponding quantum circuit will be presented. We will also present analytically the execution of this algorithm on the quantum computer simulator. Finally, quantum algorithms and possible applications of quantum computers will be presented and discussed. I. INTRODUCTION Quantum computation is one of the major challenges for computer science and engineering in the 21st century [1, 2]. Quantum computers are far more efficient than their classical counterparts in factoring large numbers [3], searching databases [4–6] and simulating physical systems [7]. All the aspects of quantum computing are currently under intensive study and, as a result, the first quantum algorithms appeared before the actual fabrication of the first quantum gate [8-10]. Recently, several implementations of quantum computing circuits have been presented. Trapped ions [11], superconductors [12] and photonics [13]. Here we present the quantum bit (qubit), the quantum register and the quantum gates. The qubit will be described as a vector in a two-dimensional Hilbert space and the quantum register, which comprises a number of qubits, as a vector in a multidimensional Hilbert space. Quantum gates are operators of the Hilbert space that rotate the qubit or the quantum register vectors. Quantum computations will be modeled and described using a circuit model in which the inputs are the initial states of the qubits that form a quantum register and the computation is broken down in successive steps in which quantum gates act on the state of the quantum register. The output of the circuit, i.e. the result of the computation, II. THE QUBIT AND THE QUANTUM REGISTER A. The qubit The unit of quantum information is the quantum bit or qubit. As its classical analog, the qubit can be in two basis states which are symbolized as P. I. Hagouel is with Optelec, 11 Chrysostomou Smyrnis Street, GR–54622 Thessaloniki, GREECE, E–mail: hagouel@eecs.berkeley.edu I. G. Karafyllidis is with the Department of Electrical and Computer Engineering, Democritus University of Thrace, GR-67100 Xanthi, GREECE, E-mail: ykar@ee.duth.gr 978-1-4673-0238-8/12/$31.00 © 2012 IEEE 0 and 1 . While a classical bit can be only 0 or 1, a qubit states can be in 0 or 1 , or in any linear combination of these two states, called a superposition: 15 ψ ψ =a 0 +b1 , where a and b are complex numbers and are called probability amplitudes. When measuring the state of a qubit, which is in a superposition of basis states, the measurement outcome is 0 with probability a 2 q R = c 0 0 0 + c 1 01 + c 2 10 + c 3 11 The probability of measuring each basis state must be equal to one: and 1 with 2 probability b . Since probabilities must sum up to one: c a 2 + b 2 = 1 . The qubit state is a vector in a two– dimensional Hilbert space and can be described as a vector in the Bloch sphere, shown in Figure 1, and is usually written as: ψ = cos ϑ 2 iϕ 0 + e sin ϑ 2 1 (3) 0 2 + c1 2 + c 2 2 + c3 2 =1 (4) Replacing the binary state representation with decimal numbers, the state of a quantum register with n qubits is given by: qR = (1) 2 n −1 ∑c i i (5) i =0 with where ω and φ are angles that determine the position of the qubit vector direction in the Bloch sphere. The phase angle φ is related to quantum mechanical interference. 2 n −1 ∑ i =0 ci 2 =1 (6) III. QUANTUM GATES Quantum gates are operators of the Hilbert space that act on qubits and quantum registers and change their states by rotating their corresponding state vectors. Quantum gates can act on one, two or three qubits. The action of a quantum gate G on a qubit or on a quantum register is described by: G q I = qR where q I is the state of the qubit or the quantum register Fig. 1. The qubit vector in the Bloch sphere. before the action of the gate and q R is the new state after The qubit can be represented by several two-state quantum systems such as the electron spin or the polarization of the photon. the action of the gate. The most important quantum gates are presented below. The Hadamard gate, symbolized by H, acts on one qubit. If the qubit is in a basis state the H gate brings it to a state superposition in which the probability to measure both basis states equals to 0.5. The circuit symbol and the action of the H gate are shown in Figure 2. The phase shift gate, Φ, acts on one qubit and changes its phase angle φ as shown in Figure 3. The controlled–NOT (CNOT) gate acts on a two-qubit quantum resister and is shown in Figure 4. The upper B. The quantum register A quantum register is a physical system that comprises more than one qubits. The state of a quantum register is also a vector in a multi-dimensional Hilbert space and is given by the tensor product of the states of its qubits. In the case of a quantum register that comprises two qubits q 1 and q 0 its state q R (7) qubit, c , is the control qubit and the lower qubit, t , is is given by: q R = q1 ⊗ q0 = q1 q0 = q1 q0 the target qubit. The gate acts on the target qubit and reverses its state only if the control qubit is in state 1 . (2) The states of the quantum register before and after the where ⊗ is the tensor product symbol. For example the state of a four-qubit quantum register is written as: action of the CNOT gate are: respectively. 16 cI t I and cO tO The controlled phase gate, CΦ, shown in Figure 5, acts on a two-qubit register and changes the phase angle of the target qubit by an angle φ if the state of the control qubit is 1 . qI qO 1 2 1 2 0 1 1 2 1 2 ( 0 + 1 ) ( 0 − 1 ) ( 0 + 1 ) 0 ( 0 − 1 ) 1 Fig. 2. The circuit symbol and the action of the H gate. ci t i co t o 00 00 01 01 10 10 11 e i ϕ 11 Fig. 5. The circuit symbol and the action of the CΦ gate. qI qO 0 0 1 eiϕ 1 a 0 +b 1 a 0 + eiϕ b 1 Fig. 3. The circuit symbol and the action of the Φ gate. c 2 i c 1i t i c 2 o c 1o t o 000 000 0 01 0 01 010 010 ci t i co t o 011 011 00 00 10 0 10 0 01 01 101 101 10 11 110 111 11 10 111 110 Fig. 4. The circuit symbol and the action of the CNOT gate. Fig. 6. The circuit symbol and the action of the CCNOT gate. 17 The controlled-controlled-NOT gate, CCNOT, acts on a three-qubit quantum register. The two upper qubits The gates H, Φ and CNOT form a universal quantum gate set and any quantum computation can be carried out using only these gates. t , is the target qubit. The gate acts on the target qubit IV. QUANTUM COMPUTING c2 and c1 are the control qubits and the lower qubit, and reverses its state only if the control qubits are both in In the circuit model of quantum computation the input is the initial state of the quantum register. A sequence of computation steps is executed and at the end the final state of the quantum register, which is the computation result, is measured. In each computation step a number of quantum gates acts on the quantum register. The combined action of the gates in each step is given by the tensor product of the corresponding Hilbert space operators. If the state of the quantum register at the end of computation step n-1 is state 1 . The states of the quantum register before and after the action of the CCNOT gate are: c2 I c1I t I c2O c1O tO respectively. and The circuit symbol and the action of the CCNOT gate are shown in Figure 6. q Rn −1 , the new state at the end of step n is given by: q Rn = G n q Rn −1 8) We developed a quantum computer simulator (QCS) to simulate quantum computations on classical computers [14]. The inputs to the simulator are the number of the qubits in the quantum register, the number of computation steps, the initial state of the qubits that form a quantum register and the gates applied at each computation step. All inputs are entered through a graphical user interface. The pseudocode of the quantum computer simulator is: c i t 2 i t 1i c o t 2 o t 1o 000 000 0 01 0 01 010 010 (2). Read the number of qubits in the quantum register and the number of computation steps. 011 011 (3). Read the initial state of the quantum register. 10 0 10 0 101 110 (4). Read the quantum gate configuration at each computation step. 110 101 111 111 (1). Start (5). Calculate the tensor product of the initial state of the quantum register qubits. (6). Take the first computation step ( i=1 ). (7). Calculate the tensor product of the quantum gate matrices applied at the ith computation step. Fig. 7. The circuit symbol and the action of the F gate. (8). Calculate the new state of the quantum register. The Fredkin gate, F, acts on a three-qubit quantum register. The upper qubit, c , is the control qubit and the (9). Calculate the phase of the quantum register state. two lower qubits, t 2 and t1 , are the target qubits. The (10). If the number of computation steps is less that or equal to the number defined by the user set i=i+1 and go to step (7) else, continue. F gate swaps the states of the two target qubits if the state of the control qubit is 1 . The states of the quantum (11). Write the probability amplitudes and probability distribution at each computation step. register before and after the action of the F gate are: c I t 2 I t1I and cO t 2O t1O respectively. The circuit (12). Write the final quantum register state. symbol and the action of the F gate are shown in Figure 7. (13). Produce graphical output. 18 The quantum computation shown in Figure 8 comprises two qubits and five steps. The first step is the initial state of the quantum register, 11 . In the second step, an H gate is applied to the upper (second) qubit and no gate to the lower (first) qubit. In the third step a CNOT gate is applied with the second qubit as control and the first as target. The same gate is applied in the fourth step. In the fifth step an H gate is applied to the second qubit and no gate to the first qubit. The circuit that describes this quantum computation is shown in Figure 8(a). This circuit entangles and disentangles the two qubits in the quantum register [10]. In Figure 8(b) a matrix is shown. The columns of this matrix represent the computation steps and the rows the possible base states of the quantum register, which are also written in decimal form. The first computation step is the initial state of the quantum register, which in this case is 11 . A measurement of the quantum register at this step will give the state 11 with probability equal to 1. All matrix elements in the first column are zero except the element that corresponds to state 3 (in decimal), which is 1. At the second step an H gate is applied to the second qubit and sets its state in basis-state superposition. A measurement of the quantum register state at the end of this step will give states 01 and 11 with probability 0.5 and the matrix elements that correspond to states 1 and 3 (in decimal) are 0.5. A CNOT gate is applied at the third step. A measurement at the end of this step will give states 01 and 10 (1 and 2 in decimal) with probability 0.5 (d) Fig. 8. A quantum computation. (a) The quantum circuit. (b) The matrix showing the probability of measuring each base state of the quantum register at each computation step. (c) The QCS graphical output showing the probability distribution at each computation step. (d) The QCS graphical output showing the phase variation during the quantum computation. 19 each, and so on. A graphical representation of this matrix is shown in Figure 8(c). The x-axis represents the computation steps (matrix columns) and the y-axis the possible quantum register base states in decimal form (matrix rows). Each matrix element corresponds to a rectangle and its value, i.e. the probability to measure this state at this computation step, is represented as a gray-scale image in which probability 1 is represented by black and probability 0 by white. Figure 8(d) shows the phase of each quantum register state at each compotation step. An arrow with its initial point located at the point (i, j) corresponds to the th th phase of the j quantum register state (in decimal) at the i computation step. The direction of the arrow indicates the value of the phase, which can take any value between 0o and 360o. An arrow parallel to the x-axis pointing to the right corresponds to a phase angle of 0o. If the state j has zero probability to be measured at step i, there exist no arrow with initial point at (i, j). According to the hidden variable theorem no classical system can simulate completely a quantum system. Therefore, the complete visualization of the quantum computer operation using a classical computer is impossible. The visualization shown in Figures 8(c) and (d) is an effective visualization that depicts the most important aspects of quantum computations. It is well-known that the computational complexity of any algorithm simulating quantum systems with two base states is O(2n), where n is the number of quantum systems. This simulator is no exception to that and suffers from exponential slowdown as the number of qubits increases. Matrices representing qubits and quantum gates contain a large number of zeros and the computation complexity was somewhat improved using sparse matrix techniques. V. DEUTSCH’S QUANTUM ALGORITHM The first algorithm proving that quantum computers can outperform classical ones was developed by D. Deutsch [19]. The problem posed by Deutsch is: “Given a binary function f(x) find out if the function is constant ( i.e. f(0)=f(1) ) or balanced ( i.e. f(0) ≠ f(1) ) by performing the minimum number of computations.” On a classical computer one has to compute the value of f(x) twice and compare the results, but, as Deutsch showed, on a quantum computer one computation is enough [10, 19]. ⎧ ⎪± ⎪ ⎪⎪ ⎡0 + 1 ⎤ ⎡0 − 1 ⎤ H ⎥ ⎯⎯→ ⎨ ⎢ ⎥ ⎢ 2 2 ⎦ ⎣ ⎦ ⎣ ⎪ ⎪ ⎪± ⎪⎩ ⎡0 + 1 ⎤ ⎡0 − 1 ⎤ ⎢ ⎥ ⎢ ⎥ 2 ⎦ ⎣ 2 ⎦ ⎣ if f (0 ) = f (1) ⎡0 − 1 ⎤ ⎡0 − 1 ⎤ ⎢ ⎥ ⎢ ⎥ 2 ⎦ ⎣ 2 ⎦ ⎣ if f (0 ) ≠ f (1) (11) Figures 10(b) and 10(c) show the simulation of Deutsch’s algorithm in the case where f(x) = x. In this case the circuit of Figure 9 is a CNOT gate. (a) Fig. 9. A quantum circuit used in Deutsch’s algorithm. The key element in Deutsch’s algorithm is the quantum circuit shown in Figure 9, which acts on a twoqubit quantum register x a and leaves the x qubit in its previous state, but takes the other qubit to a state which is the modulo 2 sum of a and f(x). The action of this circuit is given by: U x a ⎯⎯→ x a ⊕ f (x ) (b) (9) The quantum circuit of Deutsch’s algorithm is shown in Figure 10(a). The initial state of the two qubits is 0 1 . This is considered as the first computation step. At the second step two H quantum gates are applied to the qubits changing their states according to: ⎡0 +1⎤ ⎡0 −1⎤ H 0 1 ⎯⎯→ ⎥ ⎢ ⎥ ⎢ 2 ⎦ ⎣ 2 ⎦ ⎣ (10) At the third step the quantum circuit of Figure 9 is applied and the states of the two qubits are taken to [10]: 20 (c) Fig.10. (a) The quantum circuit of Deutsch’s algorithm. (b) and (c) Simulation of Deutsch’s algorithm in the case of a CNOT gate. (b) The probability distribution at each computation step. (c) The phase variation during the computation. We have f(0) = 0 and f(1) = 1, therefore [6] C. P. Williams, “Quantum search algorithms in science and engineering”, IEEE Computing in Science and Engineering, vol. 3, no. 2, pp. 44-51, 2001. f (0) ≠ f (1) and the upper qubit should be 1 . Figure 10(b) shows that at the end of the fourth step two quantum register base states are possible each with probability 0.5: the state 1 0 (decimal 2) and the state 1 1 [7] S. Lloyd, “Universal quantum simulators”, Science, vol. 273, issue 5278, pp. 1073-1078, 1996. [8] C. P. Williams and S. H. Clearwater, Explorations in Quantum Computing, New York: Springer-Verlag, Telos, 1998. [9] G. P. Berman, G. D. Doolen, R. Mainieri and V. I. Tsifrinovich, Introduction to Quantum Computers, London: World Scientific, 1998. (decimal 3). In both states the upper qubit is in state 1 , as expected. Figure 10(c) shows the phase variation during the quantum computation. Note Figure 10(b) shows the same data for steps two and three, in which all four quantum register base states are equally probable, but Figure 10(c) shows differed phases for these two steps, which is very important in Deutsch’s algorithm. [10] M. A. Nielsen and I. L. Chuang, Quantum Computation and Quantum Information, Cambridge: Cambridge University Press, 2000. [11] B. P. Lanyon et al., “Universal digital quantum simulator using trapped ions, Science, vol. 334, pp. 57-61, 2011. VI. CONCLUSIONS [12] M. Mariantoni et al., “Implementing the quantum von Neumann architecture with superconducting circuits”, Science, vol. 334, 61- 65, 2011. We presented the qubit, the quantum register and the most important quantum gates. We presented the circuit model for quantum computation and a quantum computer simulator, which we used to present an analytical example of quantum computation. We presented analytically the Deutsch’s quantum algorithm. The quantum Fourier transform is an important computation and is a key subroutine of quantum algorithms for factoring and simulation and can be simulated using QCS. Two wellknown quantum algorithms are the Grover’s quantum algorithm which is used for searching unstructured databases [20] and Shor’s quantum algorithm for factoring large number, which among others can be used in cryptanalysis [21]. [13] N. K. Langford et al., “Efficient quantum computing using coherent photon conversion”, Nature, vol. 487, pp. 360363, 2011. [14] I. G. Karafyllidis, “Quantum Computer Simulator based on the Circuit Model of Quantum Computation”, IEEE Transactions on Circuits and Systems I, vol. 52, pp. 15901596, 2005. [15] I. G. Karafyllidis, “Visualization of the quantum Fourier transform using a quantum computer simulator”, Quantum Information Processing, vol. 2, no. 4, pp. 271-288, 2003. [16] I. G. Karafyllidis, “Cellular quantum computer architecture”, Physics Letters A, vol. 320, no. 1, pp. 35-38, 2003. REFERENCES [17] I. G. Karafyllidis, “Simulation of entanglement generation and variation in quantum computation”, Journal of Computational Physics, vol. 200, no. 1, pp. 383-397, 2004. [1] R. J. Hughes and C. P. Williams, “Quantum computing: The final frontier?”, IEEE Intelligent Systems, vol. 15, no. 5, pp. 10-18, 2000. [18] I. G. Karafyllidis, “Definition and evolution of quantum cellular automata with two qubits per cell”, Physical Review A, vol. 70, pp. 0044301-1 - 0044301-4, 2004. [2] A. M. Steane and E. G. Rieffel, “Beyond bits: The future of quantum information processing”, IEEE Computer, vol. 33, no. 1, pp. 38-45, 2000. [19] D. Deutsch, “Quantum theory, the Church-Turing principle and the universal quantum computer”, Proceedings Royal Society London, vol. A 400, pp. 97-117, 1985. [3] P. W. Shor, “Polynomial-time algorithms for prime factorization and discrete logarithms on a quantum computer”, SIAM Journal on Computing, vol. 26, no. 5, pp. 1484-1509, 1997. [20] L. K. Grover, “Quantum mechanics helps in searching for a needle in a haystack”, Physical Review Letters, vol. 79, no. 2, pp. 325-328, 1997. [21] P. W. Shor, “Polynomial-time algorithms for prime factorization and discrete logarithms on a quantum computer”, SIAM Journal on Computing, vol. 26, no. 5, pp. 1484-1509, 1997. [4] L. K. Grover, “Quantum mechanics helps in searching for a needle in a haystack”, Physical Review Letters, vol. 79, no. 2, pp. 325-328, 1997. [5] L. K. Grover, “Quantum computers can search rapidly by using almost any transformation”, Physical Review Letters, vol. 80, no. 19, pp. 4329-4332, 1998. 21