|q⟩ Bad Qubits

intermediate · Programming · The Quantum Fourier Transform

The Inverse QFT

The inverse QFT (written QFT\mathrm{QFT}^\dagger or IQFT\mathrm{IQFT}) undoes the quantum Fourier transform. It is an essential building block of quantum phase estimation and Shor's algorithm: after the QFT encodes a phase into register amplitudes, the inverse QFT reads that phase back out as a measurable bit string.

Inverting a unitary circuit

Every quantum gate is unitary, so its inverse is its conjugate transpose. For a product of unitaries the reversal rule is

(U1U2Uk)=UkU2U1.(U_1 U_2 \cdots U_k)^\dagger = U_k^\dagger \cdots U_2^\dagger U_1^\dagger.

To invert a circuit, reverse the gate order and replace each gate with its adjoint. Two useful special cases:

The 3-qubit inverse QFT

Recall the 3-qubit forward QFT (without final bit-reversal SWAPs), with qubit 0 as the most significant bit:

| Step | Gate | |------|------| | 1 | H(q0)H(q_0) | | 2 | CP(π/2),  ctrl=q0,  tgt=q1CP(\pi/2),\; \text{ctrl}=q_0,\; \text{tgt}=q_1 | | 3 | CP(π/4),  ctrl=q0,  tgt=q2CP(\pi/4),\; \text{ctrl}=q_0,\; \text{tgt}=q_2 | | 4 | H(q1)H(q_1) | | 5 | CP(π/2),  ctrl=q1,  tgt=q2CP(\pi/2),\; \text{ctrl}=q_1,\; \text{tgt}=q_2 | | 6 | H(q2)H(q_2) |

Applying the reversal rule gives the inverse QFT:

| Step | Gate | |------|------| | 1 | H(q2)H(q_2) | | 2 | CP(π/2),  ctrl=q1,  tgt=q2CP(-\pi/2),\; \text{ctrl}=q_1,\; \text{tgt}=q_2 | | 3 | H(q1)H(q_1) | | 4 | CP(π/4),  ctrl=q0,  tgt=q2CP(-\pi/4),\; \text{ctrl}=q_0,\; \text{tgt}=q_2 | | 5 | CP(π/2),  ctrl=q0,  tgt=q1CP(-\pi/2),\; \text{ctrl}=q_0,\; \text{tgt}=q_1 | | 6 | H(q0)H(q_0) |

The structure is a mirror image of the forward circuit: the coarsest qubit (q2q_2) is processed first, and the phase rotations go in the negative direction.

Why it matters

In quantum phase estimation, a register is left in a state whose amplitudes encode a phase φ\varphi as e2πikφ/2ne^{2\pi i k \varphi / 2^n} for each basis state k|k\rangle. Applying QFT\mathrm{QFT}^\dagger transforms that "Fourier-encoded" state back to a computational-basis state close to 2nφ|2^n \varphi\rangle, making φ\varphi directly readable by measurement. Without the inverse QFT, the phase information would be locked in the amplitudes and inaccessible.

The gate count of QFT\mathrm{QFT}^\dagger is identical to that of the QFT: nn Hadamards and n(n1)/2n(n-1)/2 controlled-phase gates, totalling O(n2)O(n^2) operations for an nn-qubit register.

Try it

Implement the 3-qubit QFT\mathrm{QFT}^\dagger by reversing the forward QFT's gate sequence and negating all phase angles. The grader checks the full unitary matrix — leaving the circuit empty or incorrect will fail.

Run your code to see the quantum state.

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