Mistake in using dirac notation when applying $X$ gate to vector

The X gate is given by $$\big(\begin{smallmatrix} 0 & 1 \\ 1 & 0 \end{smallmatrix}\big)$$ in the computational basis. In the Hadamard basis, the gate is $$X_H = \big(\begin{smallmatrix} 1 & 0\\ 0 & -1 \end{smallmatrix}\big) = |+ \rangle \langle +| - |-\rangle \langle-|$$. When I apply the gate to the Hadamard basis vectors, the vectors should flip, and they do when I use matrix notation but not when I'm using dirac notation. I know I'm making a mistake somewhere.

$$X_H |+\rangle = (|+ \rangle \langle +| - |-\rangle \langle-|)|+\rangle = |+ \rangle \langle +|+\rangle - |-\rangle \langle-|+\rangle = |+\rangle(1) - |-\rangle(0) = |+\rangle$$ and $$X_H |-\rangle = (|+ \rangle \langle +| - |-\rangle \langle-|)|-\rangle = |+ \rangle \langle +|-\rangle - |-\rangle \langle-|-\rangle = |+\rangle (0) -|-\rangle(1) = -|-\rangle$$

Meanwhile, in matrix notation,

$$X_H|+\rangle = \big(\begin{smallmatrix} 1 & 0\\ 0 & -1 \end{smallmatrix}\big) \frac{1}{\sqrt{2}}\big( \begin{smallmatrix} 1 \\ 1 \end{smallmatrix}\big) = \frac{1}{\sqrt{2}}\big( \begin{smallmatrix} 1 \\ -1 \end{smallmatrix}\big) = |-\rangle$$

$$X_H|-\rangle = \big(\begin{smallmatrix} 1 & 0\\ 0 & -1 \end{smallmatrix}\big) \frac{1}{\sqrt{2}}\big( \begin{smallmatrix} 1 \\ -1 \end{smallmatrix}\big) = \frac{1}{\sqrt{2}}\big( \begin{smallmatrix} 1 \\ 1 \end{smallmatrix}\big) = |+\rangle$$

The basis states should not flip, as these two basis states are the eigenstates of the $$X$$ gate. The $$X$$ gate flips the computational basis states, the $$Z = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}$$ gate flips the Hadamard basis states.

Expressing everything in the computational basis

In the computational basis, we have $$X = \begin{bmatrix}0 & 1 \\ 1 & 0\end{bmatrix}$$. Thus the states (expressed in the computational basis) $$|+\rangle = \begin{bmatrix}1 \\ 1\end{bmatrix}$$ and $$|-\rangle = \begin{bmatrix}1 \\ -1\end{bmatrix}$$ are the $$+1$$ and $$-1$$ eigenstates respectively, as you can readily check.

Expressing everything in the Hadamard basis

If you express everything in the Hadamard basis, the $$X$$ gate becomes $$X_{H} = \begin{bmatrix}1 & 0 \\ 0 & -1\end{bmatrix}$$.

But, the $$|+\rangle$$ and $$|-\rangle$$ states should now also be expressed in this basis. That is, $$|+\rangle_{H} = \begin{bmatrix}1 \\ 0\end{bmatrix}$$ and $$|-\rangle_{H} = \begin{bmatrix}0 \\ 1\end{bmatrix}$$. It's now obvious that these states are indeed the $$+1$$ and $$-1$$ eigenstates of $$X$$, expressed in whatever basis.

So you dirac notation is correct, and in your matrix notation you expressed the $$X$$ operator in the Hadamard basis, but the states in the computational basis.

But wait, then what are these states if not the $$|+\rangle$$ and $$|-\rangle$$ states?

So what are the states $$\begin{bmatrix}1 \\ 1\end{bmatrix}_{H}$$ and $$\begin{bmatrix}1 \\ -1\end{bmatrix}_{H}$$, i.e. these states in the Hadamard basis? As you showed with your matrix notation, they are those states that are flipped under operation of the $$X$$ gate - they are the computational basis states/eigenstates of the $$Z$$ operator!

Of course, you can write this out mathematically as well:

$$\begin{bmatrix}1 \\ 1\end{bmatrix}_{H} = \begin{bmatrix}1 \\ 0\end{bmatrix}_{H} + \begin{bmatrix}0 \\ 1\end{bmatrix}_{H} = \begin{bmatrix}1 \\ 1\end{bmatrix} + \begin{bmatrix}1 \\ -1\end{bmatrix} = \begin{bmatrix}1 \\ 0\end{bmatrix}$$ As you can see, I've been very sloppy with the normalization factor - the above equation is a factor of $$2$$ off.

• Oh this makes sense. In matrix notation, if I do $X_H |+ \rangle_H$, I get $|+\rangle_H$, and $X_H |-\rangle = -|-\rangle_H$. This agrees with the dirac notation. I was confused because this is an exercise in "Quantum Computing Explained" where the author asks to show that $X_H$ acts as the NOT gate when applied to the Hadamard basis. So the book is wrong? Dec 21, 2020 at 18:43
• Well, I wouldn't go so far as saying 'wrong' - but it's ambiguous to say the least. As you showed, the $X_{H}$ gate acting on the $|+\rangle$, $|-\rangle$ states (as in, the vectors in the computational basis) flips them around. But normally you don't get to 'pick and choose' your basis separately like that - you have to be consistent.
– JSdJ
Dec 22, 2020 at 8:51