Matrices

Matrices are the mathematical building blocks for quantum bits, quantum gates, and quantum circuits.

This quick review of matrices will prime you to learn what qubits actually represent—including a concrete, non-woo-woo definition of superposition. Let’s get started.

Grid of numbers

A matrix is just a grid of numbers; rows and columns containing values. Matrices can be of any size. Here’s an example of a 3×2 matrix. It is 3 columns wide and 2 rows tall, containing the values 1 through 6.

[ 1 2 3 4 5 6 ]

When describing the dimensions of a matrix we always specify the number of rows first, then the number of columns. The above is an example of a 3×2 matrix, while below is a matrix containing similar data, but in a 2×3 configuration.

[ 1 2 3 4 5 6 ]

Order matters

For our purposes, we’ll express our matrices in row-major order. This means we read the values just as they are ordered above, starting with the top-most row, reading values from left to right, then proceeding to the next row down and repeating that process. Our choice of row-major order makes reading and writing matrix values more akin to reading and writing in English; easier to type and program here.

[ 1 2 3 4 5 6 ]
Row-major order.
[ 1 3 5 2 4 6 ]
Column-major order.

Vectors are slices

While a matrix is a two-dimensional grid of numbers, a vector is more like a slice of numbers—such as a “skinny” matrix that is only one column wide, or a “flat” matrix that is only one row high. Let’s look at some examples of matrices that are simultaneously vectors.

[ 1 2 3 4 ]
Any “flat” matrix is a row vector.
[ 1 2 3 4 ]
Any “skinny” matrix is a column vector.
[ 1 2 3 4 ]
But matrices with more than one column or more than one row are not vectors.

While the above 2×2 matrix is not a vector, you could say that it contains vectors: Two column vectors or two row vectors. Because vectors are just a type of matrix we can add them, multiply them, and so on—just like any other matrix. Vectors will play a prominent role in defining qubits and expressing the state of a quantum circuit.

Complex numbers

In addition to storing regular numbers, matrices can contain complex numbers. This is both useful and necessary: Qubits are really just a pair of complex numbers that we store in a 1×2 matrix. So, yes—the example matrices above are each larger than a qubit!