# Can Dirac notation be used with 2 or more gates?

Can Dirac notation be used with 2 or more gates?

I've been trying to do the math with the $$X$$ and $$Z$$ ($$X\otimes Z$$) gates but I'm not getting the answer I should. In fact, the answer makes no sense. I'm new, so I'm trying to understand whether or not this notation will work mathematically when combining gates.

It works out fine when using matrix math, so I'm wondering if something like this is a limitation of Dirac notation.

• it absolutely can. "Dirac notation", by which I assume you mean bra-ket notation, is nothing but a convenient way to denote basis elements in the underlying space. Writing something like $|i\rangle$ is equivalent to writing things like $e_i,\vec e_i,{\bf e}_i$, or whatever notation you prefer. Similarly, ket-bras like $|i\rangle\!\langle j|$ are the same as writing matrix components, which you can equivalently denote with $E_{ij}, e_i e_j^\dagger$, or similar notation. Any operator can be decomposed in such a way. Think of these as ways to write matrices focusing on the nonzero elements.
– glS
Jun 6, 2021 at 9:19
• – glS
Jun 6, 2021 at 9:21

Dirac notations, as far as I have seen, concerns quantum states (kets) and their complex conjugates (bras). For gates, you could simply use the capitalized letter that represents the particular gate. For example, $$H$$ for Hadamard gate, $$X$$ for bit flip, and so on. Please note that, when you apply two quantum gates on the same quantum state, the notation looks like the following. If you use $$Z$$ and $$X$$ on some single qubit quantum state $$|\psi\rangle$$, then it should read $$ZX |\psi\rangle$$, not $$(Z \otimes X) |\psi\rangle$$. The $$\otimes$$ sign means a tensor product.

• I see what you're saying, but the qiskit textbook in the chapter multiple qubits and entangled states does use the notation. It shows X⊗H in section 2.
– Doug
Jun 4, 2021 at 3:19
• My apologies, I should have been more precise. The tensor product would imply the gates are being applied on two qubits, not a single qubit. Jun 4, 2021 at 3:24
• of course bra-ket notation works for gates as well. For example, $X=|0\rangle\!\langle1|+|1\rangle\!\langle0|$ and $Z=|0\rangle\!\langle0|-|1\rangle\!\langle1|$
– glS
Jun 6, 2021 at 9:23
• Thanks for your help with. I'm still wrapping my head around this, but it's becoming clearer. Whereas the other answers present beneficial information for a newbie, yours appears to be closest to correct for me. Again, I thank you and the others for the help.
– Doug
Jun 13, 2021 at 16:44

$$X \otimes Z = \begin{pmatrix} 0 & 1\\ 1 & 0 \end{pmatrix} \otimes \begin{pmatrix} 1 & 0\\ 0 & -1 \end{pmatrix} = \begin{pmatrix} 0 \cdot \begin{pmatrix} 1 & 0\\ 0 & -1 \end{pmatrix} & 1\cdot \begin{pmatrix} 1 & 0\\ 0 & -1 \end{pmatrix}\\ 1 \cdot \begin{pmatrix} 1 & 0\\ 0 & -1 \end{pmatrix} & 0 \cdot \begin{pmatrix} 1 & 0\\ 0 & -1 \end{pmatrix} \end{pmatrix} = \begin{pmatrix} 0 & 0 & 1 & 0\\ 0 & 0 & 0 & -1\\ 1 & 0 & 0 & 0\\ 0 & -1 & 0 & 0 \end{pmatrix}$$

Note that here, $$X \otimes Z$$ acts on a two qubits system. For instance, if your two qubits is in the state $$|\psi \rangle = |10\rangle = |1\rangle \otimes |0\rangle$$ then $$(X \otimes Z) |\psi \rangle = \big(X \otimes Z \big) (|1\rangle \otimes |0\rangle) = X|1\rangle \otimes Z|0\rangle = |0\rangle \otimes |0\rangle =|00\rangle$$

This is the same if you have done the matrix multiplication, by first notice that $$|10\rangle = |1\rangle \otimes |0\rangle= \begin{pmatrix} 0 \\ 1 \end{pmatrix} \otimes \begin{pmatrix} 1 \\ 0 \end{pmatrix}= \begin{pmatrix}0 \cdot \begin{pmatrix} 1 \\ 0 \end{pmatrix} \\ 1 \cdot \begin{pmatrix} 1 \\ 0 \end{pmatrix} \end{pmatrix}= \begin{pmatrix}0\\ 0\\ 1\\ 0 \end{pmatrix}$$ then $$(X \otimes Z) |\psi \rangle = \begin{pmatrix} 0 & 0 & 1 & 0\\ 0 & 0 & 0 & -1\\ 1 & 0 & 0 & 0\\ 0 & -1 & 0 & 0 \end{pmatrix} \begin{pmatrix}0\\ 0\\ 1\\ 0 \end{pmatrix} = \begin{pmatrix}1\\ 0\\ 0\\ 0 \end{pmatrix} = |00\rangle$$

How this would appear on the quantum circuit is as follow:

Now, if you consider $$XZ$$, this is not the same as $$X \otimes Z$$ as the other answer by Hasan iqbal mentioned. This is just regular matrix multiplication. That is,

$$X Z = X \cdot Z = \begin{pmatrix} 0 & 1\\ 1 & 0 \end{pmatrix} \cdot\begin{pmatrix} 1 & 0\\ 0 & -1 \end{pmatrix} = \begin{pmatrix} 0 & -1\\ 1 & 0\end{pmatrix}$$

This is a $$2 \times 2$$ matrix, and hence it acts only on a single qubit. So suppose you single qubit system is in the state $$|\psi \rangle = |0 \rangle$$. Then what this does is as follow:

$$(XZ) |0 \rangle = X (Z|0 \rangle) = X(|0\rangle) = |1\rangle$$

How this would appear on the quantum circuit is as follow: