Lesson 6 of 15

Controlled-Phase Gate

The Controlled-Phase Gate CRkCR_k

The controlled-phase gate CRkCR_k is fundamental to the Quantum Fourier Transform. It applies a phase e2πi/2ke^{2\pi i/2^k} to the 11|11\rangle component only, leaving all other basis states unchanged:

CRk=(100001000010000e2πi/2k)CR_k = \begin{pmatrix}1&0&0&0\\0&1&0&0\\0&0&1&0\\0&0&0&e^{2\pi i/2^k}\end{pmatrix}

The state vector for a 2-qubit system is represented as a 4-element list ordered by basis state:

ψ=c0000+c0101+c1010+c1111|\psi\rangle = c_{00}|00\rangle + c_{01}|01\rangle + c_{10}|10\rangle + c_{11}|11\rangle

So the list [c00, c01, c10, c11] maps index 0 → 00|00\rangle, index 1 → 01|01\rangle, index 2 → 10|10\rangle, index 3 → 11|11\rangle.

Special Cases

  • k=1k=1: phase =eiπ=1= e^{i\pi} = -1 (a ZZ gate on the target, conditioned on control)
  • k=2k=2: phase =eiπ/2=i= e^{i\pi/2} = i (the SS gate, conditioned)
  • k=3k=3: phase =eiπ/4=1+i2= e^{i\pi/4} = \frac{1+i}{\sqrt{2}} (the TT gate, conditioned)
import cmath, math

def cphase(k, state):
    phase = cmath.exp(2j * math.pi / (2**k))
    result = list(state)
    result[3] = state[3] * phase
    return result

# k=1 applies e^(iπ) = -1 to |11⟩ amplitude
result = cphase(1, [0, 0, 0, 1.0])
print(round(abs(result[3]), 4))    # 1.0
print(round(result[3].real, 4))    # -1.0

Why CR_k Matters

In the QFT circuit, CRkCR_k gates with increasing kk build up finer phase increments. The kk-th gate contributes a phase of 2π/2k2\pi / 2^k radians, so larger kk values give smaller phase kicks — encoding higher-frequency information into the transform.

Your Task

Implement cphase(k, state) where:

  • k is a positive integer (the phase order)
  • state is a 4-element list representing amplitudes [c00,c01,c10,c11][c_{00}, c_{01}, c_{10}, c_{11}]

The function returns a new list with the 11|11\rangle amplitude multiplied by e2πi/2ke^{2\pi i/2^k}.

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