
# Complex Numbers & Functions

> A quantum amplitude is not a probability — it is a *complex number*. Probabilities are the
> $|\cdot|^2$ shadow it casts. Everything distinctively quantum, from interference to the Fourier
> transform that powers Shor's algorithm, lives in the *phase* that the shadow throws away. This
> lesson rebuilds the complex field from the ground up so that phase is never mysterious again.

## Learning Objectives

By the end of this lesson you will be able to:

1. **Manipulate** complex numbers fluently in both Cartesian ($a+bi$) and polar ($re^{i\theta}$) form, converting between them and computing modulus, argument, and conjugate.
2. **Derive** Euler's formula $e^{i\theta}=\cos\theta+i\sin\theta$ from the Maclaurin series and use it to prove de Moivre's theorem.
3. **Define** the $N$-th roots of unity $\omega^k$ with $\omega = e^{2\pi i/N}$ and **prove** their summation property $\sum_{k=0}^{N-1}\omega^{k}=0$.
4. **Explain** why quantum amplitudes must be complex — that *relative phase* is physically observable through interference — and connect this to the Fourier machinery developed later in the course.
5. **Compute and visualize** roots of unity in NumPy and verify their algebraic identities numerically.

---

## Intuition

A real number is a point on a line; a complex number is a point in a plane. That extra dimension is
not a bookkeeping convenience — it is *rotation*. Multiplying by $i$ rotates the plane by $90°$;
multiplying by $e^{i\theta}$ rotates it by $\theta$. The single most important picture to carry
forward is this:

> **A unit-modulus complex number $e^{i\theta}$ is a pure rotation by angle $\theta$.**

Why does quantum mechanics need this and not just real probabilities? Consider two paths an
amplitude can take to the same outcome. Classically you add *probabilities*: $p = p_1 + p_2 \ge 0$,
and more paths can only help. Quantum mechanically you add *amplitudes*: $\alpha = \alpha_1 +
\alpha_2$, and then square. If $\alpha_1 = \tfrac12$ and $\alpha_2 = -\tfrac12$, the outcome
probability is $|\alpha_1+\alpha_2|^2 = 0$: the two paths *cancel*. That sign — more generally, that
relative phase $e^{i\theta}$ — is the whole game. Real numbers give you only the signs $\pm 1$;
complex numbers give you a continuous dial of cancellation. We forward-reference this as
**interference**, the engine of every quantum speedup.

Hold two facts together as you read the theory: complex numbers are (1) the algebra of rotations and
(2) the only number system rich enough to let amplitudes interfere continuously while still
collapsing to real probabilities via $|\cdot|^2$.

---

## Theory

### The complex field

**Definition (complex numbers).** The set $\mathbb{C} = \{a + bi : a,b\in\mathbb{R}\}$ with the
symbol $i$ satisfying $i^2 = -1$, equipped with

$$
(a+bi) + (c+di) = (a+c) + (b+d)i,\qquad
(a+bi)(c+di) = (ac-bd) + (ad+bc)i,
$$

forms a **field**: addition and multiplication are commutative, associative, and distributive;
$0 = 0+0i$ and $1 = 1+0i$ are the identities; and every nonzero $z$ has an inverse (derived below).
We call $a = \operatorname{Re}(z)$ the **real part** and $b = \operatorname{Im}(z)$ the **imaginary
part**. (We freely write $i$ where Python writes `1j`; see [Appendix B §1](../../appendix/B-python-numpy-refresher.md).)

**Definition (conjugate and modulus).** The **complex conjugate** of $z = a+bi$ is
$\bar z = z^{*} = a - bi$, and the **modulus** is

$$
|z| = \sqrt{a^2 + b^2} = \sqrt{z\,z^{*}}.
$$

The conjugate flips the sign of the imaginary part (a reflection across the real axis). Two
identities we use constantly:

$$
z\,z^{*} = (a+bi)(a-bi) = a^2 + b^2 = |z|^2 \in \mathbb{R}_{\ge 0},
\qquad
(zw)^{*} = z^{*}w^{*}.
$$

The first gives the multiplicative inverse for $z\neq 0$:

$$
z^{-1} = \frac{z^{*}}{|z|^2} = \frac{a - bi}{a^2+b^2},
$$

which proves $\mathbb{C}$ is a field. Conjugation is an *involution* ($(z^{*})^{*}=z$) and is
additive ($(z+w)^{*}=z^{*}+w^{*}$); together with $(zw)^{*}=z^{*}w^{*}$ it is a *field
automorphism*. This is exactly the operation that turns a ket into a bra: $\langle\psi| =
|\psi\rangle^{\dagger}$ conjugates amplitudes (see [Appendix C §1](../../appendix/C-notation-glossary.md)).

### Cartesian and polar form

Plotting $z=a+bi$ at Cartesian coordinates $(a,b)$ in the **complex plane** (Argand diagram), the
point also has polar coordinates $(r,\theta)$:

$$
a = r\cos\theta,\quad b = r\sin\theta,\qquad
r = |z| = \sqrt{a^2+b^2},\quad \theta = \arg(z) = \operatorname{atan2}(b,a).
$$

We call $r$ the modulus and $\theta$ the **argument**. The argument is only defined modulo $2\pi$;
the **principal value** $\operatorname{Arg}(z)\in(-\pi,\pi]$ is the standard choice (NumPy's
`np.angle` returns it). Use `atan2`, not $\arctan(b/a)$, so the correct quadrant is selected.

### Euler's formula — derivation via power series

We want a meaning for $e^{i\theta}$. Take the real Maclaurin series of $e^x$, $\cos x$, $\sin x$ —
each converges for all real arguments, and the exponential series converges *absolutely* for every
complex argument, so we may extend it to $z\in\mathbb C$ and rearrange freely:

$$
e^{z} = \sum_{n=0}^{\infty}\frac{z^n}{n!},\qquad
\cos x = \sum_{m=0}^{\infty}\frac{(-1)^m x^{2m}}{(2m)!},\qquad
\sin x = \sum_{m=0}^{\infty}\frac{(-1)^m x^{2m+1}}{(2m+1)!}.
$$

Substitute $z = i\theta$ and use the cycle $i^0=1,\ i^1=i,\ i^2=-1,\ i^3=-i,\ i^4=1,\dots$:

$$
e^{i\theta} = \sum_{n=0}^{\infty}\frac{(i\theta)^n}{n!}
= \sum_{n=0}^{\infty}\frac{i^n\theta^n}{n!}.
$$

Split into even ($n=2m$, giving $i^{2m}=(-1)^m$) and odd ($n=2m+1$, giving $i^{2m+1}=(-1)^m i$)
terms. Absolute convergence lets us regroup:

$$
e^{i\theta}
= \underbrace{\sum_{m=0}^{\infty}\frac{(-1)^m\theta^{2m}}{(2m)!}}_{=\,\cos\theta}
\;+\; i\underbrace{\sum_{m=0}^{\infty}\frac{(-1)^m\theta^{2m+1}}{(2m+1)!}}_{=\,\sin\theta}.
$$

This is **Euler's formula**:

$$
\boxed{\,e^{i\theta} = \cos\theta + i\sin\theta\,}.
$$

Immediate consequences:

- $|e^{i\theta}| = \sqrt{\cos^2\theta+\sin^2\theta} = 1$ — the unit circle, as the intuition promised.
- $\theta=\pi$ gives **Euler's identity** $e^{i\pi}+1 = 0$.
- $(e^{i\theta})^{*} = \cos\theta - i\sin\theta = e^{-i\theta}$, hence the inverse-on-the-circle:
  $e^{i\theta}e^{-i\theta}=1$.
- The **complex exponential** of a general $z=a+bi$ factors a stretch and a rotation:
  $$
  e^{z} = e^{a+bi} = e^{a}\,e^{ib} = e^{a}\big(\cos b + i\sin b\big).
  $$

We can now read **polar form** as an exponential:

$$
z = r(\cos\theta + i\sin\theta) = r\,e^{i\theta},\qquad r=|z|,\ \theta=\arg z.
$$

Multiplication becomes transparent — moduli multiply, arguments add:

$$
(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 precise sense in which *multiplying by $e^{i\theta}$ rotates by $\theta$*.

### De Moivre's theorem

Setting $r=1$ and iterating the multiplication rule (or, formally, by induction on $n$ using
$e^{i(n+1)\theta}=e^{in\theta}e^{i\theta}$) gives **de Moivre's theorem**:

$$
\big(\cos\theta + i\sin\theta\big)^{n} = \cos n\theta + i\sin n\theta,\qquad n\in\mathbb{Z}.
$$

It is just $\big(e^{i\theta}\big)^{n} = e^{in\theta}$ in disguise. It is the workhorse for deriving
multiple-angle identities and, next, the roots of unity.

### The $N$-th roots of unity

We want all solutions of $z^N = 1$ for a positive integer $N$. Write $z = r e^{i\theta}$. Then
$z^N = r^N e^{iN\theta} = 1 = 1\cdot e^{i\cdot 0}$. Matching moduli forces $r=1$; matching arguments
(modulo $2\pi$) forces $N\theta = 2\pi k$ for integer $k$, i.e. $\theta = 2\pi k/N$. Distinct values
arise only for $k=0,1,\dots,N-1$. Defining the **primitive $N$-th root of unity**

$$
\boxed{\,\omega := e^{2\pi i/N}\,}\qquad(\text{matches }[\text{Appendix E §6}](../../appendix/E-math-identities.md)),
$$

the $N$ roots are exactly the powers of $\omega$:

$$
z_k = \omega^{k} = e^{2\pi i k/N},\qquad k = 0,1,\dots,N-1.
$$

Geometrically they are the $N$ vertices of a regular $N$-gon inscribed in the unit circle, starting
at $1$ and stepping counter-clockwise by $2\pi/N$. (We use the sign convention $\omega =
e^{+2\pi i/N}$ throughout the program; see [Appendix C §4](../../appendix/C-notation-glossary.md). The
DFT in lesson 3 uses $e^{-2\pi i/N}$ as its forward kernel — a deliberate, consistent choice.)

**Theorem (vanishing sum).** For $N>1$,

$$
\sum_{k=0}^{N-1}\omega^{k} = 0.
$$

*Proof.* The sum is a finite geometric series with ratio $\omega$. Since $N>1$, $\omega = e^{2\pi
i/N}\neq 1$ (its argument $2\pi/N\in(0,2\pi)$ is nonzero mod $2\pi$), so the closed form applies:

$$
\sum_{k=0}^{N-1}\omega^{k} = \frac{1-\omega^{N}}{1-\omega}.
$$

But $\omega^{N} = e^{2\pi i} = 1$, so the numerator is $1-1 = 0$ while the denominator $1-\omega\neq
0$. Hence the sum is $0$. $\blacksquare$

This is the algebraic heart of all Fourier analysis: distinct frequency components *cancel* when
summed over a full period. We generalize it now.

**Corollary (orthogonality of roots).** For integers $j,k$,

$$
\frac{1}{N}\sum_{x=0}^{N-1} \omega^{x(j-k)} = \delta_{jk}
\qquad\text{(indices taken mod }N),
$$

matching the DFT/QFT orthogonality in [Appendix E §6](../../appendix/E-math-identities.md).

*Proof.* Let $m = j-k$. If $m\equiv 0\pmod N$ then every term is $\omega^{0}=1$ and the average is
$\tfrac1N\cdot N = 1$. Otherwise $\omega^{m}\neq 1$ and the same geometric-series argument gives

$$
\sum_{x=0}^{N-1}(\omega^{m})^{x} = \frac{1-(\omega^{m})^{N}}{1-\omega^{m}}
= \frac{1-(\omega^{N})^{m}}{1-\omega^{m}} = \frac{1-1}{1-\omega^{m}} = 0. \qquad\blacksquare
$$

**Other useful properties.**

- **Closure / group structure.** The roots $\{1,\omega,\dots,\omega^{N-1}\}$ are closed under
  multiplication: $\omega^{j}\omega^{k} = \omega^{(j+k)\bmod N}$. They form the cyclic group
  $\mathbb Z/N\mathbb Z$ under addition of exponents — the same group that indexes computational
  basis states in the QFT.
- **Conjugate = inverse.** $\overline{\omega^{k}} = \omega^{-k} = \omega^{N-k}$, since
  $|\omega^k|=1$.
- **Product of all roots.** $\prod_{k=0}^{N-1}\omega^{k} = \omega^{\,0+1+\cdots+(N-1)} =
  \omega^{N(N-1)/2} = (-1)^{N-1}$.

### Why quantum amplitudes are complex

A pure state is $|\psi\rangle = \alpha|0\rangle + \beta|1\rangle$ with $\alpha,\beta\in\mathbb C$ and
$|\alpha|^2 + |\beta|^2 = 1$ ([Appendix C §1](../../appendix/C-notation-glossary.md)). Measurement
gives outcome $0$ with probability $|\alpha|^2$ — so why not just store the probabilities
$(|\alpha|^2,|\beta|^2)$ and stay real and nonnegative?

Because *evolution mixes the components*, and the mixing is sensitive to phase. Apply a Hadamard to
$|+\rangle = \tfrac1{\sqrt2}(|0\rangle+|1\rangle)$ versus $|-\rangle =
\tfrac1{\sqrt2}(|0\rangle-|1\rangle)$:

$$
H|+\rangle = |0\rangle,\qquad H|-\rangle = |1\rangle.
$$

Both $|+\rangle$ and $|-\rangle$ have the *same* measurement statistics in the computational basis
($50/50$), so the probability vector $(\tfrac12,\tfrac12)$ cannot tell them apart. Yet $H$ sends one
to a certain $0$ and the other to a certain $1$. The only thing distinguishing them is the
**relative phase** $\beta/\alpha = +1$ versus $-1$ — a phase $e^{i\pi}$. Relative phase is therefore
*physically observable*: it changes future measurement outcomes after interference.

Two more points pin this down:

- **Global phase is unobservable.** $|\psi\rangle$ and $e^{i\gamma}|\psi\rangle$ give identical
  statistics for *every* measurement, because $|e^{i\gamma}\alpha|^2 = |\alpha|^2$. Only phase
  *differences between amplitudes* matter — exactly the relative phase above.
- **Why not just signs $\pm1$?** Real amplitudes ($\beta/\alpha\in\{\pm1\}$ up to scale) allow only
  two-way cancellation. Continuous phases $e^{i\theta}$ let amplitudes interfere by *any* angle, and
  the canonical phases are precisely the roots of unity $\omega^k$. When a quantum register holds a
  uniform superposition and we apply a phase $\omega^{xy}$ to basis state $|y\rangle$, the
  interference pattern is governed by sums like $\sum_y \omega^{xy}$ — which, by the vanishing-sum
  theorem above, are zero except at special $x$. That selective cancellation *is* the Quantum
  Fourier Transform, developed in [Term 2.4 · The Quantum Fourier Transform](../../term-2-qc-core/c04-qft-qpe/01-quantum-fourier-transform.md).

So: amplitudes are complex because nature lets probability amplitudes *rotate and interfere*, and
$\mathbb C$ is the minimal arena — a field where $|\cdot|^2$ recovers probabilities — in which
continuous rotation lives.

---

## Worked Examples

### Example 1 — Polar form, powers, and a root

Let $z = 1 + i\sqrt 3$.

**Modulus and argument.** $|z| = \sqrt{1^2 + (\sqrt3)^2} = \sqrt{4} = 2$. The point $(1,\sqrt3)$ is
in the first quadrant, so $\arg z = \operatorname{atan2}(\sqrt3, 1) = \pi/3$. Thus

$$
z = 2\,e^{i\pi/3}.
$$

**A power, via de Moivre.** Compute $z^{6}$:

$$
z^{6} = 2^{6}\,e^{i\cdot 6\pi/3} = 64\,e^{i2\pi} = 64\cdot 1 = 64.
$$

The phase wraps exactly once around the circle and lands back on the positive real axis — a clean
illustration of "arguments add (mod $2\pi$), moduli multiply."

**A square root.** $\sqrt z = \sqrt2\,e^{i\pi/6} = \sqrt2(\cos\tfrac\pi6 + i\sin\tfrac\pi6) =
\sqrt2\big(\tfrac{\sqrt3}{2} + \tfrac{i}{2}\big) = \tfrac{\sqrt6}{2} + \tfrac{\sqrt2}{2}\,i$. (The
other root is its negative.)

### Example 2 — The cube roots of unity and their sum

Take $N=3$, $\omega = e^{2\pi i/3}$. The roots are:

$$
\omega^{0} = 1,\qquad
\omega^{1} = e^{2\pi i/3} = \cos\tfrac{2\pi}{3} + i\sin\tfrac{2\pi}{3} = -\tfrac12 + \tfrac{\sqrt3}{2}i,
$$
$$
\omega^{2} = e^{4\pi i/3} = -\tfrac12 - \tfrac{\sqrt3}{2}i.
$$

They are the vertices of an equilateral triangle on the unit circle. Their sum:

$$
1 + \Big(-\tfrac12 + \tfrac{\sqrt3}{2}i\Big) + \Big(-\tfrac12 - \tfrac{\sqrt3}{2}i\Big)
= (1 - \tfrac12 - \tfrac12) + \big(\tfrac{\sqrt3}{2} - \tfrac{\sqrt3}{2}\big)i = 0,
$$

confirming $\sum_{k=0}^{2}\omega^k = 0$. Note also $\omega^2 = \overline{\omega^1} = \omega^{-1}$, as
the conjugate-inverse property predicts.

### Example 3 — Interference: distinguishing $|+\rangle$ from $|-\rangle$

Let $\alpha = \tfrac1{\sqrt2}$ and consider $|\pm\rangle = \alpha|0\rangle \pm \alpha|1\rangle$. The
Hadamard $H = \tfrac1{\sqrt2}\begin{psmallmatrix}1&1\\1&-1\end{psmallmatrix}$ acts as

$$
H|+\rangle = \tfrac12\big[(1+1)|0\rangle + (1-1)|1\rangle\big] = |0\rangle,
$$
$$
H|-\rangle = \tfrac12\big[(1-1)|0\rangle + (1+1)|1\rangle\big] = |1\rangle.
$$

In $H|+\rangle$ the $|1\rangle$ amplitudes $\tfrac12$ and $-\tfrac12$ cancel by *destructive
interference* (their relative phase is $e^{i\pi}=-1$); in $H|-\rangle$ the $|0\rangle$ amplitudes
cancel instead. A purely real, nonnegative probability description $(\tfrac12,\tfrac12)$ for both
inputs could never predict these opposite, deterministic outputs. The complex (here, just signed)
relative phase is doing physical work — this is the smallest possible instance of the interference
that the Fourier methods in this course exploit at scale.

The same two lines describe a Mach–Zehnder interferometer: a beam splitter $H$, a phase
$e^{i\varphi}$ on one arm, and a second $H$. At $\varphi = 0$ the photon is in $|+\rangle$ between the
splitters and always exits to detector $D_0$. At $\varphi = \pi$ it is in $|-\rangle$ and always exits
to $D_1$. In between, $D_0$ fires with probability $\cos^2(\varphi/2)$, the result of E6 below:

```qm-demo mach-zehnder

```

---

## Hands-on (Python)

```python
import numpy as np
import matplotlib.pyplot as plt

# ----- Cartesian <-> polar -----
z = 1 + 1j * np.sqrt(3)          # 1 + i*sqrt(3)
print("z            =", z)
print("|z|          =", abs(z))            # 2.0   = modulus
print("arg(z) [rad] =", np.angle(z))       # ~1.047 = pi/3
print("conj(z)      =", z.conjugate())     # 1 - i*sqrt(3)
print("z * conj(z)  =", (z * z.conjugate()).real)  # |z|^2 = 4.0

# Reconstruct z from polar form r * e^{i*theta}
r, theta = abs(z), np.angle(z)
z_polar = r * np.exp(1j * theta)
print("polar matches Cartesian:", np.isclose(z, z_polar))  # True


def roots_of_unity(N):
    """Return the N-th roots of unity as a complex array [omega^0, ..., omega^{N-1}]."""
    k = np.arange(N)
    omega = np.exp(2j * np.pi / N)         # primitive root  ω = e^{2πi/N}
    return omega ** k                      # equivalently np.exp(2j*np.pi*k/N)


# ----- Verify the vanishing-sum theorem  Σ ω^k = 0  for several N -----
for N in (2, 3, 4, 8, 16):
    s = roots_of_unity(N).sum()
    print(f"N={N:2d}:  Σ ω^k = {s:.2e}   (|sum| = {abs(s):.2e})")
    assert np.isclose(s, 0.0, atol=1e-12), "vanishing-sum theorem failed!"

# ----- Verify orthogonality  (1/N) Σ_x ω^{x(j-k)} = δ_{jk} -----
N = 8
omega = np.exp(2j * np.pi / N)
x = np.arange(N)
# Build the N x N matrix M[j, k] = (1/N) Σ_x ω^{x(j-k)}; it should be the identity.
M = np.array([[np.mean(omega ** (x * (j - k))) for k in range(N)] for j in range(N)])
print("orthogonality gives identity:", np.allclose(M, np.eye(N), atol=1e-12))  # True


def plot_roots_of_unity(N):
    """Plot the N-th roots of unity on the unit circle."""
    roots = roots_of_unity(N)
    fig, ax = plt.subplots(figsize=(5, 5))
    circle = plt.Circle((0, 0), 1.0, fill=False, linestyle="--", color="gray")
    ax.add_patch(circle)
    ax.scatter(roots.real, roots.imag, zorder=3)
    for k, w in enumerate(roots):
        ax.annotate(rf"$\omega^{{{k}}}$", (w.real, w.imag),
                    textcoords="offset points", xytext=(6, 6))
    ax.axhline(0, color="black", lw=0.5); ax.axvline(0, color="black", lw=0.5)
    ax.set_aspect("equal"); ax.set_xlim(-1.3, 1.3); ax.set_ylim(-1.3, 1.3)
    ax.set_title(rf"$N={N}$ roots of unity,  $\omega=e^{{2\pi i/{N}}}$")
    ax.set_xlabel("Re"); ax.set_ylabel("Im")
    plt.tight_layout(); plt.show()


plot_roots_of_unity(8)

# ----- Interference demo: H distinguishes |+> from |-> -----
H = np.array([[1, 1], [1, -1]], dtype=complex) / np.sqrt(2)
ket_plus  = np.array([1,  1], dtype=complex) / np.sqrt(2)
ket_minus = np.array([1, -1], dtype=complex) / np.sqrt(2)
print("H|+> =", np.round(H @ ket_plus, 12).real)    # [1, 0]  -> |0>
print("H|-> =", np.round(H @ ket_minus, 12).real)   # [0, 1]  -> |1>
```

Running this prints `|z|=2.0`, `arg(z)≈1.047` ($=\pi/3$), confirms $\sum\omega^k=0$ to machine
precision for every $N$, verifies the orthogonality matrix is the identity, draws the regular
$8$-gon of roots, and shows that $H$ maps $|+\rangle\mapsto|0\rangle$ and
$|-\rangle\mapsto|1\rangle$ — interference made visible.

---

## Exercises

Attempt each before expanding the solution.

**1. (Easy) Cartesian ↔ polar.** Write $z = -\sqrt3 + i$ in polar form $re^{i\theta}$ with
$\theta\in(-\pi,\pi]$, then compute $z^{4}$.

<details><summary>Solution</summary>

$|z| = \sqrt{(\sqrt3)^2 + 1^2} = 2$. The point $(-\sqrt3, 1)$ is in the second quadrant:
$\theta = \operatorname{atan2}(1, -\sqrt3) = \pi - \pi/6 = 5\pi/6$. So $z = 2\,e^{i5\pi/6}$.
Then $z^4 = 2^4 e^{i\cdot 20\pi/6} = 16\,e^{i10\pi/3}$. Reduce the argument mod $2\pi$:
$10\pi/3 - 2\pi = 4\pi/3$, so $z^4 = 16\,e^{i4\pi/3} = 16(-\tfrac12 - \tfrac{\sqrt3}{2}i)
= -8 - 8\sqrt3\,i$.

</details>

**2. (Easy) Conjugate identities.** Prove $(zw)^{*} = z^{*}w^{*}$ directly from $z=a+bi$,
$w=c+di$, and use it to show $|zw| = |z|\,|w|$.

<details><summary>Solution</summary>

$zw = (ac-bd) + (ad+bc)i$, so $(zw)^{*} = (ac-bd) - (ad+bc)i$. Meanwhile $z^{*}w^{*} =
(a-bi)(c-di) = (ac - bd) - (ad+bc)i$ (the cross terms $-adi - bci$ combine to $-(ad+bc)i$, and
$(-bi)(-di) = bd i^2 = -bd$). They match. Then $|zw|^2 = (zw)(zw)^{*} = z w z^{*} w^{*} =
(zz^{*})(ww^{*}) = |z|^2|w|^2$; taking nonnegative square roots gives $|zw| = |z||w|$. (In polar
form this is just "moduli multiply.")

</details>

**3. (Medium) De Moivre → trig identity.** Use de Moivre with $n=3$ to derive
$\cos 3\theta = 4\cos^3\theta - 3\cos\theta$.

<details><summary>Solution</summary>

$(\cos\theta + i\sin\theta)^3 = \cos3\theta + i\sin3\theta$. Expand the left side with the binomial
theorem: $\cos^3\theta + 3\cos^2\theta(i\sin\theta) + 3\cos\theta(i\sin\theta)^2 + (i\sin\theta)^3
= \cos^3\theta - 3\cos\theta\sin^2\theta + i(3\cos^2\theta\sin\theta - \sin^3\theta)$. Match real
parts: $\cos3\theta = \cos^3\theta - 3\cos\theta\sin^2\theta$. Substitute $\sin^2\theta = 1 -
\cos^2\theta$: $\cos3\theta = \cos^3\theta - 3\cos\theta(1-\cos^2\theta) = 4\cos^3\theta -
3\cos\theta$. $\blacksquare$

</details>

**4. (Medium) Sum of a subset of roots.** For $N=6$, compute $\sum_{k=0}^{5}\omega^{2k}$ where
$\omega = e^{2\pi i/6}$. Explain the result group-theoretically.

<details><summary>Solution</summary>

$\omega^{2} = e^{4\pi i/6} = e^{2\pi i/3}$ is a primitive *cube* root of unity. As $k$ runs over
$0,\dots,5$, $\omega^{2k}$ runs over the cube roots $\{1, e^{2\pi i/3}, e^{4\pi i/3}\}$ *twice*
(period 3). So $\sum_{k=0}^{5}\omega^{2k} = 2\sum_{j=0}^{2}(e^{2\pi i/3})^{j} = 2\cdot 0 = 0$ by the
vanishing-sum theorem for $N=3$. Group-theoretically, $\{\omega^{2k}\}$ is the subgroup generated by
$\omega^2$, which is the cyclic group of order $3$; the sum over any nontrivial finite cyclic
subgroup (here covered twice) vanishes.

</details>

**5. (Hard) Geometric-series proof, general phase.** Show that for any real $\phi$ with
$\phi\not\equiv 0\pmod{2\pi}$, $\big|\sum_{k=0}^{N-1} e^{ik\phi}\big| =
\big|\frac{\sin(N\phi/2)}{\sin(\phi/2)}\big|$ (the *Dirichlet kernel*). Then recover $\sum_{k}\omega^k
= 0$ as the special case $\phi = 2\pi/N$.

<details><summary>Solution</summary>

Sum the geometric series with ratio $e^{i\phi}\neq 1$:
$S = \sum_{k=0}^{N-1} e^{ik\phi} = \frac{1 - e^{iN\phi}}{1 - e^{i\phi}}$. Factor out the
half-angle from numerator and denominator ("$1-e^{i\alpha} = e^{i\alpha/2}(e^{-i\alpha/2} -
e^{i\alpha/2}) = -2i\,e^{i\alpha/2}\sin(\alpha/2)$"):
$$
S = \frac{-2i\,e^{iN\phi/2}\sin(N\phi/2)}{-2i\,e^{i\phi/2}\sin(\phi/2)}
= e^{i(N-1)\phi/2}\,\frac{\sin(N\phi/2)}{\sin(\phi/2)}.
$$
Taking the modulus (the leading exponential has modulus 1) gives
$|S| = \big|\sin(N\phi/2)/\sin(\phi/2)\big|$. For $\phi = 2\pi/N$: $N\phi/2 = \pi$, so
$\sin(N\phi/2) = \sin\pi = 0$ while $\sin(\phi/2) = \sin(\pi/N)\neq 0$ for $N>1$. Hence $|S|=0$,
i.e. $\sum_k \omega^k = 0$. $\blacksquare$

</details>

**6. (Hard) Phase encodes a number.** A single qubit is prepared in
$|\psi_\varphi\rangle = \tfrac1{\sqrt2}(|0\rangle + e^{2\pi i\varphi}|1\rangle)$ for some unknown
$\varphi\in[0,1)$. (a) Show that measuring in the computational basis cannot reveal $\varphi$.
(b) Show that applying $H$ first and then measuring gives outcome $0$ with probability
$\cos^2(\pi\varphi)$, so the *relative phase* becomes measurable. (This is the seed of phase
estimation.)

<details><summary>Solution</summary>

(a) $|\langle 0|\psi_\varphi\rangle|^2 = |\tfrac1{\sqrt2}|^2 = \tfrac12$ and likewise for outcome
$1$, independent of $\varphi$ — the global phase on $|1\rangle$ is washed out by $|\cdot|^2$.

(b) $H|\psi_\varphi\rangle = \tfrac1{\sqrt2}\big[\tfrac1{\sqrt2}(|0\rangle+|1\rangle) + e^{2\pi
i\varphi}\tfrac1{\sqrt2}(|0\rangle-|1\rangle)\big] = \tfrac12\big[(1+e^{2\pi i\varphi})|0\rangle +
(1-e^{2\pi i\varphi})|1\rangle\big]$. The amplitude of $|0\rangle$ is $\tfrac12(1+e^{2\pi
i\varphi})$. Using $1+e^{i\alpha} = e^{i\alpha/2}(e^{-i\alpha/2}+e^{i\alpha/2}) = 2e^{i\alpha/2}
\cos(\alpha/2)$ with $\alpha = 2\pi\varphi$, the amplitude is $e^{i\pi\varphi}\cos(\pi\varphi)$, so
$p(0) = |{\cdot}|^2 = \cos^2(\pi\varphi)$. The previously hidden phase $\varphi$ now controls a
measurable probability — interference has converted *relative phase* into *statistics*. This is
exactly the mechanism scaled up in [Term 2.4](../../term-2-qc-core/c04-qft-qpe/01-quantum-fourier-transform.md).

</details>

---

## Checkpoint

<details><summary>1. State Euler's formula and give the one-line reason $|e^{i\theta}|=1$.</summary>

$e^{i\theta} = \cos\theta + i\sin\theta$. Its modulus is $\sqrt{\cos^2\theta+\sin^2\theta}=1$, so it
lies on the unit circle — a pure rotation by $\theta$.

</details>

<details><summary>2. Why does $\sum_{k=0}^{N-1}\omega^k = 0$ for $N>1$, in one sentence?</summary>

It is a geometric series with ratio $\omega\neq1$; its closed form $(1-\omega^N)/(1-\omega)$ has
numerator $1-\omega^N = 1-1 = 0$ because $\omega^N = e^{2\pi i} = 1$.

</details>

<details><summary>3. What is the difference between global phase and relative phase, and which is physical?</summary>

A global phase $e^{i\gamma}$ multiplies the *whole* state and is unobservable ($|e^{i\gamma}\alpha|^2
= |\alpha|^2$). A relative phase is a phase *difference between amplitudes* (e.g. $\beta/\alpha$); it
is physically observable because it changes interference and hence future measurement statistics.

</details>

<details><summary>4. Concretely, why can't real nonnegative probabilities replace complex amplitudes?</summary>

Because evolution mixes amplitudes, and the result depends on phases. $|+\rangle$ and $|-\rangle$
share the probability vector $(\tfrac12,\tfrac12)$ but $H$ maps them to $|0\rangle$ and $|1\rangle$
respectively — opposite deterministic outcomes. Only the complex (relative) phase distinguishes the
inputs.

</details>

<details><summary>5. How are the $N$-th roots of unity related to the group $\mathbb Z/N\mathbb Z$?</summary>

$\omega^j\omega^k = \omega^{(j+k)\bmod N}$, so the roots are closed under multiplication and form a
cyclic group isomorphic to $(\mathbb Z/N\mathbb Z, +)$ via $k\mapsto\omega^k$. This is the group that
indexes basis states in the (Quantum) Fourier Transform.

</details>

<details><summary>6. What single identity from this lesson is the algebraic core of the DFT/QFT?</summary>

The orthogonality relation $\tfrac1N\sum_{x=0}^{N-1}\omega^{x(j-k)} = \delta_{jk}$ — distinct
frequency components cancel over a full period, leaving only the matching term. We use it to prove
the DFT matrix is unitary in [lesson 3](03-discrete-fourier-transform.md).

</details>

---

## Further Reading

- **[NC, §2.1]** — complex linear algebra background the program relies on.
- **[Axl]** — *Linear Algebra Done Right*: clean treatment of $\mathbb C$ as the scalar field.
- **[Appendix E §6](../../appendix/E-math-identities.md)** — roots of unity, the QFT kernel, Euler's
  formula, in the program's exact notation.
- **[Appendix C §1, §4](../../appendix/C-notation-glossary.md)** — global vs. relative phase; the
  Fourier sign convention.

---

← Prev: [Classical Information Theory](../c02-probability-information/03-classical-information-theory.md) · Up: [Term 0](../README.md) · Next: [Fourier Series & Transforms](02-fourier-series-transforms.md) →
