Lesson 7 of 15
Quantum Fourier Transform
The Quantum Fourier Transform
The Quantum Fourier Transform (QFT) is the quantum analogue of the Discrete Fourier Transform. It is a unitary operation that maps basis states as:
where for an -qubit system.
For a general superposition , linearity gives the -th output amplitude:
Connection to the Hadamard Gate
For a single qubit (), the QFT is exactly the Hadamard gate :
Applying to gives — equal superposition.
Unitarity
The QFT is unitary: it preserves the norm of the state vector. If , then .
import cmath, math
def qft(state):
N = len(state)
result = []
for k in range(N):
amp = sum(state[j] * cmath.exp(2j * math.pi * j * k / N)
for j in range(N))
result.append(amp / math.sqrt(N))
return result
# QFT on |0⟩ is the Hadamard: each amplitude = 1/√2
result = qft([1.0, 0.0])
print(round(abs(result[0]), 4)) # 0.7071
print(round(abs(result[1]), 4)) # 0.7071
Applications
The QFT is a key subroutine in:
- Shor's algorithm — integer factorization in polynomial time
- Quantum phase estimation — extracting eigenphases of unitary operators
- Hidden subgroup problems — a broad class of quantum speedups
Your Task
Implement qft(state) that takes an -element amplitude list and returns the QFT output as a list of complex amplitudes. Use the formula:
Python runtime loading...
Loading...
Click "Run" to execute your code.