# How do I apply a matrix to a ket state?

If we have the following matrix:
$$\frac{1}{\sqrt{2}}\begin{pmatrix}1&1&0&0\\ 1&-1&0&0\\ 0&0&1&-1\\ 0&0&1&1\end{pmatrix}$$
How do we find the output for $$|00\rangle$$?

– glS
May 15 at 10:17
• Normally, the number of the ket (if it is in the computationnal basis) gives the number of the column to look at May 15 at 14:10
• @BrockenDuck The first column?
– Xavi
May 15 at 14:12

Welcome to quantum computing. When we apply a quantum gate (a unitary matrix) to a state, it is just matrix multiplication. It is good to note that: $$|0\rangle = \begin{pmatrix} 1 \\ 0 \end{pmatrix} \hspace{1 cm} |1\rangle = \begin{pmatrix} 0 \\ 1\end{pmatrix}$$ These are the computational basis states for a single qubit. For multi-qubit system, the basis states are built from the tensor product. That is, for a two-qubit system, you have $$|0\rangle \otimes |0\rangle = |00\rangle = \begin{pmatrix} 1 \\ 0 \\0 \\0 \end{pmatrix} \hspace{1 cm} |0\rangle \otimes |1\rangle = |01\rangle = \begin{pmatrix} 0 \\ 1 \\0 \\0 \end{pmatrix}$$ $$|1\rangle \otimes |0\rangle = |10\rangle = \begin{pmatrix} 0 \\ 0 \\1 \\0 \end{pmatrix} \hspace{1 cm} |1\rangle \otimes |1\rangle = |10\rangle = \begin{pmatrix} 0 \\ 0 \\0 \\1 \end{pmatrix}$$ And so suppose you have a unitary matrix $$U = \begin{pmatrix} 0 & 1 & 0 &0\\ 1 & 0 & 0 & 0 \\0 & 0 & 0 & 1 \\0 & 0 & 1 & 0 \end{pmatrix}$$ and $$U$$ acts on the state $$|11\rangle$$, then to know the output of that, you can simply do:
$$U|11\rangle = \begin{pmatrix} 0 & 1 & 0 &0\\ 1 & 0 & 0 & 0 \\0 & 0 & 0 & 1 \\0 & 0 & 1 & 0 \end{pmatrix} \begin{pmatrix} 0 \\ 0 \\0 \\1 \end{pmatrix} = \overbrace{\begin{pmatrix} 0 \\ 0 \\1 \\0 \end{pmatrix}}^{\textrm{output state}}$$
However, looking at the calculation this way is pretty cumbersome. What you can do is to recognize that the unitary matrix $$U$$ can be written as \begin{align} U = I \otimes X = \begin{pmatrix} 1 & 0\\ 0 & 1 \end{pmatrix} \otimes \begin{pmatrix} 0 & 1\\ 1 & 0 \end{pmatrix} = \begin{pmatrix} 0 & 1 & 0 &0\\ 1 & 0 & 0 & 0 \\0 & 0 & 0 & 1 \\0 & 0 & 1 & 0 \end{pmatrix} \end{align} That is you can think of $$U$$ just as $$I \otimes X$$. This is better because you now recall that $$X$$ is a bit-flip gate. That is, $$X|0\rangle = |1\rangle$$ and $$X|1\rangle = |0\rangle$$. You can verify this to yourself by take the matrix representation of $$X$$ and multiply by the statevector representation of $$|0\rangle$$, and you will see the result is the state vector representation of $$|1\rangle$$. Furthermore, there is a property of tensor product, which essentially says that if you two operators, $$U$$ and $$V$$ and it acts on the tensor product state $$|\psi\rangle \otimes |\phi\rangle$$, then it is equivalent to $$U$$ acts on $$|\psi\rangle$$ tensor $$V$$ acts on $$|\phi$$. That is, $$\big( U\otimes V \big) ( |\psi \rangle \otimes |\phi \rangle) = \big(U |\psi \rangle \big) \otimes \big(V |\phi \rangle \big)$$ This tells us that $$U|11\rangle$$ is essentially just $$(I \otimes X) |11\rangle = I |1\rangle \otimes X|1\rangle = |1\rangle \otimes |0\rangle = |10\rangle$$ And now, remember the statevector representation of $$|10\rangle$$ is the same as the output state we got when we did the matrix representation. This way of doing the calculation is less cumbersome and easy to deal with when your system is larger.
Back to your original problem, you can follow the steps I have shown above, just note that your matrix can be written as the tensor product of $$I$$ and $$H$$. I will let you figure this out as this is a good practice. Once you can write your matrix as the tensor product of $$I$$ and $$H$$, remember that $$H|0\rangle = \dfrac{|0\rangle + |1\rangle}{\sqrt{2}}$$ and $$H|1\rangle = \dfrac{|0\rangle - |1\rangle}{\sqrt{2}}$$. And of course, as before, $$I$$ is just the identity operator so it doesn't do anything.
To add onto KAJ226's answer, you can see that $$|00\rangle, |01\rangle, |10\rangle, |11\rangle$$ form the computational basis. You can also see that since there is a $$1$$ in only one coefficient of the vector, it will only "consider" one column when you multiply it. For example : $$|11\rangle = \begin{pmatrix} 0 \\ 0 \\ 0 \\ 1 \\ \end{pmatrix}$$ where the $$1$$ is the 4th coefficient, and all other coefficients are $$0$$. This means that when multiplying your matrix : $$\frac{1}{\sqrt{2}}\begin{pmatrix}1&1&0&0\\ 1&-1&0&0\\ 0&0&1&-1\\ 0&0&1&1\end{pmatrix}*\begin{pmatrix} 0 \\ 0 \\ 0 \\ 1 \\ \end{pmatrix} = \frac{1}{\sqrt{2}}\begin{pmatrix} 0 \\ 0 \\ -1 \\ 1 \\ \end{pmatrix}$$, you can see, this gives us the 4th column of the matrix. This neat little trick can save a lot of time.