# Trying to use matrices for Hadamard and Controlled Not gates

I have the following simple quantum circuit: This outputs are 00 and 11 for the two qubits. Using matrices, I have applied the H gate to the first qubit (ket 0):

$$\frac{1}{\sqrt{2}}\begin{pmatrix}1&1\\ 1&-1\end{pmatrix}\begin{pmatrix}1\\0\end{pmatrix}=\begin{pmatrix}\frac{1}{\sqrt{2}}\\\frac{1}{\sqrt{2}}\end{pmatrix}$$

Is this right? Moreover, I don't understand how to apply the Controlled Not to to resulting matrix. I assume it's applied to a product basis state of the resulting:

$$\begin{pmatrix}\frac{1}{\sqrt{2}}\\\frac{1}{\sqrt{2}}\end{pmatrix}$$ and $$\begin{pmatrix}0\\1\end{pmatrix}$$

I would be grateful for any help on continuing this, and if anyone could point out if I am wrong with my previous calculations. I appreciate the help in advance.

The application of Hadamard gate on the first qubit is correct.

Since CNOT is two qubit gate, it has to be described by matrix 4x4, so far you have only 2x2 matrix. However, there is a identity operator $$I$$ described by unit matrix on the second qubit. Hence the first step in you circuit can be described by matrix $$H \otimes I$$. Resulting matrix is of type 4x4. Now, you can apply CNOT gate.

So, first step is

$$H \otimes I = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ 1 & 0 & -1 & 0 \\ 0 & 1 & 0 & -1 \\ \end{pmatrix}.$$

Second step is CNOT gate $$CNOT= \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \\ \end{pmatrix}.$$

The whole circuit is described by matrix

$$CNOT(H \otimes I)= \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ 0 & 1 & 0 & -1 \\ 1 & 0 & -1 & 0 \\ \end{pmatrix}.$$

If you apply the circuit on input $$|00\rangle$$ you will get state

$$\frac{1}{\sqrt{2}} \begin{pmatrix} 1 \\ 0 \\ 0 \\ 1 \\ \end{pmatrix}.$$

This is so-called Bell state $$\beta_{00}$$. If you set inputs $$|01\rangle$$, $$|10\rangle$$ or $$|11\rangle$$, you will get different Bell states.

EDIT: a manual how to compute tensor product mechanically

Based on comments below, here is a manual how to computer tensor product: • Thank you for your response. I am confused as to why CNOT is a unitary matrix; isn't it defined $\begin{pmatrix}1&0&0&0\\ 0&1&0&0\\ 0&0&0&1\\ 0&0&1&0\end{pmatrix}$ Apr 6, 2020 at 9:06
• Also, for the first step, where did the matrix from my earlier calculation go? What is $H⊗I$ and how does it create $\frac{1}{\sqrt{2}}\begin{pmatrix}1&0&1&0\\ 0&1&0&1\\ 1&0&-1&0\\ 0&1&0&-1\end{pmatrix}$ Apr 6, 2020 at 9:10
• Sorry for the typo in CNOT, just corrected. Apr 6, 2020 at 9:20
• $H \otimes I$ is so-called tensor product. In simple words, you put matrix $I$ on each position in $H$ and multiply it by element in $H$. Be aware that tensor product is not generally commutative operation. See here for more information: en.wikipedia.org/wiki/Tensor_product Apr 6, 2020 at 9:22
• Ooh, very nice. So $|a_i|$ is $\frac{1}{\sqrt{2}}$ and the square of that is the probability (or 0.5 - 50%)? Thank you for all your help. I have to admit, I have always loved dealing with matrices and vectors, but never found a really cool use for them and so lost interest. But with quantum computing I am learning something new and cool everyday. Thanks again! Apr 6, 2020 at 11:53