← Home 📘 Track 2: Mathematics for Quantum Hook Modular Arithmetic Roots of Unity Interactive Summary
M11 §2 · Periodicity & Structure ~20 min

Modular arithmetic & roots of unity

Imagine a clock that never stops — numbers that wrap around forever. Now imagine dots perfectly spaced around a circle, like hour marks. These two ideas look unrelated. They're secretly the same thing. And that shared secret is exactly what Shor's algorithm exploits to break modern encryption.

✦ One Idea The $N$-th roots of unity $\omega_N^k = e^{2\pi i k/N}$ are $N$ equally spaced points on a circle. Multiplying by $\omega_N$ rotates you one step. After $N$ steps you're back to 1 — exactly like clock arithmetic wrapping back to 0. This cycle, expressed as complex phases, is how the Quantum Fourier Transform finds hidden patterns.
modular arithmetic roots of unity $\omega_N = e^{2\pi i/N}$ periodicity unit circle QFT
Hook
🪝 Hook

A pattern hides inside numbers — and a quantum machine finds it.

Here's something that looks like magic at first. Take the number 2 and keep multiplying it by itself, but after each step, ask: what's the remainder when you divide by 5?

Powers of 2 mod 5

$2^1 \mod 5 = 2$

$2^2 \mod 5 = 4$

$2^3 \mod 5 = 3$

$2^4 \mod 5 = 1$

$2^5 \mod 5 = 2 \quad \leftarrow\text{ back to the start}$

$2^6 \mod 5 = 4$

The sequence 2, 4, 3, 1 repeats with period 4. It will repeat forever — never ending, never changing.

This isn't a coincidence. It's a consequence of arithmetic that wraps around like a clock — that's called modular arithmetic. That repeating period (the number 4 here) is exactly what Shor's algorithm is designed to find — and finding it efficiently is what makes it exponentially faster than any classical computer.

🔗
Why this matters — the key to breaking encryption

Finding the period of $a^k \bmod N$ classically takes exponential time for large $N$ — a problem so hard it underpins RSA encryption. Shor's algorithm finds that period in polynomial time using quantum interference: the periodic structure in mod arithmetic becomes a repeating pattern of complex phases (roots of unity), and the Quantum Fourier Transform amplifies exactly those phases into a measurable signal. This lesson gives you both mathematical tools Shor needs.

Modular Arithmetic
🗺️ Framework

The clock idea — numbers that wrap around and repeat.

What "mod" means — start with the intuition

Think of a clock with $N$ positions, labeled 0 through $N-1$. You start at 0. You take $a$ steps forward. Where do you land? That's exactly what modular arithmetic computes. Formally, $a \bmod N$ is the remainder when $a$ is divided by $N$:

$$a \bmod N = r \quad \text{where} \quad a = q \cdot N + r, \quad 0 \le r < N$$

Here $q$ is the quotient — how many full loops you've completed — and $r$ is the remainder: how many extra steps you took after the last full loop. The remainder $r$ always falls between $0$ and $N-1$. It's your position on the clock.

🕐
Think of it like this — a 12-hour clock

Your phone shows 3:00. You add 15 hours. Does it show 18:00? No — it wraps to 6:00. That's $15 \bmod 12 = 3$, then $3 + 3 = 6$. Add 24 hours to anything and you're back where you started: $24 \bmod 12 = 0$. Modular arithmetic works exactly like this for any $N$: count forward, and when you hit $N$, wrap back to 0. Simple as that.

Try a few — the pattern will become instinct

Basic examples

$7 \bmod 3 = 1$  — because $7 = 2 \times 3 + \mathbf{1}$ (two full loops, 1 step left over)

$12 \bmod 5 = 2$  — because $12 = 2 \times 5 + \mathbf{2}$

$9 \bmod 4 = 1$  — because $9 = 2 \times 4 + \mathbf{1}$

$15 \bmod 15 = 0$  — because $15 = 1 \times 15 + \mathbf{0}$ (a perfect full loop!)

The key property — cycles are unavoidable

Here's what makes modular arithmetic so special for quantum computing: it always cycles. With only $N$ possible values (0 through $N-1$), any sequence must eventually repeat. Try starting at 0 and adding 3 each time, with $N = 7$:

$0, 3, 6, 2, 5, 1, 4, 0, 3, 6, 2, \ldots$

After 7 steps you're back at 0. The cycle has period 7. This isn't a coincidence — there are only $N$ possible remainders, so any sequence must repeat before taking more than $N$ steps. This guaranteed cycling is the core structure Shor's algorithm exploits.

⚡ Instinct Check What does mod N mean intuitively? Advisory — won't block you
A clock has $N$ positions (0 through $N-1$). After advancing $a$ steps from 0, which position do you land on?
Roots of Unity
🔷 Theory

Dots on a circle — the clock idea, dressed in complex numbers.

What is a root of unity?

A complex number $z$ is called an $N$-th root of unity if $z^N = 1$. There are exactly $N$ of them, and they all live on the unit circle (the circle of radius 1). The most important one is the primitive $N$-th root of unity:

$$\omega_N = e^{2\pi i / N}$$

Think of it as a rotation: $\omega_N$ starts at the point $(1, 0)$ on the complex plane and is rotated $\tfrac{2\pi}{N}$ radians counterclockwise — exactly one $N$-th of a full turn. Its powers step through $N$ equally spaced positions:

$$\omega_N^k = e^{2\pi i k / N}$$

These $N$ points divide the circle into $N$ equal arcs — like hour marks on a clock, but on the complex unit circle. Together they form the complete set of $N$-th roots of unity: every complex number $z$ satisfying $z^N = 1$.

Geometric picture

Multiplying by $\omega_N$ is like stepping one notch on the clock

Picture a circular clock with $N$ marks. You start at 12 o'clock (that's $\omega_N^0 = 1$). Multiply by $\omega_N$: you rotate by $\tfrac{2\pi}{N}$ and land at the next mark ($\omega_N^1$). Multiply again and you advance one more notch ($\omega_N^2$). After $N$ multiplications you've gone all the way around — a full rotation of $2\pi$ — and you're back at the start. This is exactly the mod $N$ clock cycle, just drawn on the complex unit circle instead of a number line.

Proving it: $\omega_N^N = 1$ (step by step, no gaps)

Step 1 — Start from the definition

$\omega_N^N = \left(e^{2\pi i / N}\right)^N$

Step 2 — Apply the exponent rule $(e^a)^b = e^{ab}$

$= e^{2\pi i / N \cdot N} = e^{2\pi i}$

Step 3 — Apply Euler's formula: $e^{i\theta} = \cos\theta + i\sin\theta$

$e^{2\pi i} = \cos(2\pi) + i\sin(2\pi) = 1 + 0 \cdot i = 1$

$$\boxed{\omega_N^N = 1}$$

After $N$ multiplications you've rotated a full $2\pi$ — back to where you started. Roots of unity are periodic with period $N$, exactly like mod $N$ arithmetic.

The beautiful connection — clock arithmetic and circle rotations are the same thing

Here's the insight that ties everything together. Both systems — mod $N$ arithmetic and $N$-th roots of unity — are the same abstract cycle, just written in different languages.

In mod $N$: add 1 to move forward; add $N$ to wrap back to start. In roots of unity: multiply by $\omega_N$ to move forward; multiply by $\omega_N^N = 1$ to wrap back. The dictionary between them is simple: the integer $k$ on the clock corresponds to the complex number $\omega_N^k$ on the circle.

🔗
Why the QFT — and Shor's algorithm — uses this

The Quantum Fourier Transform encodes the integer $k$ as the phase $\omega_N^k = e^{2\pi ik/N}$. When the input has period $r$, only phases at multiples of $N/r$ add up constructively — everything else cancels. The periodic structure of mod $N$ arithmetic becomes an interference pattern in complex phases. The QFT reads that pattern by measuring which phases survived. This is Shor's algorithm in one sentence: turn period-finding into phase interference, then measure.

⚡ Instinct Check Why are roots of unity equally spaced? Advisory — won't block you
The $N$-th roots of unity $\omega_N^0, \omega_N^1, \ldots, \omega_N^{N-1}$ are equally spaced on the unit circle. What is the angle between consecutive roots?

Micro practice — three conceptual checks

Concept — What does mod N mean intuitively?

Mod $N$ is wrap-around arithmetic. The answer to $a \mod N$ is always between 0 and $N-1$. Think of a clock with $N$ positions: after reaching $N$, you return to 0. The value $a \mod N$ tells you your position after counting $a$ steps forward on that clock. Modular arithmetic is finite and cyclic — it never escapes the range $\{0, 1, \ldots, N-1\}$.

Prediction — What is 9 mod 4?

$9 = 2 \times 4 + 1$, so $9 \mod 4 = 1$. You can verify by counting on a 4-position clock: 0, 1, 2, 3, 0, 1, 2, 3, 0, 1 — the 9th step lands on 1. Alternatively: the remainder when 9 is divided by 4 is 1 (since $4 \times 2 = 8$ and $9 - 8 = 1$).

Insight — Why are roots of unity equally spaced?

Each root $\omega_N^k = e^{2\pi ik/N}$ has angle $2\pi k / N$ on the unit circle. As $k$ steps from 0 to $N-1$, the angle steps by $2\pi/N$ each time — a constant increment. Equal angle increments mean equal arc lengths, which means equal spacing. This is because multiplication by $\omega_N$ is always the same rotation: the spacing is built into the definition of $\omega_N$ as a rotation of $2\pi/N$.

Interactive
🔬 Explorer

Three tools to make it real — feel the clock, see the circle, watch the cycle.

Start with Tool 1 to feel modular arithmetic with your own numbers. Then use Tool 2 to see how those numbers place points on a circle. Finally, use Tool 3 to watch multiplication by $\omega_N$ step through the cycle one position at a time.

🕐 Tool 1 Modular arithmetic — clock view

Enter any $a$ and $N$. The clock face shows exactly where you land after $a$ steps — that's $a \bmod N$. Watch the blue dot jump to the right position as you type.

$a$ =
$N$ =
7 mod 3 = 1
7 = 2 × 3 + 1
Highlighted position = $a \mod N$
What to try
Full loop: Try $a = 12$, $N = 12$ — remainder 0, you've done a perfect loop. One extra: Now $a = 13$, $N = 12$ — remainder 1, just one step past. Spot the period: Set $N = 5$ and try $a = 2, 4, 8, 16, 32$ in order. Watch the remainders: 2, 4, 3, 1, 2 — the period is 4!
⭕ Tool 2 Roots of unity — $N$ equally spaced points on the unit circle

Drag the slider to choose $N$. You'll see $N$ equally spaced points appear on the unit circle — one for each power $\omega_N^k$. Click any point to see its angle, real part, and imaginary part.

6
Click a point on the circle to see its coordinates.
Angle between consecutive points: 60°
Key fact: After $N$ steps, $\omega_N^N = 1$ — back to the start.
🔄 Tool 3 Step-by-step multiplication by $\omega_N$ — watch the cycle

Click "Next step" to multiply by $\omega_N$ — watch the blue dot rotate one position around the circle. After $N$ steps it returns to $(1, 0)$. That's $\omega_N^N = 1$: the same wrap-around as mod $N$ arithmetic, now visible as a rotation.

6
Step k = 0
$\omega_6^0 = e^{0} = 1$
Angle: 0°
Position: (1.000, 0.000)
⚔️ Prediction Battle
Use the period — don't just compute
Step 1 of 3 — Predict
The problem
$$2^{10} \bmod 5 = \ ?$$
Hint: find the repeating pattern first, then use it to shortcut the calculation.

Don't compute $2^{10} = 1024$ directly — that's the hard way. Instead: compute $2^1, 2^2, 2^3, 2^4 \bmod 5$. Do you see a cycle? What is the period? Use that to work out $2^{10} \bmod 5$ the smart way.

My prediction:
$2^{10} \bmod 5$ = (must be 0, 1, 2, 3, or 4)
📌 Your prediction: —

Good — you've committed. Now think through the steps before you see the full derivation. What pattern did you notice? What was the period?

📌 Your prediction: —
1
Find the cycle — compute small powers mod 5
$2^1 \bmod 5 = 2$
$2^2 \bmod 5 = 4$
$2^3 \bmod 5 = 8 \bmod 5 = 3$
$2^4 \bmod 5 = 16 \bmod 5 = 1$
$2^5 \bmod 5 = 32 \bmod 5 = 2$ ← back to the start!
2
Identify the period
The sequence 2, 4, 3, 1 repeats with period $r = 4$.
Every 4 exponents, you return to the same value.
3
Use the period to reduce the exponent
$10 = 2 \times 4 + 2$, so $10 \bmod 4 = 2$
This means $2^{10}$ gives the same remainder as $2^2$.
$$2^{10} \bmod 5 = 2^2 \bmod 5 = 4$$
Verify
$2^{10} = 1024$ and $1024 = 204 \times 5 + 4$, so $1024 \bmod 5 = 4$. ✓
You never needed to compute 1024. The period did all the work.
Lesson Summary

Three ideas, now yours — the foundation Shor's algorithm stands on.

  • 🕐
    Modular arithmetic is wrap-around counting

    $a \mod N$ is the remainder when $a$ is divided by $N$, always in the range $\{0, 1, \ldots, N-1\}$. Think of a clock with $N$ positions: you advance $a$ steps and read off where you land. Because there are only $N$ possible values, every sequence must eventually repeat — and that period is the key quantity quantum algorithms detect.

  • Roots of unity are $N$ equally spaced points on the unit circle

    The primitive $N$-th root of unity is $\omega_N = e^{2\pi i/N}$. Its powers $\omega_N^k = e^{2\pi ik/N}$ for $k = 0, \ldots, N-1$ are $N$ equally spaced points on the unit circle separated by angle $2\pi/N$. After $N$ multiplications by $\omega_N$, you complete a full circle and return to 1: $\omega_N^N = e^{2\pi i} = 1$.

  • 🔗
    Both structures encode the same periodicity — and QFT exploits it

    Mod $N$ arithmetic and the $N$-th roots of unity are two faces of the same cyclic structure of size $N$. The Quantum Fourier Transform encodes inputs as phases $\omega_N^k$. When the input has a period $r$, those phases interfere constructively only at multiples of $N/r$ — making the period visible as an interference peak. This is Shor's secret weapon.

How confident do you feel about modular arithmetic and roots of unity right now?
Quick Check 4 questions — mod arithmetic, roots of unity, periodicity

You now understand why periodic structure matters.
The next step: how the Quantum Fourier Transform
uses these phases to extract that period at quantum speed.

→ The Quantum Fourier Transform — M12
Sources & Further Reading
  • Nielsen, M. A. & Chuang, I. L. — Quantum Computation and Quantum Information, Cambridge, 2000. §5.2: Quantum Fourier Transform and periodicity. §5.3: Shor's algorithm and order finding.
  • Preskill, J. — Lecture Notes for Physics 219/Computer Science 219, Caltech. Chapter 6: Quantum algorithms — order finding and modular exponentiation. Available online
  • Shor, P. W. — "Polynomial-Time Algorithms for Prime Factorization and Discrete Logarithms on a Quantum Computer," SIAM J. Comput. 26(5), 1997. The original paper. arXiv:quant-ph/9508027
  • Artin, M. — Algebra, 2nd ed., Pearson, 2011. Chapter 11: Rings — Roots of unity, cyclotomic polynomials, and cyclic groups.