# How to interpret the matrix representation of a quantum gate?

I am trying to understand how the quantum gates work, so I started with the simplest one, the Pauli X gate.

I get that it turns $$|0\rangle$$ into $$|1\rangle$$ and $$|1\rangle$$ to $$|0\rangle$$.

So my question is how do I read its matrix:

$$$$X = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}$$$$

What maps to it?

• Welcome to quantum computing SE! Does this question look like what you want to know? If not, what's the difference between that question (and the answers) and what you're looking for? – Mithrandir24601 Apr 30 '19 at 18:04
• @Mithrandir24601 Thanks for the welcoming. For starters, the question isnt exactly on my experience level! I am only now past getting the besic concepts in QC. So the question and answers are not very related to this(from my POV) – Aleksandar Kostovic Apr 30 '19 at 18:43

Lets understand this first using Bra-Ket notation then we move on to answering : what does a matrix maps by just looking at it.

Lets get some basics out of the way, the vectors $$\vert 0 \rangle$$ and $$\vert 1 \rangle$$ are represented by,

$$$$\vert 0 \rangle = \begin{bmatrix} 1 \\ 0 \end{bmatrix} \ \ \ \ \ \& \ \ \ \vert 1 \rangle = \begin{bmatrix} 0 \\ 1 \end{bmatrix}.$$$$

This implies, $$$$\vert 0 \rangle \langle 1\vert = \begin{bmatrix} 0 & 1 \\ 0 & 0 \end{bmatrix} \ \ \ \ \ \& \ \ \ \vert 1 \rangle \langle 0\vert = \begin{bmatrix} 0 & 0 \\ 1 & 0 \end{bmatrix}.$$$$

Now, I can write my $$X$$ gate as, $$$$X = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix} = \begin{bmatrix} 0 & 1 \\ 0 & 0 \end{bmatrix} + \begin{bmatrix} 0 & 0 \\ 1 & 0 \end{bmatrix} = \vert 0 \rangle \langle 1\vert + \vert 1 \rangle \langle 0\vert .$$$$

The term $$\vert 1 \rangle \langle 0\vert$$ maps $$\vert 0 \rangle \rightarrow \vert 1 \rangle$$, and the term $$\vert 0 \rangle \langle 1\vert$$ maps $$\vert 0 \rangle \rightarrow \vert 1 \rangle$$. You can see this by:

$$$$\left(\vert 0 \rangle \langle 1 \vert\right) \vert 1\rangle = \vert 0 \rangle \ \ \ \ \ \& \ \ \ \left(\vert 1 \rangle \langle 0 \vert\right) \vert 0\rangle = \vert 1 \rangle.$$$$

Given a matix you can always write it in this bra-ket notation, and easily see how it maps.

As you gain experience working with these it is easy to see that a general matrix pictorially can be represented as, $$$$\begin{bmatrix} a & b \\ c & d \end{bmatrix} = \begin{bmatrix} a\vert 0 \rangle\langle 0 \vert & b \vert 0 \rangle\langle 1 \vert \\ c\vert 1 \rangle\langle 0 \vert & d\vert 1 \rangle\langle 1 \vert \end{bmatrix}$$$$ Note the word pictorially, cause the way I wrote it, in standard text it would imply a $$4\times4$$ matrix. Now given a matrix you can easily work out how each of the non-zero term acts on the basis states $$\vert 0 \rangle, \vert 1 \rangle$$ ans see where the matrix maps to.

For example, $$$$Z = \begin{bmatrix}1 & 0 \\ 0 & -1 \end{bmatrix}$$$$ has non-zero terms $$\vert 0 \rangle\langle0 \vert$$ which maps $$\vert 0 \rangle \rightarrow \vert 0 \rangle$$, and $$-\vert 1 \rangle\langle1 \vert$$ which maps $$\vert 1 \rangle \rightarrow -\vert 1 \rangle$$.

Now a homework for you, Understand the mapping of Hadamard gate and then move on to understand $$CNOT$$ gate.

Note: I did not worry about what $$\vert 1 \rangle \langle 0\vert$$ maps $$\vert 1 \rangle$$ to, cause of orthogonality.

EDIT : After writing this I realized maybe you are asking the following

Lets say someone gives you a mapping and ask you to find the matrix that applies the said mapping. Note that $$\vert x \rangle \langle b \vert$$ maps $$\vert b \rangle$$ to $$\vert x \rangle$$. So as an example if one asks you find the matrix that maps $$\vert 0 \rangle \rightarrow (\vert 0 \rangle + \vert 1 \rangle)/\sqrt{2}$$ and $$\vert 1 \rangle \rightarrow (\vert 0 \rangle - \vert 1 \rangle)/\sqrt{2}$$ you can easily write the matrix being

$$\frac{\vert 0 \rangle + \vert 1 \rangle}{\sqrt{2}}\langle 0 \vert + \frac{\vert 0 \rangle - \vert 1 \rangle}{\sqrt{2}}\langle 1 \vert$$

$$=\frac{1}{\sqrt{2}}(\vert 0 \rangle\langle 0 \vert + \vert 0 \rangle\langle 1 \vert + \vert 1 \rangle\langle 0 \vert - \vert 1 \rangle\langle 1 \vert) = \frac{1}{\sqrt{2}}\begin{bmatrix}1 & 1 \\ 1 & -1 \end{bmatrix}$$

• Thank you very much for your answer! Its now pretty clear to me how it all works. BTW, is there an typo when you wrote $d\vert 1 \rangle\langle 01 \vert$ and shouldnt that be $d\vert 1 \rangle\langle 1 \vert$ ? – Aleksandar Kostovic May 1 '19 at 7:10
• You are welcome! And thanks for pointing out the typo. – Hemant May 1 '19 at 8:33
• Hi again, i thought i understood but turns out i dont. So my question is how does this happen: $$\vert 0 \rangle \langle 1\vert = \begin{bmatrix} 0 & 1 \\ 0 & 0 \end{bmatrix} \ \ \ \ \ \& \ \ \ \vert 1 \rangle \langle 0\vert = \begin{bmatrix} 0 & 0 \\ 1 & 0 \end{bmatrix}.$$ how does $\vert 0 \rangle \langle 1\vert$ and $\vert 1 \rangle \langle 0\vert$map to matrix? Thanks! – Aleksandar Kostovic May 1 '19 at 17:11
• @AleksandarKostovic: If you know what column-vectors are represented by $\lvert 0 \rangle$ and $\lvert 1 \rangle$, and you know what row-vectors are represented by $\langle 0 \rvert$ and $\langle 1 \rvert$, then you should be able to see how that works by simple matrix multiplication. There is no mystery in this case --- it's all just basic matrix algebra. – Niel de Beaudrap May 1 '19 at 17:19
• Thanks! Now i get it :) – Aleksandar Kostovic May 1 '19 at 17:56