Quantum Computation & Cryptography · Lecture 13

Lecture 13
The Quantum Fourier Transform

Week 7  |  the Fourier transform on 2n amplitudes with about n2/2 gates, and why that does not make it a fast FFT  |  reading: Watrous Ch. 7 (the QFT); de Wolf Ch. 4

Cartoon: hearing the beat of a drumA stick figure wearing headphones listens to a drummer hitting a drum at regular intervals, shown as evenly spaced marks along a timeline. A speech bubble says: I can't tell you every beat, but I can tell you the rhythm. I can't tell you every beat,but I can tell you the rhythm.
the QFT turns a hidden period into a measurable peak; it cannot hand you the whole spectrum
In this lecture
  1. From the DFT to the QFT
  2. The product formula
  3. The circuit
  4. What the QFT can and cannot do
  5. The approximate QFT
  6. Detecting periods
  7. Try it in code
  8. Summary and exercises

Simon's algorithm found a hidden XOR-period with the Hadamard transform. Shor's algorithm finds an ordinary period, \(f(x+r)=f(x)\) with integer addition, and for that it needs the Fourier transform over the integers mod \(N\). This lecture builds it. By the end you should be able to define the quantum Fourier transform, prove that it is unitary, state and use its product formula, build its circuit and count its gates, explain why it is not a faster FFT, and show how it turns a periodic state into peaks at multiples of \(N/r\).

1 — From the DFT to the QFT

The discrete Fourier transform of a list \((a_0,\dots,a_{N-1})\) is the list \(b_y=\tfrac{1}{\sqrt N}\sum_x\omega^{xy}a_x\), where \(\omega=e^{2\pi i/N}\) is a primitive \(N\)-th root of unity. Engineers use it to find the frequencies hidden in a signal: a signal that repeats every \(r\) samples has a spectrum concentrated on multiples of \(N/r\). The quantum version applies the same matrix to the amplitudes of a state.

definition 13.1 — quantum Fourier transform

For \(N=2^n\) and \(\omega=e^{2\pi i/N}\), the quantum Fourier transform on \(n\) qubits is the linear map with

$$\mathrm{QFT}_N\,|x\rangle=\frac{1}{\sqrt N}\sum_{y=0}^{N-1}\omega^{xy}\,|y\rangle ,\qquad x=0,1,\dots,N-1 ,$$

where \(|x\rangle\) is the basis state whose bits are the binary digits of \(x\) (qubit \(j\) holds the \(2^j\) digit, as in Lecture 5). Its matrix has entry \(\omega^{xy}/\sqrt N\) in row \(y\), column \(x\).

In \(\mathrm{QFT}_8|2\rangle\), the amplitude of \(|3\rangle\) is \(\tfrac{1}{\sqrt8}e^{i\varphi}\) with \(0\le\varphi\lt2\pi\). Find \(\varphi\).

By Definition 13.1 the amplitude is \(\omega^{xy}/\sqrt8\) with \(\omega=e^{2\pi i/8}\). Here \(xy=6\).
\(\omega^6=e^{2\pi i\cdot6/8}=e^{3\pi i/2}=-i\), so \(\varphi=\tfrac{3\pi}{2}\). Every amplitude has the same size; only the phase \(2\pi xy/N\) carries information.

For \(N=2\), \(\omega=-1\) and the matrix is \(\tfrac{1}{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix}=H\): the one-qubit QFT is the Hadamard gate. For larger \(N\) the QFT is not \(H^{\otimes n}\); the Hadamard transform of Lecture 9 is the Fourier transform for XOR, and the QFT is the one for addition mod \(N\).

proposition 13.1 — the QFT is unitary

The columns of \(\mathrm{QFT}_N\) are orthonormal, so \(\mathrm{QFT}_N\) is unitary, and its inverse is \(\mathrm{QFT}_N^{-1}|y\rangle=\tfrac{1}{\sqrt N}\sum_x\omega^{-xy}|x\rangle\).

The inner product of columns \(x\) and \(x'\) is \(\tfrac1N\sum_y\overline{\omega^{xy}}\,\omega^{x'y}=\tfrac1N\sum_y\omega^{ky}\) with \(k=x'-x\). If \(k\equiv0\pmod N\) every term is 1 and the sum is \(N\). Otherwise \(\omega^k\neq1\), and the geometric series gives

$$\sum_{y=0}^{N-1}\big(\omega^k\big)^y=\frac{\omega^{kN}-1}{\omega^k-1}=0 ,$$

since \(\omega^{kN}=1\). (This is Lecture 2's fact that the \(N\)-th roots of unity, walked around the circle, return to the start.) So the columns are orthonormal. The inverse of a unitary is its conjugate transpose, whose entries are \(\overline{\omega^{xy}}/\sqrt N=\omega^{-xy}/\sqrt N\).

By Proposition 13.1, \(\mathrm{QFT}_8^{-1}|1\rangle\) is equal to \(\mathrm{QFT}_8|x\rangle\) for exactly one \(x\in\{0,\dots,7\}\). Which?

The inverse puts the phase \(\omega^{-y}\) on \(|y\rangle\). Which power \(\omega^{xy}\) equals \(\omega^{-y}\) for every \(y\), given \(\omega^8=1\)?
\(\omega^{-y}=\omega^{7y}\) because \(\omega^{8y}=1\), so \(\mathrm{QFT}_8^{-1}|1\rangle=\mathrm{QFT}_8|7\rangle\): the same winding, run backwards.
example 13.1 — QFT|x⟩ as a winding pattern, N = 8

Describe \(\mathrm{QFT}_8|0\rangle\), \(\mathrm{QFT}_8|1\rangle\) and \(\mathrm{QFT}_8|3\rangle\).

Every output amplitude has size \(1/\sqrt8\); only the phases differ. For \(x=0\) all phases are \(\omega^0=1\): \(\mathrm{QFT}|0\rangle\) is the uniform superposition, exactly like \(H^{\otimes3}|000\rangle\). For \(x=1\) the phase of \(|y\rangle\) is \(\omega^y\), which advances by one eighth of a turn per step of \(y\) and winds once around the circle as \(y\) runs from 0 to 7. For \(x=3\) the phase \(\omega^{3y}\) advances by three eighths per step and winds three times. In general \(\mathrm{QFT}|x\rangle\) is a "wave" of frequency \(x\).

Phases of QFT|x> for N = 8 and x = 1, 3Two rows of eight small circles, one per output y = 0 to 7. In each circle an arrow shows the phase of the amplitude of |y>, which is omega^(xy) with omega = e^(2 pi i/8). Top row, x = 1: the arrow turns by one eighth of a turn from each circle to the next, completing one full turn across the row. Bottom row, x = 3: it turns by three eighths each step, completing three turns. All amplitudes have the same size, 1/sqrt 8.x = 1y = 00/8y = 11/8y = 22/8y = 33/8y = 44/8y = 55/8y = 66/8y = 77/8x = 30/83/86/81/84/87/82/85/8arrow angle = (xy mod 8)/8 of a full turn; every amplitude has size 1/sqrt8
Example 13.1: the phase of each amplitude of \(\mathrm{QFT}_8|x\rangle\), drawn as an arrow. Input \(x\) becomes a pattern that winds \(x\) times around the circle as \(y\) goes from 0 to 7.

Phase wheels

Choose \(N\) and an input \(x\). Each wheel shows the phase of the amplitude of \(|y\rangle\) in \(\mathrm{QFT}_N|x\rangle\); all amplitudes have size \(1/\sqrt N\). Try \(x=N/2\): every other arrow points backwards.

2 — The product formula

The QFT of a basis state is not entangled: it is a product of single-qubit states. That fact is what makes it cheap to implement. We write \(e^{2\pi i\,x/2^k}\) for the phase that a full turn, divided into \(2^k\) parts, reaches after \(x\) steps; it depends only on the last \(k\) bits of \(x\), since adding multiples of \(2^k\) to \(x\) adds whole turns.

theorem 13.2 — product formula

For \(N=2^n\) and every \(x\),

$$\begin{aligned}\mathrm{QFT}_N|x\rangle=\;&\frac{|0\rangle+e^{2\pi i\,x/2}|1\rangle}{\sqrt2}\otimes\frac{|0\rangle+e^{2\pi i\,x/4}|1\rangle}{\sqrt2}\\[4pt] &\otimes\cdots\otimes\frac{|0\rangle+e^{2\pi i\,x/2^n}|1\rangle}{\sqrt2},\end{aligned}$$

with the factors in ket order: the leftmost is qubit \(n-1\) and the rightmost is qubit 0. So output qubit \(j\) is in the state \(\tfrac{1}{\sqrt2}\big(|0\rangle+e^{2\pi i\,x/2^{n-j}}|1\rangle\big)\).

Proof. HW7 asks you to derive this for \(n=3\); Example 13.2 does \(n=2\). The idea: write \(y=\sum_jy_j2^j\), so \(\omega^{xy}=\prod_j\omega^{xy_j2^j}\), and the sum over \(y\) splits into a product of sums over each bit \(y_j\).

By Theorem 13.2, in \(\mathrm{QFT}_8|5\rangle\) qubit 2 is in the state and qubit 1 is in the state .

Qubit \(j\) carries the phase \(e^{2\pi i\,x/2^{n-j}}\) on its \(|1\rangle\): with \(n=3\), qubit 2 uses \(x/2\) and qubit 1 uses \(x/4\).
\(e^{2\pi i\cdot5/2}=-1\) gives \(|-\rangle\) on qubit 2 and \(e^{2\pi i\cdot5/4}=i\) gives \(|{+i}\rangle\) on qubit 1. Qubit 0 gets \(e^{2\pi i\cdot5/8}\), which is not a cardinal state.
example 13.2 — the product formula for n = 2

Show that \(\mathrm{QFT}_4|x\rangle=\tfrac{1}{\sqrt2}\big(|0\rangle+(-1)^{x_0}|1\rangle\big)\otimes\tfrac{1}{\sqrt2}\big(|0\rangle+i^{x}|1\rangle\big)\), where \(x=2x_1+x_0\).

Here \(\omega=i\). Write \(y=2y_1+y_0\), so \(\omega^{xy}=i^{2xy_1}\,i^{xy_0}=(-1)^{xy_1}\,i^{xy_0}\). Then

$$\begin{aligned}\mathrm{QFT}_4|x\rangle&=\frac12\sum_{y_1,y_0}(-1)^{xy_1}i^{xy_0}\,|y_1\rangle|y_0\rangle\\[4pt] &=\Big(\frac{1}{\sqrt2}\sum_{y_1}(-1)^{xy_1}|y_1\rangle\Big)\otimes\Big(\frac{1}{\sqrt2}\sum_{y_0}i^{xy_0}|y_0\rangle\Big).\end{aligned}$$

Finally \((-1)^x=(-1)^{x_0}\), because \(2x_1\) is even. The left factor (qubit 1) depends only on the last bit of \(x\), and the right factor (qubit 0) on all of \(x\), matching Theorem 13.2: \(e^{2\pi ix/2}=(-1)^x\) and \(e^{2\pi ix/4}=i^x\).

3 — The circuit

Theorem 13.2 says that each output qubit needs the phase \(e^{2\pi ix/2^k}\) on its \(|1\rangle\) part for one value of \(k\). Expanding \(x=\sum_jx_j2^j\), that phase is a product of factors \(e^{2\pi i\,x_j2^j/2^k}\), one for each input bit \(j\lt k\). The circuit creates them with one Hadamard and a ladder of controlled phase gates \(CP(\varphi)=\mathrm{diag}(1,1,1,e^{i\varphi})\), which multiply \(|11\rangle\) by \(e^{i\varphi}\) and, like CZ, have no preferred control.

The QFT circuit for n = 3Three wires, q0 on top. The circuit applies H to q2, then a controlled phase P(pi/2) between q1 and q2 and a controlled phase P(pi/4) between q0 and q2; then H to q1 and P(pi/2) between q0 and q1; then H to q0; finally a SWAP of q0 and q2. After the swap, q0 holds |0> + e^(2 pi i x/8)|1>, q1 holds |0> + e^(2 pi i x/4)|1> and q2 holds |0> + e^(2 pi i x/2)|1>, each up to a factor 1/sqrt2.q0|x0>q1|x1>q2|x2>HP(pi/2)P(pi/4)P(pi/2)HH|0> + e^(2pi i x/8)|1>|0> + e^(2pi i x/4)|1>|0> + e^(2pi i x/2)|1>3 H + 3 controlled phases + 1 SWAP; outputs shown up to the factor 1/sqrt2 each
The QFT on three qubits. \(H\) on \(q_2\) puts \(e^{2\pi i\,x_2/2}\) on its \(|1\rangle\) part; the controlled phases \(P(\pi/2)\) and \(P(\pi/4)\) from \(q_1\) and \(q_0\) add \(e^{2\pi i\,x_1/4}\) and \(e^{2\pi i\,x_0/8}\). So \(q_2\) ends with the phase \(e^{2\pi ix/8}\), the factor that belongs on qubit 0. The final SWAP puts the factors in the right order.
theorem 13.3 — the QFT circuit

For \(j=n-1,n-2,\dots,0\): apply \(H\) to qubit \(j\), then for each \(k\lt j\) a controlled phase \(CP(\pi/2^{\,j-k})\) between qubits \(k\) and \(j\). Finally reverse the order of the qubits with \(\lfloor n/2\rfloor\) SWAPs. This circuit implements \(\mathrm{QFT}_{2^n}\) with \(n\) Hadamards and \(n(n-1)/2\) controlled phases: \(n(n+1)/2\) gates, plus the SWAPs, which a compiler can often absorb by relabelling qubits.

When \(H\) acts on qubit \(j\), that qubit still holds \(x_j\), and \(H|x_j\rangle=\tfrac{1}{\sqrt2}(|0\rangle+e^{2\pi i\,x_j2^j/2^{j+1}}|1\rangle)\) because \(e^{\pi ix_j}=(-1)^{x_j}\). Each \(CP(\pi/2^{\,j-k})\) controlled by qubit \(k\), which still holds \(x_k\), multiplies the \(|1\rangle\) part by \(e^{i\pi x_k/2^{j-k}}=e^{2\pi i\,x_k2^k/2^{j+1}}\). After the ladder, qubit \(j\) carries \(\prod_{k\le j}e^{2\pi i\,x_k2^k/2^{j+1}}=e^{2\pi i\,x/2^{j+1}}\), using that only the bits of \(x\) below \(2^{j+1}\) matter. Qubits below \(j\) have not been touched yet, so they still hold their bits when their turn comes. Qubit \(j\) now holds the factor that Theorem 13.2 assigns to qubit \(n-1-j\); the SWAPs move each factor to its place. (verify_L13.py also checks the circuit against the matrix for \(n\le5\).)

How many controlled phases and how many SWAPs does the circuit of Theorem 13.3 use for \(n=9\) qubits?

Qubit \(j\) receives one controlled phase from each lower qubit \(k\lt j\); add these up. Reversing 9 qubits swaps them in pairs.
\(0+1+\dots+8=9\cdot8/2=36\) controlled phases and \(\lfloor9/2\rfloor=4\) SWAPs (the middle qubit stays put), plus 9 Hadamards.

4 — What the QFT can and cannot do

The classical fast Fourier transform computes the DFT of \(N=2^n\) numbers with about \(N\log_2N=n2^n\) arithmetic operations. The QFT uses about \(n^2/2\) gates. The gap is exponential:

\(n\)\(N=2^n\)QFT gates \(n(n+1)/2\)FFT operations \(\approx n2^n\)
101,02455about \(1.0\times10^4\)
201,048,576210about \(2.1\times10^7\)
30about \(1.1\times10^9\)465about \(3.2\times10^{10}\)
idea — why this is not a faster FFT

The comparison is unfair in both directions. The input: loading \(N\) arbitrary numbers into the amplitudes of a state generally takes about \(N\) gates, which already costs as much as the FFT. The output: the QFT leaves the \(N\) Fourier coefficients in the amplitudes, and a measurement returns one \(y\), with probability \(|b_y|^2\). Reading all coefficients would take about \(N\) repetitions per digit of precision. So the QFT is useful only inside algorithms that prepare the input state efficiently and need a single sample from the output distribution. Period finding is exactly such a problem.

Tick every true statement about the \(n\)-qubit QFT with \(N=2^n\).

Separate the cost of the circuit from the cost of getting data in and results out.
The circuit is cheap (\(\approx n^2/2\) gates), but input preparation costs about \(N\) and a measurement yields one sample. Only algorithms that need one sample from an efficiently prepared state benefit.

5 — The approximate QFT

The controlled phases \(CP(\pi/2^d)\) for large distance \(d\) are nearly the identity: \(\pi/2^{10}\) is under 0.2 degrees. Coppersmith (1994) observed that they can simply be dropped.

proposition 13.4 — dropping small rotations

Keep only the controlled phases \(CP(\pi/2^d)\) with \(d\lt m\). The resulting circuit \(\widetilde{\mathrm{QFT}}\) satisfies \(\|\widetilde{\mathrm{QFT}}-\mathrm{QFT}\|\le n\pi/2^{m-1}\) in operator norm, and it uses about \(nm\) controlled phases instead of \(n^2/2\). Choosing \(m\approx\log_2(n/\varepsilon)+3\) gives error at most \(\varepsilon\).

A dropped gate \(CP(\varphi)\) differs from the identity by \(|e^{i\varphi}-1|\le\varphi\) in operator norm. Replacing gates one at a time and using that unitaries preserve norms, the errors of a sequence of gates add up. There are \(n-d\le n\) dropped gates at each distance \(d\ge m\), so the total is at most \(\sum_{d\ge m}n\pi/2^d=n\pi/2^{m-1}\). For the gate count, each qubit keeps at most \(m-1\) controlled phases.

For a 16-qubit QFT that keeps only the controlled phases with distance \(d\lt10\), what error bound does Proposition 13.4 give? (Three decimal places.)

The bound is \(n\pi/2^{m-1}\), here with \(n=16\) and \(m=10\).
\(16\pi/2^9=\pi/32\approx0.098\). The bound grows only linearly in \(n\) but halves with each extra distance kept.

For \(n=8\) the exact operator-norm errors, computed in verify_L13.py, are 0.414, 0.123 and 0.025 for \(m=5,6,7\). For a 20-qubit QFT with \(m=8\), 112 of the 190 controlled phases are kept. In Shor's algorithm \(n\) is in the thousands, so dropping all but about \(\log n\) rotations per qubit turns \(O(n^2)\) into \(O(n\log n)\) gates, and it removes the need for absurdly precise rotation angles, which a fault-tolerant machine would have to synthesise from many \(T\) gates (Lecture 7).

6 — Detecting periods

Here is the property Shor's algorithm uses.

proposition 13.5 — periodic states have peaked transforms

Let \(r\) divide \(N\), let \(0\le x_0\lt r\), and let \(|\psi\rangle=\sqrt{r/N}\sum_{j=0}^{N/r-1}|x_0+jr\rangle\), the uniform superposition of an arithmetic progression with step \(r\). Then measuring \(\mathrm{QFT}|\psi\rangle\) gives each multiple of \(N/r\) with probability \(1/r\), and never anything else. The offset \(x_0\) only changes phases.

The amplitude of \(|y\rangle\) is

$$\frac{1}{\sqrt N}\sqrt{\frac rN}\sum_{j=0}^{N/r-1}\omega^{(x_0+jr)y}=\frac{\sqrt r}{N}\,\omega^{x_0y}\sum_{j=0}^{N/r-1}\big(\omega^{ry}\big)^j .$$

Now \(\omega^{r}=e^{2\pi i/(N/r)}\) is a primitive \((N/r)\)-th root of unity, so by the geometric-series argument of Proposition 13.1 the sum is \(N/r\) when \(N/r\) divides \(y\) and 0 otherwise. In the first case the amplitude has size \(\tfrac{\sqrt r}{N}\cdot\tfrac Nr=\tfrac{1}{\sqrt r}\), so its probability is \(\tfrac1r\); there are exactly \(r\) multiples of \(N/r\) below \(N\). The factor \(\omega^{x_0y}\) is a phase.

Take \(N=32\) and the periodic state with period \(r=8\) and offset \(x_0=3\). After the QFT, what are the probabilities of measuring \(y=12\) and \(y=6\)?

By Proposition 13.5 the outcomes are the multiples of \(N/r=4\), each with probability \(1/r\). The offset does not matter.
12 is a multiple of 4, so \(P(12)=\tfrac18\); 6 is not, so \(P(6)=0\). The offset 3 changes only the phases \(\omega^{3y}\).
A periodic state before and after the QFT, N = 16Four bar charts. Top left: the state with period 4 starting at 1, equal weight on 1, 5, 9, 13. Top right: after the QFT, probability 1/4 on each of 0, 4, 8, 12, the multiples of 16/4. Bottom left: period 3 starting at 0, equal weight on 0, 3, 6, 9, 12, 15. Bottom right: after the QFT the probability concentrates near multiples of 16/3: 0.375 at 0, 0.234 at 5 and at 11, and 0.036 at 6 and 10, with small values elsewhere.period 4: |amplitude|^2 before0246810121415after the QFT (amber: multiples of 16/4)0246810121415period 3: |amplitude|^2 before0246810121415after the QFT (amber: multiples of 16/3)0246810121415
Period 4 (top) and period 3 (bottom) with \(N=16\). When \(r\) divides \(N\), the transform is exactly \(r\) equal peaks at multiples of \(N/r\). When it does not, the peaks sit near the multiples of \(16/3\approx5.33\) and leak into neighbours: here 0.375 at 0, 0.234 at 5 and at 11, and 0.036 at 6 and at 10. Shor's algorithm recovers \(r\) from such near-multiples with continued fractions (Lecture 15).

A measured \(y\) is a multiple of \(N/r\), say \(y=c\,N/r\), so \(y/N=c/r\): the measurement reveals a random fraction with denominator \(r\). A few samples pin \(r\) down. Shor's algorithm (Lectures 15–16) prepares such a periodic state from \(f(x)=a^x\bmod M\), where the period \(r\) is unknown and in general does not divide \(N\), which is why the bottom row of the figure matters.

With \(N=32\) and a period \(r\) that divides 32, one run returns \(y=20\). The period \(r\) is .

Write \(y/N=c/r\) and reduce \(20/32\) to lowest terms. Which part is the period?
\(20/32=5/8=c/r\). The denominator in lowest terms is 8, so \(r\) is 8, or a multiple of 8 if \(c\) and \(r\) share a factor. A second sample usually settles which.

Periodicity detector

Choose \(N\), a period \(r\) and an offset. Top: the probabilities of the periodic state. Bottom: the probabilities after the QFT, with the multiples of \(N/r\) marked. Compare a period that divides \(N\) with one that does not, and check that the offset never changes the bottom row.

7 — Try it in code

tool — QFTGate on periodic states (tested with qiskit 2.5)
import numpy as np
from qiskit import QuantumCircuit
from qiskit.circuit.library import QFTGate
from qiskit.quantum_info import Statevector

n = 4; N = 2 ** n
def periodic_state(r, x0):
    """uniform superposition of x0, x0 + r, x0 + 2r, ... below N"""
    amps = np.zeros(N); idx = np.arange(x0, N, r); amps[idx] = 1 / np.sqrt(len(idx))
    return Statevector(amps)

qft = QuantumCircuit(n); qft.append(QFTGate(n), range(n))
for r, x0 in [(4, 1), (3, 0)]:
    p = periodic_state(r, x0).evolve(qft).probabilities()
    top = np.argsort(-p)[:5]
    print(f"r = {r}:", {int(y): round(float(p[y]), 3) for y in sorted(top) if p[y] > 1e-9})
r = 4: {0: 0.25, 4: 0.25, 8: 0.25, 12: 0.25}
r = 3: {0: 0.375, 5: 0.234, 6: 0.036, 10: 0.036, 11: 0.234}

QFTGate(n) implements Definition 13.1 with Qiskit's usual ordering: the integer \(x\) is read with qubit 0 as the \(2^0\) digit, and the output index \(y\) the same way. The two runs reproduce Proposition 13.5 and the bottom row of the figure.

tool — how many gates?
from qiskit import QuantumCircuit, transpile
from qiskit.circuit.library import QFTGate

for n in range(3, 9):
    qc = QuantumCircuit(n); qc.append(QFTGate(n), range(n))
    textbook = transpile(qc, basis_gates=["h", "cp", "swap"], optimization_level=0)
    ibm = transpile(qc, basis_gates=["cx", "rz", "sx", "x"], optimization_level=1, seed_transpiler=1)
    print(n, dict(textbook.count_ops()), "  cx after transpiling:", ibm.count_ops()["cx"])
3 {'h': 3, 'cp': 3, 'swap': 1}   cx after transpiling: 9
4 {'cp': 6, 'h': 4, 'swap': 2}   cx after transpiling: 18
5 {'cp': 10, 'h': 5, 'swap': 2}   cx after transpiling: 26
6 {'cp': 15, 'h': 6, 'swap': 3}   cx after transpiling: 39
7 {'cp': 21, 'h': 7, 'swap': 3}   cx after transpiling: 51
8 {'cp': 28, 'h': 8, 'swap': 4}   cx after transpiling: 68

The counts match Theorem 13.3: \(n\) Hadamards, \(n(n-1)/2\) controlled phases and \(\lfloor n/2\rfloor\) SWAPs. Each controlled phase costs 2 CNOTs and each SWAP 3 (Lecture 6), which gives the CNOT column exactly: for \(n=8\), \(2\cdot28+3\cdot4=68\).

8 — Summary and exercises

summary

Next time: phase estimation, which uses the inverse QFT to read eigenvalues of unitaries. HW7 covers Lectures 13 and 14; the midterm follows.

exercises 13
  1. Show that \(\mathrm{QFT}_8|4\rangle=|+\rangle|+\rangle|-\rangle\) (kets \(|q_2q_1q_0\rangle\)), and check it against Theorem 13.2.
  2. Show that the QFT maps the uniform superposition \(\tfrac{1}{\sqrt N}\sum_x|x\rangle\) to \(|0\rangle\).
  3. Show that \(\mathrm{QFT}_N^2|x\rangle=|{-x}\bmod N\rangle\), and deduce \(\mathrm{QFT}_N^4=I\).
  4. Using Proposition 13.5, what does the QFT do to the state \(\tfrac{1}{\sqrt8}\sum_{j=0}^{7}|2j\rangle\) when \(N=16\)?
  5. How many controlled phases does the 20-qubit QFT use, and how many are kept with \(m=8\)?
  6. A student claims the QFT computes the DFT of a million numbers with only 210 gates, so quantum computers make signal processing exponentially faster. Give two reasons this is wrong.
  1. \(\omega=e^{2\pi i/8}\), so \(\omega^{4y}=e^{\pi iy}=(-1)^y=(-1)^{y_0}\). Hence \(\mathrm{QFT}|4\rangle=\tfrac{1}{\sqrt8}\sum_y(-1)^{y_0}|y\rangle\), which factors as \(|+\rangle\) on \(q_2\), \(|+\rangle\) on \(q_1\) and \(|-\rangle\) on \(q_0\). Theorem 13.2 gives qubit \(j\) the phase \(e^{2\pi i\cdot4/2^{3-j}}\): \(e^{2\pi i\cdot4/2}=1\) for \(j=2\), \(e^{2\pi i\cdot4/4}=1\) for \(j=1\), and \(e^{2\pi i\cdot4/8}=-1\) for \(j=0\).
  2. Apply the definition and add up. The amplitude of \(|y\rangle\) is \(\tfrac1N\sum_x\omega^{xy}\), which is 1 for \(y=0\) and 0 otherwise by the roots-of-unity sum. So the output is \(|0\rangle\).
  3. The amplitude of \(|z\rangle\) in \(\mathrm{QFT}^2|x\rangle\) is \(\tfrac1N\sum_y\omega^{xy}\omega^{yz}=\tfrac1N\sum_y\omega^{y(x+z)}\), which is 1 if \(x+z\equiv0\pmod N\) and 0 otherwise. So \(\mathrm{QFT}^2|x\rangle=|{-x}\rangle\), and applying it twice more returns \(|x\rangle\).
  4. This is the periodic state with \(r=2\), \(x_0=0\). The output is \(|0\rangle\) or \(|8\rangle\), each with probability \(\tfrac12\).
  5. \(20\cdot19/2=190\) controlled phases. With \(m=8\), those with distance \(d\le7\) are kept: \(\sum_{d=1}^{7}(20-d)=140-28=112\).
  6. Loading a million arbitrary numbers into amplitudes takes about a million gates, and the output cannot be read: a measurement returns one index \(y\), sampled with probability \(|b_y|^2\). Estimating all the coefficients would need far more than a million repetitions.

Reading and sources

all numbers and figures in these notes are computed in python (verify_L13.py) and follow the page theme