# What does it mean to express a gate in Dirac notation?

When discussing the Dirac notation of an operator, for example, let's just say we have the bit flip gate $$X$$ if we want to write this in the Dirac notation does that just mean writing it as follows?

$$X|\psi\rangle=X(c_0|0\rangle+c_1|1\rangle)=c_0|1\rangle+c_1|0\rangle$$

The Dirac notation for the Pauli-$$X$$ gate is:

$$|1\rangle \langle0| + |0\rangle \langle1|.$$

Now you might be wondering where this comes from. The term you're looking for is outer product representation of the $$X$$ gate. It follows from the spectral decomposition theorem (check Nielsen & Chuang 10th edition, p. 72) which holds for all normal operators. The key point:

In terms of the outer product representation, this means that $$M$$ can be written as $$M=\sum_i\lambda_i|i\rangle\langle i|$$,where $$\lambda_i$$ are the eigenvalues of $$M$$,$$|i\rangle$$ is an orthonormal basis for $$V$$, and each $$|i\rangle$$ an eigenvector of $$M$$ with eigenvalue $$\lambda_i$$.

The eigenvectors of the Pauli-$$X$$ gate are $$-|0\rangle+|1\rangle$$ and $$|0\rangle+|1\rangle$$, and the corresponding eigenvalues are $$-1$$ and $$+1$$ cf. Wolfram Alpha. Normalize the eigenvectors to get an orthonormal basis for $$X$$ i.e. $$\{\frac{-|0\rangle+|1\rangle}{\sqrt{2}},\frac{|0\rangle+|1\rangle}{\sqrt{2}}\}$$. According the spectral decomposition theorem you can represent the $$X$$ gate as:

$$-1(\frac{-|0\rangle+|1\rangle}{\sqrt{2}})(\frac{-\langle 0|+\langle1|}{\sqrt{2}}) + 1(\frac{|0\rangle+|1\rangle}{\sqrt{2}})(\frac{\langle 0|+\langle1|}{\sqrt{2}})$$ $$=-\frac{1}{2}(|0\rangle\langle0|-|0\rangle\langle1|-|1\rangle\langle0|+|1\rangle\langle1|)+\frac{1}{2}(|0\rangle\langle0|+|0\rangle\langle1|+|1\rangle\langle0|+|1\rangle\langle1|)$$ $$=|1\rangle \langle0| + |0\rangle \langle1|$$

To convince you that this result is correct let's apply it on an arbitrary qubit state $$c_0|0\rangle+c_1 |1\rangle$$:

$$(|1\rangle \langle0| + |0\rangle \langle1|)(c_0|0\rangle+c_1|1\rangle)$$ $$=c_0|1\rangle\langle0|0\rangle+c_1|0\rangle\langle 1|1\rangle$$ $$=c_0 |1\rangle + c_1 |0\rangle$$

So yes, our result is correct and the bits were indeed flipped upon application of $$X=|1\rangle \langle0| + |0\rangle \langle1|$$ to $$c_0|0\rangle + c_1|1\rangle$$.The last step followed from the fact that $$\langle 0|0\rangle$$ and $$\langle 1|1\rangle$$ are both equal to $$1$$, as $$|0\rangle$$ and $$|1\rangle$$ are orthonormal vectors i.e. their inner product $$\langle \psi|\psi\rangle=1$$ by definition.

We're done. As an exercise, find the outer product representation of the Pauli-$$Z$$ gate by yourself. And definitely, do go through the proof of the spectral theorem in Nielsen and Chung if time permits!

This might mean using the ketbra notation:

$$X = |1\rangle \langle0| + |0\rangle \langle1|$$

This notation describes the effect the operator has on the basis vectors: in this case $$X$$ converts $$|0\rangle$$ into $$|1\rangle$$ and vice versa.

A couple of other examples:

$$Z = |0\rangle \langle0| - |1\rangle \langle1|$$

$$\operatorname{CNOT} = |0 \rangle\langle0| \otimes I + |1 \rangle\langle 1| \otimes X = |00\rangle \langle00| + |01\rangle \langle01| + |11\rangle \langle10| + |10\rangle \langle11|$$

• 0 and 1 in one of the outer products in X-gate should be flipped, I tried editing myself but says "Edits must be at least 6 characters; is there something else to improve in this post?" And I think everything else is perfect, P.S. The accepted answer has same typo, cheers! – Hemant May 1 at 1:32
• @Hemant Fixed, thank you! – Mariia Mykhailova May 1 at 1:53