Complex Numbers¶
Objective¶
Get comfortable with complex numbers and complex arithmetic. Understand how complex numbers can be visualized and interpreted geometrically.
Real Numbers¶
"Real numbers" is the formal math name for the set of numbers that we, as software engineers, usually call "floating point" numbers. Some languages call these floats, some call them doubles, some have both terms. Anything that can be written out as a single sequence of digits (even if it has an infinite number of digits) is a real number. They can be positive, negative, or zero. Integers, fractions, irrational numbers like \(\sqrt{2}\) and even transcendental numbers like \(\pi\) are all included in the real numbers. Essentially, they are all of the numbers that can be found on a onedimensional number line like this:
Real numbers can be used to represent the solution to any algebraic equation, with one exception. Equations of this form cannot be solved with them:
To solve this, \(x^2\) would need to be a negative number. However, since a positive number times a positive number is positive, and a negative number times a negative number is positive, there isn't a real number that produces a negative number when multiplied by itself. Thus, we say that this equation has no real solutions.
The Imaginary Unit¶
Equations like this come up a lot in physics and quantum mechanics, so we can't just ignore it  we need to solve it somehow. The way we do this is by defining a special number that specifically satisfies this equation:
We call it the imaginary unit, which is kind of an unfortunate derogatory name given to it a long time ago, when mathematicians didn't like dealing with the square roots of negative numbers. The traditional symbol for the imaginary unit is the letter \(i\):
The imaginary unit is a completely separate entity from the real numbers. It isn't anywhere on the number line. However, we can still do arithmetic with it. For example, consider this equation:
As shown before, it doesn't have any real solutions, but we can solve it by using the imaginary unit:
Because the imaginary unit is a totally separate thing from the real numbers, this solution can't be reduced any further. We have to write it in two parts: a real part (the 3) and an imaginary part (the 4\(i\)). This is an example of what's called a complex number. Complex numbers take this form:
The value \(a\) is a real number that corresponds to the real part. The value \(b\) is a real number that corresponds to the imaginary part, and the \(i\) is used to denote which part is the imaginary one. \(a\) and \(b\) can be any real numbers you want, but as a whole, complex numbers have to be written in two parts like this.
Here are some more examples of complex numbers:
Note that if \(b = 0\), as is the case with the \(w\) example, then the imaginary part isn't included. It's just a regular old real number. If \(a = 0\), as in the \(v\) example, then the real part isn't included. It's just a pure imaginary number.
The Complex Plane¶
Because complex numbers are represented by two independent real numbers, you can think of a complex number as an array of two floats. Many software libraries will treat them like this, or like an object with two separate fields (a floatingpoint number for the real component, and a floatingpoint number for the imaginary component). In other words, complex numbers are twodimensional entities, where the real component represents one dimension and the imaginary component represents the other.
Naturally, an easy way to visualize a twodimensional thing is to plot it on a graph. When we do this for complex numbers, we can represent the real component with the X axis and the imaginary component with the Y axis. This specific plot is called the complex plane. To demonstrate, let's graph the five example numbers from above on the complex plane:
In this picture, each complex number is drawn in two ways: the first is a point on the plane, and the second is a vector from the origin to that point.
Math Properties¶
Addition¶
When adding two complex numbers, you just add the real part to the real part, and the imaginary part to the imaginary part. For example:
Multiplication¶
When multiplying two complex numbers, it's easiest just to follow this formula:
Absolute Value / Magnitude¶
The magnitude of a complex number is represented inbetween straight vertical bars, like this:
It is equal to the length of the vector when the number is plotted on the complex plane. This vector will produce a right triangle where one side is the length of the real component, one side is the length of the imaginary component, and the hypotenuse is the complex number itself. For example, using the point \(x = 3 + 4i\), the two sides would have lengths 3 and 4:
Following Pythagoras's theorem, \(A^2 + B^2 = C^2\), the length of the vector is equal to the square root of the sum on both other sides squared:
Thus, the magnitude of a complex number is just the real component squared plus the imaginary component squared:
Complex Conjugate¶
The complex conjugate is used sometimes when converting a column vector into a row vector (discussed in the next page). It's the same number, but with the sign of the imaginary part flipped. It is represented with an asterisk, like this:
Euler's formula¶
One important formula that comes up in quantum computing is Euler's formula:
Any complex number, \(z\), with absolute value equal to 1 can be written in this form for some \(\theta\) : \(z=e^{i\theta}\) . These complex numbers lie on the unit circle in the complex plane and one can think of the angle \(\theta\) as the angle the complex number, \(e^{i\theta}\) makes with the \(x\)axis.
Additional Materials¶

Khan Academy unit on complex numbers
 What are the complex numbers?
 The complex plane
 Adding and subtracting complex numbers
 Multiplying complex numbers
 Complex conjugates and dividing complex numbers
 Absolute value and angle of complex numbers

3Blue1Brown video on complex numbers
 This is a long video, but if offers a clear and deep understanding of complex numbers.
Knowledge Check¶
Q1¶
Which arrow represents \(23i\) on the complex plane?
Q2¶
Q3¶
Q4¶
Q5¶
Q6¶
Let \(x\) be a complex number as shown on the complex plane. Which arrow represents \(i \cdot x\)?
Q7¶
Q8¶
Q9¶
Q10¶
What is the complex conjugate of \(2+5i\)?