Skip to content
ImagineWorld

The Matrix

node_idnode-book_essential-mathematics-for-quantum-computing_chapter-02-the-matrix
node_typechapter_node
schema_profileworld.chapter_node.v1
entropyhigh
manifoldworld
domainimagineworld.net
authorityinforms
layercorpus
statusactive
chapter_num2
chapter_titleThe Matrix
governed_byCORPUS
constitutional_citationCONSTITUTION
local graph

In the famous movie, The Matrix, Morpheus says, “The Matrix is everywhere. It is all around us. Even now, in this very room.” Morpheus was not far off the mark, for there is a theory in physics called the matrix string theory where essentially, reality is governed by a set of matrices. But while a matrix is one entity in the movie, a matrix in physics is a concept that is used again and again to model reality.

Figure 2.1 – Text rendering inspired by the GLmatrix program by Jamie Zawinski

As you will see, the definition of a matrix is deceptively simple, but its power derives from all the ways mathematicians have defined that it can be used. It is a central object in quantum mechanics and, hence, quantum computing. Indeed, if I were forced to select the most important mathematical tool in quantum computing, it would be a matrix.

In this chapter, we are going to cover the following main topics:

  • Defining a matrix
  • Simple matrix operations
  • Defining matrix multiplication
  • Special types of matrices
  • Quantum gates

Mathematicians define a matrix as simply a rectangular array that has m rows and n columns, like the one shown in the following diagram:

Figure 2.2 – Model of a matrix with m rows and n columns

In math, matrices are written out a particular way. An example 4 × 5 matrix is shown in the following expression. Notice that it has four rows and five columns:

Figure 2.3 – Example of a 4 x 5 matrix

In math and quantum computing, matrix variable names are in capital letters, and each entry in a matrix is referred to by a lowercase letter that corresponds to the variable name with subscripts (aij). Subscript i refers to the row the entry is in and subscript j refers to the column it is in. The following formula shows this for a 3 × 3 matrix:

A=[a11a12a13a21a22a23a31a32a33]=[543217890]A = \begin{bmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{bmatrix} = \begin{bmatrix} 5 & 4 & 3 \\ 2 & 1 & 7 \\ 8 & 9 & 0 \end{bmatrix}

In our example matrix A, a22 = 1. What is a32? Hint—it’s the only number that begins with the letter n.

One thing we will do in this book is iteratively define things so that we start simple, and as we learn more, we will add or even redefine objects to make them more advanced. So, in our previous chapter, our Euclidean vectors only had two dimensions. What if they have more? Well, we can represent them with n × 1 matrices, like so:

[a1a2⋮an]\begin{bmatrix} a_1 \\ a_2 \\ \vdots \\ a_n \end{bmatrix}

What do we call a 1 × n matrix such as the following one?

[a1a2⋯an]\begin{bmatrix} a_1 & a_2 & \cdots & a_n \end{bmatrix}

Well, we will call it a row vector. To distinguish between the two types, we will call the n × 1 matrix a column vector. Also, while we have been using kets (for example, |x⟩) to notate column vectors so far, we will use something different to notate row vectors. We will introduce the bra, which is the other side of the bra-ket notation. A bra is denoted by an opening angle bracket, the name of the vector, and a pipe or vertical bar. For example, a row vector with the name b would be denoted like this: ⟨b|. This is the other side of the bra-ket notation explained further in the appendix. To make things clearer, here are our definitions of a column vector and a row vector for now:

column vector:=∣x⟩=[a1a2⋮an]\text{column vector} := |x\rangle = \begin{bmatrix} a_1 \\ a_2 \\ \vdots \\ a_n \end{bmatrix} row vector:=⟨y∣=[a1a2⋯an]\text{row vector} := \langle y| = \begin{bmatrix} a_1 & a_2 & \cdots & a_n \end{bmatrix}

Important Note

A bra has a deeper definition that we will look at later in this book. For now, this is enough for us to tackle matrix multiplication.

Now that we have introduced how column and row vectors can be represented by one-dimensional (1D) matrices, let’s next look at some operations we can do on matrices.

As mentioned in the introduction to this chapter, the power of matrices is the operations defined on them. Here, we go through some of the basic operations for matrices that we will build on as the book progresses. You have already encountered some of these operations with vectors in the previous chapter, but we will now expand them to matrices.

Addition is one of the easiest operations, along with its inverse subtraction. You basically just perform addition on each entry of one matrix that corresponds with another entry in the other matrix, as shown in the following formula. Addition is only defined for matrices with the same dimensions:

A+B=[a11a12a13a21a22a23a31a32a33]+[b11b12b13b21b22b23b31b32b33]=[a11+b11a12+b12a13+b13a21+b21a22+b22a23+b23a31+b31a32+b32a33+b33]A + B = \begin{bmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{bmatrix} + \begin{bmatrix} b_{11} & b_{12} & b_{13} \\ b_{21} & b_{22} & b_{23} \\ b_{31} & b_{32} & b_{33} \end{bmatrix} = \begin{bmatrix} a_{11}+b_{11} & a_{12}+b_{12} & a_{13}+b_{13} \\ a_{21}+b_{21} & a_{22}+b_{22} & a_{23}+b_{23} \\ a_{31}+b_{31} & a_{32}+b_{32} & a_{33}+b_{33} \end{bmatrix}

Here is an example of matrix addition:

[2345]+[530−1]=[2+53+34+05−1]=[7644]\begin{bmatrix} 2 & 3 \\ 4 & 5 \end{bmatrix} + \begin{bmatrix} 5 & 3 \\ 0 & -1 \end{bmatrix} = \begin{bmatrix} 2+5 & 3+3 \\ 4+0 & 5-1 \end{bmatrix} = \begin{bmatrix} 7 & 6 \\ 4 & 4 \end{bmatrix}

What is the sum of the following two matrices? (Answers to exercises are at the end of the chapter.)

[1234]+[2102]\begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} + \begin{bmatrix} 2 & 1 \\ 0 & 2 \end{bmatrix}

Scalar multiplication is also rather easy. A scalar is just a number, and so scalar multiplication is just multiplying a matrix by a number. We define it for a scalar b and matrix A thusly:

b⋅A=bA=b⋅[a11a12⋯a1na21a22⋯a2n⋮⋮⋱⋮am1am2⋯amn]=[b⋅a11b⋅a12⋯b⋅a1nb⋅a21b⋅a22⋯b⋅a2n⋮⋮⋱⋮b⋅am1b⋅am2⋯b⋅amn]b \cdot A = bA = b \cdot \begin{bmatrix} a_{11} & a_{12} & \cdots & a_{1n} \\ a_{21} & a_{22} & \cdots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m1} & a_{m2} & \cdots & a_{mn} \end{bmatrix} = \begin{bmatrix} b \cdot a_{11} & b \cdot a_{12} & \cdots & b \cdot a_{1n} \\ b \cdot a_{21} & b \cdot a_{22} & \cdots & b \cdot a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ b \cdot a_{m1} & b \cdot a_{m2} & \cdots & b \cdot a_{mn} \end{bmatrix}

As always, an example can definitely help:

3⋅[472−3]=[3⋅43⋅73⋅23⋅−3]=[12216−9]3 \cdot \begin{bmatrix} 4 & 7 \\ 2 & -3 \end{bmatrix} = \begin{bmatrix} 3 \cdot 4 & 3 \cdot 7 \\ 3 \cdot 2 & 3 \cdot -3 \end{bmatrix} = \begin{bmatrix} 12 & 21 \\ 6 & -9 \end{bmatrix}

Calculate the following:

3[3421]3 \begin{bmatrix} 3 & 4 \\ 2 & 1 \end{bmatrix}

An important operation involving matrices and vectors is to transpose them. To transpose a matrix, you essentially convert the rows into columns and the columns into rows. It is denoted by a superscript T. Here is the definition:

If A=[a11a12⋯a1na21a22⋯a2n⋮⋮⋱⋮am1am2⋯amn], then AT=[a11a21⋯am1a12a22⋯am2⋮⋮⋱⋮a1na2n⋯amn]\text{If } A = \begin{bmatrix} a_{11} & a_{12} & \cdots & a_{1n} \\ a_{21} & a_{22} & \cdots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m1} & a_{m2} & \cdots & a_{mn} \end{bmatrix}, \text{ then } A^T = \begin{bmatrix} a_{11} & a_{21} & \cdots & a_{m1} \\ a_{12} & a_{22} & \cdots & a_{m2} \\ \vdots & \vdots & \ddots & \vdots \\ a_{1n} & a_{2n} & \cdots & a_{mn} \end{bmatrix}

Notice how the subscripts for the diagonal entries stay the same, but the subscripts for all other entries are switched (for example, the entry at a12 becomes a21). Also, as a consequence of this operation, the dimensions of the matrix are switched. A 2 × 4 matrix becomes a 4 × 2 matrix.

Here is an example of a 3 × 4 matrix transposed:

[123456789012]T=[159260371482]\begin{bmatrix} 1 & 2 & 3 & 4 \\ 5 & 6 & 7 & 8 \\ 9 & 0 & 1 & 2 \end{bmatrix}^T = \begin{bmatrix} 1 & 5 & 9 \\ 2 & 6 & 0 \\ 3 & 7 & 1 \\ 4 & 8 & 2 \end{bmatrix}

Here is an example of a square matrix transposed:

[3520]T=[3250]\begin{bmatrix} 3 & 5 \\ 2 & 0 \end{bmatrix}^T = \begin{bmatrix} 3 & 2 \\ 5 & 0 \end{bmatrix}

Now, let’s move on to matrix multiplication.

Matrix multiplication can be a complicated procedure, and we will build up to it gradually. It is defined as an operation between an m × n matrix and an n × p matrix that produces an m × p matrix. The following diagram shows this well:

Figure 2.4 – Schematic of matrix multiplication

Notice that matrix multiplication is only defined if the number of columns in the first matrix equals the number of rows in the second matrix—or, in other words, the ns have to match in our preceding figure. This is so important that we will give it a special name: the matrix multiplication definition rule, or definition rule for short. Based on this, the first thing you should do when presented with two matrices to multiply is to make sure they pass the definition rule. Otherwise, the operation is undefined. For example, do the following two matrices pass the definition rule?

[abcd]⋅[cdzefxghy]\begin{bmatrix} a & b \\ c & d \end{bmatrix} \cdot \begin{bmatrix} c & d & z \\ e & f & x \\ g & h & y \end{bmatrix}

The answer is no because you have a 2 × 2 matrix being multiplied by a 3 × 3 matrix. The number of columns of the first matrix does not equal the number of rows of the second matrix. What about the following matrix multiplication?

[abecdf]⋅[cdghik]\begin{bmatrix} a & b & e \\ c & d & f \end{bmatrix} \cdot \begin{bmatrix} c & d \\ g & h \\ i & k \end{bmatrix}

(1)

Yes, it is defined! It is a 2 × 3 matrix multiplied by a 3 × 2 matrix. The number of columns in the first equals the number of rows in the second!

If the matrices pass the definition rule, the second step you should take when multiplying two matrices is to draw out the answer’s dimensions. For instance, when presented with the preceding matrix multiplication from Equation (1) of a 2 × 3 matrix and a 3 × 2 matrix, we would draw out a 2 × 2 matrix, like so. I like to write the dimensions of each matrix on the top:

Figure 2.5 – Writing dimensions of matrix multiplication

Remember—the number of rows in the first matrix determines the number in rows of the product or resultant matrix. The number of columns in the second matrix determines the number of columns in the product.

Okay—to summarize, here are the first two steps you should take when doing matrix multiplication:

  1. Does it pass the definition rule? Do the number of columns in the first matrix equal the number of rows in the second matrix?
  2. Draw out the dimensions of the product matrix. For an m × n matrix and an n × p matrix, the dimensions of the resulting matrix will be m × p.

Based on all of this, do you think matrix multiplication is commutative (that is, A ⋅ B = B ⋅ A)? Think about it—I’ll give you the answer later in this chapter. Now, let’s look at how to multiply two vectors to produce a scalar.

Earlier, we defined column and row vectors as one-dimensional matrices. Since they are one-dimensional, they are the easiest matrices to multiply. A bracket, denoted by ⟨x|y⟩, is essentially matrix multiplication of a row vector and a column vector. Here is our definition:

⟨x∣y⟩=[x1x2⋯xn][y1y2⋮yn]=x1⋅y1+x2⋅y2+⋯+xn⋅yn\langle x|y\rangle = \begin{bmatrix} x_1 & x_2 & \cdots & x_n \end{bmatrix} \begin{bmatrix} y_1 \\ y_2 \\ \vdots \\ y_n \end{bmatrix} = x_1 \cdot y_1 + x_2 \cdot y_2 + \cdots + x_n \cdot y_n

Important Note

A bracket has a deeper definition that we will look at later in this book. For now, this is enough for us to tackle matrix multiplication.

Let’s look at an example to make this more concrete.

Let’s say ⟨y| and |x⟩ are defined this way:

⟨y∣=[3214]∣x⟩=[1234]\langle y| = \begin{bmatrix} 3 & 2 & 1 & 4 \end{bmatrix} \qquad |x\rangle = \begin{bmatrix} 1 \\ 2 \\ 3 \\ 4 \end{bmatrix}

Now, let’s calculate the bracket ⟨y| x⟩:

⟨y∣x⟩=[3214]⋅[1234]={3⋅1+2⋅2+1⋅3+4⋅43+4+3+1626\langle y|x\rangle = \begin{bmatrix} 3 & 2 & 1 & 4 \end{bmatrix} \cdot \begin{bmatrix} 1 \\ 2 \\ 3 \\ 4 \end{bmatrix} = \begin{cases} 3 \cdot 1 + 2 \cdot 2 + 1 \cdot 3 + 4 \cdot 4 \\ 3 + 4 + 3 + 16 \\ 26 \end{cases}

Here are two more examples of matrix multiplication of a row vector with a column vector:

[32][41]=3⋅4+2⋅1=12+2=14\begin{bmatrix} 3 & 2 \end{bmatrix} \begin{bmatrix} 4 \\ 1 \end{bmatrix} = 3 \cdot 4 + 2 \cdot 1 = 12 + 2 = 14 [123][456]=1⋅4+2⋅5+3⋅6=4+10+18=32\begin{bmatrix} 1 & 2 & 3 \end{bmatrix} \begin{bmatrix} 4 \\ 5 \\ 6 \end{bmatrix} = 1 \cdot 4 + 2 \cdot 5 + 3 \cdot 6 = 4 + 10 + 18 = 32

What is the answer to the matrix multiplication of this row vector and column vector?

[123][123]\begin{bmatrix} 1 & 2 & 3 \end{bmatrix} \begin{bmatrix} 1 \\ 2 \\ 3 \end{bmatrix}

We are building up to pure matrix multiplication, and the next step to getting there is matrix-vector multiplication. Let’s look at a typical expression for matrix-vector multiplication:

[213445]⋅[23]\begin{bmatrix} 2 & 1 \\ 3 & 4 \\ 4 & 5 \end{bmatrix} \cdot \begin{bmatrix} 2 \\ 3 \end{bmatrix}

Now, this is a 3 × 2 matrix multiplied by a 2 × 1 column vector. Does this pass the matrix multiplication rule? Yes! 2=2. What are the dimensions of the product? Well, taking the outer dimensions of the two matrices involved in the product, it will be a 3 × 1 column vector. If the matrix and column vector are variables, we can write out the product this way:

A∣x⟩A|x\rangle

(2)

This denotes the matrix A multiplying the vector |x⟩.

Alright—how do we actually do the multiplication? Well, first, we separate the rows of the matrix into row vectors. Wait—there are vectors in matrices?! Yes—you can see a matrix as a set of row vectors or column vectors when it is convenient to do so. Let’s look at an example of doing this:

[432413242]⇒[432]=⟨R1∣[413]=⟨R2∣[242]=⟨R3∣\begin{bmatrix} 4 & 3 & 2 \\ 4 & 1 & 3 \\ 2 & 4 & 2 \end{bmatrix} \Rightarrow \begin{bmatrix} 4 & 3 & 2 \end{bmatrix} = \langle R_1| \qquad \begin{bmatrix} 4 & 1 & 3 \end{bmatrix} = \langle R_2| \qquad \begin{bmatrix} 2 & 4 & 2 \end{bmatrix} = \langle R_3|

(3)

See how I separated the three rows of the matrix into three row vectors? I even gave them names, with the letter R standing for row and the subscript number showing which row it came from. So, after performing the first two steps of matrix multiplication, the next step is:

  1. Separate the matrix on the left into row vectors, ⟨R1|, ⟨R2|, … , ⟨Rm|.

From there, we will calculate the bracket between each row vector from the separated matrix and the column vector we are multiplying by. Let’s see an example.

Let’s say we are trying to find the answer to the matrix-vector multiplication between matrix A and vector |x⟩ as in Equation (2) and matrix A is the one defined in Equation (3). We will create a simple vector |x⟩ to give us:

A∣x⟩=[432413242]⋅[wyz]=[abc]A|x\rangle = \begin{bmatrix} 4 & 3 & 2 \\ 4 & 1 & 3 \\ 2 & 4 & 2 \end{bmatrix} \cdot \begin{bmatrix} w \\ y \\ z \end{bmatrix} = \begin{bmatrix} a \\ b \\ c \end{bmatrix}

Okay—so, how do we figure out what a*,* b, and c are? Let’s calculate the brackets!

a=⟨R1∣x⟩=[432][wyz]=4w+3y+2za = \langle R_1|x\rangle = \begin{bmatrix} 4 & 3 & 2 \end{bmatrix} \begin{bmatrix} w \\ y \\ z \end{bmatrix} = 4w + 3y + 2z b=⟨R2∣x⟩=[413][wyz]=4w+y+3zb = \langle R_2|x\rangle = \begin{bmatrix} 4 & 1 & 3 \end{bmatrix} \begin{bmatrix} w \\ y \\ z \end{bmatrix} = 4w + y + 3z c=⟨R3∣x⟩=[242][wyz]=2w+4y+2zc = \langle R_3|x\rangle = \begin{bmatrix} 2 & 4 & 2 \end{bmatrix} \begin{bmatrix} w \\ y \\ z \end{bmatrix} = 2w + 4y + 2z

Now that we have seen an example, let’s generalize this for the final step of matrix-vector multiplication:

  1. For a matrix-vector multiplication, A|x⟩, compute the bracket for each row in A with the column vector |x⟩. Put the result of the bracket in the corresponding row for the resultant column vector.

So, let’s write this all out for our example:

A=[432413242]⇒[432]=⟨R1∣,[413]=⟨R2∣,[242]=⟨R3∣∣x⟩=[wyz]A = \begin{bmatrix} 4 & 3 & 2 \\ 4 & 1 & 3 \\ 2 & 4 & 2 \end{bmatrix} \Rightarrow \begin{bmatrix} 4 & 3 & 2 \end{bmatrix} = \langle R_1|, \quad \begin{bmatrix} 4 & 1 & 3 \end{bmatrix} = \langle R_2|, \quad \begin{bmatrix} 2 & 4 & 2 \end{bmatrix} = \langle R_3| \qquad |x\rangle = \begin{bmatrix} w \\ y \\ z \end{bmatrix} A∣x⟩=[432413242]⋅[wyz]=[⟨R1∣x⟩⟨R2∣x⟩⟨R3∣x⟩]A|x\rangle = \begin{bmatrix} 4 & 3 & 2 \\ 4 & 1 & 3 \\ 2 & 4 & 2 \end{bmatrix} \cdot \begin{bmatrix} w \\ y \\ z \end{bmatrix} = \begin{bmatrix} \langle R_1|x\rangle \\ \langle R_2|x\rangle \\ \langle R_3|x\rangle \end{bmatrix}

Now, let’s put this all together for a proper definition of matrix-vector multiplication.

Given an m × n matrix A and an n × 1 vector |x⟩, where A is made up of m row vectors, like so:

A=[⟨R1∣⟨R2∣⋮⟨Rm∣]A = \begin{bmatrix} \langle R_1| \\ \langle R_2| \\ \vdots \\ \langle R_m| \end{bmatrix}

Matrix-vector multiplication is defined as:

A∣x⟩=∣y⟩=[⟨R1∣x⟩⟨R2∣x⟩⋮⟨Rm∣x⟩]A|x\rangle = |y\rangle = \begin{bmatrix} \langle R_1|x\rangle \\ \langle R_2|x\rangle \\ \vdots \\ \langle R_m|x\rangle \end{bmatrix}

Now, let’s apply this to an example with real numbers:

[213445]⋅[23]=[[21][23][34][23][45][23]]=[2⋅2+3⋅13⋅2+4⋅34⋅2+5⋅3]=[71823]\begin{bmatrix} 2 & 1 \\ 3 & 4 \\ 4 & 5 \end{bmatrix} \cdot \begin{bmatrix} 2 \\ 3 \end{bmatrix} = \begin{bmatrix} \begin{bmatrix} 2 & 1 \end{bmatrix}\begin{bmatrix} 2 \\ 3 \end{bmatrix} \\ \begin{bmatrix} 3 & 4 \end{bmatrix}\begin{bmatrix} 2 \\ 3 \end{bmatrix} \\ \begin{bmatrix} 4 & 5 \end{bmatrix}\begin{bmatrix} 2 \\ 3 \end{bmatrix} \end{bmatrix} = \begin{bmatrix} 2 \cdot 2 + 3 \cdot 1 \\ 3 \cdot 2 + 4 \cdot 3 \\ 4 \cdot 2 + 5 \cdot 3 \end{bmatrix} = \begin{bmatrix} 7 \\ 18 \\ 23 \end{bmatrix}

Now, it’s your turn to do matrix-vector multiplication.

If you have matrices A*,* B, and C defined as so:

A=[123456]B=[1234]C=[123456]A = \begin{bmatrix} 1 & 2 \\ 3 & 4 \\ 5 & 6 \end{bmatrix} \qquad B = \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} \qquad C = \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{bmatrix}

and three vectors defined as so:

∣x⟩=[0−1−2]∣y⟩=[1−1]∣z⟩=[22]|x\rangle = \begin{bmatrix} 0 \\ -1 \\ -2 \end{bmatrix} \qquad |y\rangle = \begin{bmatrix} 1 \\ -1 \end{bmatrix} \qquad |z\rangle = \begin{bmatrix} 2 \\ 2 \end{bmatrix}

what are the following matrix-vector products? If the operation is undefined, say so.

A∣x⟩C∣x⟩A∣y⟩B∣z⟩A|x\rangle \qquad C|x\rangle \qquad A|y\rangle \qquad B|z\rangle

Alright—we have finally arrived at matrix multiplication! Trust me, it is worth the wait because matrix multiplication is used all over quantum computing and you now have the basis to do the calculations correctly and succinctly.

Remember in the previous section that I said you could view a matrix as a set of row vectors? Well, it ends up you can view them as set of column vectors as well. Let’s take our matrix from before and repurpose it to see matrices as a set of column vectors:

[432413242]⇒[442]=∣C1⟩,[314]=∣C2⟩,[232]=∣C3⟩\begin{bmatrix} 4 & 3 & 2 \\ 4 & 1 & 3 \\ 2 & 4 & 2 \end{bmatrix} \Rightarrow \begin{bmatrix} 4 \\ 4 \\ 2 \end{bmatrix} = |C_1\rangle, \qquad \begin{bmatrix} 3 \\ 1 \\ 4 \end{bmatrix} = |C_2\rangle, \qquad \begin{bmatrix} 2 \\ 3 \\ 2 \end{bmatrix} = |C_3\rangle

So, this time, I separated the matrix into three column vectors. I gave each one a name with the letter C, standing for column, and the subscript number showing which column it came from.

We will use the first three steps we have defined so far for matrix multiplication as well and replace the fourth step from matrix-vector multiplication. Here are the first four steps of matrix multiplication:

  1. Does it pass the definition rule? Do the number of columns in the first matrix equal the number of rows in the second matrix?
  2. Draw out the dimensions of the product matrix. For an m × n matrix and an n × p matrix, the dimensions of the resulting matrix will be m × p.
  3. Separate the matrix on the left into row vectors, ⟨R1|, ⟨R2|, … , ⟨Rm|.
  4. Separate the matrix on the right into column vectors, |C1⟩, |C2⟩,…,|Cp⟩.

Alright—we have arrived at the last step! Can you guess what it is? Well, it definitely involves brackets. Without further ado, here it is:

  1. For each entry aij in the resultant matrix, compute the bracket of the ith row vector and the jth column vector, ⟨Ri*|*Cj⟩.

If matrix A is the left matrix and matrix B is the right matrix (that is, A ⋅ B), then the following diagram is a good way to look at Step 5 graphically:

Figure 2.6 – Depiction of the matrix product AB [1]

Let’s look at an example.

Say we have the following two matrices:

A=[1234]B=[123456]A = \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} \qquad B = \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{bmatrix}

Let’s go through our five steps.

  1. Does it pass the definition rule? Do the number of columns in the first matrix equal the number of rows in the second matrix?

Yes! A is a 2 × 2 matrix and B is a 2 × 3 matrix. So, the operation is defined.

  1. Draw out the dimensions of the product matrix. For an m × n matrix and an n × p matrix, the dimensions of the resulting matrix will be m × p.
A⋅B=[1234]⏞2×2⋅[123456]⏞2×3=[□□□□□□]⏞2×3A \cdot B = \overbrace{\begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix}}^{2 \times 2} \cdot \overbrace{\begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{bmatrix}}^{2 \times 3} = \overbrace{\begin{bmatrix} \square & \square & \square \\ \square & \square & \square \end{bmatrix}}^{2 \times 3}
  1. Separate the matrix on the left into row vectors, ⟨R1|, ⟨R2|, … , ⟨Rm|.
[1234]⇒[12]=⟨R1∣[34]=⟨R2∣\begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} \Rightarrow \begin{bmatrix} 1 & 2 \end{bmatrix} = \langle R_1| \qquad \begin{bmatrix} 3 & 4 \end{bmatrix} = \langle R_2|
  1. Separate the matrix on the right into column vectors, |C1⟩, |C2⟩,…,|Cp⟩.
[123456]⇒[14]=∣C1⟩[25]=∣C2⟩[36]=∣C3⟩\begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{bmatrix} \Rightarrow \begin{bmatrix} 1 \\ 4 \end{bmatrix} = |C_1\rangle \qquad \begin{bmatrix} 2 \\ 5 \end{bmatrix} = |C_2\rangle \qquad \begin{bmatrix} 3 \\ 6 \end{bmatrix} = |C_3\rangle
  1. For each entry aij in the resultant matrix, compute the bracket of the ith row vector and the jth column vector, ⟨Ri*|*Cj⟩.
A⋅B=[⟨R1∣C1⟩⟨R1∣C2⟩⟨R1∣C3⟩⟨R2∣C1⟩⟨R2∣C2⟩⟨R2∣C3⟩]A \cdot B = \begin{bmatrix} \langle R_1|C_1\rangle & \langle R_1|C_2\rangle & \langle R_1|C_3\rangle \\ \langle R_2|C_1\rangle & \langle R_2|C_2\rangle & \langle R_2|C_3\rangle \end{bmatrix}

So, the computations will look like this:

[1234]⋅[123456]=[[12][14][12][25][12][36][34][14][34][25][34][36]]\begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} \cdot \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{bmatrix} = \begin{bmatrix} \begin{bmatrix} 1 & 2 \end{bmatrix}\begin{bmatrix} 1 \\ 4 \end{bmatrix} & \begin{bmatrix} 1 & 2 \end{bmatrix}\begin{bmatrix} 2 \\ 5 \end{bmatrix} & \begin{bmatrix} 1 & 2 \end{bmatrix}\begin{bmatrix} 3 \\ 6 \end{bmatrix} \\ \begin{bmatrix} 3 & 4 \end{bmatrix}\begin{bmatrix} 1 \\ 4 \end{bmatrix} & \begin{bmatrix} 3 & 4 \end{bmatrix}\begin{bmatrix} 2 \\ 5 \end{bmatrix} & \begin{bmatrix} 3 & 4 \end{bmatrix}\begin{bmatrix} 3 \\ 6 \end{bmatrix} \end{bmatrix} =[1+82+103+123+166+209+24]=[91215192633]= \begin{bmatrix} 1+8 & 2+10 & 3+12 \\ 3+16 & 6+20 & 9+24 \end{bmatrix} = \begin{bmatrix} 9 & 12 & 15 \\ 19 & 26 & 33 \end{bmatrix}

And there’s our answer! That may have taken a while, but it will become quicker and more intuitive as you practice it. Speaking of practice…

Given the following three matrices:

D=[−123052]E=[120−2]F=[104−15−2]D = \begin{bmatrix} -1 & 2 \\ 3 & 0 \\ 5 & 2 \end{bmatrix} \qquad E = \begin{bmatrix} 1 & 2 \\ 0 & -2 \end{bmatrix} \qquad F = \begin{bmatrix} 1 & 0 & 4 \\ -1 & 5 & -2 \end{bmatrix}

what are the following products? Follow the steps! And if the operation is undefined, say so.

D⋅EE⋅FF⋅DD \cdot E \qquad E \cdot F \qquad F \cdot D

It’s good to know some general properties of matrix multiplication. These properties assume that the matrices all have the right dimensions to pass the matrix multiplication definition rule. Here they are—matrix multiplication is:

  • Not commutative: A⋅ B ≠ B⋅ A
  • Distributive with respect to matrix addition:
A(B+C)=AB+AC=(B+C)AA(B+C) = AB + AC = (B+C)A
  • Associative:
(AB)C=A(BC)(AB)C = A(BC)
  • The transpose of a matrix product A ⋅ B is the product of the transpose of each matrix in reverse:
(AB)T=BTAT(AB)^T = B^T A^T

That concludes our section on matrix multiplication. You might want to take a break—you’ve been through a lot! When you come back, we’ll look at some special matrices that are good to know.

In the world of matrices, some are so special that they have been singled out. Here they are.

A special type of matrix is a square matrix. A square matrix is one where the number of rows equals the number of columns. In other words, it is an m × n matrix in which m = n. Square matrices show up all over the place in quantum computing due to special properties that they can have—for example, symmetry, which is discussed later in the book. As we progress in the book, they will become one of the central types of matrices we will use. Some examples of square matrices are:

[2517][388916356][3846292916050754]\begin{bmatrix} 2 & 5 \\ 1 & 7 \end{bmatrix} \qquad \begin{bmatrix} 3 & 8 & 8 \\ 9 & 1 & 6 \\ 3 & 5 & 6 \end{bmatrix} \qquad \begin{bmatrix} 3 & 8 & 4 & 6 \\ 2 & 9 & 2 & 9 \\ 1 & 6 & 0 & 5 \\ 0 & 7 & 5 & 4 \end{bmatrix}

An important type of square matrix is an identity matrix, named I. It is defined so that it acts as the number 1 in matrix multiplication so that the following holds true:

A⋅I=AA \cdot I = A

It has ones all down its principal diagonal and zeros everywhere else. Its dimensions need to change based on the matrix it is being multiplied by. Here are some examples of I in different dimensions:

I1=[1],I2=[1001],I3=[100010001]I_1 = [1], \qquad I_2 = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}, \qquad I_3 = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}

You should multiply some of the matrices we have used before with the identity matrix to convince yourself that it does indeed return the matrix it is multiplied by. Now that we’ve gone over some special matrices, let’s get into why matrix multiplication is important in quantum computing.

In this section, I’d like to take the math you have learned in this chapter around matrices and connect it to actual quantum computing—namely, quantum gates. Please remember that this book is not about teaching you everything in quantum computing, but rather the mathematics needed to do and learn quantum computing. That being said, I want to connect the math to quantum computing and show the motivation for learning it. Do not be frustrated if this does not all make sense, and please consult the reference books in the appendix for more information on quantum gates.

In classical computing, we use logic gates to put together circuits that will implement algorithms, such as, adding two numbers. The logic gates represent Boolean logic. Here are some simple logic operations:

  • AND
  • OR
  • NOT

In a circuit, you have input, output, and logic gates. The input and outputs are represented by a binary number, with 1 being true and 0 being false. Here is an example of a NOT gate:

Figure 2.7 – NOT gate

Truth tables can be created that correspond to the inputs and outputs of the circuit. Here is a truth table for the NOT gate just described:

Figure 2.8 – Truth table for NOT gate

A slightly more complicated circuit involves the AND gate, as shown in the following figure:

Figure 2.9 – AND gate

Here is a truth table for this circuit:

Figure 2.10 – Truth table for AND gate

Much of quantum computing is modeled using quantum circuits that are similar to, but not the same as, the classical circuits we just went through. In quantum circuits, the inputs are qubits (vectors), and the gates are matrices. An example quantum logic gate is shown here:

Figure 2.11 – Quantum circuit with NOT gate

The output qubit is derived through matrix-vector multiplication! So, if we remember from Chapter 2, Superposition with Euclid, qubits are just vectors and the binary states for qubits are:

∣0⟩=[10]and∣1⟩=[01]|0\rangle = \begin{bmatrix} 1 \\ 0 \end{bmatrix} \qquad \text{and} \qquad |1\rangle = \begin{bmatrix} 0 \\ 1 \end{bmatrix}

The NOT gate in quantum computing is represented by the following matrix:

X=[0110]X = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}

So, if our input qubit is a |1⟩, then the output would be:

X∣1⟩=[0110][01]=[10]=∣0⟩X|1\rangle = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix} \begin{bmatrix} 0 \\ 1 \end{bmatrix} = \begin{bmatrix} 1 \\ 0 \end{bmatrix} = |0\rangle

If we did the computation with |0⟩ as the input, the output would be |1⟩. Basically, this is the quantum version of the NOT gate!

There are many quantum gates, but they are all modeled as matrices. Thus, the math you have learned in this chapter is directly applicable to quantum computing!

In this chapter, we have learned a good number of operations on matrices and vectors. We can now do basic computation with them, and we saw their application to quantum computing. Please note that not all matrices can be used as quantum gates. Please keep reading the book to find out which ones can.

In the next chapter, we start to go deeper and look at the foundations of mathematics.