# How is $X^q$ equal to $RX(\pi q)$?

I've seen in google cirq that a $$X^q$$ gate is converted in openqasm to $$RX(\pi q)$$, why is that?

Same for $$S^q$$ into $$RZ(\pi q/2)$$.

• Could you define the gates more specifiaclly? Or at least give a reference for where you have seen those conversions? I think that should be helpful to answer your question. Commented Feb 27, 2019 at 13:53

Note that $$RX(\phi) = \begin{pmatrix} \cos(\phi/2) & -i\sin(\phi/2) \\-isin(\phi/2) & \cos(\phi/2)\end{pmatrix}$$

Then $$RX(\pi q) = \begin{pmatrix} \cos(\pi q/2) & -i\sin(\pi q/2) \\-isin(\pi q/2) & \cos(\pi q/2)\end{pmatrix}.$$

Now, using that $$\cos(\pi k + \pi/2) = 0 = \sin(\pi k)$$ and $$\cos(\pi k) = 1 = \sin(\pi k + \pi/2)$$ for $$k\in \mathbb{Z}$$ and that a global phase does not physically affect the quantum state, we see that for odd $$q$$ we get $$X$$ and for even $$q$$ we get the identity matrix.

We can prove the other equation similarly using $$RZ(\phi) = \begin{pmatrix} e^{-\phi/2} & 0 \\ 0 & e^{\phi/2} \end{pmatrix}$$

This is the matrix for $$Z^t$$:

$$Z^t = \begin{bmatrix} 1&0\\0&(-1)^t \end{bmatrix} = \begin{bmatrix} 1&0\\0&e^{i \pi t} \end{bmatrix}$$

This is the matrix for $$R_Z(\pi t)$$:

$$R_Z(\pi t) = e^{-iZt/2} = \begin{bmatrix} e^{-i \pi t / 2}&0\\0&e^{+i \pi t / 2} \end{bmatrix} = e^{-i \pi t/2} Z^t$$

Which means that

$$Z^t \equiv R_Z(\pi t) \pmod{\text{global phase}}$$

Qiskit doesn't have a concept like $$Z^t$$, but it does have $$R_Z$$, so Cirq relies on this equality-up-to-global-phase and converts from one to the other when producing QASM. The exact same situation repeats with powers of $$X$$ and $$Y$$.

• Thanks ! this is useful, but how can I prove that $$Z^t = \begin{bmatrix} 1&0\\0&(-1)^t \end{bmatrix} = \begin{bmatrix} 1&0\\0&e^{i \pi t} \end{bmatrix}$$ for an arbitrary $$t \in R$$ Commented Feb 27, 2019 at 20:55
• @RedaDrissi $(-1)^t = (e^{\ln -1})^t = (e^{i \pi})^t = e^{i \pi t}$, at least along one of the branches of $(-1)^t$ (it's technically a multivalued function). Commented Feb 27, 2019 at 21:44
• I got that, what I want to know is how to calculate arbitrary powers of unitary gates, so that I may compute powers of matrices of other unitary gates such as Hadamard or SWAP/ISWAP etc Commented Feb 28, 2019 at 8:46
• @RedaDrissi Rule of thumb: to compute f(M) you eigendecompose M into M = sum_k a_k |v_k><v_k| then return sum_k f(a_k) |v_k><v_k|. Commented Feb 28, 2019 at 14:42