|q⟩ Bad Qubits

beginner · Programming · Rotation Gates & Universal Single-Qubit Ops

RZ and Phase

Every qubit state can be written as

ψ=α0+β1,|\psi\rangle = \alpha|0\rangle + \beta|1\rangle,

where α\alpha and β\beta are complex numbers. The relative phase between 0|0\rangle and 1|1\rangle is the argument of the ratio β/α\beta/\alpha. Although global phase is unobservable, relative phase is physically meaningful — it determines how states interfere and shapes every quantum algorithm.

The RZ gate

RZ(θ)RZ(\theta) rotates the Bloch sphere about the zz-axis by angle θ\theta. Its matrix is

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

Acting on a general state α0+β1\alpha|0\rangle + \beta|1\rangle, the gate advances the phase of 1|1\rangle by θ\theta relative to 0|0\rangle:

RZ(θ)(α0+β1)=eiθ/2α0+eiθ/2β1.RZ(\theta)\big(\alpha|0\rangle + \beta|1\rangle\big) = e^{-i\theta/2}\alpha|0\rangle + e^{i\theta/2}\beta|1\rangle.

The common factor eiθ/2e^{-i\theta/2} is a global phase and can be dropped; what remains is that 1|1\rangle picks up a factor of eiθe^{i\theta} relative to 0|0\rangle.

A concrete example: RZ(π) on |+⟩

Start with the equal superposition +=12(0+1)|+\rangle = \tfrac{1}{\sqrt{2}}(|0\rangle + |1\rangle) produced by a Hadamard gate. Applying RZ(π)RZ(\pi) gives

RZ(π)+=12(eiπ/20+eiπ/21)=eiπ/22(01).RZ(\pi)|+\rangle = \frac{1}{\sqrt{2}}\big(e^{-i\pi/2}|0\rangle + e^{i\pi/2}|1\rangle\big) = \frac{e^{-i\pi/2}}{\sqrt{2}}\big(|0\rangle - |1\rangle\big).

Dropping the global factor eiπ/2e^{-i\pi/2}, the result is =12(01)|{-}\rangle = \tfrac{1}{\sqrt{2}}(|0\rangle - |1\rangle). The magnitudes of both amplitudes are unchanged — measurement probabilities remain 50/50 — but the sign (phase) of the 1|1\rangle component has flipped.

Connection to Z and S gates

The ZZ gate is a special case: Z=RZ(π)Z = RZ(\pi) up to global phase. Similarly, S=RZ(π/2)S = RZ(\pi/2) and T=RZ(π/4)T = RZ(\pi/4). The parameterized family RZ(θ)RZ(\theta) generalizes all of them to arbitrary angles, giving you precise control over the phase between 0|0\rangle and 1|1\rangle.

Try it

Prepare the +|+\rangle state with a Hadamard, then apply RZ(π)RZ(\pi) to flip the relative phase and reach |{-}\rangle. The grader checks the full state vector.

Run your code to see the quantum state.

After running, inspect the amplitudes: both should have magnitude 0.707\approx 0.707. The simulator displays the raw statevector 12(i0+i1)\tfrac{1}{\sqrt{2}}(-i|0\rangle + i|1\rangle), which equals |{-}\rangle up to the global factor eiπ/2=ie^{-i\pi/2} = -i. The relative phase between the two amplitudes is π\pi — that is the relative phase in action.

Sign in on the full site to ask questions and join the discussion.