3. Complex numbers and amplitudes

Why this layer exists

This chapter is the one that separates the people who think in amplitudes from the people who think in probabilities, and it is the first fork in the road. A classical bit is 0 or 1. A classical probability distribution is a list of non-negative numbers that sum to one. A quantum state is neither: it is a list of complex numbers, and the phase of each one — the angle, not the magnitude — is a physical degree of freedom. Get that through your fingers now, before you have built up the habit of thinking in probabilities, and the rest of the book is coherent. Get it only later, after you have memorised the circuit model, and you will be fighting an intuition that has to be rebuilt.

What breaks without this chapter is interference. Chapter 5 is interference, and interference is the whole reason a quantum computer is more than a probabilistic one. But interference is not a phenomenon you can describe without complex numbers: it is the addition of amplitudes, and the addition of complex numbers depends on their phases. If you think of the amplitudes as just “probabilities with a sign,” you get half the story — you will understand the Hadamard but not the phase gate, the constructive case but not the destructive one. This chapter is the place to pay the small price of learning complex arithmetic so that you never have to relearn it.

The complex numbers

A complex number is $z = x + iy$, where $x$ and $y$ are real and $i$ is the imaginary unit, $i^2 = -1$. The real part is $\mathrm{Re} z = x$; the imaginary part is $\mathrm{Im} z = y$. The conjugate is $\bar z = x - iy$, and the modulus is $|z| = \sqrt{x^2 + y^2}$.

The thing that matters for quantum mechanics is the polar form. Every complex number can be written as

z=reiθ=r(cosθ+isinθ), z = r\,e^{i\theta} = r(\cos\theta + i\sin\theta) ,

where $r = |z|$ is the modulus and $\theta = \arg z$ is the phase. Euler’s formula, $e^{i\theta} = \cos\theta + i\sin\theta$, is what makes this work, and it is the reason the phase is an angle: multiply by $e^{i\theta}$ and you rotate the number in the complex plane by $\theta$, without changing its length. That is not a coincidence; it is the definition of the phase.

The arithmetic is where the phase lives. Multiplying two complex numbers multiplies their moduli and adds their phases:

(r1eiθ1)(r2eiθ2)=r1r2ei(θ1+θ2). (r_1 e^{i\theta_1})(r_2 e^{i\theta_2}) = r_1 r_2\, e^{i(\theta_1 + \theta_2)} .

This is the single fact that classical probability has no analogue for. A probability is a non-negative real number, and multiplying probabilities only rescales them; there is no angle to add. The phase is a genuinely complex phenomenon, and it is the thing a quantum computer manipulates.

In tqp the complex numbers are numpy’s complex128, and the polar form is just abs for the modulus and angle for the phase:

import numpy as np
z = 1 + 1j          # x = 1, y = 1
r = abs(z)          # |z| = sqrt(2)
theta = np.angle(z) # arg z = pi/4

The phase is measured in radians, from the positive real axis, counterclockwise.

Amplitudes

A quantum state is a list of complex numbers, the amplitudes. For a single qubit,

∣ψ⟩=a∣0⟩+b∣1⟩,a,b∈C,∣a∣2+∣b∣2=1. |\psi\rangle = a|0\rangle + b|1\rangle, \qquad a, b \in \mathbb{C}, \qquad |a|^2 + |b|^2 = 1 .

The amplitudes are $a$ and $b$, and they are complex. The probability of measuring $|0\rangle$ is $|a|^2$ and of $|1\rangle$ is $|b|^2$, by the Born rule; but the amplitudes are not the probabilities, and the phase of each one is not the phase of a probability. The phase of an amplitude is a direction in the complex plane, and it is what lets amplitudes interfere.

The reason the amplitudes are complex and not real is that a real amplitude carries only a sign, $+$ or $-$, and a sign can interfere constructively or destructively, but it cannot carry the full range of relative phases that a qubit state has. The Bloch sphere is a sphere, not a line: a qubit state has two angles, $\theta$ and $\phi$, and $\phi$ is the phase. A real amplitude can describe the polar angle $\theta$ but not the azimuthal phase $\phi$, and so a real amplitude cannot describe a qubit. This is why the amplitudes must be complex.

The phase

The phase of an amplitude is the angle $\theta$ in the polar form $a = |a|e^{i\theta}$. There are two kinds of phase, and the distinction between them is the whole game.

A global phase is a phase applied to every amplitude at once:

∣ψ⟩↦eiγ∣ψ⟩=eiγ(a∣0⟩+b∣1⟩). |\psi\rangle \mapsto e^{i\gamma}|\psi\rangle = e^{i\gamma}(a|0\rangle + b|1\rangle) .

A global phase is unobservable: it changes every amplitude by the same factor, so it changes every probability $|a|^2$ by $|e^{i\gamma}|^2 = 1$, and the measurement statistics are identical. You can never detect a global phase, and you should never build a computation that depends on one.

A relative phase is a phase difference between two amplitudes:

a∣0⟩+b∣1⟩↦a∣0⟩−b∣1⟩. a|0\rangle + b|1\rangle \mapsto a|0\rangle - b|1\rangle .

A relative phase is observable: it changes the probabilities of a measurement in a different basis, and it is the resource interference is built from. The difference between $a|0\rangle + b|1\rangle$ and $a|0\rangle - b|1\rangle$ is invisible in the computational basis but catastrophic in the Hadamard basis, and that is the entire content of “phase matters.”

In tqp the phase is read off with np.angle, and the two kinds of phase are distinguished by whether the factor is global or relative:

import numpy as np
a, b = 1j, 1                # amplitudes
# global phase: multiply both by e^{i gamma}
gamma = np.pi / 3
a_g, b_g = a*np.exp(1j*gamma), b*np.exp(1j*gamma)
# both amplitudes rotate the same way -> probabilities unchanged
# relative phase: multiply only b
a_r, b_r = a, b*np.exp(1j*gamma)
# only b rotates -> the relative phase between a and b has changed

The global-phase case leaves abs(a)**2 and abs(b)**2 unchanged; the relative-phase case does not, once you measure in a basis that is sensitive to the phase.

Why phase is physical

The reason a relative phase is physical is that it is a direction, and a direction is only a direction relative to something else. The state $a|0\rangle + b|1\rangle$ has a phase relative to $|0\rangle$; the state $a|0\rangle - b|1\rangle$ has a different phase relative to $|0\rangle$, and that difference is what a measurement in the Hadamard basis detects.

The canonical example is the Hadamard gate. It maps

∣0⟩↦∣+⟩=12(∣0⟩+∣1⟩),∣1⟩↦∣−⟩=12(∣0⟩−∣1⟩). |0\rangle \mapsto |+\rangle = \tfrac{1}{\sqrt{2}}(|0\rangle + |1\rangle), \qquad |1\rangle \mapsto |-\rangle = \tfrac{1}{\sqrt{2}}(|0\rangle - |1\rangle) .

The states $|+\rangle$ and $|-\rangle$ differ only in the relative phase between $|0\rangle$ and $|1\rangle$, and that difference is exactly what makes them orthogonal and measurable. A computation that ignores phase would treat $|+\rangle$ and $|-\rangle$ as the same, and it would be wrong: the phase is the difference, and the difference is what the computation exploits.

This is the lesson of the chapter: a phase is not a number you can discard, and a relative phase is not a number you can measure directly. It is a direction in the complex plane, and it is physical only relative to another amplitude. Get that through your fingers now, and interference will make sense.

Exercises

(a) Write $z = 1 + i$ in polar form: give the modulus and the phase.

Answer

The modulus is $|z| = \sqrt{1^2 + 1^2} = \sqrt{2}$, and the phase is $\arg z = \arctan(1/1) = \pi/4$. So $z = \sqrt{2}\,e^{i\pi/4}$.

(b) Multiply $z_1 = e^{i\pi/6}$ and $z_2 = e^{i\pi/3}$ using the polar rule, and verify by direct multiplication.

Answer

The polar rule says the product has modulus $1 \cdot 1 = 1$ and phase \tfrac{\pi}{6} + \tfrac{\pi}{3} = \tfrac{\pi}{2}$, so $z_1 z_2 = e^{i\pi/2} = i$. Direct multiplication: $(\cos\tfrac{\pi}{6} + i\sin\tfrac{\pi}{6})(\cos\tfrac{\pi}{3} + i\sin\tfrac{\pi}{3})$. The real part is $\cos\tfrac{\pi}{6}\cos\tfrac{\pi}{3} - \sin\tfrac{\pi}{6}\sin\tfrac{\pi}{3} = \tfrac{\sqrt3}{2}\cdot\tfrac12 - \tfrac12\cdot\tfrac{\sqrt3}{2} = 0$, and the imaginary part is $\sin\tfrac{\pi}{6}\cos\tfrac{\pi}{3} + \cos\tfrac{\pi}{6}\sin\tfrac{\pi}{3} = \tfrac12\cdot\tfrac12 + \tfrac{\sqrt3}{2}\cdot\tfrac{\sqrt3}{2} = \tfrac14 + \tfrac34 = 1$. So the product is $0 + i = i$, confirming the polar rule.

(c) Why is a global phase unobservable but a relative phase is not?

Answer

A global phase multiplies every amplitude by the same factor $e^{i\gamma}$, so every probability $|a|^2$ is multiplied by $|e^{i\gamma}|^2 = 1$; the measurement statistics are identical in every basis, so no measurement can detect it. A relative phase changes the *difference* between two amplitudes, which is invisible in the basis the phases are defined in but visible in a different basis: $a|0\rangle + b|1\rangle$ and $a|0\rangle - b|1\rangle$ give the same probabilities in the computational basis but different probabilities in the Hadamard basis. The phase is a direction, and a direction is only detectable relative to a reference.

(d) Why must the amplitudes be complex and not real?

Answer

A real amplitude carries only a sign, $+$ or $-$, which can interfere constructively or destructively but cannot carry the full range of relative phases. The Bloch sphere is a sphere, parametrised by two angles $\theta$ and $\phi$; a real amplitude can describe the polar angle $\theta$ but not the azimuthal phase $\phi$, and so cannot describe a general qubit state. The phase gate, which adds a relative phase, is a rotation about the $z$-axis of the Bloch sphere, and that rotation is invisible to any real amplitude. The phase is a genuinely complex phenomenon, and the amplitudes must be complex to carry it.

Lab: phase in tqp

The first circuit that runs is chapter 14’s, but this lab runs the phase directly, in tqp, so you can see the difference between a global and a relative phase.

Build labs/ch03/ from the repository root:

mkdir -p labs/ch03

Write a script that does three things:

  1. Build the state $|+\rangle = (|0\rangle + |1\rangle)/\sqrt{2}$ and print its amplitudes with np.angle.
  2. Apply a global phase $e^{i\pi/4}$ to both amplitudes and check the probabilities are unchanged.
  3. Apply a relative phase $e^{i\pi/4}$ to $|1\rangle$ only and check the probabilities change when measured in the Hadamard basis.

Run it:

make lab CH=03

The acceptance test checks that a global phase leaves the probabilities unchanged and a relative phase changes them in the Hadamard basis.

make test

should be green.

Further reading

The three documents this book keeps open:

  • Complex number — polar form, Euler’s formula, the phase as an angle. The why behind the arithmetic.
  • Euler’s formula — the identity that makes the phase an angle.
  • Quantum phase — global versus relative phase, and why a relative phase is physical.

And the paper behind the cloud QPU, read in Part III:

results matching ""

    No results matching ""