1
$\begingroup$

I know that SWAP2 (swaps 2 qubits) gate looks like:

$$ SWAP2=\begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} $$

and SWAP3 gate looks like $$ SWAP3=\begin{bmatrix} 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{bmatrix} $$

The question is, how do I generate SWAP of N qubits, SWAPN?
I need this for my Fourier transform algorithm.

$\endgroup$

2 Answers 2

2
$\begingroup$

"SWAPN" isn't something that would be universally understood. But you say you want it for your Fourier Transform algorithm, so by that, I interpret that what you want is: SWAP2(1,N).SWAP2(2,N-1).SWAP2(3,N-2)...., i.e. the pairwise swap between opposite qubits.

It depends on context as to what it is you actually want to write down. For implementing in some sort of quantum circuit, the decompostion into pairwise swaps, as I've just given it, is probably ideal. Your question seems to imply that you want a matrix. In which case, $$ \text{SWAPN}=\sum_{x\in\{0,1\}^N}|x\rangle\langle x^R|, $$ where $x^R$ is just the bit string $x$, reversed.

However, there is a reason why you rarely see the swap gates explicitly written out at the end of the Fourier transform: they're rarely necessary. In many algorithms, you simply measure the qubits at the end. It's much easier to reorder the classical values of the outcomes after the measurement than the quantum state before the measurement. Even if you're not measuring, you're typically doing a sequence like: inverse Fourier transform - diagonal operator - Fourier transform (for example, HHL algorithm). So, you can get rid of the swaps at the end of the IQFT and the start of the QFT by cancelling them and just reordering the elements of the diagonal operator. Since this is usually associated with some sort of classical calculation, it's easily incorporated there.

$\endgroup$
2
  • $\begingroup$ I thought measuring would just collapse the states to one of the bases - |0> or |1> What do you mean by classical values? $\endgroup$
    – Penter Pro
    Dec 10, 2019 at 9:09
  • $\begingroup$ @PenterPro Measuring does do that. But that's what you want to do at the end of a computation. For example, look at the circuits for factoring. You finish with the inverse Fourier transform, and then measure. $\endgroup$
    – DaftWullie
    Dec 10, 2019 at 9:11
6
$\begingroup$

Depends on what you mean by SWAPN, that is what qubits are swapped. Your SWAP3 gate in Dirac notation is $$|000\rangle\langle 000|+|001\rangle\langle100|+|010\rangle\langle010|+|011\rangle\langle110|+|100\rangle\langle001|+|101\rangle\langle101|+|110\rangle\langle011|+|111\rangle\langle111|$$ that is the first and third qubits are swapped; assuming SWAPN means swapping first and N-th qubit, write SWAPN in Dirac notation and then convert it to matrix notation.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.