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.
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
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:
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}}$.