# Apply Hadamard on a qubit in a register

I want to implement a Hadamard gate on a single qubit in a register.
Given two qubits
q0 := $$|0\rangle$$ and
q1 := $$|+\rangle$$
I would like to use a Hadamard gate on the first qubit (q0).

My intuition is that

• using Hadamard on the first qubit and building the register afterwards:
Apply: q0' = Had(q0) = $$\begin{bmatrix} 1/\sqrt{2} \\ 1/\sqrt{2} \end{bmatrix}$$
Build Register: reg0 := q0' tensor q1 = $$\begin{bmatrix} 1/2 \\ 1/2 \\ 1/2 \\ 1/2 \end{bmatrix}$$
would lead to the same result as

• using Hadamard Gate (H) on the first qubit after building the register:
Building the register: reg1 := q0 tensor q1 = $$\begin{bmatrix} 1/\sqrt{2} \\ 0 \\ 1/\sqrt{2} \\ 0 \end{bmatrix}$$ Apply: H tensor I mul reg1 =
$$\begin{bmatrix} 1/\sqrt{2} && 0 && 1/\sqrt{2} && 0 \\ 0 && 1/\sqrt{2} && 0 && 1/\sqrt{2} \\ 1/\sqrt{2} && 0 && -1/\sqrt{2} && 0 \\ 0 && 1/\sqrt{2} && 0 && -1/\sqrt{2} \end{bmatrix}$$ mul reg1 = $$\begin{bmatrix} 1 \\ 0 \\ 0 \\ 0 \end{bmatrix}$$ So this is not the same. But what would be same is when we swap H and I: I tensor H mul reg1 = $$\begin{bmatrix} 1/\sqrt{2} && 1/\sqrt{2} && 0 && 0 \\ 1/\sqrt{2} && -1/\sqrt{2} && 0 && 0 \\ 0 && 0 && 1/\sqrt{2} && 1/\sqrt{2} \\ 0 && 0 && 1/\sqrt{2} && -1/\sqrt{2} \end{bmatrix}$$ mul reg1 = $$\begin{bmatrix} 1/2 \\ 1/2 \\ 1/2 \\ 1/2 \end{bmatrix}$$

I found a Microsoft article and I think it has something to with that. It says:

I think this is weird. Can someone explain it?

• "I think it is weird." Unclear what "it" refers to, and which part you're finding weird. Nov 30, 2022 at 2:05
• Also useful would be this answer: quantumcomputing.stackexchange.com/questions/14066/… Nov 30, 2022 at 2:35
• The equation after "Building the register: reg1 := q0 tensor q1 =" is not correct. As Frank Yellin says in his answer below, the vector you wrote is $|+\rangle \otimes |0\rangle$, whereas you are looking for $|0\rangle \otimes |+\rangle = \begin{bmatrix} 1/\sqrt{2} \\ 1/\sqrt{2} \\ 0 \\ 0 \end{bmatrix}$. Then if you follow your logic after that, you will get the same result as your first method. Jan 6, 2023 at 13:14

$$\begin{bmatrix} 1/\sqrt2 \\ 0 \\ 1/\sqrt2 \\ 0 \end{bmatrix}$$ which is $$|+\rangle \otimes |0\rangle$$.
Then: $$(H\otimes I)(|+\rangle \otimes |0\rangle) = (H|+\rangle) \otimes (I|0\rangle) = |0\rangle|0\rangle$$
$$(I\otimes H)(|+\rangle \otimes |0\rangle) = (I|+\rangle) \otimes (H|0\rangle) = |+\rangle|+\rangle$$