# Can someone show the linear algebra calculations for X, H, and CNOT gates?

I am on Ch.1 of the Mike & Ike book. On page 18, the text shows an X gate that essentially flips the $$\alpha$$ and $$\beta$$ amplitudes. The text shows the $$X$$ matrix but it doesn't show those for alpha and beta. I think the $$\alpha$$ is [1,0] and $$\beta$$ is [0,1], but I don't think that was ever defined or explained anywhere? I don't understand this excerpt from the text:

Notice that the action of the NOT gate is to take the state $$|0\rangle$$ and replace it by the state corresponding to the first column of the matrix $$X$$. Similarly, the state $$|1\rangle$$ is replaced by the sate corresponding to the second column of the matrix $$X$$.

Can someone show me what matrixes are multiplied to make this flip happen? I would accept hand drawings!

I have the same question for the H and the CNOT gates - the matrices are shown on pages 19 and 21, but not the multiplication of matrices.

I'm refreshing on linear algebra, so please excuse me!

Thanks in advance for any help or guidance.

Yogesh

A quantum bit can be represented by a two-level quantum mechanical system, and described by a state vector in two-dimensional Hilbert space. Traditionally, Dirac, or bra-ket notation has been used to represent them. The two computational basis states are therefore often written as |0〉 and |1〉 (pronounced: 'ket 0' and 'ket 1' respectively). A pure qubit state is a linear superposition of the two states. This means that such a qubit can be represented as: |ψ〉 = α|0〉 + β |1〉 or as $$\begin{bmatrix} α \\ β \end{bmatrix}$$ where α and β are probability amplitudes and are in general complex numbers. When a qubit is measured in the standard basis, the probability that the outcome is |0〉 is $$|α|^2$$ and the probability that the outcome is |1〉 is $$|β|^2$$. As the absolute squares of the amplitudes represent probabilities, therefore α and β are constrained by the following equation: $$|α|^2$$ + $$|β|^2$$ = 1

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

|ψ'〉 = X|ψ〉 = $$\begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}\begin{bmatrix} α \\ β \end{bmatrix} = \begin{bmatrix} 0*α + 1*β \\ 1*α + 0*β \end{bmatrix} = \begin{bmatrix} β \\ α \end{bmatrix}$$

Now |0〉 is $$\begin{bmatrix} 1 \\ 0 \end{bmatrix}$$

and |1〉 is $$\begin{bmatrix} 0 \\ 1 \end{bmatrix}$$

|1〉 = X|0〉 = $$\begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}\begin{bmatrix} 1 \\ 0 \end{bmatrix} = \begin{bmatrix} 0*1 + 1*0 \\ 1*1 + 0*0 \end{bmatrix} = \begin{bmatrix} 0 \\ 1 \end{bmatrix}$$

|0〉 = X|1〉 = $$\begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}\begin{bmatrix} 0 \\ 1 \end{bmatrix} = \begin{bmatrix} 0*0 + 1*1 \\ 1*0 + 0*1 \end{bmatrix} = \begin{bmatrix} 1 \\ 0 \end{bmatrix}$$

Similarly for H = $$\begin{bmatrix} \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \\ \frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}} \end{bmatrix}$$

|ψ'〉 = H|ψ〉 = $$\begin{bmatrix} \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \\ \frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}} \end{bmatrix}\begin{bmatrix} α \\ β \end{bmatrix} = \begin{bmatrix} \frac{1}{\sqrt{2}}*α + \frac{1}{\sqrt{2}}*β \\ \frac{1}{\sqrt{2}}*α -\frac{1}{\sqrt{2}}*β \end{bmatrix} = \begin{bmatrix} \frac{α + β}{\sqrt{2}} \\ \frac{α - β}{\sqrt{2}} \end{bmatrix}$$

Now |0〉 is $$\begin{bmatrix} 1 \\ 0 \end{bmatrix}$$

and |1〉 is $$\begin{bmatrix} 0 \\ 1 \end{bmatrix}$$

H|0〉 = $$\begin{bmatrix} \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \\ \frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}} \end{bmatrix}\begin{bmatrix} 1 \\ 0 \end{bmatrix} = \begin{bmatrix} \frac{1}{\sqrt{2}}*1 + \frac{1}{\sqrt{2}}*0 \\ \frac{1}{\sqrt{2}}*1 -\frac{1}{\sqrt{2}}*0 \end{bmatrix} = \begin{bmatrix} \frac{1}{\sqrt{2}} \\ \frac{1 }{\sqrt{2}} \end{bmatrix}$$ = $$\frac{1}{\sqrt{2}}$$[|0〉 + |1〉]

H|1〉 = $$\begin{bmatrix} \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \\ \frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}} \end{bmatrix}\begin{bmatrix} 0 \\ 1 \end{bmatrix} = \begin{bmatrix} \frac{1}{\sqrt{2}}*0 + \frac{1}{\sqrt{2}}*1 \\ \frac{1}{\sqrt{2}}*0 -\frac{1}{\sqrt{2}}*1 \end{bmatrix} = \begin{bmatrix} \frac{1}{\sqrt{2}} \\ -\frac{1 }{\sqrt{2}} \end{bmatrix}$$ =$$\frac{1}{\sqrt{2}}$$[|0〉 - |1〉]

CNOT is a two qubit gate so matrix representation is 4 X 4

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

and lets define |$$\phi$$〉 = (α|0〉 + β|1〉) ⊗ ( б|0〉 + η|1〉) = $$\begin{bmatrix} \alpha_1 \\ \alpha_2 \\ \alpha_3 \\ \alpha_4 \end{bmatrix}$$ where $$|α|^2$$ + $$|β|^2$$ = 1 and $$|б|^2$$ + $$|η|^2$$ = 1

|$$\phi$$〉 = $$α_1|00〉 + α_2|01〉 + α_3|10〉 + α_4|11〉$$
where $$|α_1|^2$$ + $$|α_2|^2$$ + $$|α_3|^2$$ + $$|α_4|^2$$ = 1.

$$α_1 = α ⊗ б$$ $$α_2 = α ⊗ η$$ $$α_3 = β ⊗ б$$ $$α_4 = β ⊗ η$$

|$$\phi'$$〉 = CNOT|$$\phi$$〉 = $$\begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{bmatrix}\begin{bmatrix} \alpha_1 \\ \alpha_2 \\ \alpha_4 \\ \alpha_4 \end{bmatrix} = \begin{bmatrix} \alpha_1 \\ \alpha_2 \\ \alpha_3 \\ \alpha_3 \end{bmatrix} = \begin{bmatrix} \alpha_1 \\ \alpha_2 \\ \alpha_4 \\ \alpha_4 \end{bmatrix} = \begin{bmatrix} α ⊗ б \\ α ⊗ η \\ β ⊗ б \\ β ⊗ η \end{bmatrix}$$

Now when α = 1, there is no change in the state of second qubit, however, when β = 1 then the state of second qubit is flipped. It is easy to understand when α, β, б and η are either 0 or 1 but not otherwise. CNOT gate is one of the fundamental entangling gates. so if you have difficulty then I can elaborate further. I hope it helps...

• Thank you Ashish, this is a very helpful answer! I have a question about this piece: H|0〉 = ⎡⎣12√12√12√−12√⎤⎦[10]=⎡⎣12√∗1+12√∗012√∗1−12√∗0⎤⎦=⎡⎣12√12√⎤⎦ = 12√[|0〉 + |1〉]. How does the|1〉 state come in at the very end of this? That part doesn't yet make sense to me since this is a H on the |0〉 state? I know I will probably have questions on the CNOT gate as well, I just need some time to think about that. Can I email you? My email is yogesh.riyat@gmail.com – Yogesh Riyat Sep 14 '19 at 0:52
• @YogeshRiyat, That's a good question, which shows that you are inquisitive and interested rather than being a rote learner. A single qubit can be represented on a Bloch Sphere as a unit vector comprising of two basis states |0〉 and |1〉, so application of any unitary gate is a rotation of the unit vector on Bloch Sphere. So even though amplitude of |1〉 be zero but when H gate is applied on |0〉, it is confined to move towards |1〉 only, it has no other place to go in Hilbert Space. Its like hand of a wall clock, if its going to rotate, it has to point to a mark on the scale. I hope it helps. – Ashish Sep 14 '19 at 11:54
• Hi, Ashish. Welcome to Quantum Computing SE! Please use proper LaTeX formatting in your answers. – Sanchayan Dutta Sep 29 '19 at 9:57
• @SanchayanDutta, thanks for the suggestion. It would be of great help if you could point out the specific mistakes. – Ashish Sep 29 '19 at 14:26
• @Ashish The first step would be avoid using Unicode characters in mathematical expressions. It looks terrible. For instance, use $\alpha$. – Sanchayan Dutta Sep 29 '19 at 14:43