Foundations to Frontier
Tests
A. Mathematical Foundations › A1 Prerequisites and Mathematical Thinking

Complex Numbers and Euler's Formula

Numbers that live on a plane instead of a line. Multiplying them turns and stretches arrows, which makes them the natural language of rotations, waves, signals and control.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Numbers as turns

Stand facing forward. Turn around (180°) and you face backwards. Turn around again and you face forward. Two half-turns make a full turn.

Now think of the number line. Multiplying by −1-1 is like turning around: 3 becomes −3, pointing the other way. Doing it twice brings you back, because (−1)×(−1)=1(-1)\times(-1) = 1.

Here’s a puzzle: is there a number that’s half of a turn-around? A quarter-turn, so that doing it twice gives −1-1? On the number line, no: any number times itself is positive. But if we allow ourselves to step off the line and turn sideways, yes! That sideways quarter-turn is called ii, the imaginary unit.

Numbers on a map

With ii, numbers live on a flat map instead of a line. “3 steps east and 2 steps north” is the number 3+2i3 + 2i. Every point on the map is a number, called a complex number.

In robotics

A robot on the floor has a position (a point on the map) and a heading (which way it’s facing). Complex numbers handle both. Turning the robot is just multiplying by a complex number.

📝 Quick check (Level 0)
0/3 answered
  1. 1. You face north and make two quarter-turns to the right. Which way do you face?
  2. 2. How many quarter-turns bring you back to facing the same way?
  3. 3. What does i × i equal?

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

The rules

i2=−1,z=a+bi(a=Re⁡z,  b=Im⁡z)i^2 = -1, \qquad z = a + bi \quad (a = \operatorname{Re} z,\ \ b = \operatorname{Im} z)
Operation Rule Example
Add add real and imaginary parts (2+3i)+(1−i)=3+2i(2+3i) + (1-i) = 3 + 2i
Multiply expand and use i2=−1i^2 = -1 (1+2i)(3+i)=3+i+6i+2i2=1+7i(1+2i)(3+i) = 3 + i + 6i + 2i^2 = 1 + 7i
Conjugate flip the sign of the imaginary part 3+4i‾=3−4i\overline{3+4i} = 3-4i
Modulus (length) ∣a+bi∣=a2+b2\lvert a+bi\rvert = \sqrt{a^2+b^2} ∣3+4i∣=5\lvert 3+4i\rvert = 5
Divide multiply top and bottom by the conjugate 11+i=1−i(1+i)(1−i)=1−i2\frac{1}{1+i} = \frac{1-i}{(1+i)(1-i)} = \frac{1-i}{2}

Powers of ii cycle with period 4: i,−1,−i,1,i,−1,…i, -1, -i, 1, i, -1, \dots.

A useful identity: zzˉ=a2+b2=∣z∣2z\bar z = a^2 + b^2 = \lvert z\rvert^2, which is always a non-negative real number.

The complex plane

Plot a+bia + bi at the point (a,b)(a, b). The horizontal axis is real, and the vertical axis is imaginary. Adding complex numbers is like adding arrows tip to tail, just like vectors.

Solving the “impossible” equations

x2+1=0x^2 + 1 = 0 has no real solution, but it has two complex ones: x=±ix = \pm i. The quadratic formula always works if we allow complex answers. For x2−2x+5=0x^2 - 2x + 5 = 0: x=2±4−202=1±2ix = \frac{2 \pm \sqrt{4 - 20}}{2} = 1 \pm 2i.

📝 Quick check (Level 1)
0/3 answered
  1. 1. (1 + i)(1 − i) = ?
  2. 2. |−5 + 12i| = ?
  3. 3. i⁷ = ?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.

Polar form

Every complex number is an arrow with a length r=∣z∣r = \lvert z\rvert and an angle θ=arg⁡z\theta = \arg z, measured from the positive real axis:

z=r(cos⁡θ+isin⁡θ),r=a2+b2,θ=atan2⁡(b,a)z = r(\cos\theta + i\sin\theta), \qquad r = \sqrt{a^2+b^2}, \quad \theta = \operatorname{atan2}(b, a)
Common mistake

Don’t compute the angle with arctan⁡(b/a)\arctan(b/a). It can’t tell 1+i1+i from −1−i-1-i. Use atan2(b, a), which looks at both signs.

Euler’s formula

eiθ=cos⁡θ+isin⁡θe^{i\theta} = \cos\theta + i\sin\theta

So the polar form is simply z=reiθz = r e^{i\theta}. Setting θ=π\theta = \pi gives the famous eiπ+1=0e^{i\pi} + 1 = 0.

Euler’s formula: e^{iθ} walks around the circle
ReIme^{iθ}
e^{i·40°} = cos θ + i sin θ = 0.77 + 0.64i. The orange part is cos θ (real), and the purple height is sin θ (imaginary).

Multiplication = rotate and scale

r1eiθ1⋅r2eiθ2=(r1r2) ei(θ1+θ2)r_1 e^{i\theta_1} \cdot r_2 e^{i\theta_2} = (r_1 r_2)\, e^{i(\theta_1 + \theta_2)}

Lengths multiply, and angles add. Multiplying by eiθe^{i\theta} (length 1) is a pure rotation by θ\theta.

Multiplying complex numbers: lengths multiply, angles add
ReImzwzw
z = 0.77 + 0.64i, w = 0.75 + 1.30i, zw = -0.26 + 1.48i. Length 1.0 × 1.5 = 1.50, angle 40° + 60° = 100°.

De Moivre’s formula: (cos⁡θ+isin⁡θ)n=cos⁡nθ+isin⁡nθ(\cos\theta + i\sin\theta)^n = \cos n\theta + i \sin n\theta. For example, (eiπ/6)6=eiπ=−1(e^{i\pi/6})^6 = e^{i\pi} = -1.

Roots of unity

The solutions of zn=1z^n = 1 are nn points equally spaced around the unit circle:

ωk=e2πik/n,k=0,1,…,n−1\omega_k = e^{2\pi i k / n}, \qquad k = 0, 1, \dots, n-1

They’re the building blocks of the Fourier transform (Level 4).

Rotations in 2D robotics

A robot at position pp (a complex number) with heading θ\theta that drives forward a distance dd ends up at p+d eiθp + d\,e^{i\theta}. Turning by Δθ\Delta\theta multiplies its heading by eiΔθe^{i\Delta\theta}. Complex numbers are the cleanest way to write 2D poses.

🐍 Exercise 1: rotation by complex multiplication
rotate(x, y, θ) must use complex numbers (cmath.exp(1j*θ)). The tests compare it with the rotation matrix [[cos, −sin], [sin, cos]].
Why AI cares

Rotary position embeddings (RoPE), used in most modern LLMs, treat pairs of features as complex numbers and rotate them by an angle proportional to the token’s position. Because rotations compose by adding angles, the attention score between two tokens depends only on how far apart they are (Su et al., 2021). You’ll build this in Practice Code 5.

📝 Quick check (Level 2)
0/3 answered
  1. 1. What is e^{iπ/2}?
  2. 2. z has length 2 and angle 30°; w has length 3 and angle 60°. What is zw?
  3. 3. How many solutions does z⁵ = 1 have in the complex numbers?

Level 3: Advanced

★★★★☆ Advanced⏱ 45 minGraduate level, with full derivations and proofs.

Proving Euler’s formula

Theorem (Euler, 1748)

For all real θ\theta: eiθ=cos⁡θ+isin⁡θe^{i\theta} = \cos\theta + i\sin\theta.

Proof via power series. Use ex=∑kxk/k!e^x = \sum_k x^k/k! (A1-4) with x=iθx = i\theta, and the cycle i0,i1,i2,i3=1,i,−1,−ii^0, i^1, i^2, i^3 = 1, i, -1, -i. Split even and odd terms:

eiθ=(1−θ22!+θ44!−⋯)+i(θ−θ33!+θ55!−⋯)=cos⁡θ+isin⁡θ.e^{i\theta} = \Big(1 - \frac{\theta^2}{2!} + \frac{\theta^4}{4!} - \cdots\Big) + i\Big(\theta - \frac{\theta^3}{3!} + \frac{\theta^5}{5!} - \cdots\Big) = \cos\theta + i\sin\theta.

The two brackets are the Taylor series of cosine and sine (A3). ∎ Both series converge for every θ\theta, so the rearrangement is justified.

Proof via a differential equation. Let f(θ)=e−iθ(cos⁡θ+isin⁡θ)f(\theta) = e^{-i\theta}(\cos\theta + i\sin\theta). Differentiating, f′=−ie−iθ(cos⁡θ+isin⁡θ)+e−iθ(−sin⁡θ+icos⁡θ)=0f' = -i e^{-i\theta}(\cos\theta + i \sin\theta) + e^{-i\theta}(-\sin\theta + i\cos\theta) = 0. So ff is constant, and f(0)=1f(0) = 1. ∎

Consequences

  • De Moivre, by induction or directly: (eiθ)n=einθ(e^{i\theta})^n = e^{in\theta}.
  • Trig identities for free. Compare real and imaginary parts of ei(α+β)=eiαeiβe^{i(\alpha+\beta)} = e^{i\alpha}e^{i\beta} to get cos⁡(α+β)=cos⁡αcos⁡β−sin⁡αsin⁡β\cos(\alpha+\beta) = \cos\alpha\cos\beta - \sin\alpha\sin\beta and the matching sine formula.
  • cos⁡θ=eiθ+e−iθ2\cos\theta = \frac{e^{i\theta} + e^{-i\theta}}{2} and sin⁡θ=eiθ−e−iθ2i\sin\theta = \frac{e^{i\theta} - e^{-i\theta}}{2i}.
Theorem

For n≥2n \ge 2, the nn-th roots of unity sum to zero: ∑k=0n−1ωk=0\sum_{k=0}^{n-1} \omega^k = 0 with ω=e2πi/n\omega = e^{2\pi i/n}.

Proof. It’s a geometric series (A1-3) with ratio ω≠1\omega \ne 1: 1−ωn1−ω=1−11−ω=0\frac{1 - \omega^n}{1 - \omega} = \frac{1 - 1}{1 - \omega} = 0. ∎

Theorem (properties of modulus and conjugate)

∣zw∣=∣z∣∣w∣\lvert zw\rvert = \lvert z\rvert\lvert w\rvert, zw‾=zˉwˉ\overline{zw} = \bar z \bar w, z+w‾=zˉ+wˉ\overline{z + w} = \bar z + \bar w, and ∣z+w∣≤∣z∣+∣w∣\lvert z + w\rvert \le \lvert z\rvert + \lvert w\rvert.

Proof of the first. ∣zw∣2=zwzw‾=zzˉ wwˉ=∣z∣2∣w∣2\lvert zw\rvert^2 = zw\overline{zw} = z\bar z\, w \bar w = \lvert z\rvert^2\lvert w\rvert^2. ∎ The triangle inequality is proved in A1-6.

Conjugate root theorem

If a polynomial has real coefficients and zz is a root, then zˉ\bar z is also a root.

Proof. If ∑akzk=0\sum a_k z^k = 0 with real aka_k, take conjugates: ∑akzˉk=0ˉ=0\sum a_k \bar z^k = \bar 0 = 0. ∎

Fundamental theorem of algebra

Every non-constant polynomial with complex coefficients has a complex root. Hence a degree-nn polynomial has exactly nn roots, counted with multiplicity.

(First essentially proved by Gauss in 1799. A full proof needs analysis or topology and is beyond this page.) It’s why every square matrix has complex eigenvalues (A2.3).

Exercise 3.1: Use Euler’s formula to derive sin(2θ) = 2 sin θ cos θ

e2iθ=(cos⁡θ+isin⁡θ)2=cos⁡2θ−sin⁡2θ+2isin⁡θcos⁡θe^{2i\theta} = (\cos\theta + i \sin\theta)^2 = \cos^2\theta - \sin^2\theta + 2i\sin\theta\cos\theta. Its imaginary part must equal sin⁡2θ\sin 2\theta. ∎

Exercise 3.2: Show that multiplying by e^(iθ) is the same as multiplying (x, y) by the rotation matrix

(cos⁡θ+isin⁡θ)(x+iy)=(xcos⁡θ−ysin⁡θ)+i(xsin⁡θ+ycos⁡θ)(\cos\theta + i \sin\theta)(x + iy) = (x\cos\theta - y\sin\theta) + i(x\sin\theta + y\cos\theta), which is (cos⁡θ−sin⁡θsin⁡θcos⁡θ)(xy)\begin{pmatrix}\cos\theta & -\sin\theta\\ \sin\theta & \cos\theta\end{pmatrix}\begin{pmatrix}x\\y\end{pmatrix}. ∎

📝 Quick check (Level 3)
0/3 answered
  1. 1. A real polynomial has root 2 − 3i. Which must also be a root?
  2. 2. How many complex roots (with multiplicity) does z⁷ − 3z + 1 have?
  3. 3. cos θ written with exponentials is…

Level 4: Expert

★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.

The Fourier transform: signals as sums of rotating arrows

The discrete Fourier transform (DFT) writes any list of NN numbers as a sum of rotating complex exponentials:

Xk=∑n=0N−1xn e−2πikn/N,xn=1N∑k=0N−1Xk e2πikn/NX_k = \sum_{n=0}^{N-1} x_n\, e^{-2\pi i k n / N}, \qquad x_n = \frac1N\sum_{k=0}^{N-1} X_k\, e^{2\pi i k n/N}

Each XkX_k measures how much of frequency kk is in the signal. Computing it directly costs O(N2)O(N^2). The fast Fourier transform (Cooley and Tukey, 1965) uses the symmetry of the roots of unity to do it in O(Nlog⁡N)O(N\log N), one of the most important algorithms ever written. It powers vibration analysis of spacecraft and robot joints, radar and sonar, image compression, and fast convolutions in CNNs (A10).

🐍 Exercise 2 (research): a DFT from the definition
Implement X_k = Σₙ xₙ e^(−2πikn/N) with cmath. The tests check an impulse, a constant, and a pure cosine.

Stability lives in the complex plane

The behaviour of a linear system x˙=Ax\dot{\mathbf x} = A\mathbf x, such as a robot joint under feedback control, is set by the eigenvalues of AA, which are usually complex. An eigenvalue λ=σ+iω\lambda = \sigma + i\omega produces a motion like eλt=eσt(cos⁡ωt+isin⁡ωt)e^{\lambda t} = e^{\sigma t}(\cos\omega t + i\sin\omega t). That’s an oscillation at frequency ω\omega whose amplitude grows if σ>0\sigma > 0 and decays if σ<0\sigma < 0. A linear system is stable exactly when every eigenvalue (pole) has a negative real part. Control engineers design by moving poles in the complex plane (S1, S2).

Beyond complex numbers: quaternions

Hamilton (1843) looked for a 3D version of complex numbers and found quaternions q=w+xi+yj+zkq = w + xi + yj + zk with i2=j2=k2=ijk=−1i^2 = j^2 = k^2 = ijk = -1. Multiplication is no longer commutative. Unit quaternions represent 3D rotations without the gimbal lock of Euler angles, and they’re the standard for spacecraft attitude, drones, VR headsets and robot arms (R2). Beware: two conventions (Hamilton vs JPL) multiply in opposite orders. Sommer et al. (2018) explain the confusion this causes.

Complex numbers in modern ML

  • RoPE (Su et al., 2021): rotating query and key features by position-dependent angles makes attention depend on relative position. Its frequencies θk=base−2k/d\theta_k = \text{base}^{-2k/d} and extensions for long context are an active research area (F4).
  • Fourier features (Tancik et al., 2020): mapping inputs through cos⁡(2πBx)\cos(2\pi B\mathbf x) and sin⁡(2πBx)\sin(2\pi B\mathbf x) lets MLPs learn high-frequency detail, which is key to NeRF (G4).
  • Fourier Neural Operators (J4) learn PDE solutions by multiplying Fourier coefficients.
  • Complex-valued networks are used for radar (SAR) and MRI data, which are naturally complex.

References

  1. G. Cardano (1545). Ars Magna. (First use of square roots of negative numbers to solve cubics.)
  2. L. Euler (1748). Introductio in analysin infinitorum. (Euler’s formula.)
  3. C. F. Gauss (1799). Doctoral dissertation, Helmstedt. (Early proof of the fundamental theorem of algebra.)
  4. W. R. Hamilton (1844). “On quaternions; or on a new system of imaginaries in algebra.” Philosophical Magazine, 25.
  5. J. Cooley and J. Tukey (1965). “An algorithm for the machine calculation of complex Fourier series.” Mathematics of Computation, 19(90).
  6. T. Needham (1997). Visual Complex Analysis. Oxford University Press.
  7. H. Sommer, I. Gilitschenski, M. Bloesch, S. Weiss, R. Siegwart, J. Nieto (2018). “Why and how to avoid the flipped quaternion multiplication.” Aerospace, 5(3).
  8. M. Tancik et al. (2020). “Fourier features let networks learn high frequency functions in low dimensional domains.” NeurIPS.
  9. J. Su, Y. Lu, S. Pan, A. Murtadha, B. Wen, Y. Liu (2021). “RoFormer: Enhanced Transformer with rotary position embedding.” arXiv:2104.09864 (published in Neurocomputing, 2024).