sequence of gates has the following sequence of effects on a computational basis state |a, bi, |a, bi ! |a, a ! |a ! |b, (a bi (a b), a b) bi = |b, a bi = |b, ai , bi (1.20) where all additions are done modulo 2. The effect of the circuit, therefore, is to inter- 126 CHAPTER III. QUANTUM COMPUTATION change the state of the two qubits. Figure 1.7. Circuit swapping two qubits, and an equivalent schematic symbol notation for this common and useful circuit. Figure III.11: Diagram for swap (from NC). There are a few features allowed in classical circuits that are not usually present in quantum circuits. First of all, we don’t allow ‘loops’, that is, feedback from one part of the C.3 Quantum circuits quantum circuit to another; we say the circuit is acyclic. Second, classical circuits allow , with the resulting single wire wires to be ‘joined’ together, an operation known as ¶1. Quantum circuit: A quantum circuit is a sequential series of quantum of the inputs. Obviously this operation is not reversible and containing the bitwise transformations ondon’t a quantum register. in our quantum circuits. Third, the inverse therefore not unitary, so we allow , whereby several copies of a bit are produced is also not allowed in operation, ¶2. The inputs are usually computational basis states (all |0i unless stated quantum circuits. In fact, it turns out that quantum mechanics forbids the copying of a operation impossible! We’ll see an example of this in the next qubit,otherwise). making the section when we attempt to design a circuit to copy a qubit. ¶3. Quantum circuit diagrams are drawn with time going from left to right, As we proceed we’ll introduce new quantum gates as needed. It’s convenient to inwith the quantum gates crossing one or more “wires” (qubits) as aptroduce another convention about quantum circuits at this point. This convention is propriate. illustrated in Figure 1.8. Suppose U is any unitary matrix acting on some number n of It represents a sequence of unitary on Then a quantum register qubits, so U can be regarded as a quantum gate operations on those qubits. we can define a rather than physical wires. extension of the controlledgate. Such a gate controlled-U gate which is a natural has a single control qubit, indicated by the line with the black dot, and n target qubits, ¶4. Unique arenothing not allowed. indicated by thefeatures: boxed U . IfAcyclic: the controlloops qubit(feedback) is set to 0 then happens to the target qubits. If the control qubit is set to 1 then the gate U is applied to the target qubits. ¶5. (equivalent to OR) is not gate allowed, it it notgate, reversible which is or The Fan-In prototypical example of the controlled-U is the since controlledunitary. gate with U = X, as illustrated in Figure 1.9. a controlled-U Another important operation is measurement, which we represent by a ‘meter’ symbol, ¶6. Fan-Out is not allowed, because it would violate the No-cloning Theorem. (N.B.: This does not contradict the universality of the To↵oli or Fredkin gates, which are universal only with respect to classical states.) ¶7. CNOT: Fig. III.9 (right) shows the symbol for CNOT and its e↵ect. ¶8. Swap: The swap operation is defined |xyi 7! |yxi, or explicitly X |yxihxy|. x,y22 ¶9. We can put three CNOTs in series to swap two qubits (Exer. III.27). It has a special symbol as shown in Fig. III.11. C.24 QUANTUM INFORMATION Introduction and overview 127 Figure 1.8. Controlled-U gate. Figure III.12: Diagram for controlled-U (from NC). ¶10. Controlled-U: In general, any unitary operator (on any number of qubits) canFigure be controlled (see Fig. III.12). If the control bit is 0, it 1.9. Two different representations for the controlled. does nothing, otherwise it does U . as shown in Figure 1.10. As previously described, this operation converts a single qubit ¶11. This is implemented by |0ih0| ⌦ I + |1ih1| ⌦ U . state | i = |0i + |1i into a probabilistic classical bit M (distinguished from a qubit by E↵ectively, the operators are entangled. 2 drawing it as a double-line wire), which is 0 with probability | | , or 1 with probability | |2 . ¶12. Example: Suppose the control bit is in superposition, | i = a|0i+b|1i. ❴✤✤ ❴ ❴ ❴ ❴ ❴ ! ❴ ❴ ✤✤ (|0ih0| ⌦ I + |1ih1| ⌦ U )| , ✤✤✤✤ i ✙ ✙ ✙ ✙ ✤✤✤✤ ✤❴ ❴ ❴ ❴ ❴✙ ✙ ❴ ❴ ❴ ✤ = (|0ih0| ⌦ I + |1ih1| ⌦ U )(a|0i + b|1i) ⌦ | i Figure 1.10. Quantum circuit symbol for measurement. = |0ih0|(a|0i + b|1i) ⌦ I| i + |1ih1|(a|0i + b|1i) ⌦ U | i We shall find=quantum a|0i ⌦circuits | i + useful b|1i ⌦asUmodels | i of all quantum processes, including but not limited = to computation, communication, and even quantum noise. Several simple a|0, i + b|1, U i. examples illustrate this below. We have a superposition of entangled outputs. 1.3.5 Qubit copying circuit? The Recallgate useful for=demonstrating one particularly fundamental property of ¶13. thatis CNOT controlled X. quantum information. Consider the task of copying a classical bit. This may be done gate, which takes transformation: in the bit to copy (in some x) usingConditional a classical ¶14. or controlled If U0unknown and U1 state are uniand atary ‘scratchpad’ bit initialized to zero, as illustrated in Figure 1.11. The output is two operators, then we can make the choice between them conditional bits, on botha ofcontrol which are same state x. bitinasthefollows: Suppose we try to copy a qubit in the unknown state | i = a |0i + b |1i in the same manner by using a gate. The input state of the two qubits may be written as |0ih0|i⌦ U0 + |1ih1| ⌦ U1 . h a |0i + b |1i |0i = a |00i + b |10i, (1.21) ¶15. For example, is to negate the second qubit when the first qubit is 1, and thus The function of = |0iwe h0| successfully ⌦ I + |1ih1|copied ⌦ X.| i? That is, have (III.17) the output is simply a |00i +CNOT b |11i. Have we created the state | i| i? In the case where | i = |0i or | i = |1i that is indeed what this circuit does; it is possible to use quantum circuits to copy classical information encoded as a |0i or a |1i. However, for a general state | i we see that | i| i = a2 |00i + ab|01i + ab|10i + b2 |11i. (1.22) 26 Introduction and overview understood via the equations | xy i |0, yi + ( 1)x |1, ȳi p , 2 Figure 1.8. Controlled-U CHAPTER III. gate. QUANTUM 128ȳ is the negation of y. where (1.27) COMPUTATION In |00i Out p (|00i + |11i)/ 2 | 00 i p |01i (|01i + |10i)/ 2 | 01 i p Figure 1.9. Two different for the controlled. |10i (|00i |11i)/ 2 |representations 10 i p |11i (|01i |10i)/ 2 | 11 i as shown in Figure 1.10. As previously described, this operation converts a single qubit state | i = |0i + |1i into a probabilistic classical bit M (distinguished from a qubit by Figure 1.12. Quantum circuit to create Bell states, and its input–ouput quantum2‘truth table’. 1 withNC probability drawing it as a double-line which is 0 with probability | | , or[from Figure III.13: Quantum wire), circuit for generating Bell states. fig. 1.12] | |2 . 1.3.7 Example: quantum ❴✤✤ ❴ ❴ teleportation ❴ ❴ ❴ ! ❴ ❴ ✤✤ ✙ ✤✤ We will now apply the techniques of the last few✤✤✤ pages ✙✙ ✤✤ to understand something non✤✤ ✙✙ ✙ trivial, surprising, and a lot of fun – quantum teleportation! Quantum teleportation is a ❴ ❴ ❴ ❴ ❴ ❴ ❴ ❴ ✤ technique for moving quantum states around,circuit even symbol in theforabsence of a quantum commuFigure 1.10. Quantum measurement. nications channel linking the sender the quantum state the recipient. Figure III.14: Symbol for ofmeasurement of atoquantum state (from NC). Here’s teleportation and Bob long ago but nowincluding live Wehow shallquantum find quantum circuitsworks. useful Alice as models of allmet quantum processes, far apart. While together they generated an EPR pair, each taking one qubit of the EPR but not limited to computation, communication, and even quantum noise. Several simple pair when theyillustrate separated. Many years later, Bob is in hiding, and Alice’s mission, should examples this below. gates: The| symbol gatestate is of show in she¶16. chooseOther to acceptspecial it, is to deliver a qubit i to Bob.for Shethe doesCCNOT not know the Fig. III.10, the qubit, and moreover can only1.3.5 send classical information to Bob. Should Alice accept Qubit copying circuit? or with • for top two connections and forfundamental bottom, representing the mission? The gate is useful for demonstrating one particularly property of CCNOT|x, y, zi = |x, xytask zi, Intuitively, things look pretty bady,the for Alice. doesn’t know the i of be thedone quantum information. Consider ofShe copying a classical bit.state This| may qubitusing she or has to send to Bob, laws of prevent her from put “CCNot” inwhich athe box. gate,and takes in quantum the bit to mechanics copy (in some unknown state x) a classical determining the state when she only has a single copy of | i in her possession. What’s and a ‘scratchpad’ bit initialized to zero, as illustrated in Figure 1.11. The output is two ¶17. Other operations may shown letter symbol in a box, worse, even if she did know thethe state |bei,state describing preciselyatakes an or infinite amount bits, both of which are in same x. by itputting of classical information since | for a continuous if she didsame for example “H” the values Hadamard gate. Suppose we try to copy ai takes qubit in the in unknown state | space. i = aSo |0ieven + b |1i in the knowmanner | i, it by would forThe Aliceinput to describe to Bob. It’sbenot looking usingtake a forever gate. state of the state two qubits may written as ¶18. H canFortunately be used to Bell states (Exer.is III.26): good for Alice. for Alice, quantum teleportation a way of utilizing the h generate i |0i +| bi|1i |0i =with a |00i + ba|10i, entangled EPR pair in order to asend to Bob, only small overhead of classical(1.21) communication. CNOT(H ⌦ I)|xyi = | xy i. (III.18) is solution to negateare theassecond qubit the first and thus function of of the InThe outline, the steps follows: Alicewhen interacts the qubit qubit is| 1, i with the of output is simply a |00i + bmeasures |11i. Have wetwo successfully copied | i? That is, have we her half the EPR pair, and then qubits in her possession, obtaining ¶19. The circuit fori?generating Bellthe states (Eq. III.18) isthat shown in Fig. III.13. created the state | i| In the case where | i = |0i or | i = |1i is indeed what one of four possible classical results, 00, 01, 10, and 11. She sends this information to this does;on it is possible to usemessage, quantumBob circuits to copy information Bob. circuit Depending Alice’s classical performs one classical of four operations onencoded his as a |0i or a |1i. However, for a general state | i we see that half of the EPR pair. Amazingly, by doing this he can recover the original state | i! ¶20. Measurement: It’s also convenient to have a symbol for quantum 2 1.13 gives a more precise2description of quantum The quantum circuit shown ini Figure |00i + ab|01i + ab|10i + b |11i. (1.22) | i| = a state measurement, such as Fig. III.14. teleportation. The state to be teleported is | i = |0i+ |1i, where and are unknown amplitudes. The state input into the circuit | 0 i is | 0i = | i| 00 i (1.28) be seen from the fact that it can be used to construct the AND and NOT operators in the following way: T |1, 1, xi = |1, 1, ¬xi T |x, y, 0i = |x, y, x ^ yi The T gate is sufficient to construct arbitrary combinatorial circuits. The following quantum circuit, for example, implements a 1 bit full adder using Toffoli129 C. QUANTUM INFORMATION and controlled-NOT gates: |ci |ci |xi |xi |yi |yi ⇥ |0i |0i ⇥ ⇥ ⇥ ⇥ ⇥ |si |c i Figure circuit for 1-bit full adder IQC].carry “x and y are whereIII.15: x and y Quantum are the data bits, s is their sum (modulo 2), c is[from the incoming bit, and is the bits, new carry Vedral, Barenco and Ekert et al. 1996] define morebit, complex thec data s isbit. their sum (modulo 2), [Vedral c is the incoming carry and c0 circuits include in-place addition and modular addition. is the newthatcarry bit.” The Fredkin gate is a “controlled swap” and can be defined as F = |0ih0| ⌦ I ⌦ I + |1ih1| ⌦ S where S is the swap operation x 0 x S = |00ih00| + |01ih10| + |10ih01| + |11ih11|. f(x) f(x) x -1 Φ The0reader canΦverify that F , like T , is complete for combinatorial circuits. y g(x) g(x) CNOT y y⊕f(x) 0 0 y⊕f(x) Uf Figure III.16: Quantum gate array for reversible quantum computation. C.4 Quantum gate arrays ¶1. Full adder: Fig. III.15 shows a quantum circuit for a 1-bit full adder. ¶2. As we will see (Sec. C.7), it is possible to construct reversible quantum gates for any classically computable function. In particular the Fredkin and To↵oli gates are universal. ¶3. Reversibility: Because quantum computation is a unitary operator, it must be reversible. You know that an irreversible computation x 7! f (x) can be embedded in a reversible computation (x, c) 7! (f (x), g(x)), where c are suitable constants and g(x) represents the garbage bits. 130 CHAPTER III. QUANTUM COMPUTATION ¶4. Note that throwing away the garbage bits (dumping them in the environment) will collapse the state (equivalent to measurement) by entangling them in the many degrees of freedom of the environment. ¶5. Since NOT is reversible, each 1 bit in c can be replaced by a 0 bit followed by a NOT, so we need only consider (x, 0) 7! (f (x), g(x)). See Fig. III.16. ¶6. The garbage must be produced in a standard state independent of x, “because garbage bits whose value depends upon x will in general destroy the interference properties crucial to quantum computation.” ¶7. Uncomputation: This is accomplished by uncomputing. Specifically, perform the computation on four registers (data, result, workspace, target): (x, 0, 0, y) 7! (x, f (x), g(x), y). Notice that x and y (data and target) are passed through. ¶8. Now use CNOTs to compute y f (x), where exclusive-or, in the fourth register: (x, 0, 0, y) 7! (x, f (x), g(x), y represents bitwise f (x)). ¶9. Now we uncompute f , but since the data and target registers are passed through, we get (x, 0, 0, y f (x)). Ignoring the result and workspace registers, we write (x, y) 7! (x, y f (x)). ¶10. Quantum gate array: Therefore, for any computable f : 2m ! 2n , there is a reversible quantum gate array Uf : Hm+n ! Hm+n such that for x 2 2m and y 2 2n , See Fig. III.17. Uf |x, yi = |x, y f (x)i, ¶11. The first m qubits are called the data register and the last n are called the target register. ¶12. In particular, Uf |x, 0i = |x, f (x)i. gates for any classically computable function. In fact, it is possible to conceive of a universal quantum Turing machine [Bernstein and Vazirani 1997]. In this construction we must assume a sufficient supply of bits that correspond to the tape of a Turing machine. Knowing that an arbitrary classical function f with m input and k output bits can be implemented on quantum computer, we assume the existence of a quantum gatearray Uf that implements f . Uf is a m + k bit transformation of the form Uf : |x, yi ! |x, y f (x)i where denotes the bitwise exclusive-OR6. Quantum gate arrays Uf , defined in this way, are unitary for any function f . To compute f (x) we apply Uf to |xi tensored with k C. QUANTUM INFORMATION zores |x, 0i. Since f (x) f (x) = 0 we have Uf Uf = I. Graphically the transformation Uf : |x, yi ! |x, y f (x)i is depicted as |xi 131 |xi Uf |yi |y f (x)i. While the T and F gates are complete for combinatorial circuits, they cannot achieve arFigurequantum III.17:state Computation ofInfunction by quantum gatetransformations array [from 7IQC]. bitrary transformations. order to realize arbitrary unitary , single bit rotations need to be included. Barenco et. al. [Barenco et al. 1995] show that Cnot together with all 1-bit quantum gates is a universal gate set. It suffices to include the following one-bit transformations C.5 Quantum ✓parallelism ◆ ✓ i ◆ cos sin e 0 ¶1. Since Uf is linear, if sin it is cos applied, to 0a superposition of bit strings, it will e i produce a superposition of the results of applying f to them in parallel for all 0(i.e., in 2thetogether a universal gates. As we shall not to obtain same with timetheitCtakes to compute it set onofone vector): see, such non-classical transformations are crucial for exploiting the power of quantum computers. U (c x + c x + · · · + c x ) = c U x + c U x + · · · + c U x f 1 1 2 2 k k 1 f 1 2 f 2 k f k. 5.2 Quantum Parallelism ¶2. For example, What happens if Uf is applied to input which is in a superposition? The answer is easy ! papplied to all basis vectors in the but powerful: since p Uf is a linear transformation, it is 3 1 3 1 superpositionU simultaneously and will a superposition results. way, |x1 i + |x2 igenerate ⌦ |0i = |x1 , fof(xthe + |xIn2 ,this f (x f 1 )i 2 )i. 2 f (x) for2n values of x in a single 2 application of Uf2. This effect is it is possible to compute called quantum parallelism. The power of quantum algorithms comes from taking quantum parallelism ¶3. The amplitude of a result y will be theadvantage sum ofofthe amplitudes of all and entanglement. So most quantum algorithms begin by computing a function of interest such that y = f (x). on a superposition of all values as follows. Start with an n-qubit state |00 . . . 0i. Apply the x ¶4. Quantum parallelism: If we apply Uf to a superposition of all possiis notble the direct of vectors. 2m sum inputs, it will compute a superposition of all the corresponding 7 More precisely, we mean arbitrary unitary transformations up to a constant phase factor. A constant phase shift outputs in parallel (i.e., in the same time as required for one function of the state has no physical, and therefore no computational, significance. evaluation)! 6 ¶5. The Walsh-Hadamard transformation can be used to produce this superposition of all possible inputs: 1 Wm |00 . . . 0i = p (|00 . . . 0i + |00 . . . 1i + · · · + |11 . . . 1i) 2m 1 X = p |xi 2m x22m 132 CHAPTER III. QUANTUM COMPUTATION m 2 1 1 X = p |xi. 2m x=0 In the last line we are obviously interpreting the bit strings as natural numbers. ¶6. Hence, m Uf Wm |0i = Uf 2 1 1 X p |x, 0i 2m x=0 ! m m 2 1 2 1 1 X 1 X =p Uf |x, 0i = p |x, f (x)i. 2m x=0 2m x=0 ¶7. A single circuit does all 2m computations simultaneously! ¶8. “Note that since n qubits enable working simultaneously with 2n states, quantum parallelism circumvents the time/space trade-o↵ of classical parallelism through its ability to provide an exponential amount of computational space in a linear amount of physical space.” [IQC] ¶9. If we measure the input bits, we will get a random value, and the state will be projected into a superposition of the outputs for the inputs we measured. ¶10. If we measure an output bit, we will get a value probabilistically, and a superposition of all the inputs that can produce the measured output. ¶11. Neither of the above is especially useful, so most quantum algorithms transform the state in such a way that the values of interest have a high probability of being measured. ¶12. The other thing we can do is extract common properties of all values of f (x). ¶13. Both of these require di↵erent programming techniques than classical computing.