Complex Number Arithmetic
Pillar: SET --- "Complex numbers are ordered pairs with a special multiplication rule."
The Problem That Broke Real Numbers
Try solving \(x^2 + 1 = 0\).
Move \(1\) to the right: \(x^2 = -1\). Take the square root: \(x = \sqrt{-1}\).
But no real number squares to \(-1\). Positive numbers square to positive. Negative numbers square to positive. Zero squares to zero. The equation has no solution in the real numbers.
Mathematicians didn't accept "no solution" as a final answer. Instead, they invented a new number:
This single invention --- defining \(i\) and allowing it to combine with real numbers --- opens the door to complex numbers. And complex numbers turn out to be far more than a curiosity: they power the Fast Fourier Transform (Ch11), simplify rotation geometry, and unify dozens of algebraic identities.
What Is a Complex Number?
A complex number is an expression of the form:
where \(a\) and \(b\) are real numbers, and \(i^2 = -1\).
| Term | Name | Notation |
|---|---|---|
| \(a\) | Real part | \(\text{Re}(z)\) |
| \(b\) | Imaginary part | \(\text{Im}(z)\) |
| \(i\) | Imaginary unit | \(i^2 = -1\) |
Every real number is a complex number with \(b = 0\). The number \(5\) is really \(5 + 0i\). The number \(3i\) is \(0 + 3i\), a purely imaginary number.
Two complex numbers are equal if and only if their real parts match AND their imaginary parts match:
Think of a complex number as an ordered pair \((a, b)\). The real part and imaginary part are independent coordinates --- just like \(x\) and \(y\) on a graph. This is the Set perspective: a complex number is a pair of real numbers, equipped with operations.
Addition and Subtraction
Add component-wise, just like adding 2D vectors:
Example: \((3 + 4i) + (1 - 2i) = 4 + 2i\)
Example: \((5 + i) - (2 + 3i) = 3 - 2i\)
Nothing surprising here. Real parts add with real parts, imaginary parts with imaginary parts.
Multiplication
This is where complex numbers become interesting. Multiply using FOIL (or distribution), then use \(i^2 = -1\):
The formula to remember:
Example: \((3 + 4i)(1 - 2i)\)
- Real part: \(3 \cdot 1 - 4 \cdot (-2) = 3 + 8 = 11\)
- Imaginary part: \(3 \cdot (-2) + 4 \cdot 1 = -6 + 4 = -2\)
- Result: \(11 - 2i\)
Let's verify with a trace table:
| Term | Calculation | Value |
|---|---|---|
| \(ac\) | \(3 \times 1\) | \(3\) |
| \(adi\) | \(3 \times (-2i)\) | \(-6i\) |
| \(bci\) | \(4i \times 1\) | \(4i\) |
| \(bdi^2\) | \(4i \times (-2i) = -8i^2\) | \(8\) |
| Sum | \((3 + 8) + (-6 + 4)i\) | \(11 - 2i\) |
The Complex Conjugate
The complex conjugate of \(z = a + bi\) is:
You flip the sign of the imaginary part. Geometrically, you reflect across the real axis.
The conjugate has a key property:
This is always a non-negative real number. No imaginary part survives. This property is the key to division.
| \(z\) | \(\overline{z}\) | \(z \cdot \overline{z}\) |
|---|---|---|
| \(3 + 4i\) | \(3 - 4i\) | \(9 + 16 = 25\) |
| \(1 - 2i\) | \(1 + 2i\) | \(1 + 4 = 5\) |
| \(5i\) | \(-5i\) | \(25\) |
| \(7\) | \(7\) | \(49\) |
Division
To divide \(\frac{z_1}{z_2}\), multiply top and bottom by \(\overline{z_2}\):
The denominator becomes a real number, so you can split into real and imaginary parts.
Example: \(\frac{3 + 4i}{1 - 2i}\)
Multiply by \(\frac{1 + 2i}{1 + 2i}\):
Check: \((-1 + 2i)(1 - 2i) = -1 + 2i + 2i - 4i^2 = -1 + 4i + 4 = 3 + 4i\). Correct.
Magnitude (Modulus)
The magnitude (or modulus) of \(z = a + bi\) is:
This is the distance from the origin to the point \((a, b)\) in the complex plane. Note that \(|z|^2 = z \cdot \overline{z} = a^2 + b^2\).
Example: \(|3 + 4i| = \sqrt{9 + 16} = \sqrt{25} = 5\)
Example: \(|1 - 2i| = \sqrt{1 + 4} = \sqrt{5}\)
Key properties:
- \(|z_1 \cdot z_2| = |z_1| \cdot |z_2|\) --- magnitudes multiply
- \(\left|\frac{z_1}{z_2}\right| = \frac{|z_1|}{|z_2|}\) --- magnitudes divide
- \(|z| = 0\) if and only if \(z = 0\)
The first property is important. It says multiplication scales distances. We'll see why geometrically in Lesson 2.
The Complex Plane
Plot complex numbers on a 2D plane:
- Horizontal axis = real axis (\(a\))
- Vertical axis = imaginary axis (\(b\))
- The number \(a + bi\) sits at the point \((a, b)\)
| Number | Point on plane |
|---|---|
| \(3 + 4i\) | \((3, 4)\) |
| \(-2 + i\) | \((-2, 1)\) |
| \(5\) | \((5, 0)\) --- on the real axis |
| \(-3i\) | \((0, -3)\) --- on the imaginary axis |
Addition is vector addition. To add \(z_1 + z_2\), place \(z_2\)'s arrow at the tip of \(z_1\)'s arrow. The result is the diagonal of the parallelogram.
Multiplication does two things at once: it scales the magnitude and rotates the angle. We'll formalize this in Lesson 2 with polar form, but the intuition is: multiplying by \(i\) rotates \(90^\circ\) counterclockwise.
- \(1 \times i = i\) --- the point \((1, 0)\) moves to \((0, 1)\)
- \(i \times i = -1\) --- the point \((0, 1)\) moves to \((-1, 0)\)
- \(-1 \times i = -i\) --- the point \((-1, 0)\) moves to \((0, -1)\)
- \(-i \times i = 1\) --- the point \((0, -1)\) moves back to \((1, 0)\)
Four rotations of \(90^\circ\) return to the start. That's the cycle of powers of \(i\).
Powers of \(i\)
Since \(i^2 = -1\), the powers of \(i\) cycle with period 4:
| Power | Value | Geometric position |
|---|---|---|
| \(i^0\) | \(1\) | \((1, 0)\) |
| \(i^1\) | \(i\) | \((0, 1)\) |
| \(i^2\) | \(-1\) | \((-1, 0)\) |
| \(i^3\) | \(-i\) | \((0, -1)\) |
| \(i^4\) | \(1\) | \((1, 0)\) --- back to start |
To find \(i^n\) for any integer \(n\): compute \(n \bmod 4\).
- \(i^{17} = i^{4 \cdot 4 + 1} = i^1 = i\)
- \(i^{50} = i^{4 \cdot 12 + 2} = i^2 = -1\)
- \(i^{103} = i^{4 \cdot 25 + 3} = i^3 = -i\)
C++ Implementation
C++ provides complex<double> in <complex> (included by <bits/stdc++.h>):
complex<double> z1(3, 4); // 3 + 4i
complex<double> z2(1, -2); // 1 - 2i
// Arithmetic
complex<double> sum = z1 + z2; // (4, 2)
complex<double> product = z1 * z2; // (11, -2)
complex<double> quotient = z1 / z2; // (-1, 2)
// Properties
double mag = abs(z1); // 5.0
complex<double> conj_z1 = conj(z1); // (3, -4)
double r = z1.real(); // 3.0
double i = z1.imag(); // 4.0
The norm(z) function returns \(|z|^2 = a^2 + b^2\) (not \(|z|\)). This avoids a square root and is usually what you want in competitive programming.
Why This Matters
Complex numbers might seem like pure algebra at this point. But they encode geometry:
- Addition = translation
- Multiplication = rotation + scaling
- Conjugation = reflection
In Lesson 2, we'll see how polar form makes the rotation explicit. In Ch11 (FFT), complex numbers --- specifically the roots of unity --- are the engine that makes polynomial multiplication run in \(O(n \log n)\) instead of \(O(n^2)\).
For now, get comfortable with the arithmetic. Everything that follows builds on it.
Practice Problems
Problem 1. Compute \((2 + 3i)(4 - i)\) and express the result in the form \(a + bi\).
Answer
\((2 + 3i)(4 - i) = 8 - 2i + 12i - 3i^2 = 8 + 10i + 3 = 11 + 10i\)
Problem 2. Compute \(\frac{5 + i}{2 - 3i}\).
Answer
Multiply by \(\frac{2 + 3i}{2 + 3i}\): $\(\frac{(5 + i)(2 + 3i)}{(2 - 3i)(2 + 3i)} = \frac{10 + 15i + 2i + 3i^2}{4 + 9} = \frac{7 + 17i}{13} = \frac{7}{13} + \frac{17}{13}i\)$
Problem 3. Find \(|4 - 3i|\) and verify that \(|4 - 3i|^2 = (4 - 3i)(4 + 3i)\).
Answer
\(|4 - 3i| = \sqrt{16 + 9} = 5\). And \((4 - 3i)(4 + 3i) = 16 + 9 = 25 = 5^2\). Confirmed.
Problem 4. What is \(i^{2025}\)?
Answer
\(2025 \bmod 4 = 1\) (since \(2025 = 4 \times 506 + 1\)). So \(i^{2025} = i\).
Problem 5. If \(z = a + bi\) and \(z^2 = -5 + 12i\), find \(a\) and \(b\).
Answer
\(z^2 = (a + bi)^2 = (a^2 - b^2) + 2abi\). Matching real and imaginary parts: \(a^2 - b^2 = -5\) and \(2ab = 12\), so \(ab = 6\) and \(b = 6/a\). Substituting: \(a^2 - 36/a^2 = -5\). Let \(u = a^2\): \(u - 36/u = -5\), so \(u^2 + 5u - 36 = 0\), giving \((u + 9)(u - 4) = 0\). Since \(u = a^2 \geq 0\), we get \(u = 4\), so \(a = \pm 2\) and \(b = 6/a = \pm 3\). The solutions are \(z = 2 + 3i\) or \(z = -2 - 3i\).