## Difference between R1 and Rz gate in quantum computing

In this post we will have a look at the subtle difference between two single qubit rotation gates – Rz and R1. Q# distinguishes between them, and the are de facto the same, yet differ in a very subtle way.

### Exploring the difference with Q

First, let us have a look at the matrix representation of both gates Rz and R1.

$$R_z^{\varphi}=\begin{bmatrix} e^{-i\frac{\varphi}{2}} & 0 \\ 0 & e^{i\frac{\varphi}{2}} \end{bmatrix}$$

$$R1^{\varphi}=\begin{bmatrix} 1 & 0 \\ 0 & e^{i\varphi} \end{bmatrix}$$

These are gates that change the phase of the qubit by $\varphi$. In either case, $0 \leq \varphi \lt 2\pi$.

While the first form Rz is most commonly used in the field, some literature uses the R1 matrix representation as well, confusingly referring to it as Rz as well. The major difference that can be seen here is that while Rz performs a rotation about the z-axis by a given angle $\theta$, the R1 transformation rotates about the $\ket{1}$ state.

Consider now the commonly used gates I, S and Z

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

$$S=\begin{bmatrix} 1 & 0 \\ 0 & i \end{bmatrix} \\$$

$$Z=\begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}$$

We can immediately see here that because

$$e^{i0} = 0$$

$$e^{\frac{{\pi}i}{2}} = i$$

$$e^{i\pi} = -1$$

we can use R1 with angles $\varphi = 0$, $\varphi = \frac{\pi}{2}$ and $\varphi = \pi$ to construct those I, S and Z gates respectively.

$$R1^0 = I$$

$$R1^{\frac{{\pi}}{2}} = S$$

$$R1^{\pi} = Z$$

The difference between the two gates becomes apparent once we try to construct these three gates out of Rz gate. For example trying to create S out of Rz, we arrive at:

$$Rz^{\frac{{\pi}}{2}}=e^{-i\frac{\pi}{4}}\begin{bmatrix} e^{-i\frac{\pi}{4}} & 0 \\ 0 & e^{i\frac{\pi}{4}} \end{bmatrix} = \begin{bmatrix} 1 & 0 \\ 0 & e^{\frac{{\pi}i}{2}} \end{bmatrix} = S$$

This is also a reason why the S gate is referred to as $\frac{\pi}{4}$-gate, even though the "regular" S matrix contains $e^{\frac{{\pi}i}{2}}$.

One final thing worth noting is that many of the built-in algorithmic features of Q#, such as phase estimation, use R1 internally. If you construct the same feature manually using Rz you will arrive at the same results, but with a different global phase. In the end, we can say that Rz and R1 are equivalent, with the global phase offset of $e^{-i\frac{\pi}{2}}$.

$$R1^{\varphi}=\begin{bmatrix} 1 & 0 \\ 0 & e^{i\varphi} \end{bmatrix} = e^{-i\frac{\varphi}{2}}R_z^{\varphi}$$