# 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? Apr 30, 2019 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) Apr 30, 2019 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$ ? May 1, 2019 at 7:10
• You are welcome! And thanks for pointing out the typo. May 1, 2019 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! May 1, 2019 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. May 1, 2019 at 17:19
• Thanks! Now i get it :) May 1, 2019 at 17:56
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 34, "wp-katex-eq": 0, "align": 0, "equation": 8, "x-ck12": 0, "texerror": 0, "math_score": 0.9985450506210327, "perplexity": 271.52972440017874}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2022-21/segments/1652662543797.61/warc/CC-MAIN-20220522032543-20220522062543-00731.warc.gz"}