Lesson 2 of 15

Rotation Gates Rx, Ry, Rz

Rotation Gates

The rotation gates RxR_x, RyR_y, and RzR_z rotate the qubit state around the X, Y, and Z axes of the Bloch sphere by an angle θ\theta.

Rx Gate

Rx(θ)=(cosθ2isinθ2isinθ2cosθ2)R_x(\theta) = \begin{pmatrix} \cos\frac{\theta}{2} & -i\sin\frac{\theta}{2} \\ -i\sin\frac{\theta}{2} & \cos\frac{\theta}{2} \end{pmatrix}

Applied to [α,β][\alpha, \beta]:

Rx(θ)[α,β]=[cosθ2αisinθ2β, isinθ2α+cosθ2β]R_x(\theta)[\alpha, \beta] = \left[\cos\tfrac{\theta}{2}\,\alpha - i\sin\tfrac{\theta}{2}\,\beta,\ -i\sin\tfrac{\theta}{2}\,\alpha + \cos\tfrac{\theta}{2}\,\beta\right]

Ry Gate

Ry(θ)=(cosθ2sinθ2sinθ2cosθ2)R_y(\theta) = \begin{pmatrix} \cos\frac{\theta}{2} & -\sin\frac{\theta}{2} \\ \sin\frac{\theta}{2} & \cos\frac{\theta}{2} \end{pmatrix}

Applied to [α,β][\alpha, \beta]:

Ry(θ)[α,β]=[cosθ2αsinθ2β, sinθ2α+cosθ2β]R_y(\theta)[\alpha, \beta] = \left[\cos\tfrac{\theta}{2}\,\alpha - \sin\tfrac{\theta}{2}\,\beta,\ \sin\tfrac{\theta}{2}\,\alpha + \cos\tfrac{\theta}{2}\,\beta\right]

Rz Gate

Rz(θ)=(eiθ/200eiθ/2)R_z(\theta) = \begin{pmatrix} e^{-i\theta/2} & 0 \\ 0 & e^{i\theta/2} \end{pmatrix}

Applied to [α,β][\alpha, \beta]:

Rz(θ)[α,β]=[eiθ/2α, eiθ/2β]R_z(\theta)[\alpha, \beta] = \left[e^{-i\theta/2}\,\alpha,\ e^{i\theta/2}\,\beta\right]

Special Cases

At θ=π\theta = \pi, these gates recover familiar Pauli gates (up to global phase):

  • Rx(π)XR_x(\pi) \propto X (bit flip with imaginary phase)
  • Ry(π)YR_y(\pi) \propto Y (bit flip, real entries)
  • Rz(π)ZR_z(\pi) \propto Z (phase flip, no amplitude change)

Note that RzR_z only changes phases, never measurement probabilities.

Implementation

import cmath, math

def rx(theta, state):
    c = math.cos(theta / 2)
    s = math.sin(theta / 2)
    return [
        c * complex(state[0]) + (-1j * s) * complex(state[1]),
        (-1j * s) * complex(state[0]) + c * complex(state[1])
    ]

def ry(theta, state):
    c = math.cos(theta / 2)
    s = math.sin(theta / 2)
    return [
        c * complex(state[0]) + (-s) * complex(state[1]),
        s * complex(state[0]) + c * complex(state[1])
    ]

def rz(theta, state):
    return [
        cmath.exp(-1j * theta / 2) * complex(state[0]),
        cmath.exp(1j * theta / 2) * complex(state[1])
    ]

Your Task

Implement rx(theta, state), ry(theta, state), and rz(theta, state).

Python runtime loading...
Loading...
Click "Run" to execute your code.