# How to translate CNOT gate by Hadamard and Pauli Z gate in matrix form?

I am trying to understand how CNOT or X gate can be explained by even more basic gates.

I went through these 2 links that explained the relation, but for my understanding, I am trying to prove it by matrix form. And yes I am clearly disabled in mathematics. So, let's take the case where first Qbit(Q1) is the control and the second Qbit(Q2) is the target.

As per the articles, CNOT can be explained by $$(I\times H)\cdot Z\cdot(I\times H)$$. where X is matrix multiplication and (.) refers to dot product.

So, I went on to first convert all of them to the matrix Step 1:

$$\left(\begin{bmatrix}1 & 0\\0 & 1\end{bmatrix}\times{1\over\sqrt2}\begin{bmatrix}1 & 1\\1 & -1\end{bmatrix}\right)\cdot\begin{bmatrix}1 & 0\\0 & -1\end{bmatrix}\cdot\left(\begin{bmatrix}1 & 0\\0 & 1\end{bmatrix}\times{1\over\sqrt2}\begin{bmatrix}1 & 1\\1 & -1\end{bmatrix}\right)$$

I have my doubts if this understanding itself is correct but let's continue hoping it is.

Step 2: $$\left({1\over\sqrt2}\begin{bmatrix}1 & 1 & 0 & 0\\1 & -1 & 0 & 0\\0 & 0 & 1 & 1\\0 & 0 & 1 & -1 \end{bmatrix}\right)\cdot\begin{bmatrix}1 & 0\\0 & -1\end{bmatrix}\cdot\left({1\over\sqrt2}\begin{bmatrix}1 & 1 & 0 & 0\\1 & -1 & 0 & 0\\0 & 0 & 1 & 1\\0 & 0 & 1 & -1 \end{bmatrix}\right)$$

Does this approach look right? if so, how should I approach further? if not what am I missing?

I even tried to take a smaller bit to solve and tried to solve this:

$$X = H\cdot Z \cdot H$$

Step 1: $$X = {1\over\sqrt2}\begin{bmatrix}1 & 1\\1 & -1\end{bmatrix}\cdot \begin{bmatrix}1 & 0\\0 & -1\end{bmatrix} \cdot {1\over\sqrt2}\begin{bmatrix}1 & 1\\1 & -1\end{bmatrix}$$

Step 2: $$X = {1\over2}\begin{bmatrix} 1*1 & 1*0 \\ 1*0 & -1*-1\end{bmatrix}\cdot \begin{bmatrix}1 & 1 \\ 1 & -1\end{bmatrix}$$

Step 3: $$X = {1\over2}\begin{bmatrix} 1 & 0 \\ 0 & 1\end{bmatrix}\cdot \begin{bmatrix}1 & 1 \\ 1 & -1\end{bmatrix}$$

Step 4: $$X = {1\over2}\begin{bmatrix} 1*1 & 0*1 \\ 0*1 & 1*-1\end{bmatrix}$$

Step 5: $$X = {1\over2}\begin{bmatrix} 1 & 0 \\ 0 & -1\end{bmatrix}$$

once again, this is not Pauli-X gate, so I must be doing something stupid. Please help and guide me.

• For starters, your matrix multiplication in going from step 1 to step 2 (in the 5 step sequence) is incorrect. Nov 22, 2019 at 14:47
• $CNOT$ gate can't be 'explained' by more basic gates; you can't 'translate' $CNOT$ gate by Hadamard and Pauli $Z$ gate; you need 2 Hadamard and $CZ$ gate to construct $CNOT$, and $CZ$ is not more basic than $CNOT$. Nov 22, 2019 at 15:06
• So, we can get the same output from |00>,|01>,|10> or |11> by either running it through a single CNOT configuration or by running then by the $(I\times H)\cdot Z\cdot(I\times H)$ configuration? Is that a correct understanding? Nov 22, 2019 at 15:34
• @DaftWullie : I was trying to perform a dot multiplication, If you can help me with a hint what I did wrong/ or even the correct term of the operation I should be using, i can google it and look it up. Nov 22, 2019 at 15:41
• You're supposed to be doing a matrix multiplication, which is not the same thing as multiplying corresponding pairs of elements together. Nov 22, 2019 at 16:26

I think you have a slight misunderstanding of what the $$Z$$ gate in the screenshot you attached is. It is, in fact, not a Z gate, but a (2-qubit) $$CZ$$ or controlled-$$Z$$. gate, also referred to as a controlled-phase gate (because the $$Z$$ operation is a flip of the phase of the $$|1\rangle$$ state).
This $$CZ$$ gate is a lot like the $$CX$$ gate, however, it performs a $$Z$$ operation on the second qubit, but only if the state of the first qubit is $$|1\rangle$$ state. If the first is in the $$|0\rangle$$ state it performs nothing (i.e. $$I$$ operation) on the second qubit instead.
In more technical terms, we can write thus: $$\begin{equation} CZ = |0\rangle \langle0| \otimes I + |1\rangle \langle1| \otimes Z. \end{equation}$$
Then: $$\begin{equation} (I \otimes H) CZ(I\otimes H) = |0\rangle \langle0| \otimes HIH + |1\rangle \langle1| \otimes HZH. \end{equation}$$
We can simplify the $$HIH$$ term easily: $$HIH = HH = I$$, from the properties of $$I$$ and $$H$$. The $$HZH$$ term is actually equal to $$X$$: $$\begin{equation} \begin{split} HZH &= \frac{1}{2}\begin{bmatrix}1 & 1 \\ 1 & -1\end{bmatrix}\begin{bmatrix}1 & 0 \\ 0 & -1\end{bmatrix}\begin{bmatrix}1 & 1 \\ 1 & -1\end{bmatrix}\\ &= \frac{1}{2}\begin{bmatrix}1 & -1 \\ 1 & 1\end{bmatrix}\begin{bmatrix}1 & 1 \\ 1 & -1\end{bmatrix} \\ &= \frac{1}{2}\begin{bmatrix}0 & 2 \\ 2 & 0\end{bmatrix}\\ &= \begin{bmatrix}0 & 1 \\ 1 & 0\end{bmatrix} = X. \end{split} \end{equation}$$ So we can write: $$\begin{equation} (I \otimes H) CZ(I\otimes H) = |0\rangle \langle0| \otimes HIH + |1\rangle \langle1| \otimes HZH = |0\rangle \langle0| \otimes I + |1\rangle \langle1| \otimes X. \end{equation}$$ That is to say, an operation that performs the $$X$$ operation on the second qubit if the first qubit is in the $$|1\rangle$$ state (and nothing if the first qubit is in the $$|0\rangle$$ state). This is, of course, exactly the $$CX$$ gate which we are looking for.