Interactive Notes ยท Note 05

Quantum Fourier Transform

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.

6 sections 12 exercises Interactive circuit visualizer
Section 01

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:

Definition โ€” DFT
Forward DFT:
Xq = 1/โˆšN ฮฃk=0Nโˆ’1 xk ยท ej2ฯ€kq/N = 1/โˆšN ฮฃk=0Nโˆ’1 xk ยท ฯ‰Nkq

Inverse DFT:
xk = 1/โˆšN ฮฃq=0Nโˆ’1 Xq ยท eโˆ’j2ฯ€kq/N = 1/โˆšN ฮฃq=0Nโˆ’1 Xq ยท ฯ‰Nโˆ’kq

Root of unity:
ฯ‰N = ej2ฯ€/N    (a complex number of modulus 1)
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
111โ€ฆ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")

ฯ‰โ‚„ =
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โ‚‚ =
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)

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:

Step 1:
QFT|kโŸฉ = 1/โˆšN ฮฃq=0Nโˆ’1 ฯ‰Nqk |qโŸฉ
Step 2:
= 1/โˆšN (|0โŸฉ + ฯ‰Nk|1โŸฉ + ฯ‰N2k|2โŸฉ + โ€ฆ + ฯ‰N(Nโˆ’1)k|Nโˆ’1โŸฉ)
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:

Product form:
QFT|kโŸฉ โˆ (|0โŸฉ + ฯ‰Nk|1โŸฉ) โŠ— (|0โŸฉ + ฯ‰N2k|1โŸฉ) โŠ— โ€ฆ โŠ— (|0โŸฉ + ฯ‰N2nโˆ’1k|1โŸฉ)
Why factors?
Each factor (|0โŸฉ + ฯ‰2jk|1โŸฉ) only depends on a few bits of k because ฯ‰2jk = ej2ฯ€ยท2jk/N and higher powers of 2 above N wrap around to 1.

Example: N=16, n=4

For a 4-qubit system N=16, the QFT on |kโŸฉ = |kโ‚ƒkโ‚‚kโ‚kโ‚€โŸฉ gives:

QFT|kโŸฉ โˆ
(|0โŸฉ + ฯ‰โ‚โ‚†8k|1โŸฉ) โŠ— (|0โŸฉ + ฯ‰โ‚โ‚†4k|1โŸฉ) โŠ— (|0โŸฉ + ฯ‰โ‚โ‚†2k|1โŸฉ) โŠ— (|0โŸฉ + ฯ‰โ‚โ‚†k|1โŸฉ)
 
qโ‚ƒ                 qโ‚‚                 qโ‚                 qโ‚€
Key insight:
ฯ‰โ‚โ‚†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.

ฯ‰โ‚ˆ =
Ex 3.2Bit parity and ฯ‰

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:
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โ‚.
So QFT|kโŸฉ โˆ
(|0โŸฉ + (โˆ’1)kโ‚€|1โŸฉ) โŠ— (|0โŸฉ + ฯ‰โ‚„kโ‚€(โˆ’1)kโ‚|1โŸฉ)   = qโ‚ โŠ— qโ‚€

Identifying the gates

Qubit qโ‚:
(|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 =
10
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)
H on kโ‚€:
H|1โŸฉ โŠ— (|0โŸฉ โˆ’ j|1โŸฉ)/โˆš2 = (|0โŸฉโˆ’|1โŸฉ)/โˆš2 โŠ— (|0โŸฉ โˆ’ j|1โŸฉ)/โˆš2
Output (qโ‚,qโ‚€):
= |qโ‚โŸฉ|qโ‚€โŸฉ as expected (reversed order โ€” swap to fix)
Interactive N=4 QFT circuit. Select an input basis state to trace the signal through each gate.
Input |kโŸฉ =
Ex 4.1QFT on |00โŸฉ for N=4

For k=0 (|kโŸฉ = |00โŸฉ), apply the QFT formula. What should be the probability of each basis state |00โŸฉ, |01โŸฉ, |10โŸฉ, |11โŸฉ?

P(each state) =
Section 05

QFT Circuit for N = 8 (3 qubits)

Extending to 3 qubits shows the recursive structure of the QFT. With k = kโ‚€ + 2kโ‚ + 4kโ‚‚ we write |kโŸฉ = |kโ‚‚kโ‚kโ‚€โŸฉ and factor:

QFT|kโŸฉ โˆ
(|0โŸฉ + ฯ‰โ‚ˆ4k|1โŸฉ) โŠ— (|0โŸฉ + ฯ‰โ‚ˆ2k|1โŸฉ) โŠ— (|0โŸฉ + ฯ‰โ‚ˆk|1โŸฉ)
Simplify ฯ‰โ‚ˆ4k:
ฯ‰โ‚ˆ4k = ejฯ€k = (โˆ’1)k = (โˆ’1)kโ‚€    (only kโ‚€ matters)
Simplify ฯ‰โ‚ˆ2k:
ฯ‰โ‚ˆ2k = ฯ‰โ‚„k = ฯ‰โ‚„kโ‚€ยท(โˆ’1)kโ‚    (depends on kโ‚€ and kโ‚)
Simplify ฯ‰โ‚ˆk:
ฯ‰โ‚ˆk = ฯ‰โ‚ˆkโ‚€ยทฯ‰โ‚„kโ‚ยท(โˆ’1)kโ‚‚    (depends on kโ‚€, kโ‚, kโ‚‚)

So the full factored form is:

QFT|kโŸฉ โˆ (|0โŸฉ + (โˆ’1)kโ‚€|1โŸฉ) โŠ— (|0โŸฉ + ฯ‰โ‚„kโ‚€(โˆ’1)kโ‚|1โŸฉ) โŠ— (|0โŸฉ + ฯ‰โ‚ˆkโ‚€ฯ‰โ‚„kโ‚(โˆ’1)kโ‚‚|1โŸฉ)

Circuit structure

|kโ‚€โŸฉ
โ—
โ—
H
|qโ‚‚โŸฉ
|kโ‚โŸฉ
โ—
H
ฮฉโ‚„
|qโ‚โŸฉ
|kโ‚‚โŸฉ
H
ฮฉโ‚„
ฮฉโ‚ˆ
|qโ‚€โŸฉ
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 =
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 =
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.

Gate count

# Hadamard gates:
n (one per qubit, applied once)
# Controlled-ฮฉ gates:
Wire 0 (|kโ‚‚โŸฉ): 1 controlled gate (ฮฉโ‚„)
Wire 1 (|kโ‚โŸฉ): 2 controlled gates (ฮฉโ‚„, ฮฉโ‚ˆ)
Wire j: j controlled gates
Total: 1 + 2 + โ€ฆ + (nโˆ’1) = n(nโˆ’1)/2
Total gates:
n + n(nโˆ’1)/2 = n(n+1)/2 โ‰ˆ nยฒ/2    (quadratic in n!)
Complexity comparison
QFTN:
O(nยฒ) = O((logโ‚‚ N)ยฒ) gates    with n = logโ‚‚ N qubits
Classical FFTN:
O(N logโ‚‚ N) = O(n ยท 2n) operations    (exponential in n)
Speedup:
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?

Total gates =
Ex 6.2Classical vs quantum for n=10

For n = 10 (N = 1024): how many operations does the classical FFT need (โ‰ˆ N logโ‚‚ N)? How many gates for QFT (โ‰ˆ nยฒ)? Compute the ratio FFT/QFT.

FFT ops โ‰ˆ QFT gates =