# Example of Quantum Fourier Computation for three qubits

I am currently going through Nielsen's QC bible and having still some foundational / conceptual problems with the matter.

I have tried to retrieve this $8 {\times} 8$ matrix describing the QFT of 3 qubits via Kronecker product in various attempts.

Hadamard transform can be decomposed into $H \otimes 1 \otimes 1$, and the others are fundamentally kronecker products of the 4x4 matrices of S resp. T with the 2x2 identity.

Whats wrong with my approach?

EDIT:

$T\text{=}\left( \begin{array}{cccccccc} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & e^{\frac{\pi i}{4}} & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & e^{\frac{\pi i}{4}} \\ \end{array} \right)$

which is derived from $R_k = \left( \begin{array}{cc} 1 & 0 \\ 0 & e^{2 i \pi /2^k} \\ \end{array} \right)$, being $S$ for $k=1$ and $T$ for $k=2$.

EDIT 2:

The controlled T-operation can be represented in computational basis as

$\left( \begin{array}{cccc} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & e^{2 \pi i / 2^k } \\ \end{array} \right)$.

EDIT 3:

In mathematica, one faulty calculation of mine is:

$\text{SWAP}\text{=}\left( \begin{array}{cccccccc} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ \end{array} \right)$

SWAP*KroneckerProduct[IdentityMatrix[2], IdentityMatrix[2], H]KroneckerProduct[IdentityMatrix[2], S] KroneckerProduct[ IdentityMatrix[2], H, IdentityMatrix[2]] * T KroneckerProduct[S, IdentityMatrix[2]] KroneckerProduct[H, IdentityMatrix[2], IdentityMatrix[2]] // MatrixForm

which gives:

$\left( \begin{array}{cccccccc} \frac{1}{2 \sqrt{2}} & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & -\frac{1}{2 \sqrt{2}} & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & \frac{e^{\frac{i \pi }{2}}}{2 \sqrt{2}} & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & -\frac{e^{\frac{i \pi }{2}} i^2}{2 \sqrt{2}} \\ \end{array} \right)$

• when you say "the others are fundamentally kronecker products of the 4x4 matrices of S resp. T with the 2x2 identity", what 8x8 matrix are you using for the controlled-T operation? I suspect if you tell us that, we'll have more hope of identifying your troubles! – DaftWullie May 31 '18 at 14:43
• controlled-$T$ is a $2$-qubit operation, so its matrix should be $4\times 4$. If you want to add the third qubit, then you apply the identity. – Josu Etxezarreta Martinez May 31 '18 at 14:57
• @JosuEtxezarretaMartinez Yes, but in this particular case, that identity has to be added in the middle, not at either end. – DaftWullie May 31 '18 at 15:03
• So, that looks OK. The next things to check are that you're multiplying the matrices together in the right order (remembering the diagram reads left to right, but you multiply matrices right to left). If that's your problem, you'll just have the transpose of what you want – DaftWullie May 31 '18 at 15:13
• You're doing this in Mathematica? Are you really using the * operation (element by element multiplication), rather than matrix multiplication, as given by .? – DaftWullie May 31 '18 at 15:28