# What is the general matrix for the Swap gate?

In section 3.3.2 of this PDF, The general SWAP gate is defined as

$$S (\alpha, \hat{y}) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos(\alpha/2) & -\sin(\alpha/2) & 0 \\ 0 & \sin(\alpha/2) & \cos(\alpha/2) & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix}$$

The same lecture notes claim that for $$\alpha = \pi$$, you get the SWAP gate. This is not correct if we perform the computation.

$$S (\pi, \hat{y}) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & -1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix}$$

Those lecture notes also say the square root of SWAP can be created by setting $$\alpha=\frac{\pi}{2}$$. When we do that we get

$$S (\frac{\pi}{2}, \hat{y}) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}} & 0 \\ 0 & \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix}$$

The matrix for the square root of Swap is $$\begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \frac{1}{{2}} (1+i) & \frac{1}{{2}} (1-i) & 0 \\ 0 & \frac{1}{{2}} (1-i) & \frac{1}{{2}} (1+i) & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix}$$

This is not the same matrix as the one we get when we use the general SWAP matrix. Is the matrix for the general SWAP from those lecture notes correct? I haven't been able to find another source to cross-reference.

• Swap should have a +1 not a -1. Those lecture notes are defining something else, but it doesn't deserve to be called swap. Feb 19, 2020 at 23:05
• Yup. Just edited my question based on your comment. Thanks. Feb 20, 2020 at 0:09

A gate $$S (\alpha, \hat{y})$$ implements this circuit:

Here is an example of code for $$\alpha = \pi/4$$ (other parameters of $$U3$$ have to be set as stated):

cx q[1], q[0];
cu3(pi/4,-pi,pi) q[0],q[1];
cx q[1], q[0];


Setting $$\alpha = \pi$$ leads to something similar to swap gate up to a phase for input $$|10\rangle$$ in which case $$-|01\rangle$$ is returned.

• Sure. I said something similar in my question: "The same lecture notes claim that for $\alpha = \pi$, you get the SWAP gate. This is not correct if we perform the computation. $S (\pi, \hat{y}) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & -1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix}$". Now that we've established that those notes are not completely accurate. What is the matrix that is similar to the one the lecture notes claim but would give us the right SWAP matrix and the right square root of SWAP based on the inputs given? Feb 20, 2020 at 16:00
• @VictoryOmole: It is possible only in case you can set inputs of $C-U3$ to get $CNOT$. But if you change other parameter than $\theta$, you will not be implement matrix $S(\alpha, \hat{y})$. So, it seems to me impossible to do so. Feb 20, 2020 at 16:41