From the classical Discrete Fourier Transform to its quantum analogue: how the QFT maps amplitudes, how to implement it with H and controlled-phase gates, and why it is exponentially faster than the FFT.
Recalling the Classical Discrete Fourier Transform
Before diving into the quantum version, we need to understand what the Fourier transform does and why it is so useful. The central idea is simple: any signal that oscillates in time can be decomposed into a sum of pure sinusoids at different frequencies. The Fourier transform performs exactly this decomposition.
What is the DFT?
Suppose we have a list of N complex numbers x = (xโ, xโ, โฆ, xNโ1). Think of these as samples of a signal at N equally spaced moments in time. The Discrete Fourier Transform (DFT) converts this time-domain list into a frequency-domain list X = (Xโ, Xโ, โฆ, XNโ1) via:
Why ฯN? The number ฯN = ej2ฯ/N is a complex number sitting on the unit circle at angle 2ฯ/N. Raising it to the power k rotates by k steps of angle 2ฯ/N. For N=2: ฯโ = ejฯ = โ1. For N=4: ฯโ = ejฯ/2 = j. These specific values make the math beautiful.
Matrix form of the DFT
The DFT is a linear transformation, so it can be written as a matrix multiplication. Writing ฯ = ฯN for brevity:
Xโ
Xโ
โฎ
XNโ1
= 1/โN
1
1
1
โฆ
1
1
ฯ
ฯยฒ
โฆ
ฯNโ1
โฎ
โฎ
โฎ
โฑ
โฎ
1
ฯNโ1
ฯ2(Nโ1)
โฆ
ฯ(Nโ1)ยฒ
xโ
xโ
โฎ
xNโ1
Compact form: X = FN ยท x
FN is a unitary matrix! This is why the DFT can be directly implemented as a quantum gate โ unitary matrices are exactly what quantum gates are. The entry at row q, column k is (FN)qk = ฯNkq/โN.
Basis vector notation
Adopting the standard basis vectors uโ = (1,0,โฆ,0)แต, uโ = (0,1,0,โฆ)แต, โฆ, uNโ1 = (0,โฆ,0,1)แต, any vector x can be written as:
Decomposition:
x = ฮฃk=0Nโ1 xk uk and X = ฮฃq=0Nโ1 Xq uq
This notation anticipates the quantum version where uk will become the ket |kโฉ.
Ex 1.1Computing ฯโ
For N = 4, compute ฯโ = ej2ฯ/4 = ejฯ/2. Using Euler's formula ejฮธ = cos ฮธ + j sin ฮธ, what is the value? (Enter as "a+bj")
ฯโ =
ejฯ/2 = cos(ฯ/2) + jยทsin(ฯ/2) = 0 + jยท1 = j
Ex 1.2DFT matrix for N=2
For N = 2 we have ฯโ = ejฯ = โ1. Write out the 2ร2 DFT matrix Fโ = (1/โ2)ยท((1, 1),(1, ฯโ)). What famous quantum gate does Fโ equal?
Fโ =
Fโ = (1/โ2)ยท((1,1),(1,โ1)) = H (Hadamard). The 2-point DFT is exactly the Hadamard gate!
Section 02
The Quantum Fourier Transform
The quantum analogue of the DFT acts on quantum states instead of classical vectors. The key idea is that a quantum state |ฯโฉ is itself a vector of amplitudes โ so the DFT matrix FN can be applied to it directly as a unitary gate.
Definition โ Quantum Fourier Transform
Input state:
|xโฉ = ฮฃk=0Nโ1 xk|kโฉ (amplitudes form the vector x)
QFT action:
QFTN|xโฉ = |Xโฉ = ฮฃq=0Nโ1 Xq|qโฉ where X = FNx
Compact form:
QFTN|ฯโฉ = FN|ฯโฉ
The QFT acts on an n-qubit system with N = 2n.
The circuit representation is:
|ฯโฉ
QFTN
|ฯโฉ = FN|ฯโฉ
n qubits in, n qubits out, N = 2n
Why is this powerful?
Classical DFT: Given a vector of N numbers, the FFT (Fast Fourier Transform) computes the DFT in O(N log N) operations. For N = 2n this is O(nยท2n) โ exponential in the number of bits.
QFT: Computes the same transform using only O(nยฒ) = O((log N)ยฒ) quantum gates โ a double-exponential improvement in terms of the number of bits.
The catch: The QFT computes the DFT of the amplitude vector, but we cannot directly read out all N amplitudes after the QFT โ measuring collapses the state to a single outcome. The power of the QFT emerges when combined cleverly with other operations (like in Shor's algorithm). The QFT is a subroutine, not a standalone tool.
Visualization: a periodic amplitude pattern (left) and its QFT (right). The QFT concentrates amplitude at the frequency of the pattern.
4
Ex 2.1Size of QFT
The QFTN acts on n qubits where N = 2n. If we use n = 3 qubits, what is N?
N =
Ex 2.2Is QFT unitary?
For the QFT to be a valid quantum gate it must be unitary: FNโ FN = I. Given that the rows of FN form an orthonormal set (because different Fourier basis vectors are orthogonal), does this guarantee unitarity? (yes/no)
Yes. A matrix whose rows form an orthonormal set is unitary by definition. The Fourier basis vectors {ej2ฯkq/N/โN} are orthonormal in โN.
Section 03
QFT on Computational Basis States
To understand how to implement the QFT as a circuit, we first compute what it does to a computational basis state |kโฉ. By linearity, once we know this, we know what the QFT does to any state.
Key strategy: It suffices to work out QFT|kโฉ for a generic basis state |kโฉ. By linearity of quantum mechanics, QFT(ฮฃ xk|kโฉ) = ฮฃ xk QFT|kโฉ. So understanding basis states gives us everything.
Computing QFT|kโฉ
The basis state |kโฉ is a vector with a single 1 at position k. Its DFT amplitudes are Xq = (1/โN) ยท ฯNqk, so:
Product form: Writing k in binary as |kโฉ = |knโ1โฆkโkโโฉ and using the binary expansion k = kโ + 2kโ + โฆ + 2nโ1knโ1, the QFT output factors into a tensor product of single-qubit states. This is the crucial insight that makes circuit implementation possible!
Binary representation
Write k in binary: k = kโ + 2kโ + 4kโ + โฆ + 2nโ1knโ1, and represent |kโฉ = |knโ1โฆkโkโโฉ (MSB first). Then:
ฯโโ8k = ejฯk = (โ1)k = (โ1)kโ (only depends on the last bit!)
This is because 8k/16 = k/2, so only the parity of k matters, which is kโ mod 2 = kโ.
Fractional binary notation: Define 0.kโkโ+1โฆknโ1 = kโ/2 + kโ+1/4 + โฆ Then ฯN2jk = ej2ฯยท0.kjkj+1โฆknโ1. The j-th qubit factor only depends on bits kj through knโ1 โ crucially, NOT on the more significant bits!
Ex 3.1Evaluating ฯโ
For N = 8, ฯโ = ej2ฯ/8 = ejฯ/4. Using cos(ฯ/4) = sin(ฯ/4) = 1/โ2, write ฯโ in rectangular form a + bj.
For N = 8, compute ฯโ4k. Recall ฯโ = ejฯ/4 so ฯโ4 = ejฯ = โ1. Therefore ฯโ4k = (โ1)k. In binary k = kโ + 2kโ + 4kโ, which single bit determines (โ1)k?
The bit is:
(โ1)k = (โ1)kโ+2kโ+4kโ = (โ1)kโยท((โ1)ยฒ)kโยท((โ1)โด)kโ = (โ1)kโยท1ยท1. Only kโ (the least significant bit) matters!
Section 04
QFT Circuit for N = 4 (2 qubits)
Now we build the actual circuit. For N = 4, n = 2 qubits, and k = kโ + 2kโ, we have |kโฉ = |kโkโโฉ. The QFT output factors as:
QFT|kโฉ โ
(|0โฉ + ฯโ2k|1โฉ) โ (|0โฉ + ฯโk|1โฉ)
Step A:
ฯโ2k = (ej2ฯ/4)2k = ejฯk = (โ1)k = (โ1)kโยท((โ1)2)kโ = (โ1)kโ Only depends on kโ!
Step B:
k = kโ + 2kโ, so ฯโk = ฯโkโยทฯโ2kโ = ฯโkโยท(โ1)kโ Depends on both kโ and kโ.
(|0โฉ + (โ1)kโ|1โฉ) โ this is exactly H|kโโฉ!
Hadamard maps |0โฉ โ (|0โฉ+|1โฉ)/โ2 and |1โฉ โ (|0โฉโ|1โฉ)/โ2.
Qubit qโ:
After H on |kโโฉ we get (|0โฉ + (โ1)kโ|1โฉ). We then want to multiply the |1โฉ component by ฯโkโ = jkโ โ but only when kโ = 1. This is a controlled-phase gate!
Definition โ Controlled-Phase Gate ฮฉN
ฮฉN =
1
0
0
ฯN
ฮฉN|0โฉ = |0โฉ, ฮฉN|1โฉ = ฯN|1โฉ
When controlled (applied only when the control qubit is |1โฉ), it multiplies the |1โฉ amplitude by ฯN โ and does nothing if the control is |0โฉ.
Special case: ฮฉโ = S gate (phase gate, adds phase j to |1โฉ). ฮฉโ = Z gate. In general, ฮฉ2k is a controlled rotation of angle 2ฯ/2k around the Z axis.
The N=4 QFT circuit
|kโโฉ
โ
H
|qโโฉ
|kโโฉ
H
ฮฉโ
|qโโฉ
Note: The ฮฉโ gate on wire |kโโฉ is controlled by |kโโฉ (the dot โ above). The output is in reverse order: swap gates are needed if you want |qโโฉ on top.
Step-by-step walkthrough for |kโฉ = |1,1โฉ = |11โฉ (k=3)
Initial:
|kโ=1โฉ|kโ=1โฉ = |1โฉ|1โฉ
H on kโ:
|1โฉ โ H|1โฉ = |1โฉ โ (|0โฉโ|1โฉ)/โ2
Ctrl-ฮฉโ:
Since kโ = 1, apply ฮฉโ to target: |1โฉ โ (|0โฉ โ j|1โฉ)/โ2 (ฮฉโ multiplies |1โฉ by j, leaving |0โฉ unchanged)
The โ symbols indicate control wires coming from above. ฮฉโ = S (phase by j), ฮฉโ = T (phase by ejฯ/4). Output in reverse order.
Recursive structure: Notice that QFTโ contains QFTโ as a sub-circuit! The bottom two wires (|kโโฉ, |kโโฉ) form a QFTโ structure, and then |kโโฉ adds one more stage. In general, QFT2n contains QFT2nโ1 โ this is why the algorithm is efficient.
General pattern for n qubits
For an n-qubit QFT with input |knโ1โฆkโkโโฉ:
Wire j (from top):
receives H, then controlled-ฮฉ4, ฮฉ8, โฆ, ฮฉ2j+1 gates
controlled by wires above (kโ is the topmost control wire)
Phase gates:
ฮฉN where N = 2m means a phase of ฯ2m = ej2ฯ/2m applied to |1โฉ
Ex 5.1Identifying ฮฉโ = S gate
The gate ฮฉโ applies phase ฯโ = j to |1โฉ. What standard single-qubit gate has matrix diag(1, j) and therefore equals ฮฉโ?
Gate =
The S gate (phase gate) has matrix diag(1, j) = diag(1, ฯโ). So ฮฉโ = S.
Ex 5.2Identifying ฮฉโ = T gate
Similarly, ฮฉโ applies phase ฯโ = ejฯ/4 to |1โฉ. What standard gate equals ฮฉโ? (Hint: look at the T (ฯ/8) gate from the earlier notes.)
Gate =
The T gate (ฯ/8 gate) has matrix diag(1, ejฯ/4) = diag(1, ฯโ). So ฮฉโ = T.
Section 06
Complexity of the QFT
The QFT's exponential speedup over the classical FFT is one of the most striking results in quantum computing. Let us count the gates precisely.
n ยท 2n vs nยฒ โ exponential speedup!
For n = 1000 (an RSA-like problem): 1000 ร 2ยนโฐโฐโฐ vs 10โถ gates
Complexity comparison: QFT gates (blue, nยฒ) vs FFT operations (red, nยท2โฟ). Drag the slider to see the gap grow.
5
Important caveat: Despite its O(nยฒ) gate complexity, the QFT does not directly give exponential speedup over FFT for all tasks. Why? Because after the QFT, measuring the state gives only a single random sample from the output distribution โ not all N amplitudes simultaneously. The QFT only provides a speedup when used as a subroutine in a cleverly designed algorithm (like Shor's period-finding) where a single sample is enough.
Ex 6.1Gate count for n=4
For n = 4 qubits (N = 16), how many total gates (H + controlled-ฮฉ) does the QFT require?