Skip to main content
← Quantum Computing Math

Lesson 3 of 3

Exponentials, Fourier and Interference

Matrix exponentials, the Fourier transform, and the one demonstration that shows phase changing an answer.

What you will learn

  • Taylor series
  • the matrix exponential
  • expm
  • involutory matrices
  • rotation gates
  • the Fourier transform
  • fft and ifft
  • frequency bins
  • constructive interference
  • destructive interference

Before you start

Multi-Qubit States and Gates. The capstone uses H, plus and minus from the setup cell, and the Fourier section uses sine_wave.

Matrix exponentials

0:00–0:20 · Part One, slides 11–14

The exponential of a matrix is defined by the exponential's Taylor series with the matrix plugged in, and the terms shrink fast.

If B squared is the identity, the series collapses to cos γ · I + i sin γ · B. The slide calls such a B involuntary; the word is involutory.

gamma = 0.7
exact = expm(1j * gamma * X)
shortcut = np.cos(gamma) * I2 + 1j * np.sin(gamma) * X   # allowed because X @ X = I
print(np.allclose(exact, shortcut))

def expm_taylor(M, terms):
    return sum(np.linalg.matrix_power(M, n) / factorial(n) for n in range(terms))

for k in range(1, 9):
    err = np.abs(expm_taylor(1j * gamma * X, k) - exact).max()
    print(f"{k} terms: max error {err:.1e}")

print(np.allclose(dag(exact) @ exact, I2))   # X is Hermitian, so this is unitary

Explain it. Answer each of these in a sentence or two before you open the answers at the foot of the page.

  1. What does the exponential of a matrix mean?
  2. Why do a few terms usually suffice?
  3. What does B squared being the identity buy you?
  4. Why does this matter for gates?

Fourier transform

0:20–0:45 · Part Two, slides 12–23

Time domain in, frequency domain out, and the inverse brings you back. The magnitudes show which frequencies are present.

Skip the integral's details. Know what goes in, what comes out, and why it is useful.

N, duration = 256, 2.0
t = np.linspace(0, duration, N, endpoint=False)
signal = sine_wave(t, 5, 0) + 0.5 * sine_wave(t, 12, 0)   # two frequencies

yf = fft(signal)
xf = fftfreq(N, duration / N)          # frequency of each bin, in Hz
strong = np.abs(yf) > 10
for f, size in sorted(zip(xf[strong], np.abs(yf[strong]))):
    print(f"{f:+5.1f} Hz  |FFT| = {size:.1f}")

kept = np.where(strong, yf, 0)         # keep 4 of 256 bins: the mp3 idea
recovered = ifft(kept).real            # .real: ifft returns complex numbers
print("max reconstruction error:", np.abs(recovered - signal).max())

plt.plot(xf, np.abs(yf))
plt.xlabel("frequency (Hz)")
plt.show()

Explain it.

  1. What does the Fourier transform give you?
  2. Why are there peaks at both +5 and −5 Hz?
  3. How does this make compression possible?
  4. Why did the slide's ifft plot print a warning?
  5. Why do quantum computers care?

Capstone: phase changes outcomes

0:45–0:55 · ties Part Two's phase to Part One's gates

|+⟩ and |−⟩ measure identically, yet one Hadamard sends them to different answers. Relative phase is doing the work.

states = {"|+⟩": plus, "|−⟩": minus, "e^(iπ/3)|+⟩": np.exp(1j * np.pi / 3) * plus}
for name, s in states.items():
    before = np.round(np.abs(s) ** 2, 3)
    after = np.round(np.abs(H @ s) ** 2, 3)
    print(f"{name:>12}  before H: {before}  after H: {after}")

Explain it.

  1. |+⟩ and |−⟩ both measure 50/50. How does H tell them apart?
  2. Why doesn't a global phase on |+⟩ behave any differently from |+⟩ itself?

Write the week down

0:55–1:00

In one paragraph, explain how complex amplitudes, unitary gates, phase and the Fourier transform fit together. Then compare what you wrote with the seven steps at the foot of the page.

Try these changes

Make these changes in the files beside this guide. Each one only uses what this lesson has already covered. Tick each one when it works.

Check yourself

Three quick questions on this lesson. Get them all right to finish the lesson and earn a pack.

Loading your answers

Teacher's versionHow to run this lesson, what to check, and any answers. Students do not need this.

Answers to the prompts

  1. The exponential of a matrix. Substitute the matrix into the Taylor series for the exponential and sum the terms. The result is another matrix.
  2. Why a few terms suffice. The factorial in the denominator grows faster than the powers, so the terms shrink quickly for moderate γ.
  3. What B squared being the identity buys you. Powers of B alternate between I and B, so the series splits into the cosine and sine series. X, Y, Z and H all qualify.
  4. Why it matters for gates. If M is Hermitian, the exponential of iγM is unitary, so it is a valid gate. Rotation gates are built this way — Rx(θ) is the exponential of −iθX/2.
  5. What the Fourier transform gives you. The same signal described by the frequencies it contains, with an amplitude and phase for each, instead of its value at each moment.
  6. Why peaks at both +5 and −5 Hz. By Euler's formula a real sine is a sum of two counter-rotating complex exponentials, so both frequencies appear.
  7. How compression follows. Most frequency bins are near zero. Keep the strong ones, drop the rest, and invert to get a close copy back. That is the idea behind mp3.
  8. Why the slide's ifft plot warned. ifft returns complex numbers with tiny imaginary parts from rounding. Plotting silently drops the imaginary part, so take .real yourself.
  9. Why quantum computers care. The quantum Fourier transform runs efficiently on qubits and is the key step in phase estimation and Shor's algorithm.
  10. How H tells |+⟩ and |−⟩ apart. The minus sign, a relative phase of π, makes the amplitudes cancel on |0⟩ and add on |1⟩ after H. It is the same cancellation as the π-shifted sine waves.
  11. Why a global phase changes nothing. It multiplies every amplitude by the same unit-length factor, before and after any gate, so no modulus squared ever changes.

The week in seven steps

The answer key for the last block of this lesson.

  1. Amplitudes are complex, so probabilities use the modulus: P(0) = |α|².
  2. States are vectors. The bra's conjugate makes ⟨ψ|ψ⟩ a real length, and ⟨ψ|ψ⟩ = 1 is the Born rule.
  3. Tensor products combine qubits, so n qubits need 2ⁿ amplitudes.
  4. Gates are unitary matrices: they keep lengths and can be undone.
  5. A unitary's eigenvalues are pure phases.
  6. Relative phase is invisible to an immediate measurement but decides how amplitudes interfere after the next gate.
  7. The Fourier transform exposes frequency and phase. Its quantum version is how algorithms like Shor's read out a hidden phase.

Where the slides simplify

  • The 1/(2π) factor depends on convention (Part Two, slide 18). With the form on the slide the transform pair needs no prefactor. The 1/(2π), or 1/√(2π) on each side, appears when you write the transform with angular frequency instead.
  • Typo, Part One slide 14. “Involuntary” should be involutory, meaning B squared is the identity. Use the right word when you look it up.