# Hadamard transform for two qubit

This question has been fussy me for two hours so I'd appreciate some help.

The Hadamard operator on one qubit may be written as

$$H = \frac{1}{\sqrt{2}}[(|0\rangle + |1\rangle)\langle0| + (|0\rangle - |1\rangle)\langle 0|]$$

For this transform to act on a two qubits, my working leads me to $$\frac{1}{2}[|0\rangle\langle 0| + |1\rangle \langle 0| + |0\rangle \langle 1| + |1\rangle \langle 1| + |0\rangle \langle 0| - |1\rangle \langle 0| - |0\rangle \langle 1| + |1\rangle \langle 1|]$$

to give

$$|0\rangle\langle0| + |1\rangle\langle 1|$$.

But this does not conform to the general expression

$$H^{\otimes n} = \frac{1}{\sqrt{2^{n}}}\sum_{x,y}(-1)^{xy}|x\rangle \langle y|$$

Where have I gone wrong?

You've computed $$H^2$$ (which acts on one qubit), not $$H \otimes H$$ (acting on two). As an aside, your computation of $$H^2$$ is correct since $$|0\rangle\langle0| + |1\rangle\langle 1|$$ is the identity.
To show the desired result, it's convenient to expand your expression for $$H$$ (although in your first line, note your final $$\langle 0|$$ should be a $$\langle 1|$$), $$H = \frac{1}{\sqrt{2}} \left[ |0 \rangle \langle 0| + |1 \rangle \langle 0 | + |0\rangle \langle 1| - |1\rangle \langle 1| \right]$$ Then we can compute $$H \otimes H$$, somewhat tediously expanding all 16 terms (and taking the half to the other side), \begin{aligned} 2H \otimes H &= \left[ |0 \rangle \langle 0| + |1 \rangle \langle 0 | + |0\rangle \langle 1| - |1\rangle \langle 1| \right] \otimes \left[ |0 \rangle \langle 0| + |1 \rangle \langle 0 | + |0\rangle \langle 1| - |1\rangle \langle 1| \right] \\ &= |00\rangle \langle00| + |01\rangle \langle00| + |00\rangle \langle01| - |01\rangle \langle01| \\ &+|10\rangle \langle00| + |11\rangle \langle00| + |10\rangle\langle01|-|11\rangle\langle01| \\ &+|00\rangle \langle10| + |01\rangle \langle10| + |00\rangle \langle11| - |01\rangle \langle11| \\ &-|10\rangle \langle10| - |11\rangle \langle10| - |10\rangle \langle11| + |11\rangle \langle11| \end{aligned} where the each of the four subsequent lines comes from $$|0\rangle\langle0| \otimes H, \dots, |1\rangle\langle1| \otimes H$$ respectively, using the fact that $$|i\rangle \langle j| \otimes |k\rangle \langle l| = |i, k\rangle\langle j, l|$$ where I'm using the convention that the left-most index in $$\langle j, l|$$ corresponds to the qubit in the first slot - that is to say, $$\langle j, l|_{12} = \langle j |_1 \otimes \langle l |_2$$ (where the subscript $$1$$ and $$2$$ denote the qubit on which to act).
One can verify that this is as required: each $$|x\rangle\langle y|$$ for $$x, y \in B_2$$ appears once, with the correct factor of $$(-1)^{x \cdot y}$$ - you don't explicitly write this dot product in your expression, but I find it best to explicitly identify $$x$$ and $$y$$ as elements of $$B_2 \cong\mathbb{Z}_2^2$$, with $$x \cdot y = x_1 y_1 + x_2 y_2$$