EVERYTHING AIAI engineering, made visual
0/23 complete
LESSON 19 · MATHEMATICS × AI · LEARN

Not imaginary.
Just a quarter turn.

e^(iθ) = cos θ + i sin θ is one arrow spinning on a circle. Complex multiplication rotates and scales, roots of unity turn the circle into a frequency ruler, and RoPE turns it into relative position inside a transformer.

60 MIN · 8 CHAPTERSPREREQ · LESSONS 01–04
FIG. 19 / ONE ARROW, TWO SHADOWS
θ = 0.00 rad multiplying z turns it by θ e^(iθ) z·e^(iθ)
LESSON 19TYPE · LEARN~60 MINPREREQ · LESSONS 01–04ORIGINAL LESSON ↗
THE 60-SECOND VERSIONThen turn the dial ↓
01 / A QUARTER TURN

i is a rotation, not a fiction.

Defined by i² = −1, i looks like a trick — until you draw it. Multiplying by i is a 90° turn, so i² is two quarter turns: a half-turn, which is multiplying by −1. The powers cycle 1, i, −1, −i and come home after four steps.

1 → i → −1 → −i → 1
02 / ROTATE, THEN SCALE

Multiplication is one motion.

(a + bi)(c + di) looks like bookkeeping, but on the plane it is a single motion: rotate by the sum of the angles and stretch by the product of the lengths. Rectangular form is for adding; polar form makes multiplying trivial.

|z·w| = |z|·|w| · arg(zw) = arg z + arg w
03 / THE CIRCLE THAT POWERS AI

Euler, DFT, RoPE — one circle.

e^(iθ) = cos θ + i sin θ traces the unit circle. Its N evenly spaced stops, the roots of unity, sum to zero — that is what makes the DFT invertible (next lesson). Rotating q by m·θ and k by n·θ makes attention depend only on m − n: RoPE.

e^(iθ) = cos θ + i sin θ
MENTAL MODEL IN ONE SENTENCE

A complex number is a point in a plane written a + bi, and multiplying by i is a quarter turn: two quarter turns make a half turn, which is multiplying by −1, and that single fact is all “i² = −1” means.

By the end you will be able to do complex arithmetic by hand, convert between rectangular and polar form, explain why multiplication rotates and scales, derive Euler’s formula from power series, use roots of unity to see what the DFT measures, and say exactly why RoPE makes attention relative.

A QUARTER TURN

What number squares
to −1?

On the number line the answer does not exist: every square is non-negative. Step off the line into the plane and the question turns into a rotation.

A complex number has two parts: z = a + bi. The real part a sits on the familiar number line; the imaginary part b is measured along a second axis, and i is a new number defined by the single property i² = −1. That is the whole definition. The word “imaginary” is a 17th-century insult that stuck — negative numbers were called absurd once too.

The definition looks like a trick until you stop treating numbers as positions and treat them as moves. Multiplying by −1 flips an arrow to point the other way: a half turn. Multiplying by i is a quarter turn. Two quarter turns are a half turn, so i·i = −1, exactly as promised. Multiplication by i is not an amount, it is an instruction: turn 90° counter-clockwise.

Worked check: i² = −1 as two quarter turns
start at 1 on the real axis: (1, 0) × i → (0, 1) = i one 90° turn × i → (−1, 0) = −1 two 90° turns = a 180° turn so applying i twice sends 1 to −1, which is what i² = −1 means. the same thing in rectangular form, expanding like any bracket: (0 + 1i)(0 + 1i) = 0 + 0i + 0i + 1i² = i² = −1 powers repeat with period 4: i¹ = i i² = −1 i³ = i²·i = −i i⁴ = i²·i² = 1 i⁵ = i i⁶ = −1 … (the cycle restarts)

Numeric check on a point that is not 1: take 2 + 0.5i and apply i once. (2 + 0.5i)·i = 2i + 0.5i² = −0.5 + 2i. The length is unchanged (√4.25 on both sides); only the direction turned by 90°. Multiplying by i never stretches, only rotates.

Multiply by i, one quarter turn at a time

Each press sends z₀ through another 90° rotation. Four turns bring it home, which is why i⁴ = 1 and i² = −1.

k = 0: z₀·i^0 = (2 + 0.5i)·(1) = 2 + 0.5i k = 1: z₀·i^1 = (2 + 0.5i)·(i) = -0.5 + 2i k = 2: z₀·i^2 = (2 + 0.5i)·(−1) = -2 − 0.5i k = 3: z₀·i^3 = (2 + 0.5i)·(−i) = 0.5 − 2i k = 4: z₀·i^4 = (2 + 0.5i)·(1) = 2 + 0.5i four turns → i⁴ = 1 → back to z₀ ✓ two turns → i² = −1 → the point is opposite z₀ (a 180° rotation)

i is not an amount, it is an instruction: rotate a quarter turn. Everything else about it follows.

Quick check

Multiplying a complex number by i twice is the same as…

THE COMPLEX PLANE

Every number is
a point and an arrow.

Plot the real part across, the imaginary part up, and the whole number system becomes a map. The map is called the complex plane, and it is where complex arithmetic turns into geometry.

The horizontal axis is the real axis; the vertical axis is the imaginary axis. The number z = a + bi is the point (a, b). So 3 + 2i is (3, 2), the real number −1 is (−1, 0), and the purely imaginary 4i is (0, 4). Nothing new is hidden: the plane is just a place to put the two parts.

The second reading is the one that matters. A point is also an arrow from the origin — a vector, in the language of Lesson 01. Two complex numbers can be added as arrows (head to tail) and multiplied as rotations and stretches. That double life — point and vector, position and transformation — is why complex numbers keep showing up wherever something spins.

Complex plane playground

Drag the blue point z (or use the sliders). It is multiplied by w = r·e^(iθ); the orange arrow is the product, turned by θ and scaled by r. The purple dashed arrow is the conjugate, reflected across the real axis.

z = 2 + 1i |z| = 2.236 arg z = 26.6° z̄ = 2 − 1i z·z̄ = 5 w = 0.71 + 0.71i = 1.0·e^(i45°) rectangular: z·w = (a·c − b·d) + (a·d + b·c)i = (2·0.71 − 1·0.71) + (2·0.71 + 1·0.71)i = 0.71 + 2.12i polar: |z·w| = 2.236·1.0 = 2.236 arg(z·w) = 26.6° + 45° = 71.6° same point, and the second line is why multiplication rotates.

Magnitudes multiply, angles add. Every multiplication in the plane is one rotation (by the angle) and one scale (by the length).

Worked check: coordinates → polar, and back again

A point can be described by its coordinates (a, b) or by its distance from the origin r and its angle θ measured from the positive real axis. The conversion is the one from Lesson 01, with new names.

z = 3 + 2i r = |z| = √(3² + 2²) = √13 ≈ 3.6056 θ = atan2(2, 3) ≈ 0.5880 rad ≈ 33.69° back: r·cos θ = 3.6056 · 0.8321 ≈ 3.0000 ✓ r·sin θ = 3.6056 · 0.5547 ≈ 2.0000 ✓ second example, in the second quadrant: z = −1 + i r = √((−1)² + 1²) = √2 ≈ 1.4142 θ = atan2(1, −1) = 2.3562 rad = 135° back: 1.4142 · cos 135° = 1.4142 · (−0.7071) = −1.0000 ✓ 1.4142 · sin 135° = 1.4142 · 0.7071 = 1.0000 ✓ why atan2 and not atan(b/a)? atan(1/−1) also returns −45°, which is the point 1 − i. Only the signs of both parts tell you which of the two points you actually have.

In words: the magnitude is Pythagoras, the phase is atan2 (which reads the quadrant from the signs), and the pair (r, θ) names the same point as (a, b). Polar form is just that pair, written r·(cos θ + i sin θ).

ROTATE AND SCALE

Multiplying is
one motion, not four.

Addition walks two arrows head to tail. Multiplication looks like bookkeeping, but on the plane it does exactly two things: turn by the sum of the angles, stretch by the product of the lengths.

Addition is part-by-part: add the real parts, add the imaginary parts. (a + bi) + (c + di) = (a + c) + (b + d)i, so (3 + 2i) + (1 + 4i) = 4 + 6i. On the plane this is vector addition — walk one arrow, then the other.

Multiplication expands like any two brackets, with one extra rule: every becomes −1. (a + bi)(c + di) = (ac − bd) + (ad + bc)i. The formula looks lopsided, but the geometry it produces is perfectly even: the lengths multiply, and the angles add.

The complex arithmetic console

Edit z = a + bi and w = c + di, pick an operation, and read every step of the arithmetic before the result.

z = 3 + 2i
w = 1 + 4i
(3 + 2i)·(1 + 4i) FOIL, treating i as a symbol and i² = −1: 1) 3·1 = 3 2) 3·4i = 12i 3) 2i·1 = 2i 4) 2i·4i = 8i² = -8 combine: (3 − 8) + (12 + 2)i = -5 + 14i = -5 + 14i check: |z|·|w| = 3.606·4.123 = 14.866 = |z·w| ✓ angles add: 33.7° + 76° = 109.7°
Worked check: two products, two geometries

FOIL the source example, then check the answer against the two rules that do not mention FOIL at all.

source example: (3 + 2i)(1 + 4i) 3·1 = 3 3·4i = 12i 2i·1 = 2i 2i·4i = 8i² = −8 = 3 + 12i + 2i − 8 = −5 + 14i lengths: |3 + 2i| = √13 ≈ 3.6056, |1 + 4i| = √17 ≈ 4.1231 product length √221 ≈ 14.8661 = |−5 + 14i| ✓ angles: 33.69° + 75.96° = 109.65° = atan2(14, −5) ✓ second example: (1 + 2i)(3 − i) = 3 − i + 6i − 2i² = 3 + 5i + 2 = 5 + 5i lengths: √5 ≈ 2.2361 × √10 ≈ 3.1623 = √50 ≈ 7.0711 = |5 + 5i| ✓ angles: 63.43° + (−18.43°) = 45.00° = arg(5 + 5i) ✓ division is multiplication by the conjugate of the denominator: (5 + 2i)/(1 − 3i) = (5 + 2i)(1 + 3i) / (1² + 3²) = (−1 + 17i)/10 = −0.1 + 1.7i check: (−0.1 + 1.7i)(1 − 3i) = 5.0 + 2.0i ✓

Plain-English reading: multiplication never moves a point to a random place. It picks the arrow up, turns it by the second number’s angle, and stretches it by the second number’s length.

MIRROR AND RULER

Flip the sign of i,
measure the length.

The conjugate reflects a point across the real axis. Multiply a number by its own reflection and the imaginary parts cancel, leaving a single real number: the squared length.

The conjugate of z = a + bi is z̄ = a − bi: same point, mirrored across the real axis. That little sign flip is the workhorse of complex algebra, because the product z · z̄ = a² + b² is always real — the cross terms cancel. And a² + b² is Pythagoras, so z · z̄ = |z|², the squared distance from the origin.

The magnitude |z| = √(a² + b²) is the ruler: the length of the arrow. The conjugate is also how division works. Dividing by a complex number means multiplying top and bottom by its conjugate, which makes the denominator real — no different in spirit from clearing a square root from a denominator.

Worked check: the conjugate product, and a full division
z = 3 + 4i, z̄ = 3 − 4i z·z̄ = (3 + 4i)(3 − 4i) = 9 − 12i + 12i − 16i² = 9 + 16 = 25 the cross terms cancel, as always |z| = √25 = 5 a 3–4–5 right triangle in the plane for contrast, the square: z² = (3 + 4i)(3 + 4i) = 9 + 24i + 16i² = −7 + 24i different number, different job: z² rotates, z·z̄ measures. division: (5 + 2i) / (1 − 3i) multiply top and bottom by the conjugate of the denominator, 1 + 3i: denominator: (1 − 3i)(1 + 3i) = 1² + 3² = 10 numerator: (5 + 2i)(1 + 3i) = 5 + 15i + 2i + 6i² = −1 + 17i result: (−1 + 17i)/10 = −0.1 + 1.7i verify by multiplying back: (−0.1 + 1.7i)(1 − 3i) = −0.1 + 0.3i + 1.7i − 5.1i² = 5.0 + 2.0i ✓ (the original numerator)

In plain English: conjugation turns magnitude into arithmetic. The mirror image is chosen precisely so that the two imaginary parts annihilate, and what survives is the squared length.

Quick check

What is (3 + 4i)(3 − 4i)?

EULER'S FORMULA

One exponential,
wearing sin and cos.

The most important formula in this lesson compresses the two projections of a rotating arrow into a single exponential: e^(iθ) = cos θ + i sin θ.

Polar form says z = r·(cos θ + i sin θ), where r is the length and θ the angle. Euler’s formula replaces the bracket with a complex exponential: z = r·e^(iθ). The two forms are the same point; the exponential is shorter, and — as the previous chapter showed — multiplication in it is trivial.

On the unit circle (r = 1) the formula reads e^(iθ) = cos θ + i sin θ. At θ = 0 the point is 1; at θ = π/2 it is i; at θ = π it is −1, which is the famous e^(iπ) + 1 = 0 linking e, i, π, 1 and 0. A full trip is θ = 2π and lands back at 1.

The Euler dial

Slide θ around the circle. The arrow is e^(iθ); its shadow on the real axis is cos θ and its shadow on the imaginary axis is sin θ.

θ = 45° = 0.785 rad e^(iθ) = cos 45° + i·sin 45° = 0.707 + 0.707i |e^(iθ)| = √(0.707² + 0.707²) = 1 cos² + sin² = 0.5 + 0.5 = 1 ✓

The point never leaves the circle: the magnitude is always 1. Only the angle changes, which is why e^(iθ) is a pure rotation.

Derivation: Euler's formula from power series, with numbers

The exponential, cosine and sine all have power series (Lesson 04). Substitute x = iθ into the exponential’s and use the cycling powers of i: i² = −1, i³ = −i, i⁴ = 1.

eˣ = 1 + x + x²/2! + x³/3! + x⁴/4! + x⁵/5! + … cos θ = 1 − θ²/2! + θ⁴/4! − … sin θ = θ − θ³/3! + θ⁵/5! − … e^(iθ) = 1 + iθ + (iθ)²/2! + (iθ)³/3! + (iθ)⁴/4! + … = 1 + iθ − θ²/2! − iθ³/3! + θ⁴/4! + iθ⁵/5! − … = (1 − θ²/2! + θ⁴/4! − …) + i(θ − θ³/3! + θ⁵/5! − …) = cos θ + i sin θ ✓ numeric check at θ = π/6 = 0.5236 (exact: 0.8660254 + 0.5000000i) real: 1 − 0.137078 + 0.003132 = 0.866054 → 0.8661 (terms 1, θ²/2, θ⁴/24) imaginary: 0.523599 − 0.023925 + 0.000328 = 0.500002 → 0.5000 (terms θ, θ³/6, θ⁵/120) rotation check: multiply 2 + i by e^(iπ/3) = 0.5 + 0.8660i (2 + i)(0.5 + 0.8660i) = (1 − 0.8660) + (1.7321 + 0.5)i = 0.1340 + 2.2321i |0.1340 + 2.2321i| = √5.0000 ≈ 2.2361 = |2 + i| ✓ the length did not change — e^(iπ/3) has magnitude 1, so it only rotated.

Plain-English reading: an exponential with an imaginary exponent is not a growth curve, it is a point going around a circle. The real part of that motion is a cosine wave, the imaginary part is a sine wave — the same wave, shifted a quarter period.

Quick check

What is e^(iπ/2)?

ROOTS OF UNITY

N stops around the circle
that always cancel.

Take the unit circle and mark N equally spaced points. Those points are the roots of unity — and their sum is zero for every N. That one fact is what makes the Fourier transform work.

The N-th roots of unity are w_k = e^(2πik/N) for k = 0, 1, …, N−1. Each is a point on the unit circle, and together they sit exactly 360°/N apart. For N = 4 they are the compass points: 1, i, −1, −i. For N = 8, add the diagonals.

Two properties make them the natural frequency vocabulary. First, every root has magnitude 1, so multiplying by a root never changes a signal’s size — it only rotates its phase. Second, the roots sum to zero: N arrows pulling equally in all directions cancel. That cancellation is what lets the DFT separate one frequency from another, and it is the forward link to Lesson 20.

Roots of unity

N evenly spaced points on the unit circle. The grey arrow is their vector sum — it stays pinned at zero for every N.

angles step by 360°/8 = 45° w0 = e^(2πi·0/8) = 1 + 0i w1 = e^(2πi·1/8) = 0.707 + 0.707i w2 = e^(2πi·2/8) = 0 + 1i w3 = e^(2πi·3/8) = -0.707 + 0.707i w4 = e^(2πi·4/8) = -1 + 0i w5 = e^(2πi·5/8) = -0.707 − 0.707i … sum of all 8 roots = 0 ≈ 0 ✓ highlighted: w1 = 0.707 + 0.707i Lesson 20 link: the DFT's k-th output X[k] = Σ x[n]·e^(−2πikn/N) is the signal correlated with exactly this w_k.

Multiplying any root by w₁ jumps to the next one, so w₁ generates all of them — that is what “primitive” root means.

Derivation: why the roots sum to zero, with N = 4 and N = 3

Let w = e^(2πi/N) be the first root. The others are w², w³, …, and w^N = e^(2πi) = 1 closes the loop. Multiply the sum by w and watch what happens.

S = 1 + w + w² + … + w^(N−1) w·S = w + w² + … + w^(N−1) + w^N = S because w^N = 1 subtract: w·S − S = 0 → S(w − 1) = 0 → S = 0 (N ≥ 2, so w ≠ 1) N = 4, w = i: 1 + i + i² + i³ = 1 + i − 1 − i = 0 ✓ N = 3, w = e^(2πi/3) = −0.5 + 0.8660i: 1 + (−0.5 + 0.8660i) + (−0.5 − 0.8660i) = (1 − 0.5 − 0.5) + (0.8660 − 0.8660)i = 0 ✓ every root has magnitude 1: |w_k| = √(cos²(2πk/N) + sin²(2πk/N)) = √1 = 1 orthogonality check for the DFT, N = 4, k = 1: Σ e^(−2πi·1·n/4) = 1 + e^(−iπ/2) + e^(−iπ) + e^(−i3π/2) = 1 − i − 1 + i = 0 ✓ the same cancellation happens for every mismatch k ≠ k′, which is why only the matching frequency survives the transform.

The geometry and the algebra say the same thing: evenly spaced arrows have no preferred direction, so their vector sum is the only point with no direction at all — zero.

Quick check

For N = 6, the primitive root w₁ = e^(2πi/6) is one sixth of the way around the circle. What is w₁ · w₁?

POSITION AS ROTATION

Rotate the query.
Only distance survives.

Attention compares a query vector with a key vector by a dot product. RoPE rotates each one by its token position before the comparison, so the score ends up depending on m − n — the relative distance.

A transformer has no built-in sense of order: shuffle the tokens and the attention scores are identical. Position must be injected. The original Transformer adds sinusoidal patterns to the embeddings; RoPE (Rotary Position Embedding) takes the rotation idea literally and multiplies the query and key vectors instead.

Concretely, RoPE splits a query into 2-D pairs and rotates each pair by an angle proportional to the token’s position: q at position m becomes q·e^(imθ), and k at position n becomes k·e^(inθ). When attention takes their dot product, the rotation angles meet as an angle difference: what is left is e^(i(m−n)θ). Absolute position vanishes; only the gap between the tokens remains.

RoPE: only the distance gets a vote

Give a query position m and a key position n. RoPE rotates each by its own position; the score on the right depends only on m − n. Shift both tokens by five and nothing changes.

q = e^(i·30°) (unrotated query) q′ = q·e^(i·5θ) = e^(i·(30° + 5·22.5°)) = -0.793 + 0.609i k′ = e^(i·3θ) = e^(i·3·22.5°) = 0.383 + 0.924i relative angle = 30° + 2·22.5° = 75° score = cos(75°) = 0.259 shift both tokens by +5: m and n change, m − n stays 2, so the score stays 0.259 — the encoding is relative.

This lab rotates one 2-D pair. Real RoPE does this to every pair of coordinates inside a head, each pair at its own frequency — the same idea, repeated. Simplified teaching model.

Derivation: why the score only sees m − n

Write the 2-D pair of the query as a complex number q and the key as k. RoPE rotates them by their positions, and the attention score is the real part of q′ times the conjugate of k′ — the complex spelling of the 2-D dot product.

q′ = q·e^(imθ) k′ = k·e^(inθ) q′·conj(k′) = q·e^(imθ) · conj(k)·conj(e^(inθ)) = q·conj(k) · e^(imθ)·e^(−inθ) = q·conj(k) · e^(i(m−n)θ) taking the real part: score = |q||k|·cos(φq − φk + (m − n)θ) the positions appear only through m − n. numbers with θ = 22.5°, query angle φq = 30°, key angle φk = 0°: m − n = 2: score = cos(30° + 45°) = cos 75° ≈ 0.2588 m − n = −2: score = cos(30° − 45°) = cos(−15°) ≈ 0.9659 shift both tokens by +10: the difference is still ±2, so both scores are exactly the same ✓ larger |m − n| rotates the score further: distance is a phase.

Plain-English reading: positions are not added on as separate numbers, they are encoded as angles. Two tokens 10 apart look the same whether they are at positions (0, 10) or (90, 100), because only their angular difference is visible to the dot product.

CHECK YOURSELF

Five questions.
Then the terms worth keeping.

Answer before you look. The Euler and roots-of-unity questions are the ones that separate “I can compute with i” from “I can see the rotation”.

0 / 5 answered · 0 correct

01What is the imaginary unit i defined by?

02What does Euler's formula e^(iθ) equal?

03What is (3 + 2i)(1 + 4i)?

04Why are complex numbers used in Rotary Position Embedding (RoPE) for transformers?

05The N-th roots of unity are N equally spaced points on the unit circle. What is their sum?

Key terms, demystified

Click a card to swap the lazy description for what it actually means.

Exercises from the lesson

Four problems, all fully worked with numeric checks. Try first; the answer is one click away.

  1. Compute (2 + 3i)(4 − i) and (5 + 2i)/(1 − 3i) by hand. Sketch both results, and check that multiplying by the second factor rotated and scaled the first number rather than merely moving it.
    Show one worked answer

    Multiplication: (2 + 3i)(4 − i) = 8 − 2i + 12i − 3i² = 8 + 10i + 3 = 11 + 10i. Check: |2 + 3i| = √13 ≈ 3.6056, |4 − i| = √17 ≈ 4.1231, so the product magnitude should be √221 ≈ 14.8661, and |11 + 10i| = √(121 + 100) = √221 ✓. Angles: atan2(3, 2) ≈ 56.31° and atan2(−1, 4) ≈ −14.04° sum to 42.27°, and atan2(10, 11) ≈ 42.27° ✓. The product is the first factor turned by the second factor's angle (−14.04°) and stretched by its length (√17 ≈ 4.1231). Division: (5 + 2i)/(1 − 3i) = (5 + 2i)(1 + 3i) / ((1)² + (−3)²) = (5 + 15i + 2i + 6i²)/10 = (−1 + 17i)/10 = −0.1 + 1.7i. Check by multiplying back: (−0.1 + 1.7i)(1 − 3i) = −0.1 + 0.3i + 1.7i − 5.1i² = −0.1 + 2.0i + 5.1 = 5.0 + 2.0i ✓. Geometrically the division rotated 5 + 2i by the negative of the denominator's angle (75.96° → −(75.96°)) and scaled it down by |1 − 3i| = √10 ≈ 3.1623.

  2. Start at the point (1, 0). Multiply by e^(iπ/6) twelve times. Show that after 12 multiplications you are back at (1, 0), and that the intermediate points trace a regular 12-gon.
    Show one worked answer

    Each multiplication adds 30°: after k steps the point is (cos(kπ/6), sin(kπ/6)). After k = 12 the angle is 12·30° = 360°, so the point is (cos 2π, sin 2π) = (1, 0) ✓. A sample of the walk: k = 0 (1, 0); k = 1 (0.8660, 0.5); k = 2 (0.5, 0.8660); k = 3 (0, 1); k = 6 (−1, 0); k = 9 (0, −1); k = 12 (1, 0). Each point is exactly 30° from its neighbours, and every point has magnitude 1 by construction, so the points are equally spaced on the unit circle — a regular 12-gon. In general, multiplying by e^(iθ) n times gives e^(inθ): n rotations through θ are one rotation through nθ.

  3. Build the 32-point signal x[n] = sin(2π·3n/32) + 0.5·sin(2π·7n/32). Run the DFT X[k] = Σ x[n]·e^(−2πikn/32) and show that the magnitude spectrum peaks at k = 3 and k = 7, with the k = 7 peak half the height of the k = 3 peak.
    Show one worked answer

    A real sine at an integer bin k₀ concentrates all of its energy at bins k₀ and 32 − k₀: a full sine of amplitude A sums to |X[k₀]| = A·N/2 = 16A. For the amplitude-1 tone at bin 3 that gives |X[3]| = 16 (and |X[29]| = 16); for the amplitude-0.5 tone at bin 7 it gives |X[7]| = 8 (and |X[25]| = 8). Every other bin is zero up to round-off, because the roots of unity are orthogonal: Σₙ e^(2πi(k−k′)n/N) = 0 whenever k ≠ k′. So the spectrum has peaks at 3 and 7 with heights 16 and 8 — the second exactly half the first, matching the input amplitudes. That is the DFT read as a bank of N correlations, one per frequency.

  4. Compute the 8th roots of unity. Verify that they sum to zero, that multiplying any root by the primitive root w₁ = e^(2πi/8) advances to the next one, and that complex multiplication matches the 2×2 rotation matrix for one of them.
    Show one worked answer

    The roots are w_k = e^(2πik/8) = cos(45k°) + i sin(45k°): k = 0 → 1; k = 1 → 0.7071 + 0.7071i; k = 2 → i; k = 3 → −0.7071 + 0.7071i; k = 4 → −1; k = 5 → −0.7071 − 0.7071i; k = 6 → −i; k = 7 → 0.7071 − 0.7071i. Sum: reals 1 + 0.7071 + 0 − 0.7071 − 1 − 0.7071 + 0 + 0.7071 = 0 and imaginaries 0 + 0.7071 + 1 + 0.7071 + 0 − 0.7071 − 1 − 0.7071 = 0 ✓. Stepping: w₁·w₁ = e^(iπ/4)·e^(iπ/4) = e^(iπ/2) = i = w₂; likewise w₁·w₇ = e^(2πi) = 1 = w₀. Matrix equivalence: rotating (2, 1) by 45° by hand gives (2·0.7071 − 1·0.7071, 2·0.7071 + 1·0.7071) = (0.7071, 2.1213); multiplying (2 + i)(0.7071 + 0.7071i) = 1.4142i + 0.7071i² + 1.4142 + 0.7071i = (1.4142 − 0.7071) + (1.4142 + 0.7071)i = 0.7071 + 2.1213i ✓. The two computations agree to floating-point precision (about 1e−16 for random inputs).

Terms this lesson borrows from later lessons (or outside)

You do not need to master these here. Each one gets a proper treatment in its own lesson; the one-line meaning is enough to keep reading. Orange dotted underlines in the prose point back to this list.

  • dot productMultiply matching coordinates and sum; it measures alignment. In complex notation it becomes q·conj(k), which is exactly what RoPE exploits. (Lesson 01)
  • rotation matrixThe 2×2 matrix [[cos θ, −sin θ], [sin θ, cos θ]] that rotates the plane. Complex multiplication produces the same numbers, which is why one complex number can replace the matrix. (Lesson 03)
  • eigenvaluesThe stretch factors λ with Av = λv. Complex eigenvalues are the algebra's way of saying a transformation rotates. (Lesson 03)
  • Taylor seriesWriting a smooth function as an infinite polynomial: f(x) = f(0) + f′(0)x + f″(0)x²/2! + … . Euler's formula comes from feeding iθ into three of them. (Lesson 04)
  • Fourier transformThe operation that decomposes a signal into frequencies. The DFT is complex multiply-and-add against roots of unity, and it is the whole of Lesson 20.
  • attentionThe mechanism inside transformers where each token scores every other token by a dot product (query · key) and reads more information from the high-scoring ones. RoPE changes what that dot product sees. (A later phase, outside Lessons 00–22)
  • tokenA word or word-piece that a language model reads or writes one at a time. Each token has a position, and that position is what RoPE rotates by. (A later phase, outside Lessons 00–22)
  • transformerThe neural network architecture behind modern language models, built from attention and dense layers; RoPE is the positional scheme most of them use. (A later phase, outside Lessons 00–22)
KEEP GOING

A picture is a start.
Practice is the rest.

This lesson is a port of an open course. Everything here traces back to it — and the next step is running the code yourself.

Lesson text adapted from AI Engineering from Scratch (Phase 01, Lesson 19) and the Math Foundations Notebook reference build. The Euler dial, complex plane playground, multiply-by-i lab, roots-of-unity lab, RoPE lab, complex arithmetic console, the second worked multiplication and division examples, the numeric series check inside the Euler derivation, the N = 4 and N = 3 root-sum checks, and the relative-position invariance demo are original to this page. Every number shown is computed in your browser. All labs run in your browser.