# How to translate the Hadamard gate matrix into Dirac notation?

$$\frac{1}{\sqrt 2}\begin{bmatrix}1 && 1 \\ 1 && -1\end{bmatrix}$$

The Dirac notation for it is:

$$\frac{|0\rangle+|1\rangle}{\sqrt 2}\langle0|+\frac{|0\rangle-|1\rangle}{\sqrt 2}\langle1|$$

I am unable to understand, how this gate matrix is translated into dirac notation?

First remember that each matrix element can be written as outer products in Dirac notation:

$$|0\rangle\langle 0| = \begin{bmatrix}1 & 0 \\ 0 & 0 \end{bmatrix},|1\rangle\langle 1| = \begin{bmatrix}0 & 0 \\ 0 & 1 \end{bmatrix},|1\rangle\langle 0| = \begin{bmatrix}0 & 0 \\ 1 & 0 \end{bmatrix}, |0\rangle\langle 1| = \begin{bmatrix}0 & 1 \\ 0 & 0 \end{bmatrix}\tag{1}.$$

This can be verified easily, for example:

zero=[1 ; 0], one=[0; 1]
one*zero'


gives:

ans =
0   0
1   0


So now let's write the matrix as a linear combination of outer products in Dirac notation:

$$\tag{2} \frac{1}{\sqrt{2}}|0\rangle\langle 0 | + \frac{1}{\sqrt{2}}|0\rangle\langle 1 | + \frac{1}{\sqrt{2}}|1\rangle\langle 0 | - \frac{1}{\sqrt{2}}|1\rangle\langle 1 |.$$

This is what you have in your question, especially if you factor out the $$|0\rangle$$ from two terms and $$|1\rangle$$ from the other two terms 😊

• Traditionally (or so I think, correct me if I'm wrong), $|0\rangle$ is $\begin{pmatrix}1\\0\end{pmatrix}$ and $|1\rangle$ is $\begin{pmatrix}0\\1\end{pmatrix}$, while it seems that you've used a reversed convention here. If it's deliberate, I think it could be helpful to state the convention you use at the beginning of your answer if you don't mind! Jan 22 at 8:23
• @TristanNemoz I think you're right but I'm not near a keyboard right now (5:46am in Waterloo!). Feel free to edit the answer. Jan 22 at 10:47