# Matrix Multiplication

This reference page just iterates the basics of multiplying Matrices along with some other matrix examples more related to quantum mechanics and, in particular, quantum computing.

Note: This is a work in progress!

#### [1×1] times [1×1]

The result we get, a 1×1 matrix, is the same as we’d get multiplying two scalars together:

$\begin{bmatrix}a_{11}\end{bmatrix}\begin{bmatrix}b_{11}\end{bmatrix} = \begin{bmatrix}a_{11}b_{11}\end{bmatrix}$

But note that a 1×1 matrix is not a scalar. (The difference becomes obvious in the next two cases.)

#### [1×1] times [1×2]

Similar to the first case, here the result, a 1×2 matrix (a row vector), is the same as we’d get multiplying the 1×2 matrix by a scalar.

$\begin{bmatrix}a_{11}\end{bmatrix}\begin{bmatrix}b_{11}&b_{12}\end{bmatrix}=\begin{bmatrix}a_{11}b_{11}&a_{11}b_{12}\end{bmatrix}$

As in the first case, the result is the same as we’d get multiplying row vector by a scalar (another row vector):

$\kappa\begin{bmatrix}b_{11}&b_{12}\end{bmatrix}=\begin{bmatrix}{\kappa}\;b_{11}&{\kappa}\;b_{12}\end{bmatrix}$

But note that, unlike the scalar multiplication, the matrix multiplication cannot be reversed because [1×2][1×1] is an illegal operation. (The number of columns in the first matrix doesn’t match the number of rows in the second.)

Bottom line, a [1×1] matrix is not (always) the same as a scalar!

#### [2×1] times [1×1]

Here’s the legal version of putting the “scalar” matrix second. In this case, the single column of the 2×1 matrix (a column vector) matches the single row of the 1×1 matrix:

$\begin{bmatrix}a_{11}\\a_{21}\end{bmatrix}\begin{bmatrix}b_{11}\end{bmatrix}=\begin{bmatrix}a_{11}b_{11}\\a_{21}b_{11}\end{bmatrix}$

The result is the same as we’d get multiplying a column vector by a scalar (another column vector):

$\begin{bmatrix}a_{11}\\a_{21}\end{bmatrix}\kappa=\begin{bmatrix}a_{11}\;{\kappa}\\a_{21}\;{\kappa}\end{bmatrix}$

However, as in the second case above, the [2×1][1×1] operation cannot be reversed (due to column/row mismatch), whereas with the scalar operation it can.

#### [1×2] times [2×1] (inner product)

Multiplying a row vector by a column vector results in a 1×1 matrix usually treated as a scalar:

$\begin{bmatrix}a_{11}&a_{12}\end{bmatrix}\begin{bmatrix}b_{11}\\b_{21}\end{bmatrix}=\begin{bmatrix}a_{11}b_{11}+a_{12}b_{21}\end{bmatrix}$

In Dirac Bra-Ket notation, generally speaking, a bra is row vector, and a ket is a column vector. Often the bra is the conjugate transpose of a ket. For example, given:

$\mid\!{\Psi}\rangle=\begin{bmatrix}\alpha_1\\\alpha_2\end{bmatrix}$

Where α is a complex number, then:

$\langle{\Psi}\!\mid\!{\Psi}\rangle=\begin{bmatrix}\alpha_1{*}&\alpha_2{*}\end{bmatrix}\begin{bmatrix}\alpha_1\\\alpha_2\end{bmatrix}=\alpha_1{*}\alpha_1+\alpha_2{*}\alpha_2$

Where α* is the conjugate of α.

#### [2×1] times [1×2] (outer product)

Multiplying a column vector by a row vector results in a matrix with as many rows and columns as the vectors (in this case, a 2×2 matrix):

$\begin{bmatrix}a_{11}\\a_{21}\end{bmatrix}\begin{bmatrix}b_{11}&b_{12}\end{bmatrix}=\begin{bmatrix}a_{11}b_{11}&a_{11}b_{12}\\a_{21}b_{11}&a_{21}b_{12}\end{bmatrix}$

In Bra-Ket notation, this is (using the definition of |Ψ〉 above):

$\mid\!{\Psi}\rangle\langle{\Psi}\!\mid=\begin{bmatrix}\alpha_1\\\alpha_2\end{bmatrix}\begin{bmatrix}\alpha_1{*}&\alpha_2{*}\end{bmatrix}=\begin{bmatrix}\alpha_1\alpha_1{*}&\alpha_1\alpha_2{*}\\\alpha_2\alpha_1{*}&\alpha_2\alpha_2{*}\end{bmatrix}$

Which, among other things, allows the definition of quantum gates in terms of combinations of state vectors.

#### [2×2] times [2×2]

Multiplying two (same-sized) square matrices results in a new matrix of the same size (in this case, 2×2).

$\begin{bmatrix}a_{11}&a_{12}\\a_{21}&a_{22}\end{bmatrix}\begin{bmatrix}b_{11}&b_{12}\\b_{21}&b_{22}\end{bmatrix}=\begin{bmatrix}a_{11}b_{11}+a_{12}b_{21}&a_{11}b_{12}+a_{12}b_{22}\\a_{21}b_{11}+a_{22}b_{21}&a_{21}b_{12}+a_{22}b_{22}\end{bmatrix}$

(Multiplying square matrices is what many think of as “matrix multiplication” but as the examples above show, it’s not the only form.)

### Quantum States

Sticking to 2×2 matrices for a moment, in quantum computing the computational basis states, |0〉 and |1〉, are generally defined as:

$\mid\!{0}\rangle=\begin{bmatrix}1\\0\end{bmatrix},\;\;\mid\!{1}\rangle=\begin{bmatrix}0\\1\end{bmatrix}$

Upon that, two common superposition states, |+〉 and |-〉, are defined as:

$\mid\!{+}\rangle=\frac{1}{\sqrt{2}}(\mid\!{0}\rangle+\mid\!{1}\rangle)=\frac{1}{\sqrt{2}}\begin{bmatrix}1\\1\end{bmatrix},\;\;\mid\!{-}\rangle=\frac{1}{\sqrt{2}}(\mid\!{0}\rangle-\mid\!{1}\rangle)=\frac{1}{\sqrt{2}}\begin{bmatrix}1\\-1\end{bmatrix}$

#### Tensor Product

The tensor product of two states, a and b, is written:

$\mid\!{a}\rangle\otimes\!\mid\!{b}\rangle=\mid\!{ab}\rangle$

Which expands to:

$\begin{bmatrix}a_1\\a_2\end{bmatrix}\otimes\begin{bmatrix}b_1\\b_2\end{bmatrix}=\begin{bmatrix}{a_1}{b_1}\\{a_1}{b_2}\\{a_2}{b_1}\\{a_2}{b_2}\end{bmatrix}$

etc

#### Quantum Gates

The Pauli sx gate:

$\sigma_x=\begin{bmatrix}{0}&{1}\\{1}&{0}\end{bmatrix}$

Note this is also a NOT gate.

The Pauli sy gate:

$\sigma_y=\begin{bmatrix}{0}&{-i}\\{i}&{0}\end{bmatrix}$

The Pauli sz gate:

$\sigma_z=\begin{bmatrix}{1}&{0}\\{0}&{-1}\end{bmatrix}$

Note that these matrices are also the spin axes representations.

$H=\frac{1}{\sqrt{2}}\begin{bmatrix}{1}&{1}\\{1}&{-1}\end{bmatrix}$