Quantum computers are therefore only practical for certain types of problems. Since quantum computers are built on quantum physics principles, we intuitively

1It is an observation that classical computers double their processing power roughly every 18 months. This is known as Moore's law.

2The Titan at Oak Ridge Laboratory as of 2018.

expect that they would be best suited for simulating quantum phenomena directly. Generally, these types of problems look for correlations between different outputs. Due to this, it is generally accepted that quantum computers will not replace classical computers but will be able to perform different calculations that classical computers simply cannot. We will study an example problem which the quantum computer can solve more efficiently than a classical computer.

#### **9.3 Deutsch-Jozsa Algorithm**

Here we provide a proof that quantum computers can be faster than classical computers by explicit construction of a problem.

#### **9.3.1 The Problem Statement**

Let *f (x)* be an unknown function that operates on a single qubit. There can only be four different functions that satisfy this requirement, and the four different functions are shown in Table 9.1.

A function is called **constant** if it always outputs the same result for all values of *x*. A function is called **balanced** if it outputs 1 for half of all the possible values of *x* and 0 for the other half. The question posed to the computer is this:

"Is the function *f (x)* a constant function or a balanced function?"

For this single qubit case, the question is answered by checking if *f (*0*)* = *f (*1*)*. It also turns out in this single qubit case that there are only constant and balanced functions. However, in multiple qubit systems, there exist functions that are neither constant nor balanced. In the multiple qubit scenario, it is important that in the problem statement the function given to the quantum computer is either constant *or* balanced, and not something else.

*Question 2* Which of the functions in Table 9.1 are constant and which are balanced?

The functions *f*1 and *f*4 are constant, while *f*2 and *f*3 are balanced.

*Question 3* If you run the classical algorithm and see that *f (*0*)* = 1, could you tell whether the function is constant or balanced?

No, it could either be the balanced function *f*3 or the constant function *f*4. A classical computer would have to evaluate both *f (*0*)* and *f (*1*)* to determine the answer. How can a quantum computer determine the answer with only one measurement instead of two?

#### **9.3.2 Conceptual Understanding**

Before we go through the Deutsch-Jozsa Algorithm in detail, it will be useful to understand a cartoon solution of the problem, which we will demonstrate using the Mach-Zehnder interferometer from Chap. 3. Once again, superposition and interference will be the key properties to utilize. The cartoon experimental setup is shown in Fig. 9.3. In the QuVis simulation, we will model the functions by placing pieces of glass in the blue boxes. The goal is to illustrate how it may be possible to classify *f (x)* as either constant or balanced by making a single measurement. Here is how the algorithm can be implemented:

**Fig. 9.3** The Mach-Zehnder interferometer altered to implement the cartoon version of the Deutsch-Jozsa algorithm. The function implementations are shown in Fig. 9.5.

*Question 4* If *f*1 is being tested, what is the phase of the yellow path upon reaching the second beamsplitter? The red path photon?

The yellow path was phase-shifted by Beam Splitter 1 and unaffected by the blue function box *f (*0*)*. The red path was unaffected by Beam Splitter 1 and phase-shifted by the blue function box *f (*1*)*. Therefore, they both have a phase shift of *π*.

3. The second beam splitter creates the interference necessary to ensure that measurement happens only in one detector. Depending on which detector is measured, this is interpreted as the function being constant or balanced.

*Question 5* For the experimental configuration *f*1, what is the phase of the yellow path photon at Detector 1? The red path photon at Detector 1?

**Fig. 9.5** The four different functions from Table 9.1 experimentally implemented by four different configurations. In this cartoon, we have denoted the function changing the bit by an *X*-gate, however in reality as described in Eq. (9.2) two qubits are needed to implement these functions.

At Detector 1, the yellow path and red path photons both have a phase shift of *π*.

*Question 6* For the experimental configuration *f*1, what is the phase of the yellow path photon at Detector 2? The red path photon at Detector 2?

At Detector 2, the yellow path photon has a phase shift of *π* while the red path photon has a phase shift of 2*π*.

4. Measure which detector is activated.

*Question 7* For the experimental configuration *f*1, which detector(s) go off and with what probability?

Detector 1 experiences constructive interference, while Detector 2 experiences destructive interference. Therefore, only Detector 1 activates for *f*1, which is a constant function. Which detector(s) go off for *f*2, *f*3, and *f*4?

After working through the exercises, you should see that thanks to superposition and interference, only one quantum measurement is needed in this cartoon picture of the Deutsch-Jozsa problem. The general algorithm is presented in the next section.

#### **9.3.3 Quantum Algorithm**

Before we describe the full quantum solution, we need to setup some useful tools. For example, in the quantum computing literature, it is common to use the mathematical tool called modular arithmetic. For this algorithm, we will not need to understand modular arithmetic more than basic notation. In quantum computing, modular arithmetic with "mod 2" is defined to be *f (*0*)*⊕*f (*1*)* = 0 if *f (*0*)*+*f (*1*)* = 0*,* 2*,* 4*,* 6*,...*. However, *f (*0*)* ⊕ *f (*1*)* = 1 if *f (*0*)* + *f (*1*)* = 1*,* 3*,* 5*,...*. Note the circle with a plus inside ⊕ denotes this modular arithmetic "mod 2" operation. The ⊕ operation outputs the remainder of dividing a number *x* by the number 2. As an example, if *f (*0*)* = 0 and *f (*1*)* = 1 then *f (*0*)* ⊕ *f (*1*)* = 1, whereas if *f (*0*)* = 1 and *f (*1*)* = 1 then *f (*0*)* ⊕ *f (*1*)* = 0.

Also, we will need a second qubit for this algorithm, and will shortly see why. In the quantum computing world, the function *f (x)* is implemented by

$$
\langle \mathbf{x} \rangle | \mathbf{y} \rangle \xrightarrow{f} \langle \mathbf{x} \rangle | \mathbf{y} \oplus f(\mathbf{x}) \rangle. \tag{9.2}
$$

As an example, assume *f (*0*)* = 1, then |0|1 *f* −→ |0|1 ⊕ *f (*0*)*=|0|0. Although the implementation of functions as in Eq. (9.2) looks strange, this is needed to ensure that the function operation is unitary.3 The circuit that implements the Deutsch-Jozsa algorithm is shown in Fig. 9.6. We will now give a walk-through of the algorithm and the circuit.

#### **Deutsch-Jozsa Procedure**:

**Fig. 9.6** The quantum circuit for the one qubit Deutsch-Jozsa algorithm. The generic function *f (x)* is represented by the box with *f* inside, and the labels below/above the lines indicate how the function is implemented.

3Taking the function *f*1 and representing its action on a single qubit as a matrix, this matrix is not unitary. Non-unitarity violates the laws of quantum mechanics.

$$\frac{1}{2}(|0\rangle+|1\rangle)(|0\rangle-|1\rangle).\tag{9.3}$$

In the Mach-Zehnder cartoon in Fig. 9.3, Beam splitter 1 performs the first Hadamard gate on the first qubit in Fig. 9.6.

3. Apply the function *f (x)* using the rule in Eq. (9.2) to the state in Eq. (9.3). After performing the arithmetic, the two qubit state can be organised as

$$\frac{1}{2}\left(|0\rangle\left(|0\oplus f(0)\rangle - |1\oplus f(0)\rangle\right) + |1\rangle\left(|0\oplus f(1)\rangle - |1\oplus f(1)\rangle\right)\right). \tag{9.4}$$

In order to get a clearer picture of the effect of *f (x)* on the state, it is useful to notice that if *f (*0*)* = 0 then |0 ⊕ *f (*0*)*−|1 ⊕ *f (*0*)*=|0−|1. Additionally, if *f (*0*)* = 1 then |0 ⊕ *f (*0*)*−|1 ⊕ *f (*0*)* = −|0+|1. We can combine these two by writing |0 ⊕ *f (*0*)*−|1 ⊕ *f (*0*)* = *(*−1*)f (*0*) (*|0−|1*)*. A similar formula is needed for the *f (*1*)* case also, and we leave this as an exercise for the reader. Applying this formula to Eq. (9.4) gives

$$\frac{1}{2}\left((-1)^{f(0)}|0\rangle\left(|0\rangle-|1\rangle\right)+(-1)^{f(1)}|1\rangle\left(|0\rangle-|1\rangle\right)\right)\tag{9.5}$$

$$=(-1)^{f(0)}\frac{1}{2}\Big(|0\rangle+(-1)^{(f(0)+f(1))}|1\rangle\Big)(|0\rangle-|1\rangle).\tag{9.6}$$

In the Mach-Zehnder cartoon in Fig. 9.3, the interaction between the two qubits was modeled by the photon passing through the blue function boxes.

4. We now throw away the second qubit. We only keep the first qubit and make sure it is normalized correctly. The first qubit is

$$\frac{1}{\sqrt{2}}(|0\rangle + (-1)^{(f(0) + f(\mathbf{l}))}|1\rangle). \tag{9.7}$$

The reason we need the second qubit is to perform the gate operations and collect the like-terms which ensures the algorithm works. This second qubit is called an ancilla qubit because it is not measured. This is shown in the circuit in Fig. 9.6 as the lack of the measurement operator in the second qubit line.

5. Apply a Hadamard gate to the qubit state in Eq. (9.7) to produce

$$\frac{1}{2}\left(\left(1+(-1)^{(f(0)+f(1))}\right)|0\rangle+\left(1-(-1)^{(f(0)+f(1))}\right)|1\rangle\right).\tag{9.8}$$

In the Mach-Zehnder cartoon in Fig. 9.3, the second Hadamard gate operation was implemented by Beam Splitter 2.

6. Measure the qubit. If *f (x)* is constant, then the state in Eq. (9.8) reduces to |0, while if *f (x)* is balanced then the state reduces to |1. In the Mach-Zehnder cartoon in Fig. 9.3, the detector measured the final state of the photon.

As this algorithm shows, a single measurement of |0 or |1 shows whether the function is constant or balanced. Impressively, this algorithm straightforwardly extends to functions that take in any number of inputs. This is impressive because only *one single* measurement can tell you whether a function of any size is constant or balanced. For a classical computer to do the same task, it would need to measure each of the inputs, which is exponentially slower.

#### **9.4 Quantum Computers Today**

While the Deutsch-Jozua problem has no known commercial applications, useful quantum algorithms such as Shor's factoring algorithm rely upon similar concepts. Quantum algorithms are believed to exist that can speed up machine learning algorithms and efficiently simulate the quantum behavior of molecules. As of 2018, companies such as IBM and Google have built different types of quantum computers that contain up to 72 qubits. To give you an idea of where we need quantum computers to be, factoring a 1024-bit modern encryption key using Shor's algorithm would require more than 5*,*000 qubits. In 2019, Google claimed to have performed4*,*5 the first quantum computation that a classical computer could not do—a milestone known as "quantum supremacy". Quantum supremacy means that a quantum computer can solve a problem that a classical computer cannot. However, the solution of the problem may not be of practical use. As such, it is important to note that Google has demonstrated quantum supremacy, not the "quantum usefulness" milestone. Google performed their task on a 53 qubit quantum computer, which took 200 s. They claimed it would take a classical computer 10,000 years to do the same task. However, shortly after, IBM suggested6 that an improved classical supercomputing technique could theoretically perform the task in just 2*.*5 days.

Different technological difficulties may be encountered when improving a quantum computer. As we have mentioned, a quantum computer can be built using lasers.7 However, there are also random photons outside of the quantum computer in the environment that may accidentally leak into the quantum computer, and these environmental photons can then cause accidental changes to the quantum state. Such accidental changes are called "noise". To reduce the number of these environmental photons, the quantum computer needs to be be cooled down to near absolute zero (around −450◦ Fahrenheit). However, this is difficult. The more qubits you add, the more you need to keep at this low temperature (a technological challenge). Also, the more qubits you add, the more lasers you need

4https://www.nature.com/articles/s41586-019-1666-5.

5https://www.sciencenews.org/article/google-quantum-supremacy-claim-controversy-topscience-stories-2019-yir.

6https://arxiv.org/abs/1910.09534.

7A laser is a source of photons which have the same wavelength and are in phase.

to interact the qubits. It is technologically difficult to keep lots of qubits in one small space, but also cause isolated interactions between them using different lasers. Further, the more qubits you add, the more likely it is that the qubits will interact accidentally with the environment, which will then destroy the system's quantum properties through a process known as decoherence. However, given how classical computers went from being the size of a room in the 1960s to an iPhone within a few decades, governments and industries are investing billions of dollars towards making quantum computers realistic. Ultimately, quantum computers are destined to complement classical computers, not replace them, so don't expect to have a quantum phone in your pocket anytime soon!8

#### **9.5 Big Ideas**

#### **9.6 Activities**

Explore more quantum algorithms from the IBM quantum textbook. 9

#### **9.7 Check Your Understanding**

	- (a) How many different classical pieces of information can be represented by eight classical bits (1 byte)?
	- (b) What about a quantum computer with eight qubits?
	- (c) What advantage does the quantum computer have over the classical computer?
	- (a) *f*1?

8Theoretical physicists and computational scientists at Fermi National Accelerator Laboratory are working on improving algorithms and the foundations of quantum science in order to expand the problems that (near term) quantum devices can solve, e.g., https://qis.fnal.gov/quantumcomputing-for-hep/.

9https://qiskit.org/textbook/ch-algorithms/index.html.

**Fig. 9.7** The gate implementation for testing the different possible three-qubit functions.

	- (a) Which detector(s) go off if the function is constant?
	- (b) Which detector(s) go off if the function is balanced?
	- (c) How many photons would you need to send to determine whether the function was constant or balanced?
	- (a) How many evaluations would be needed on a classical computer to tell whether this function is constant or balanced?
	- (b) By running this algorithm on IBM Q, can you determine whether this function is constant or balanced?

**Open Access** This chapter is licensed under the terms of the Creative Commons Attribution 4.0 International License (http://creativecommons.org/licenses/by/4.0/), which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license and indicate if changes were made.

The images or other third party material in this chapter are included in the chapter's Creative Commons license, unless indicated otherwise in a credit line to the material. If material is not included in the chapter's Creative Commons license and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder.

# **10 Worksheets**

### **10.1 Correlation in Entangled States Lab**

#### **Objectives:**

#### **Questions**

Alice and Bob each measure one of two qubits with a Stern-Gerlach apparatus. Start with both SGAs along the z-axis (Fig. 10.1)

	- (a) In the product state?
	- (b) In the entangled state?

Now rotate both SGAs along the x-axis (Fig. 10.2).

4. Try sending pairs of particles in a product state |↑*A*|↓*B*. What do Alice and Bob measure individually?

1https://www.st-andrews.ac.uk/physics/quvis/simulations\_html5/sims/entanglement/ entanglement.html.

C. Hughes et al., *Quantum Computing for the Quantum Curious*, https://doi.org/10.1007/978-3-030-61601-4\_10

**Fig. 10.1** Figure reproduced from the QuVis website, licensed under creative commons CC-BY-NC-SA.

**Fig. 10.2** Figure reproduced from the QuVis website, licensed under creative commons CC-BY-NC-SA.

	- (a) In the product state?
	- (b) In the entangled state?

#### **10.2 Polarizer Demo**

For students who have learned about polarization, the creation of superposition states can be demonstrated using three polarizing filters. When unpolarized light is sent through a vertical filter, only vertically polarized light is able to pass through. Sending vertically polarized light through a horizontal filter results in no light passing through, since the vertical and horizontal polarizations are mutually exclusive. Surprisingly, adding a diagonal filter in between recovers the light! The diagonal polarizer introduced a horizontally polarized component, similar to how passing a spin-up electron through a horizontal SGA created a horizontal superposition.

**Question** Relate the behavior of the polarizers to what you saw in the SGAs. Hint: think of the top two polarizers in Fig. 10.3 as the *z*-basis, and diagonal polarizers as the *x*-basis.

**Fig. 10.3** Unpolarized light is sent through a series of polarizing filters.

#### **10.3 Quantum Tic-Tac-Toe**

Quantum Tic-Tac-Toe was developed by Alan Goff in 2004 as a metaphor to teach quantum concepts such as superposition, entanglement, and measurement collapse. It has been found to be a helpful strategy in teaching quantum mechanics to undergraduate students at Purdue, especially for students who struggle with grasping the concepts.2

Quantum Tic-Tac-Toe resembles the classical Tic-Tac-Toe game in its setup and objective of completing three in a row. However, the game uses characteristics of quantum systems, so instead of using one marker *X* or *O*, the players use pairs of *X*s and *O*s, which are traditionally called "spooky," after Einstein's reference to entanglement as "spooky action at a distance".3 Using indices for each marker's move is important when determining the winner of the game. Additionally, we use a color code for each player and connect the spooky markers to help students better visualize the game process. We also number the squares for future reference.

#### **10.3.1 The Rules**

2Hoehn R, et al. (2014). "Using Quantum Games to teacher quantum mechanics, Part 1." *Journal of Chemical Education 91* (3), 417–422. Retrieved from https://pubs.acs.org/doi/ipdf/10.1021/ ed400385k.

3Einstein, Podolsky, and Rosen (1935) "Can quantum-mechanical description of physical reality be considered complete?" *Physical Review, 47*: 777–780. Retrieved from https://journals.aps.org/ pr/pdf/10.1103/PhysRev.47.777.

**Fig. 10.5** Example of the

**Fig. 10.7** The two collapse outcomes due to player O's decision.

the markers will be collapsed. The fair choice would be by the player who did not create the cycle (in this case, player O). When the markers are forced to collapse, only one of the two squares for each move can be chosen, so player O can choose either square 4 or 6. Depending on their choice, the outcome would be different (Fig. 10.7). Once the states are collapsed, the "spooky markers" change into classical markers and they fully occupy the state of one particular square.

**Some Other Rules Can Be Added or Modified** One of the requirements could be that players cannot place both markers in the same square like the one shown in Fig. 10.9. Another way to make the collapse more quantum (or more random) is using a coin flip to decide which player chooses the collapse.

Other modifications may include assigning different point values for three in a row, such as the winner with lowest sum of the indexes gets 1 point, while the other player gets 1*/*2 point.

One of the main challenges of playing the game is to observe when a cycle has been created so the state of the spooky markers can be collapsed at the right time. A computer-simulated game will automatically keep track of this and will force students to collapse their markers, such as this game simulator. 4

We found that using color codes and connecting lines helps visually track loops. Another way is to create a model of the game where students can see the connections and collapse the states using physical pieces. It would be interesting to see students' responses as to which medium helps them understand the game principle better.

#### **10.3.2 Connection to Quantum Physics**

How are the game rules and principles connected to the real applications of quantum mechanics? There are three major themes that can be drawn from the game: superposition, the effect of measurement, and entanglement.

#### **Superposition**

In classical physics all objects have defined states. However, quantum systems can exist in a superposition of several classical states at the same time. The example could be an electron with a spin that is in superposition of up and down, or a photon in a superposition of vertical and horizontal polarization. QTTT spooky markers exist in two separate locations on the game board, representing their state as a superposition state of two classical TTT markers.

#### **Measurement**

When measuring the state of a quantum system, the quantum state of a system collapses and only one classical state is observed with some probability. In QTTT, the rule of creating the loop forces players to collapse their markers (measure their quantum state). In this case the player decides how to collapse the markers, which corresponds to the scientist choosing the way of measuring quantum system, such as axis orientation. The rule of forcing the measurement when the loop is created does not have an exact corresponding physical meaning. Quantum systems can exist in a superposition state for an extended time, and the measurement is not forced, but chosen by the observer.

#### **Entanglement**

Entanglement is the quantum phenomenon of creating two or more particles, whose states cannot be described separately, but have some correlation even when they are separated by a significant distance. When measuring the state of one of the entangled particles, the state of the other particle can be known even without measurement. Einstein called it "spooky action at a distance." When the players collapse their states after creating a loop in QTTT, they know for sure in which state each marker would collapse into.

4http://qttt.rohanp.xyz/.

#### **10.4 Schrödinger's Worm Using Five Qubits**

#### **Objectives**

Design, build, and test quantum circuits that model systems in superposition and entanglement.

#### **Setup**

Open the IBM Q simulator5 and start a new circuit in the Circuit Composer (Fig. 10.10).

The default is 5-qubits initialized to the |0 state. Gates can be applied by dragging and dropping them onto the appropriate qubit(s). Don't forget to add the measurement gate at the end to see the results. When you are satisfied with your circuit, save the experiment and click Run (Fig. 10.11).

By default, the circuit will be evaluated 1024 times using the simulator backend. You may also run the circuit on a real quantum computer, subject to a waiting period. Increasing the number of shots will increase the statistical accuracy of the results at the expense of run-time. After you have run the circuit, the results will appear in a link at the bottom of the page.

**Fig. 10.10** A new experiment on the IBM Q Circuit Composer. Reprint courtesy of International Business Machines Corporation, ©International Business Machines Corporation.

5https://quantum-computing.ibm.com.

**Fig. 10.11** Options for running the IBM Q experiment. Reprint courtesy of International Business Machines Corporation, ©International Business Machines Corporation.

#### **Part II: Entanglement**

The worm is next to a hungry bird, such that the worm is either alive or chomped to pieces (Fig. 10.13).

#### **Further Resources**

6https://qiskit.org/.

7https://qiskit.org/events/summer-school/.

#### **10.5 Superposition vs. Mixed States Lab**

#### **Objectives**

#### **Questions**

	- (a) 100 electrons were in a 50/50 superposition state of up and down (superposition state).
	- (b) The electrons were a classical mixture of 50 electrons spin up and 50 spin down (mixed state).
	- (c) Not enough information

8https://www.st-andrews.ac.uk/physics/quvis/simulations\_html5/sims/superposition/ superposition-mixed-states.html.

**Fig. 10.14** Figure reproduced from the QuVis website, licensed under creative commons CC-BY-NC-SA.

### **10.6 Measurement Basis Lab**

#### **Objectives**

**Fig. 10.15** Figure reproduced from the PHET Stern-Gerlach Simulator website, licensed under creative commons CC-BY.

9https://phet.colorado.edu/sims/stern-gerlach/stern-gerlach\_en.html.

#### **Questions**

#### **10.7 One-Time Pad**

#### **10.7.1 One-Time Pad: Alice**

Before parting ways, you and Bob agree on a key. Using a coin with heads = 0 and tails = 1, randomly generate a key of the same length as the message. Make sure that you and Bob have the same key.

#### • Shared Key:

**Table 10.1** One-time pad (Alice)

#### • Encoding:

1. Choose a secret letter to send to Bob in binary using Table 10.1. Message:

2. Add the key to your message, bit by bit, to encode the message. In binary, 0 + 0 = 0, 0 + 1 = 1 + 0 = 1, and 1 + 1 = 0. For example, if the key = 0110 and the message = 1101, then the cipher text = 1011, as 0110+1101 = 1011. – Cipher Text:

	- 1. Write down the cipher received from Bob.

#### 2. Add the key to Bob's message, bit by bit, to decode the message.

3. What was the message?

#### • Eavesdropping

#### • Questions

#### **10.7.2 One-Time Pad (Bob)**

Before parting ways, you and Alice agree on a key. Using a coin with heads = 0 and tails = 1, randomly generate a key of the same length as the message. Make sure that you and Alice have the same key.

• Shared Key:

#### • Encoding:

1. Choose a secret letter to send to Alice in binary. (Table 10.2) Message:

2. Add the key to your message, bit by bit, to encode the message. In binary, 0 + 0 = 0, 0 + 1 = 1 + 0 = 1, and 1 + 1 = 0. For example, if the key = 0110 and the message = 1101, then the cipher text = 1011. 0110 + 1101 = 1011. – Cipher Text:

**Table 10.2** One-time pad (Bob)

3. Send the cipher text to Alice.

#### • Decoding

1. Write down the cipher received from Alice.

2. Add the key to Alice's message, bit by bit, to decode the message.

#### 3. What was the message?

#### • Eavesdropping

#### • Questions

#### **10.8 BB84 Quantum Key Distribution**

#### **10.8.1 BB84 Quantum Key Distribution: Alice**

	- 1. Randomly choose to prepare the electron in either the *x* or *z*-basis.
	- 2. The electron that's sent through your Stern-Gerlach apparatus will either be in a 0 or 1 state. You can randomize this by flipping a coin.
	- 3. Pass the correct spin card to Bob face down.

$$\begin{array}{ccccc} \begin{array}{c} \\ \\ \end{array} = 0 & \begin{array}{c} \\ \\ \end{array} = 1 \\ \end{array} = 1$$

	- 1. Repeat the procedure, but instead of passing the spin card directly to Bob, it will first pass through Eve.
	- 2. Compare the sifted key bits one at a time. How can you tell if Eve intercepted the message?

#### **10.8.2 BB84 Quantum Key Distribution: Bob**

	- 1. Randomly choose between the *x* or *z*-basis.
	- 2. Receive the spin card from Alice and flip it over.
		- If your basis is the same as the card's, record the bit value.
		- If your basis is different, the output of your Stern-Gerlach apparatus will be random. Randomly pick 0 or 1.

$$\begin{array}{ccccc} \begin{array}{c} \\ \\ \end{array} = 0 & \begin{array}{c} \\ \\ \end{array} = 1 \\ \end{array} = 1$$

	- 1. Repeat the procedure, but instead of getting the spin card directly from Alice, it will first pass through Eve.
	- 2. Compare the sifted key bits one at a time. How can you tell if Eve intercepted the message?

#### **10.8.3 BB84 Quantum Key Distribution: Eve**

```
• With Eavesdropper (You!)
```
	- If your basis is the same as the card's, record the bit value and pass it along to Bob.
	- If your basis is different, the output of your Stern-Gerlach apparatus will be random. Randomly pick 0 or 1 for your bit value, erase Alice's value, write yours on the card, and pass the card along to Bob.

**Open Access** This chapter is licensed under the terms of the Creative Commons Attribution 4.0 International License (http://creativecommons.org/licenses/by/4.0/), which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license and indicate if changes were made.

The images or other third party material in this chapter are included in the chapter's Creative Commons license, unless indicated otherwise in a credit line to the material. If material is not included in the chapter's Creative Commons license and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder.

# **A Probability**

#### **A.1 Introduction**

*Probability* is the branch of mathematics needed to understand how likely certain events are to occur. The study of probability appears all over in everyday life. Some examples of everyday probabilities include the chance you get heads when you flip a coin, or the likelihood it will rain tomorrow.

More specifically, an **event** is a group of one or more outcomes that form an observation, i.e., a coin flip. To find the probability associated with a specific outcome of an event, it is often necessary to perform many repeated experiments of the event. Each event in this set is referred to as a **trial**. The distribution of trials will follow the probability for the given event to occur. For example, Fig. A.1 shows the probability for a coin to land on heads a specific number of times after ten coin flips. Later in this appendix, we will work out the probabilities when there are five coin flips.

The set of all possible outcomes is often referred to as the **sample space**. Some examples of sample spaces are:

#### **A.2 Combining Probabilities**

With the above knowledge, we can now calculate the probabilities for more complicated scenarios. For example, by the end of this section, we will be able to find the probabilities for a specific number of heads to occur after we flip 5 coins.

When combining the probability for a specific event with that for another event, we can start by listing all the possible outcomes. For example, consider rolling a die

**Fig. A.1** The chances of flipping a specific number of heads when there are a total of 10 coin flips

and flipping a coin; the possible outcomes are shown in Fig. A.2. The total number of unique outcomes is 12, and all of the different outcomes occur exactly once. From this, we can concluded that the probability of any one of the events listed above is 1 12 . We can also find this result mathematically from the probability of rolling a given number on a die, and separately the probability of getting heads or tails when flipping a coin. To find the combined probability for a given number on the dice (lets say a 4) and flipping a heads on a coin, we can multiply the two separate probabilities together to obtain the probability for both to occur (i.e., 1 6 × 1 2 = 1 12 ), which is the same result we found from counting the different scenarios.

The total number of combinations for the outcomes of two independent events is the product of the number of outcomes for each event individually. An **independent** event is one in which the outcome is not changed by the outcome of another event. For example, each flip of a coin is an independent event. Whether the coin lands on heads or tails does not depend on whether it previously landed on heads or tails in the past flips. To understand if an event is not independent, consider a bag of six blue and six red marbles. If we remove one marble from the bag at random, and do not replace it, the next marble that is removed is no longer independent from the previous action. The probability for a blue marble to be removed in the second draw depends on whether the first marble was blue or red.

When combining two or more independent events, the total number of outcomes is simply the product of the probabilities of each individual event. This means, that if we roll 2 dice, we have 36 possible outcomes, and if we roll 3 dice, we have 216 possible outcomes, etc. The probability for each of the outcomes to occur in

**Fig. A.2** All twelve possible outcomes when both rolling a die and flipping a coin

**Fig. A.3** All possible outcomes of rolling two dice. One die is colored white and the other red to help distinguish the possible combinations for each die

this case is also the product of the probability for each individual outcome to occur. For example given a red, green, and white die, the probability of rolling a 2 on the red die, a 6 on the green die, and a 1 on the white die is simply the product of the probability for each individual die, or in this case 1 216 .

However, this is not the same when the two events are made to be dependent on each other. Take the situation when we want to find the probability that the sum of two dice adds up to a specific number. All possible outcomes of rolling two dice are shown in Fig. A.3. Here we see that there are at least two ways for the dice to come out so that result in the same number, with the exception of 2 and 12. When we count up the total number of unique sums of the two dice, we get the numbers 2 through 12. The count of the ways each sum can occur is given in Table A.1. In this case, the total number of outcomes is still the product of the number of outcomes for each die, but the probability is not the product of the individual probabilities.

#### **A.2.1 Key Words Review**

#### **Table A.1** Possible outcomes of rolling two dice

#### **A.2.2 Key Ideas Review**

#### **A.2.3 Check Your Understanding**

	- (a) have different numbers?
	- (b) sum to a number greater than 8? sum to a number less than 8?
	- (c) are both an even number? both an odd number? one even and one odd?
	- (a) Drawing a red card and rolling an even number.
	- (b) Drawing a face card and rolling a one.
	- (c) Drawing the ace of spades and rolling 4 or higher.

#### **A.3 Histograms**

There are many different ways to represent the data collected from a series of events. First, one can represent data as a frequency table. A **frequency table** contains two columns, where the first column is the possible categories that the event can fall into, and the second column is the number of times that event has occurred. It is possible to represent a frequency table as a plot by having the *x*-axis represent the different categories, and the *y*-axis representing the frequency of those events. This graphical representation of the frequency table is known as a **histogram**.

To make these concepts more concrete, consider the following example. After flipping five coins, we count the number of heads and find that we have three heads. Now we repeat this trail 29 more times, and at the end we have the following counts for the number of heads for the 30 trials:

> 3*,* 4*,* 2*,* 1*,* 1*,* 1*,* 4*,* 1*,* 4*,* 3*,* 2*,* 3*,* 2*,* 2*,* 3*,* 2*,* 2*,* 1*,* 3*,* 3*,* 2*,* 3*,* 4*,* 4*,* 3*,* 2*,* 1*,* 3*,* 3*,* 2*.*

We can put this into a frequency table as given in Table A.2.

We can then make a bar plot of the categories, and the frequency of each of those categories. The results for this example is shown in Fig. A.4.

#### **A.4 Mean, Median, and Mode**

Given a set of observations of events, it is important to calculate properties of distribution of events. The group of calculations giving a central value are referred to as **measures of central tendency**. These measures, along with other statistical measures of the data, allow us to compare a given dataset to another dataset and draw conclusions. In statistics, there are three common ways of measuring the central tendency. Each measure gives a different piece of information about the distribution.

The first method of measuring central tendency is known as the mean. The **mean** of a set of events is the sum of all the data points representing the events divided by the number of events in the sample. Often, the mean is also called the average. A typical use that you are familiar with is the average grade from a given class.

**Table A.2** Frequency table for the number of heads from 30 trails of 5 coin flips

**Fig. A.4** Histogram for the number of heads from 30 sets of 5 coin flips

The second method is known as the median. The **median** of a set of events is the middle number when the events are ordered from the smallest value to the largest value. If there happen to be two numbers in the middle, the median is the average of those two values.

The last method is known as the mode. The **mode** is simply the result in a set of events that occurs the most often.

To help make these definitions more clear, let us consider an example. A teacher gave a test to a class of 15 students, and the scores that the students achieved were 78, 100, 81, 89, 91, 88, 93, 99, 85, 75, 95, 94, 84, 81, and 87. First, we will calculate the mean (which is often represented by the symbol *μ*). Recall, the mean is found by taking the sum of the scores and dividing by the number of scores. The mean for these scores is:

$$\mu = \frac{78 + 100 + 81 + 89 + 91 + 88 + 93 + 99 + 85 + 75 + 95 + 94 + 84 + 81 + 87}{15}$$

$$= \frac{1320}{15}\tag{A.1}$$

$$= 88\text{ }.$$

The mean or average score for this test is 88. Now, to calculate the median, we first sort the data from smallest to largest, and then find the value in the middle. In the example it is given by

$$\underbrace{\overbrace{78,78,81,81,84,85,87}^{78,78,85,87}}\_{7\text{ numbers}},\underbrace{88,\underbrace{99,91,93,94,95,95,99,100}\_{7\text{ numbers}}}\_{7\text{ numbers}}\tag{A.2}$$

Therefore, the median is also given by the number 88. Finally, the mode is the number that occurs the most often. Table A.3 shows the counts for each of the different test scores, and from that we can see that the mode is the score 81.

Putting together the results for these tests, we find that both the mean score and the median score are 88 and the mode score was 81. These calculations can be extended to arbitrarily large data sets, and the techniques discussed above will still work to calculate the mean, median, and mode. In our example above, the mean and median turn out to be the exact same number. However, this is not always the case. When these two numbers are far away from each other, it could indicate that there is an outlier in the data set. An **outlier** is a point in the data set that drastically differs from the rest of the data. An example of an outlier would be to consider the test scores again. If we were to add in a test score of 5, this would be considered an outlier. Consider the impact this outlier would have on the mean, median, and mode. The mean would now be 82.8 instead of 88, while the median would be 87.5 and the mode would still be 81. From this, we can see that by combining the mean, median, and mode we learn more information about the data than by any one individual measure.

#### **A.4.1 Key Word Review**

#### **A.4.2 Check Your Understanding**

For all of the problems below, consider the 30 test scores found in Table A.4.

1. Calculate the mean, median, and mode.

2. What happens to the mean, median, and mode if 5 new test scores are added with the values of: 6, 12, 20, 14, and 5

#### **A.5 Variance and Standard Deviation**

In the previous section, we discussed commonly used measures of central tendency. In this section, we will discuss **measures of dispersion**, which provide information about the spread of data around the central values.

Here, we will cover two of the many measures of dispersion that exist. These two measures are related to each other and are known as the variance and standard deviation. The **variance** is the average squared distance that exists between all the data points and the mean of the data points. The **standard deviation** is the square root of the variance, and gives an impression of the spread of the data around the mean. The smaller the standard deviation, the more clustered the points are around the mean value. The values of the variance and the standard deviation are can never be negative. The variance is typically represented by the symbol *σ*2, while the standard deviation is represented by the symbol *σ*. To calculate the variance and standard deviation we use the following formula

$$
\sigma^2 = \frac{\sum (\mathbf{x}\_l - \mu)^2}{n},
\tag{A.3}
$$

where the sum is over all *n* data points, *xi* is the value of each point, and *μ* is the mean of the data set. As an example, let us look at the test scores given in the previous section: 78, 100, 81, 89, 91, 88, 93, 99, 85, 75, 95, 94, 84, 81, and 87. To find the variance and the standard deviation, we first calculate the mean, which was done in the previous section and is 88. Next we take the difference between each separate score and the mean value, then square each difference. Finally, we sum these squared values and divide them by the number of scores. The steps are shown here as

$$(\mathbf{x}\_{l} - \boldsymbol{\mu})^{2} = 100, 144, 49, 1, 9, 0, 25, 121, 9, 169, 49, 36, 16, 49, 1$$

$$\sum (\mathbf{x}\_{l} - \boldsymbol{\mu})^{2} = 778$$

$$\sigma^{2} = \frac{778}{15} = 51.9 \tag{A.4}$$

$$\sigma = \sqrt{\sigma^{2}} = 7.2$$

The standard deviation is 7.2, and this means that most of the scores are within 7.2 points of 88.

#### **A.5.1 Key Word Review**

#### **A.5.2 Check Your Understanding**

For all the problems below, again consider the 30 test scores found in Table A.4.

# **B Linear Algebra**

#### **B.1 Introduction**

**Linear algebra** is the field of mathematics underlying the topics of vectors and matrices. It is the backbone of mathematics used for solving systems of linear equations. You may be familiar with static physics problems, whose solution utilize linear algebra. An example of a set of linear equations is

$$\begin{aligned} \mathbf{x}\_1 + 4\mathbf{x}\_2 + 3\mathbf{x}\_3 &= -7 \\ 4\mathbf{x}\_1 + 2\mathbf{x}\_2 &= 11 \\ 9\mathbf{x}\_2 - 8\mathbf{x}\_3 &= 0 \end{aligned} \tag{\mathbf{B.l}}$$

This appendix supplies a basic introduction to some key aspects of the field of linear algebra. We will cover the topics of scalars, vectors, and matrices.

#### **B.2 Scalars, Vectors, and Matrices**

#### **B.2.1 Scalars**

A **scalar** is a number without a direction associated to it. Some common examples of scalars are speed and distance. Both speed and distance are quantified by a single number, but give no information about the direction one is traveling. In this book, the scalars that are used are either real numbers or complex numbers. Let us quickly review complex numbers since they are not as common as real numbers in everyday life.

A complex number consists of a real and an imaginary component. An **imaginary** number is one that is some multiple of *i* = √−1, i.e. 4*i*, 1*/*10*i*, and *π i* are all examples of imaginary numbers. Complex numbers are represented using the form *a* + *bi*, with both *a* and *b* as real numbers. Addition and subtraction of complex numbers is straightforward, we simply add or subtract the real components from each other and add or subtract the imaginary components from each other. Some examples are:

$$(3+4i)+(5+3i) = 8+7i$$

$$(3+4i)-(1+3i) = 2+i$$

$$(3+i)+(1-3i) = 4-2i$$

$$(9-6i)-(4+i) = 5-7i$$

On the other hand, multiplication and division are slightly more complicated. When performing multiplication and division, it is helpful to know the powers of *i*:

$$i^2 = -1, \quad i^3 = -i, \quad i^4 = 1, \quad i^5 = i, \quad \text{etc.} \tag{\text{B.2}}$$

Multiplication of complex numbers is performed by multiplying out the terms and then adding them together, i.e. given the complex numbers *x* = *a* + *bi* and *y* = *c* + *di*, then:

$$\mathbf{x} \times \mathbf{y} = (a+bi) \times (c+di) = (ac+adi+bci+bdi^2) = (ac-bd)+(ad+bc)i. \tag{\text{B.3}}$$

Before covering division, let us introduce the idea of a complex conjugate. A **complex conjugate** is the complex number where the real component is the same, but the imaginary component has the opposite sign. The complex conjugate is denoted with an ∗ symbol. For example, the complex conjugate of *a* + *bi* is *a* − *bi*. When multiplying a complex number by its complex conjugate we get a real number, and refer to it as the **magnitude squared** of a complex number and is represented by |*x*| 2, i.e. |*a* + *bi*| 2 = *(a* + *bi)* × *(a* + *bi)*∗ = *a*2 + *b*2.

In order to divide two complex numbers, first you multiply the numerator and denominator by the complex conjugate of the denominator and then perform multiplication of complex numbers, e.g.,

$$\frac{a+bi}{c+di} = \frac{a+bi}{c+di} \times \frac{c-di}{c-di} = \frac{(a+bi)\times(c-di)}{c^2+d^2} = \frac{(ac+bd)+(bc-ad)i}{c^2+d^2} \,. \tag{B.4}$$

#### **B.2.2 Vectors**

A **vector** is a mathematical object that is defined to have both size and direction. One can imagine a vector as a directed line segment as seen in Fig. B.1. The size or **magnitude** of a vector is the length of the line segment. The **tail** of a vector is the starting point, and the **head** of a vector is the ending point. The **direction** of a

**Fig. B.2** Depiction of a vector on a coordinate system in 2 dimensions

vector is from the tail to the head. Two vectors are considered equal to each other when they both have the same magnitude and the same direction.

Some common vectors that you may be familiar with are force, velocity, and acceleration. For example, a car's velocity is the speed the car is going combined with the direction the car is driving in. Typically, vectors are denoted by either *a* or **a**, and the magnitude of a vector is denoted by |*a*|. The magnitude is a scalar value (see Sect. B.2.1 for details). Additionally, we can describe a vector by imagining a coordinate system, where the origin is located at the tail of the vector (in two dimensions this would correspond to the point *(*0*,* 0*)*), and the head of the vector would be its coordinate (e.g., *(x, y)* in two dimensions). For example, given *a* as a two dimensional vector as shown in Fig. B.2, we can define the vector as *a*-= *(*2*,* 4*)*.

The magnitude of a vector can be calculated by using the distance formula between two points. Recall that the distance formula between the origin of a coordinate system in two dimensions is given by

$$d = \sqrt{\mathbf{x}^2 + \mathbf{y}^2}.\tag{\text{B.5}}$$

The formula for the distance from the origin of a vector to its endpoint can be generalized to higher dimensions in a straightforward manner. For example, given a ten dimensional vector *a*-= *(x*1*, x*2*, x*3*, x*4*, x*5*, x*6*, x*7*, x*8*, x*9*, x*10*)*, the magnitude is given by

$$|\vec{a}| = \sqrt{\mathbf{x}\_1^2 + \mathbf{x}\_2^2 + \mathbf{x}\_3^2 + \mathbf{x}\_4^2 + \mathbf{x}\_5^2 + \mathbf{x}\_6^2 + \mathbf{x}\_7^2 + \mathbf{x}\_8^2 + \mathbf{x}\_9^2 + \mathbf{x}\_{10}^2}. \tag{B.6}$$

In this book, we mainly focus on qubits which we represent as two-dimensional vectors. Qubits are also unit normalized, meaning *(x, y)* satisfies *x*2 + *y*2 = 1. If a vector *(a, b)* is not unit normalized, then the vector *(a/(a*2 + *b*2*), b/(a*2 + *b*2*))* is unit normalized.

#### **Operations with Vectors**

Consider what we can do with one vector and one scalar, or two vectors. First, let us consider the addition of two vectors. If we have the vectors *a* and *b*-, we can calculate the sum *c*- = *a* + *b* by adding each component independently. For example, given the two dimensional vectors *a*- = *(x*1*, y*1*)*, and *b*- = *(x*2*, y*2*)*, the sum of the vectors is *c*- = *a* + *b*- = *(x*1 + *x*2*, y*1 + *y*2*)*. This can be represented pictorially and is shown in Fig. B.3.

There are two important properties of vector addition:

**Fig. B.4** The parallelogram law

Subtraction of two vectors works in the same way as addition, but instead of adding the components, we subtract them. This can also be thought of taking a vector *a*-, and flipping the direction of the vector. This will change *a*- = *(x, y)* to −*a* = *(*−*x,* −*y)*. All of the rules for addition described above also apply to subtraction.

If we have a vector and a scalar, the only thing we can do is to multiply the two together. When multiplying a vector and a scalar, we simply multiply every component of the vector by the scalar. For example, given the three dimensional vector *a*- = *(*4*,* 6*,* 2*)* and the scalar *s* = 5, then *b*- = *s* × *a* = *(*20*,* 30*,* 10*)*. It is important to notice here that the result *b* is also a vector. The direction of the vector *b* is unchanged if *s >* 0, but is in the opposite direction if *s <* 0. The magnitude of the vector *b* is scaled by the value of the scalar, and thus it is stretched if |*s*| *>* 1 and compressed if |*s*| *<* 1.

Finally, we have the multiplication of two vectors. There are actually two different ways that we can multiply vectors together. The first way is known as the **dot product**. The dot product takes two vectors, and multiplies them together to produce a scalar. We denote the dot product of two vectors by *a*- · *b*-. The dot product is calculated by taking the product of all the components of the vector, and summing them up. In other words, given the vector *a*- = *(xa, ya)* and the vector *b*- = *(xb, yb)*, the dot product is given as: *a*- · *b*- = *xa* × *xb* + *ya* × *yb*. While this example is in two dimensions, the dot product can be extended to an arbitrary number of dimensions.

We can also think about the dot product geometrically. Let us take two vectors *a* and *b*-, with the magnitude of *b* larger than that of *a*-. We can then relate the dot product to the projection of *a* onto the direction of *b*-, or what portion of *a* is pointing in the direction of *b*-. The projection can be thought of as imagining what the shadow of *a* would look like when cast by a light source perpendicular to *b*- (see Fig. B.5). In other words, the dot product can be represented by multiplying the magnitudes of the two vectors, and taking the cosine of the angle between them (*a*- · *b*- = |*a*||*b*-| cos *θ*). Below are some properties that are related to dot products, where *a, b,* and *c* are vectors, and *s* is a scalar:

The other method of multiplying two vectors is known as the cross product. The cross product is written as *a*- × *b*-. Note that the notation for the cross product looks the same as multiplication. However, multiplication operates on scalars while the cross products acts on vectors. The **cross product** takes two vectors, and produces a third vector that is perpendicular to the other two. From this definition, it can easily be seen that this will not work for two dimensional vectors, so we will focus on three dimensions for this discussion. The magnitude of the resulting vector from the cross product is equal to the area of the parallelogram formed by the vectors (i.e. |*a* × *b*-| = |*a*||*b*-|sin *θ* and as shown in Fig. B.6).

The direction of the resulting vector from a cross product can be determined by the **right-hand rule**. To use the right-hand rule given the cross product *c*- = *a* × *b*-, first point the fingers of the right hand in the direction of *a*-, and curl them towards *b*-. The direction the thumb points is the direction of *c*-. Using the right-hand rule, we can make an observation that *a*- × *b*- = −*b*- × *a*. From this, we can also see that *a*-× *a* = −*a*× *a*, which is only possible if the result is the 0 vector (i.e. *c*- = *(*0*,* 0*,* 0*)*). Given the vectors *a*- = *(x*1*, y*1*, z*1*)* and *b*- = *(x*2*, y*2*, z*2*)*, the cross product can be calculated using:

$$
\vec{c} = \vec{a} \times b = (\mathbf{y}\_1 \mathbf{z}\_2 - \mathbf{y}\_2 \mathbf{z}\_1, \mathbf{x}\_2 \mathbf{z}\_1 - \mathbf{x}\_1 \mathbf{z}\_2, \mathbf{x}\_1 \mathbf{y}\_2 - \mathbf{x}\_2 \mathbf{y}\_1). \tag{\mathbf{B}.7}
$$

#### **B.2.3 Matrices**

A **matrix** (plural matrices) is a rectangular array of numbers, typically written in rows and columns with round brackets around them. We denote the size of the matrix by first listing the number of rows, followed by the number of columns. For example,

$$M = \begin{pmatrix} 3 & 7 \\ 1 \ 4 \\ 9 \ 5 \end{pmatrix},\tag{B.8}$$

is a 3 × 2 matrix. Three dimensional vectors (discussed in the previous section) can be thought of as either a 1 × 3 or a 3 × 1 matrix. Often the number of rows and columns of the matrix are referred to as the **shape** of the matrix. We say a matrix is a **square matrix** if the number of rows is equal to the number of columns. We can specify an element of a matrix by denoting its row and column position. For example, taking the matrix *M* given in Eq. (B.8), the element *M*1*,*2 = 7 and the element *M*3*,*1 = 9. This representation of the matrix is often referred to as index notation, and will be used below to make the equations easier to understand.

#### **Addition and Subtraction of Matrices**

Addition and subtraction of matrices is straightforward. The only requirement on addition and subtraction of two matrices is that they must have the shape (number of rows and number of columns). When adding or subtracting matrices of the same shape, one performs each operation between the same element location. For example, given the 3 × 3 matrices

$$A = \begin{pmatrix} 9 & 5 & -6 \\ 1 & -10 & -8 \\ 1 & 5 & -3 \end{pmatrix}, \quad B = \begin{pmatrix} -4 & 7 & -5 \\ -9 & -9 & 5 \\ 9 & -1 & 8 \end{pmatrix}, \tag{B.9}$$

then

$$A + B = \begin{pmatrix} 9 + (-4) & \mathfrak{F} + 7 & -6 + (-\mathfrak{F}) \\ 1 + (-9) - 10 + (-9) & -8 + \mathfrak{F} \\ 1 + 9 & \mathfrak{F} + (-1) & -3 + 8 \end{pmatrix} = \begin{pmatrix} \mathfrak{F} & 12 & -11 \\ -8 - 19 & -3 \\ 10 & 4 & \mathfrak{F} \end{pmatrix},\tag{B.10}$$

and

$$A - B = \begin{pmatrix} 9 - (-4) & \mathfrak{F} - 7 & -6 - (-5) \\ 1 - (-9) - 10 - (-9) & -8 - \mathfrak{F} \\ 1 - 9 & \mathfrak{F} - (-1) & -\mathfrak{z} - 8 \end{pmatrix} = \begin{pmatrix} 13 - 2 & -1 \\ 10 - 1 - 13 \\ -8 & 6 & -11 \end{pmatrix} . \tag{B.11}$$

#### **Multiplication with Matrices**

When dealing with matrices, there are three types of multiplication that we will discuss. These are the multiplication of scalars and matrices, the multiplication of vectors and matrices, and the multiplication of matrices and matrices.

The result of multiplication by a scalar is just an element-wise multiplication by the scalar, e.g.,

$$A = \begin{pmatrix} 6 & 10 \ 0 \\ 5 & 7 \ 1 \\ 5 & 6 \ 1 \end{pmatrix}, \quad \mathbf{5}A = \begin{pmatrix} 5 \times 6 \ 5 \times 10 \ 5 \times 0 \\ 5 \times 5 \ 5 \times 7 \ 5 \times 1 \\ 5 \times 5 \ 5 \times 6 \ 5 \times 1 \end{pmatrix} = \begin{pmatrix} 30 \ 50 \ 0 \\ 25 \ 35 \ 5 \\ 25 \ 30 \ 5 \end{pmatrix}. \tag{B.12}$$

If we think about vectors as 1 × *N* or *N* × 1 shaped matrices, then the product of a matrix and a vector can be thought of as the product of two matrices. It is easiest to build up to the definition of matrix-matrix multiplication with the use of examples. First, the dot product discussed in Sect.B.2.2 can be thought about as multiplying a 1 × *N* matrix by a *N* × 1 matrix. For example, with

$$A = \begin{pmatrix} 2 \\ 9 \end{pmatrix}, \text{ and } B = \begin{pmatrix} 3 \ 5 \end{pmatrix}, \tag{B.13}$$

then

$$B \times A = (\mathfrak{J} \times \mathfrak{Z}) + (\mathfrak{J} \times \mathfrak{Y}) = (\mathfrak{J} \mathfrak{l}).\tag{B.14}$$

Note that we started with matrix *B* (1 × 2) and matrix multiplied it with *A* (2 × 1) to find 1 × 1 matrix. This is the same result as the dot product between two vectors *a*- = *(*2*,* 9*)* and *b*- = *(*3*,* 5*)*. We can extend this by breaking down the matrix into a set of 1 × *N* and *N* × 1 matrices. It is important to note that the number of columns of the first matrix must be equal to the number of rows of the second matrix for matrix multiplication to make sense. Given a *m* × *n* matrix A and a *n* × *p* matrix B, then the product *A* × *B* = *C* is a *m* × *p* matrix. The *(i, j )* element of the matrix C can be calculated as

$$c\_{l,j} = \sum\_{k=1}^{n} a\_{l,k} \times b\_{k,j},\tag{B.15}$$

where the *n k*=1 symbol means we sum all indices *k* from 1 to *n*. As an example, let us calculate *A* × *B* = *C* and *B* × *A* = *D* for the 2 × 2 matrices given by

$$A = \begin{pmatrix} 3 \ 2 \\ 5 \ 6 \end{pmatrix}, \quad B = \begin{pmatrix} 2 \ 6 \\ 8 \ 7 \end{pmatrix}. \tag{B.16}$$

First, let us calculate the matrix *C* by treating the *i*th row of *A* and the *j* th column of *B* as if they were vectors as done above:

$$c\_{1,1} = \begin{pmatrix} 3 \ 2 \end{pmatrix} \begin{pmatrix} 2 \\ 8 \end{pmatrix} = (3 \times 2 + 2 \times 8) = 22$$

$$c\_{1,2} = \begin{pmatrix} 3 \ 2 \end{pmatrix} \begin{pmatrix} 6 \\ 7 \end{pmatrix} = (3 \times 6 + 2 \times 7) = 32$$

$$c\_{2,1} = \begin{pmatrix} 5 \ 6 \end{pmatrix} \begin{pmatrix} 2 \\ 8 \end{pmatrix} = (5 \times 2 + 6 \times 8) = 58$$

$$c\_{2,2} = \begin{pmatrix} 5 \ 6 \end{pmatrix} \begin{pmatrix} 6 \\ 7 \end{pmatrix} = (5 \times 6 + 6 \times 7) = 72$$

Taken together,

$$C = \begin{pmatrix} 22 \ 32 \\ \text{58 72} \end{pmatrix}. \tag{\text{B.17}}$$

Now, by following similar steps we can calculate *B* × *A* by taking the *i*th row of *B* and the *j* th column of *A* to produce

$$d\_{1,1} = \begin{pmatrix} 2 \ 6 \end{pmatrix} \begin{pmatrix} 3 \\ 5 \end{pmatrix} = (2 \times 3 + 6 \times 5) = 36$$

$$d\_{1,2} = \begin{pmatrix} 2 \ 6 \end{pmatrix} \begin{pmatrix} 2 \\ 6 \end{pmatrix} = (2 \times 2 + 6 \times 6) = 40$$

$$d\_{2,1} = \begin{pmatrix} 8 \ 7 \end{pmatrix} \begin{pmatrix} 3 \\ 5 \end{pmatrix} = (8 \times 3 + 7 \times 5) = 59$$

$$d\_{2,2} = \begin{pmatrix} 8 \ 7 \end{pmatrix} \begin{pmatrix} 2 \\ 6 \end{pmatrix} = (8 \times 2 + 7 \times 6) = 58$$

Taken together, the result is

$$D = \begin{pmatrix} \mathfrak{H} \ 40 \\ \mathfrak{H} \ \mathfrak{H} \end{pmatrix}. \tag{\mathbb{B}.18}$$

From this, we can see that the result of *A* × *B* = *C* = *D* = *B* × *A*, or in other words, that matrix multiplication is not **commutative**.

#### **Transposition**

There also exists operations on a single matrix. For this textbook, the only one that is important to cover is matrix transposition. The operation of the matrix **transpose** simply turns the rows into columns and the columns into rows. Mathematically, the transpose is represented by *AT* and can be represented using the index notation for a matrix *A* as

$$A^T = (a\_{l,j})^T = a\_{j,l}.\tag{\mathbb{B}.19}$$

For example, given the matrix

$$A = \begin{pmatrix} 9 \ 7 \ 2 \ 6 \\ 9 \ 3 \ 4 \ 4 \\ 2 \ 8 \ 8 \ 4 \end{pmatrix},$$

the transpose of *A* is given as:

$$A^T = \begin{pmatrix} 9 \ 9 \ 2 \\ 7 \ 3 \ 8 \\ 2 \ 4 \ 8 \\ 6 \ 4 \ 4 \end{pmatrix}.$$

Note that this changes a *m* × *n* matrix into a *n* × *m* matrix.

#### **B.3 Key Word Review**

#### **B.4 Check Your Understanding**

1. Find the dot product of the following two vectors:

$$
\begin{pmatrix} 1 \\ 4 \\ 3 \end{pmatrix} \quad \begin{pmatrix} -3 \\ 2 \\ s \end{pmatrix}
$$

2. Find the cross product of *v*1 × *v*2:

$$v\_1 = \begin{pmatrix} 1 \\ 10 \\ 7 \end{pmatrix} \quad v\_2 = \begin{pmatrix} 2 \\ 2 \\ 8 \end{pmatrix}$$

3. Perform the matrix operation *σ*1 × *σ*2:

$$
\sigma\_1 = \begin{pmatrix} 0 \ 1 \\ 1 \ 0 \end{pmatrix} \quad \sigma\_2 = \begin{pmatrix} 0 \ -i \\ i \ 0 \end{pmatrix}.
$$

4. Transpose the following matrix:

$$
\begin{pmatrix} 1 & -2 \ 4 \\ 5 & 3 \ 8 \\ 1 & 9 & 0 \end{pmatrix}
$$

### **Answers to Odds**

#### **Chapter 1 Solutions**

	- (b) time is continuous
	- (c) space is continuous
	- (d) quantized to \$0*.*01
	- (e) continuous because the frequency of light (which causes color) is continuous

#### **Chapter 2 Solutions**

	- (b) No, 1*/*9 + 4*/*9 = 1. Normalization means the total probabilities add up to 1.
	- (c) 75 coins.
	- (d) Measurement collapses the superposition onto either |*H* or |*T* .
	- (b) After measurement, the state in the question is in |0, since the superposition collapsed. Since it is in the |0 state after measurement, if you try to measure the same state again you will always measure |0. No new information is provided about the state after the collapse to |0.
	- (c) If |0 is measured from the unknown state, and a second identical state is prepared and is measured in the |1 state, then you know the unknown state contains some nonzero superposition of both |0 and |1, e.g., it is |*ψ* = *α*|0 + *β*|1 with *α* = 0 and *β* = 0. So you can rule out |*ψ*=|0 as the initial state, but all of the other three states given in (a) are still possible.

Measurements of many more particles are needed to determine the numerical values of *α* and *β* in order to find the exact state.

$$
\begin{pmatrix} 0 \\ 1 \end{pmatrix}, \text{ which is the } |1\rangle \text{ state.}
$$

$$
\begin{array}{l}
7. \begin{pmatrix} 1 \\ 0 \end{pmatrix}, \text{ which is the } |0\rangle \text{ state.} \\
9. \end{array}
$$

$$Y^\dagger = \begin{pmatrix} 0 \ -i \\ i \ 0 \end{pmatrix}. \tag{1}$$

11. Take |*ψ*=|0. The probability of measuring |*ψ* in the |0 state is 100%, and the probability of measuring |*ψ* in the |1 state is 0%. Here the probabilities add up to 100%. Now take any random non-unitary matrix, for example,

$$N = \begin{pmatrix} 0 \ 1 \\ 0 \ 0 \end{pmatrix}. \tag{2}$$

Applying this non-unitary matrix to |*ψ* gives the state

$$N|\psi\rangle = \begin{pmatrix} 0 \ 1 \\ 0 \ 0 \end{pmatrix} \begin{pmatrix} 1 \\ 0 \end{pmatrix} = \begin{pmatrix} 0 \\ 0 \end{pmatrix} = 0|0\rangle + 0|1\rangle. \tag{3}$$

This new state after non-unitary evolution has 0% probability of being in the |0 state, and 0% probability of being in the |1 state. The total probability does **not** add up to 100%.

#### **Chapter 3 Solutions**

	- b. Photons from different 0.4μs bursts can arrive at the detectors simultaneously.

$$
\sqrt{\frac{3}{10}}|0\rangle + \sqrt{\frac{7}{10}}|1\rangle. \tag{4}
$$

The desired beam splitter matrix *M* should perform the operation:

$$M\begin{pmatrix} 0\\1 \end{pmatrix} = \begin{pmatrix} \sqrt{\frac{3}{10}}\\\sqrt{\frac{7}{10}} \end{pmatrix} \implies M = \begin{pmatrix} 1\sqrt{\frac{3}{10}}\\1\sqrt{\frac{7}{10}} \end{pmatrix} \tag{5}$$

would give the correct probabilities, but it is not unitary. And all quantum matrices must be unitary. Using the 50/50 beamsplitter as a reference, the unitary 30*/*70 beam splitter matrix is

$$M = \begin{pmatrix} \sqrt{\frac{7}{10}} \sqrt{\frac{3}{10}} \\ -\sqrt{\frac{3}{10}} \sqrt{\frac{7}{10}} \end{pmatrix} . \tag{6}$$

#### **Chapter 4 Solutions**

(c) sin*(π/*6 + *π/*4*)*|+ + cos*(π/*6 + *π/*4*)*|−

$$\text{(d)}\ \cos^2(\pi/6 + \pi/4) \approx 0.067$$

#### **Chapter 5 Solutions**

	- (a) Alice sends +*z*, Eve measures in *z*, Bob measures +*z*. -

Therefore there is a 4*/*6 probability that Eve has not been detected.

7. Copy the state of each electron, passing the originals along to Bob. Once the correct basis is revealed publicly, pass your cloned electrons through SGAs oriented in the correct revealed basis and get the key.

#### **Chapter 6 Solutions**

1. (a)

$$X|0\rangle = \begin{pmatrix} 0 \ 1 \\ 1 \ 0 \end{pmatrix} \begin{pmatrix} 1 \\ 0 \end{pmatrix} = \begin{pmatrix} 0 \\ 1 \end{pmatrix} = |1\rangle. \tag{7}$$

(b)

$$X|\psi\rangle = \begin{pmatrix} 0 \ 1 \\ 1 \ 0 \end{pmatrix} \begin{pmatrix} \alpha \\ \beta \end{pmatrix} = \begin{pmatrix} \beta \\ \alpha \end{pmatrix} = \beta|0\rangle + \alpha|1\rangle. \tag{8}$$

$$H|1\rangle = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1\\ 1 & -1 \end{pmatrix} \begin{pmatrix} 0\\ 1 \end{pmatrix} = \frac{1}{\sqrt{2}} \begin{pmatrix} 1\\ -1 \end{pmatrix} = |-\rangle. \tag{9}$$

(b)

$$HH|1\rangle = \frac{1}{2} \begin{pmatrix} 1 & 1\\ 1 & -1 \end{pmatrix} \begin{pmatrix} 1\\ -1 \end{pmatrix} = \begin{pmatrix} 0\\ 1 \end{pmatrix} = |1\rangle. \tag{10}$$

(c)

$$HH|\psi\rangle = \frac{1}{2} \begin{pmatrix} 1 & 1\\ 1 & -1 \end{pmatrix} \begin{pmatrix} 1 & 1\\ 1 & -1 \end{pmatrix} \begin{pmatrix} \alpha\\ \beta \end{pmatrix} = \begin{pmatrix} \alpha\\ \beta \end{pmatrix}.\tag{11}$$

9.

$$|Z| + \rangle = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix} \begin{pmatrix} 1 \\ 1 \end{pmatrix} = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 \\ -1 \end{pmatrix} = |-\rangle. \tag{12}$$

	- (b) The sign on the |1 state is changed, but this does not affect probabilities and so cannot be seen in the histogram.
	- (c) The |+ is changed to a |−, which shows up as 50% |0 and |1.
	- (d) The |− is changed to a |+, which shows up as 50% |0 and |1.

13.

$$H^\dagger H = \frac{1}{2} \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix} \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix} = \frac{1}{2} \begin{pmatrix} 2 \ 0 \\ 0 \ 2 \end{pmatrix} = \begin{pmatrix} 1 \ 0 \\ 0 \ 1 \end{pmatrix}.\tag{13}$$

Performing the Hadamard operation twice is the same as multiplying by the identity matrix. Thus, the qubit is unchanged.

#### **Chapter 7 Solutions**

1. (a) The probability of measuring |00 is

$$\text{Prob}(|00\rangle) = \left(\frac{1}{\sqrt{2}}\right)^2. \tag{14}$$

We get this by taking the coefficient of the |00 term and then squaring it.

(b) The probability of measuring the first qubit as 1, Prob*(*first qubit |1*)*, is the sum of all outcomes which have the first qubit in the |1 state. In this example, this is Prob*(*first qubit |1*)* = Prob*(*|10*)* + Prob*(*|11*)*, which is equal to

$$
\left(\frac{1}{2}\right)^2 + \left(-\frac{1}{2}\right)^2 = \frac{1}{2}.\tag{15}
$$

(c) The probability of measuring the second qubit as 0, Prob*(*second qubit |0*)*, is the sum of all outcomes which have the second qubit in the |0 state. In this example, this is Prob*(*second qubit |0*)* = Prob*(*|00*)* + Prob*(*|10*)*, which is equal to

$$\frac{1}{2} + \frac{1}{4} = \frac{3}{4}.\tag{16}$$

	- (b) |11
	- (c) |01
	- (d) √ 1 2 |11 + √ 1 2 |10

$$\text{(e)}\ \frac{1}{\sqrt{2}}|00\rangle + \frac{1}{2}|10\rangle - \frac{1}{2}|01\rangle$$

	- (a) |01
	- (b) |10
	- (c) |11
	- (d) |01
	- (b) |00→|0*(* √ 1 2 |0 + √ 1 2 |1*)* → √ 1 2 *(*|00+|11*)* → √ 1 2 |0*(* √ 1 2 |0 + √ 1 2 |1*)* + √ 1 2 |1*(* √ 1 2 |0 − √ 1 2 |1*)* = 1 2 *(*|00+|01+|10−|11*)*.

#### **Chapter 8 Solutions**

#### **Chapter 9 Solutions**

	- (b) Both the classical and quantum computer can represent 28 = 256 classical pieces of information.
	- (c) The quantum computer can create a superposition of up to 256 possibilities and do a computation on all of them. However, a measurement will be only one classical value.
	- (b) Detector 2 only
	- (c) Only one photon is needed.
	- (b) Since there are results other than |000 and |111, the function is not constant (Fig. 1).

**Fig. 1** Reprint courtesy of International Business Machines Corporation, © International Business Machines Corporation.

#### **Chapter 10 Solutions**

#### **10.1**

(b) Yes. Every time Alice measures up, Bob measures down and vice versa.

5. They each see up and down 50% of the time

7.

$$|\uparrow\downarrow\rangle = \frac{1}{\sqrt{2}}\left( |+\rangle + |-\rangle \right) \times \frac{1}{\sqrt{2}}\left( |+\rangle - |-\rangle \right) = \frac{1}{2}|++\rangle - \frac{1}{2}|+ -\rangle + \frac{1}{2}|--\rangle - \frac{1}{2}|--\rangle.$$

All four possible states are observed. The middle two terms do not cancel out because they are different states: Alice measures + and Bob measures −, or Alice measures − and Bob measures +.

9. They cannot tell them apart in the *z*-basis, but they could measure the particles in the *x*-basis. If Alice and Bob always get opposite results, the source emits entangled particles. If there is no correlation, the particles are not entangled.

#### **10.4**

**Fig. 2** Reprint courtesy of International Business Machines Corporation, © International Business Machines Corporation.

#### 9. 50% chance of alive and 50% chance of very dead

**Fig. 3** Reprint courtesy of International Business Machines Corporation, © International Business Machines Corporation

#### **10.5**

$$\frac{1}{\sqrt{2}}\left(|0\rangle+|1\rangle\right) = \frac{1}{\sqrt{2}}\left(\frac{1}{\sqrt{2}}|+\rangle+\frac{1}{\sqrt{2}}|-\rangle+\frac{1}{\sqrt{2}}|+\rangle-\frac{1}{\sqrt{2}}|-\rangle\right) = |+\rangle,$$

so only +*x* will be measured. Whereas in a mix of |0 = √ 1 2 |+ + √ 1 2 |− and |1 = √ 1 2 |+ − √ 1 2 |−, both +*x* and -*x* will be measured with 50/50 probability.

$$|\alpha|0\rangle + \beta|1\rangle = \frac{1}{\sqrt{5}} \left(\frac{1}{\sqrt{2}}|-\rangle\right) + \frac{2}{\sqrt{5}} \left(\frac{1}{\sqrt{2}}|+\rangle - \frac{1}{\sqrt{2}}|-\rangle\right) = \frac{3}{\sqrt{10}}|+\rangle - \frac{1}{\sqrt{10}}|-\rangle,$$

By squaring the amplitudes, we find 90% probability of +*x* and 10% probability of -*x*.

#### **10.6**

#### **Appendix A Solutions**

#### **A.2**

	- (b) Sum to greater than 8: 10 36 = 5 18 Sum to less than 8: 21 36 = 7 12
	- (c) Both even: 9 36 = 1 4 Both odd: 9 36 = 1 4 One even, one odd: 18 36 = 1 2

#### **A.4**

1. Mean = 76.233 Median = 73.5 Mode = 72

#### **A.5**

1. Variance = 140.25 Standard deviation = 11.843

#### **Appendix B Solutions**

$$\begin{array}{l} \text{1. } 1 \times (-3) + 4 \times 2 + 3 \times 5 = 18\\ \text{3. } \begin{pmatrix} i & 0\\ 0 & -i \end{pmatrix} \end{array}$$

### **Index**

#### **A**

Algorithm, 81 Amplitudes, 8

#### **B**

BB84, 43 Beam splitter, 17 Bell state, 59, 75 Bloch sphere, 11 Bra-Ket notation, 7

#### **C**

Classical superposition, 2 CNOT gate, 65, 75 Cryptography, 42

#### **D**

Decoherence, 91 Deutsch-Jozsa algorithm, 84

#### **E**

Eavesdropper, 45 Electron, 29 Encryption, 41 Entanglement, 59 Error correction, 73

**G** Grover's algorithm, 81

#### **H**

Hadamard gate, 52, 76 Hidden variable theory, 61 Histogram, 52

**I** IBMQ, 66 Interference, 85

**L**

Logic gate, 49

#### **M**

Mach-Zehnder interferometer, 21 Matrix representation, 10 Measurement, 4, 9, 35, 50 Measurement basis, 31 Measurement collapse, 52 Measurement error, 51 Memory, 83 Modular arithmetic, 88 Multi-qubit state, 61, 75

#### **N**

No-cloning theorem, 36, 52, 78 Noise, 51, 90 Normalization, 8 NOT gate, 50

#### **O**

Orthogonal, 33

#### **P**

Parallelism, 67, 81 Photon, 18 Product state, 63

**Q** Quantized, 2

© The Author(s) 2021 C. Hughes et al., *Quantum Computing for the Quantum Curious*, https://doi.org/10.1007/978-3-030-61601-4

149

Quantum circuit, 50 Quantum computer, 20 , 37 Quantum gate, 49 Quantum key distribution, 43 Quantum superposition, 2 , 17 Qubit, 7

#### **R**

RSA encryption, 42

#### **S**

Schrödinger's cat, 4 , 12 Shor's algorithm, 43 Spin, 29 State, 3

Stern-Gerlach apparatus, 29 Superposition, 1

#### **T** Teleportation, 73

**U** Unitary, 10 , 55 , 73

**W** Wave-particle duality, 18

#### **Z**

*Z* gate, 55


**Md Rezaur Rahman**

Faculty of Engineering, Department of Chemical Engineering and Energy Sustainability, University Malaysia Sarawak, Kota Samarahan, Malaysia

**1**

Section 1

State-of-Art Nanotechnology

Section 1