# How do I apply the Hadamard gate to one qubit in a two-qubit pure state?

So in lectures I see lots of these:

And somehow I intuitively understand it (at least for the 1 qubit case), but I don't understand the math – especially for 2 qubits.

First, you should note that the Hadamaard gate is nothing more than a $$2 \times 2$$ Discrete Fourier Transform matrix (two-point DFT). That is the reason why, $$H \bigg( \dfrac{|0\rangle + |1\rangle}{2}\bigg) = |0\rangle$$, and $$H \bigg( \dfrac{|0\rangle - |1\rangle}{2}\bigg) = |1\rangle$$. Think "periodicity"...

Now, the Hadamard gate, which is again just a two-point DFT, can be written out explicitly as:

$$H = \dfrac{1}{\sqrt{2}}\begin{pmatrix} 1& 1\\ 1 & -1\\ \end{pmatrix}$$

and $$|0\rangle = \begin{pmatrix} 1 \\ 0 \end{pmatrix}$$ and $$|1\rangle = \begin{pmatrix} 0 \\ 1 \end{pmatrix}$$. These are the standard euclidean basis. So naturally we take them as the computational basis for quantum computation. Now, you can work out the linear algebra (and it seems like you already did, as you mentioned in the question):

$$H|0\rangle = \dfrac{1}{\sqrt{2}}\begin{pmatrix} 1& 1\\ 1 & -1\\ \end{pmatrix} \begin{pmatrix} 1 \\ 0 \end{pmatrix} = \dfrac{1}{\sqrt{2}}\begin{pmatrix} 1\\ 1 \\ \end{pmatrix} = \dfrac{1}{\sqrt{2}}\bigg[ \begin{pmatrix} 1\\ 0 \\ \end{pmatrix} + \begin{pmatrix} 0\\ 1 \\ \end{pmatrix} \bigg] = \dfrac{1}{\sqrt{2}}\bigg[ |0\rangle + |1\rangle\bigg]$$

For the two-qubit or more generally n-qubit case, where you apply the Hadamard gate to $$j$$-qubit, then you can think of this operator as: $$I_1 \otimes I_2 \otimes \cdots \otimes H_j \otimes \cdots \otimes I_n$$.

For instance, if you have a two qubit state $$|\psi \rangle = |00\rangle = |0\rangle \otimes |0\rangle$$ and you want to apply the Hadamard to the second qubit, then this is simply:

\begin{align} (I \otimes H) |00\rangle &= \bigg[ \begin{pmatrix} 1& 0\\ 0 & 1\\ \end{pmatrix} \otimes \dfrac{1}{\sqrt{2}}\begin{pmatrix} 1& 1\\ 1 & -1\\ \end{pmatrix} \bigg] \bigg[|0\rangle \otimes |0\rangle \bigg] \\ &= \begin{pmatrix} 1 \cdot\dfrac{1}{\sqrt{2}}\begin{pmatrix} 1& 1\\ 1 & -1\\ \end{pmatrix} & 0\cdot \dfrac{1}{\sqrt{2}}\begin{pmatrix} 1& 1\\ 1 & -1\\ \end{pmatrix} \\ 0\cdot \dfrac{1}{\sqrt{2}}\begin{pmatrix} 1& 1\\ 1 & -1\\ \end{pmatrix} & -1\cdot \dfrac{1}{\sqrt{2}}\begin{pmatrix} 1& 1\\ 1 & -1\\ \end{pmatrix} \end{pmatrix} \cdot \begin{pmatrix} 1 \\ 0\\ 0 \\ 0 \\ \end{pmatrix} \\ &= \dfrac{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} 1 \\ 0\\ 0 \\ 0 \\ \end{pmatrix} \\ &= \dfrac{1}{\sqrt{2}} \begin{pmatrix} 1 \\ 1\\ 0 \\ 0 \\ \end{pmatrix} \\ &= \dfrac{1}{\sqrt{2}} \bigg[ \begin{pmatrix} 1 \\ 0\\ 0 \\ 0 \\ \end{pmatrix} + \begin{pmatrix} 0 \\ 1 \\ 0 \\ 0 \\ \end{pmatrix} \bigg]\\ &= \dfrac{1}{\sqrt{2}}\big( |00\rangle + |01\rangle \big)\\ \end{align}

where the last equality is because

$$|00\rangle = |0\rangle \otimes |0\rangle = \begin{pmatrix} 1 \\ 0 \end{pmatrix} \otimes \begin{pmatrix} 1 \\ 0 \end{pmatrix}= \begin{pmatrix} 1 \cdot \begin{pmatrix} 1 \\ 0 \end{pmatrix} \\ 0 \cdot \begin{pmatrix} 1 \\ 0 \end{pmatrix} \end{pmatrix} = \begin{pmatrix} 1 \\ 0 \\ 0 \\ 0 \end{pmatrix}$$

and similarly

$$|01\rangle = |0\rangle \otimes |1\rangle = \begin{pmatrix} 1 \\ 0 \end{pmatrix} \otimes \begin{pmatrix} 0 \\ 1 \end{pmatrix}= \begin{pmatrix} 1 \cdot \begin{pmatrix} 0 \\ 1 \end{pmatrix} \\ 0 \cdot \begin{pmatrix} 1 \\ 0 \end{pmatrix} \end{pmatrix} = \begin{pmatrix} 0 \\ 1 \\ 0 \\ 0 \end{pmatrix}$$

and therefore you have the equality

$$\dfrac{1}{2}\bigg[ \begin{pmatrix} 1 \\ 0 \\ 0 \\ 0 \end{pmatrix} + \begin{pmatrix} 0 \\ 1 \\ 0 \\ 0 \end{pmatrix} \bigg] =\dfrac{1}{2}\bigg[ |00\rangle + |01\rangle \bigg]$$

Now also note that

\begin{align} (I \otimes H) |00\rangle &= (I \otimes H) \big(|0\rangle \otimes |0\rangle \big) = I|0\rangle \otimes H|0\rangle \ \textrm{[by tensor product properties][1]} \\ &= |0\rangle \otimes \dfrac{1}{\sqrt{2}} \big( |0\rangle + |1\rangle \big) \\ &= \dfrac{1}{\sqrt{2}}|0\rangle \otimes 0\rangle + \dfrac{1}{\sqrt{2}}|0 \rangle \otimes |1\rangle = \dfrac{1}{\sqrt{2}} \bigg(|00\rangle + |01\rangle \bigg) \end{align}

This is more convenient

Now, if we want to apply the Hadamard gate to the first qubit instead of the second qubit as your lecture note indicated, we can do it too.

\begin{align} (H \otimes I) |00\rangle &= \bigg[ \dfrac{1}{\sqrt{2}}\begin{pmatrix} 1& 1\\ 1 & -1\\ \end{pmatrix} \otimes \begin{pmatrix} 1& 0\\ 0 & 1\\ \end{pmatrix} \bigg] \bigg[|0\rangle \otimes |0\rangle \bigg] \\ &= \begin{pmatrix} \dfrac{1}{\sqrt{2}} \cdot \begin{pmatrix} 1& 0\\ 0 & 1\\ \end{pmatrix} & \dfrac{1}{\sqrt{2}} \cdot \begin{pmatrix} 1& 0\\ 0 & 1\\ \end{pmatrix} \\ \dfrac{1}{\sqrt{2}} \cdot \begin{pmatrix} 1& 0\\ 0 & 1\\ \end{pmatrix} & -\dfrac{1}{\sqrt{2}}\cdot \begin{pmatrix} 1& 0\\ 0 & 1\\ \end{pmatrix} \end{pmatrix} \cdot \begin{pmatrix} 1 \\ 0\\ 0 \\ 0 \\ \end{pmatrix} \\ &= \dfrac{1}{\sqrt{2}} \begin{pmatrix} 1 & 0 & 1 & 0\\ 0 & 1 & 0 & 1\\ 1 & 0 & -1 & 0\\ 0 & 1 & 0 & -1 \end{pmatrix}\begin{pmatrix} 1 \\ 0\\ 0 \\ 0 \\ \end{pmatrix} \\ &= \dfrac{1}{\sqrt{2}} \begin{pmatrix} 1 \\ 0\\ 1 \\ 0 \\ \end{pmatrix} \\ &= \dfrac{1}{\sqrt{2}} \bigg[ \begin{pmatrix} 1 \\ 0\\ 0 \\ 0 \\ \end{pmatrix} + \begin{pmatrix} 0 \\ 0 \\ 1 \\ 0 \\ \end{pmatrix} \bigg]\\ &= \dfrac{1}{\sqrt{2}}\big( |00\rangle + |10\rangle \big)\\ \end{align}

This is again, because

$$|10\rangle = |1\rangle \otimes |0\rangle = \begin{pmatrix} 0 \\ 1 \end{pmatrix} \otimes \begin{pmatrix} 1 \\ 0 \end{pmatrix}= \begin{pmatrix} 0 \cdot \begin{pmatrix} 1 \\ 0 \end{pmatrix} \\ 1 \cdot \begin{pmatrix} 1 \\ 0 \end{pmatrix} \end{pmatrix} = \begin{pmatrix} 0 \\ 0 \\ 1 \\ 0 \end{pmatrix}$$

and we already know from earlier that

$$|00\rangle = \begin{pmatrix} 1 \\ 0 \\ 0 \\ 0 \end{pmatrix}$$

so therefore,

$$\dfrac{1}{2}\bigg[ \begin{pmatrix} 1 \\ 0 \\ 0 \\ 0 \end{pmatrix} + \begin{pmatrix} 0 \\ 0 \\ 1 \\ 0 \end{pmatrix} \bigg] =\dfrac{1}{2}\bigg[ |00\rangle + |10\rangle \bigg]$$

I think the problem is people tend to drop off tensor notation... They assume that you know what they mean.

Going a little further: Since we are already at this point, I thought I should add this extra bit in here too. Suppose you see the following circuit:

This is quantum circuit, starting with the initial state $$|\psi_0\rangle = |00\rangle = |0 \rangle \otimes |0\rangle$$. Then it apply the Hadamard gate to the first qubit. This is similar to the question you asked. So based on what we did above, we have that

\begin{align} |\psi_1 \rangle &= (H \otimes I) \big( |0\rangle \otimes |0\rangle= \dfrac{1}{\sqrt{2}} \begin{pmatrix} 1 \\ 0\\ 1 \\ 0 \\ \end{pmatrix} = \dfrac{1}{\sqrt{2}}\big( |00\rangle + |10\rangle \big)\\ \end{align}

Now, we apply a gate known as the CNOT gate to both of the qubit. CNOT gate is a two-qubit gate as so you cannot think of it as tensor product from one-qubit gate. The function of CNOT (controlled-NOT) is to apply the $$X$$ gate to the target-qubit when the controlled-qubit is $$|1\rangle$$. It is therefore can be written in matrix form explicitly as

$$$$\label{CNOT matrix} CNOT = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \\ \end{pmatrix}$$$$

Now, we apply the CNOT gate to $$|\psi_1\rangle$$, which will give us $$|\psi_2\rangle$$. That is

$$CNOT|\psi_1\rangle = |\psi_2\rangle$$

And explicitly writing this out as matrix and vector multiplication, we have

$$|\psi_2 \rangle = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \\ \end{pmatrix} \dfrac{1}{\sqrt{2}} \begin{pmatrix} 1 \\ 0\\ 1 \\ 0 \\ \end{pmatrix} = \dfrac{1}{\sqrt{2}} \begin{pmatrix} 1 \\ 0\\ 0 \\ 1 \\ \end{pmatrix} = \dfrac{1}{\sqrt{2}} \big( |00\rangle + |11 \rangle \big)$$

This quantum circuit generate the state $$\dfrac{1}{\sqrt{2}} \big( |00\rangle + |11 \rangle \big)$$ which is one of the four Bell states, which are maximal entangled state for two qubit.

• 2. Question. a) Why does column (1,1) is same as |0>+|1>. Is there also some math for conversation, or is just assumption in QC world? b) And similarly - how does the column (1,1,0,0) turn into |00>+|01>? Commented Oct 9, 2020 at 7:04
• @JohnT I have added the reason for why that is the case. It's not assumption. It's because how the vectors, $|0\rangle$ and $|1\rangle$ are defined. Commented Oct 9, 2020 at 15:47
• @JohnT I have added even more details to the answer. Take a look. I think this will help you to understand the math going behind QC notations. Commented Oct 9, 2020 at 16:01
• Thank you. It's now much clearer to me! (thumbs up) Commented Oct 9, 2020 at 19:04
• I did go again trough the answers and Im confused. The below solution and the lecture material says that H of |00> is |00>+|10> , but ur calculus says |00>+|01>. Where is the error? Commented Oct 9, 2020 at 21:04

What don't you understand about the Hadamard? You did the math correctly.

For the two qubit states, you can ignore the qubit that the Hadamard is not modifying and factor that in the end. Notably:

$$(H \otimes I) | \psi_A \rangle |\psi_B \rangle = H |\psi_A \rangle \otimes I| \psi_B \rangle$$

Last, $$|+\rangle = \frac{1}{\sqrt{2}} (|0\rangle + |1\rangle)$$ as a notational shorthand.

Explicit description

Let's say we want to apply the Hadamard to the first qubit of $$|00\rangle$$. Then, That's just $$H|0\rangle \otimes |0\rangle = |+\rangle |0\rangle = \frac{1}{\sqrt{2}} (|0\rangle + |1\rangle) |0\rangle = \frac{1}{\sqrt{2}} (|00\rangle + |10\rangle)$$

• This is not my math. Its copied from some lectures online. I do not understand how |00> becomes |00>+|10>. Can you edit your answer and show come calculus please? Commented Oct 8, 2020 at 20:48
• For 2 qubits... Commented Oct 8, 2020 at 20:54