# What is the spectral decomposition of the Pauli $X$ gate?

The definition of spectral decomposition is as follows:

Assume the eigenvectors of $$\hat{A}$$ define a basis $$\beta=\{|\psi_j\rangle\}$$. Then $$A_{kj}=\langle\psi_k|\hat{A}|\psi_j\rangle=\alpha_j\delta_{jk},$$ and $$\hat{A}=\sum_{kj}A_{kj}|\psi_k\rangle\langle\psi_j|=\sum_{j}\alpha_{j}|\psi_j\rangle\langle\psi_j|.$$ But when I try to do this for the bit flip gate $$X$$, it doesn't seem to work. The eigenvectors are $$|0\rangle+|1\rangle$$ and $$|0\rangle-|1\rangle$$. Then if we take

\begin{align} X&=(\langle0|+\langle1|)X(|0\rangle+|1\rangle)\,\,\times\big[(|0\rangle+|1\rangle)(\langle0|+\langle1|)\big] \\ &+(\langle0|-\langle1|)X(|0\rangle-|1\rangle)\,\,\times\big[(|0\rangle-|1\rangle)(\langle0|-\langle1|)\big]. \end{align}

I don't get anything close to the $$X$$ matrix I was looking for. Could anyone please explain this to me?

The eigenvectors are $$|\psi_1 \rangle = \frac{1}{\sqrt 2} (|0\rangle + |1\rangle)$$ and $$|\psi_2 \rangle = \frac{1}{\sqrt 2} (|0\rangle - |1\rangle)$$ (remember to keep them normalized), with eigenvalues $$a_1 = 1$$ and $$a_2 = -1$$, respectively.

Now the spectral decomposition in terms of the outer product representation is:

$$X = a_1 |\psi_1 \rangle \langle \psi_1| + a_2 |\psi_2 \rangle \langle \psi_2| =$$

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

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

The red parts cancel out, so you're left with $$X = |0\rangle\langle1| + |1\rangle\langle0|$$.

Continue simplifying from what you've given

$$\begin{eqnarray*} X&=&(\langle0|+\langle1|)X(|0\rangle+|1\rangle)(|0\rangle+|1\rangle)(\langle0|+\langle1|)\\ &+&(\langle0|-\langle1|)X(|0\rangle-|1\rangle)(|0\rangle-|1\rangle)(\langle0|-\langle1|)\\ (\langle0|+\langle1|)X(|0\rangle+|1\rangle) &=& 0 + 1 + 1 + 0 = 2\\ (|0\rangle+|1\rangle)(\langle0|+\langle1|) &=& | 0 \rangle \langle 0 | + | 1 \rangle \langle 0 | + | 0 \rangle \langle 1 | + | 1 \rangle \langle 1 |\\ (\langle0|-\langle1|)X(|0\rangle-|1\rangle) &=& 0 - 1 - 1 + 0 = -2\\ (|0\rangle-|1\rangle)(\langle0|-\langle1|) &=& | 0 \rangle \langle 0 | - | 1 \rangle \langle 0 | - | 0 \rangle \langle 1 | + | 1 \rangle \langle 1 |\\ X &=& 2 (| 0 \rangle \langle 0 | + | 1 \rangle \langle 0 | + | 0 \rangle \langle 1 | + | 1 \rangle \langle 1 |) \\&+& (-2) ( | 0 \rangle \langle 0 | - | 1 \rangle \langle 0 | - | 0 \rangle \langle 1 | + | 1 \rangle \langle 1 |)\\ X &=& 4 | 1 \rangle \langle 0 | + 4 | 0 \rangle \langle 1 | \end{eqnarray*}$$

But there should be no factor of 4 there. So what was wrong? You didn't normalize your eigenvectors. That means you should divide all your vectors by $$\sqrt{2}$$.

In each of the 2 summands in your expression at the very top, there are 4 vectors. So each summand should be divided by $$(\sqrt{2})^4=4$$. Follow that through and the simplification works and you get $$X=X$$ rather than $$X=4X$$

### TL;DR: You forgot to normalize the eigenvectors!

Your description of the spectral theorem is incomplete; it requires you to use an orthonormal basis i.e. the basis $$\beta=\{|\psi_j\rangle\}$$ must be orthonormal, as I previously discussed here. When normalized, the eigenvectors of the $$X$$ gate form the basis $$\left\{{\frac{|0\rangle+|1\rangle}{\sqrt{2}}},{\frac{|0\rangle-|1\rangle}{\sqrt{2}}}\right\}$$. Now let's evaluate the terms $$\color{red}{\left(\frac{\langle 0|+\langle 1|}{\sqrt{2}}\right)X\left(\frac{|0\rangle+|1\rangle}{\sqrt{2}}\right)}$$ and $$\color{blue}{\left(\frac{\langle 0|-\langle 1|}{\sqrt{2}}\right)X\left(\frac{|0\rangle-|1\rangle}{\sqrt{2}}\right)}$$. These are actually the eigenvalues of $$X$$ corresponding to the two eigenvectors, because if $$|\psi\rangle$$ is a normalized eigenvector (i.e. $$\langle \psi|\psi\rangle = 1$$ ) of $$X$$, and $$\lambda$$ is the corresponding eigenvalue, then $$X|\psi\rangle = \lambda |\psi\rangle \implies \langle \psi|X|\psi\rangle = \langle \psi|\lambda|\psi\rangle= \lambda\langle \psi|\psi\rangle =\lambda.1=\lambda.$$

Now you know that $$X$$ is the "bit-flip" gate, so it performs $$|0\rangle \mapsto |1\rangle$$ and $$|1\rangle\mapsto|0\rangle$$.

$$\therefore \color{red}{\left(\frac{\langle 0|+\langle 1|}{\sqrt{2}}\right)X\left(\frac{|0\rangle+|1\rangle}{\sqrt{2}}\right)} = \left(\frac{\langle 0|+\langle 1|}{\sqrt{2}}\right)\left(\frac{|1\rangle+|0\rangle}{\sqrt{2}}\right)$$ $$=\frac{1}{2}(\langle 0|1\rangle + \langle0|0\rangle+\langle 1|1\rangle + \langle 1|0\rangle)$$ $$=\frac{1}{2}(0+1+1+0)=\color{red}{1} \ (\because \text{|0\rangle and |1\rangle are orthonormal})$$

$$\therefore \color{blue}{\left(\frac{\langle 0|-\langle 1|}{\sqrt{2}}\right)X\left(\frac{|0\rangle-|1\rangle}{\sqrt{2}}\right)} = \left(\frac{\langle 0|-\langle 1|}{\sqrt{2}}\right)\left(\frac{|1\rangle-|0\rangle}{\sqrt{2}}\right)$$ $$=\frac{1}{2}(\langle 0|1\rangle - \langle0|0\rangle-\langle 1|1\rangle + \langle 1|0\rangle)$$ $$=\frac{1}{2}(0-1-1+0)=\color{blue}{-1} \ (\because \text{|0\rangle and |1\rangle are orthonormal})$$

So now according the spectral decomposition theorem you can represent the $$X$$ gate as:

$$\boxed{\color{blue}{-1}\left(\frac{|0\rangle-|1\rangle}{\sqrt{2}}\right)\left(\frac{\langle 0|-\langle1|}{\sqrt{2}}\right) + \color{red}{1}\left(\frac{|0\rangle+|1\rangle}{\sqrt{2}}\right)\left(\frac{\langle 0|+\langle1|}{\sqrt{2}}\right)}\tag{*}\label{*}$$ $$\require{cancel}=-\frac{1}{2}\left(\cancel{|0\rangle\langle0|}-|0\rangle\langle1|-|1\rangle\langle0|+\cancel{|1\rangle\langle1|}\right)+\frac{1}{2}\left(\cancel{|0\rangle\langle0|}+|0\rangle\langle1|+|1\rangle\langle0|+\cancel{|1\rangle\langle1|}\right)$$ $$=\color{green}{|1\rangle \langle0| + |0\rangle \langle1|}$$

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

$$\color{green}{(|1\rangle \langle0| + |0\rangle \langle1|)}(\alpha|0\rangle+\beta|1\rangle)$$ $$=\alpha|1\rangle\langle0|0\rangle+\beta|0\rangle\langle 1|1\rangle$$ $$=\alpha|1\rangle + \beta|0\rangle$$

So yes, the bits $$|0\rangle$$ and $$|1\rangle$$ of $$|\Psi\rangle$$ are flipped and our representation $$\eqref{*}$$ of the $$X$$ gate is indeed correct!