Complex Numbers

If you have already studied complex numbers, you may skip this page.

Studying complex numbers requires some foundation in vectors; if you have not studied vectors, please visit the vector page.

Complex Numbers

Introduction

Note

The following introduction is adapted from the People's Education Press High School Mathematics, Version A, Compulsory 2.

From the perspective of equations, whether a negative real number has a square root is whether the equation x2+a=0(a>0)x^2+a=0 (a>0) has a solution; this can in turn be reduced to whether the equation x2+1=0x^2+1=0 has a solution.

Looking back at the extensions of number sets that we have already seen, we can see that each extension was closely related to practical needs. For example, to measure the diagonal of a square and to address the fact that equations such as x2−2=0x^2-2=0 have no solution in the rational numbers, people extended the rational number set to the real number set. After this extension, the addition and multiplication operations defined over the real numbers remain consistent with the addition and multiplication operations previously defined over the rational numbers; addition and multiplication both satisfy commutativity and associativity, and multiplication satisfies distributivity over addition.

Following this idea, to solve the problem that equations such as x2+1=0x^2+1=0 have no solution over the reals, we imagine introducing a new number i\mathrm{i} such that x=ix=\mathrm{i} is a solution of x2+1=0x^2+1=0, that is, such that i2=−1\mathrm{i}^2=-1.

Think about this: after adding the newly introduced number i\mathrm{i} to the real numbers, we hope that i\mathrm{i} and the real numbers can still be added and multiplied in the same way as real numbers, and that addition and multiplication still satisfy commutativity and associativity, while multiplication satisfies distributivity over addition. What numbers make up the new number system obtained by extending the real number system?

Following the idea above, denote the product of the real number bb and i\mathrm{i} by bib\mathrm{i}, and the sum of the real number aa and bib\mathrm{i} by a+bia+b\mathrm{i}. Notice that every real number and i\mathrm{i} can be written in the form a+bi(a,b∈R)a+b\mathrm{i}(a,b\in \mathbf{R}), so all these numbers belong to the extended number set.

Definition

We define a number of the form a+bia+b\mathrm{i}, where a,b∈Ra,b\in \mathbf{R}, as a complex number. Here i\mathrm{i} is called the imaginary unit, and the set of all complex numbers is called the complex number set, denoted by C\mathbf{C}.

A complex number is usually denoted by zz, namely z=a+biz=a+b\mathrm{i}. This form is called the algebraic form of a complex number. Here aa is called the real part of the complex number zz, denoted by Re⁡(z)\operatorname{Re}(z), and bb is called the imaginary part of zz, denoted by Im⁡(z)\operatorname{Im}(z). Unless otherwise specified, a,b∈Ra,b\in \mathbf{R}.

For a complex number zz, it is real if and only if b=0b=0; it is imaginary if b≠0b\not = 0; and it is purely imaginary if a=0a=0 and b≠0b\not = 0.

The relationships among purely imaginary numbers, imaginary numbers, real numbers, and complex numbers are shown below.

Figure: complex relation

Properties and Operations

Geometric Meaning

We now know that numbers of forms such as a+bia+b\mathrm{i} are called complex numbers, and we have given their definitions and classifications; we can also explore their deeper properties.

We place all real numbers on the number line and observe that points on the number line correspond one-to-one with real numbers. Let us handle complex numbers in the same way.

First, we define equality of complex numbers: two complex numbers z1=a+bi,z2=c+diz_1=a+b\mathrm{i},z_2=c+d\mathrm{i} are equal if and only if a=ca=c and b=db=d.

This definition is quite natural, so we will not explain it further here.

In other words, using the unique ordered pair of real numbers (a,b)(a,b), we can represent a complex number z=a+biz=a+b\mathrm{i}. Thinking of the Cartesian coordinate system, we can see that the set of complex numbers is in one-to-one correspondence with the set of points in the Cartesian coordinate system. Thus, we have found one geometric interpretation of complex numbers.

This Cartesian coordinate system is no longer ordinary, because its points have a special meaning: they represent complex numbers. We therefore call such a Cartesian coordinate system the complex plane; the xx-axis is called the real axis, and the yy-axis is called the imaginary axis. More precisely: the set of complex numbers is in one-to-one correspondence with the set of all points in the complex plane.

Recalling what we learned about plane vectors, we find that the coordinate representation of a vector is also an ordered pair of real numbers (a,b)(a,b). Clearly, the complex number z=a+biz=a+b\mathrm{i} corresponds to the point Z(a,b)Z(a,b) in the complex plane, and therefore also to the plane vector OZ→=(a,b)\overrightarrow{OZ}=(a,b). Thus we have found another geometric interpretation of complex numbers: the set of complex numbers is in one-to-one correspondence with the set of vectors in the complex plane (the real number 00 corresponds to the zero vector).

We can transfer our knowledge of vectors to complex numbers and define the modulus of a complex number as the modulus of the vector corresponding to that complex number. The modulus of the complex number z=a+biz=a+b\mathrm{i} is ∣z∣=a2+b2|z|=\sqrt{a^2+b^2}.

For convenience, we often call the complex number z=a+biz=a+b\mathrm{i} the point ZZ or the vector OZ→\overrightarrow {OZ}, and stipulate that equal vectors represent the same complex number.

From our knowledge of vectors, we also find that imaginary numbers cannot be compared by size (while real numbers can).

Addition and Subtraction

For complex numbers z1=a+bi,z2=c+diz_1=a+b\mathrm{i},z_2=c+d\mathrm{i}, define addition as follows:

z1+z2=(a+c)+(b+d)iz_1+z_2=(a+c)+(b+d)\mathrm{i}

Clearly, the sum of two complex numbers is still a complex number.

Taking the addition of vectors into account, we find that complex-number addition follows the rules of vector addition. This also confirms the correctness of the geometric interpretation of complex numbers.

It can likewise be verified that complex-number addition satisfies commutativity and associativity, namely:

z1+z2=z2+z1(z1+z2)+z3=z1+(z2+z3)\begin{aligned} z_1+z_2&=z_2+z_1\\ (z_1+z_2)+z_3&=z_1+(z_2+z_3) \end{aligned}

Subtraction is the inverse operation of addition. Using the addition rules and the definition of equality of complex numbers, we can derive the subtraction rule:

z1−z2=(a−c)+(b−d)iz_1-z_2=(a-c)+(b-d)\mathrm{i}

This also agrees with vector subtraction.

Multiplication, Division, and Conjugates

For complex numbers z1=a+bi,z2=c+diz_1=a+b\mathrm{i},z_2=c+d\mathrm{i}, define multiplication as follows:

z1z2=(a+bi)(c+di)=ac+bci+adi+bdi2=(ac−bd)+(bc+ad)i\begin{aligned} z_1z_2&=(a+b\mathrm{i})(c+d\mathrm{i})\\ &=ac+bc\mathrm{i}+ad\mathrm{i}+bd\mathrm{i}^2\\ &=(ac-bd)+(bc+ad)\mathrm{i} \end{aligned}

We can see that multiplying two complex numbers is similar to multiplying two polynomials: we only need to replace i2\mathrm{i}^2 with −1-1 and combine the real and imaginary parts separately.

Complex-number multiplication is similar in form to the vector product.

It follows that complex multiplication satisfies commutativity, associativity, and distributivity over addition, namely:

  • z1z2=z2z1z_1z_2=z_2z_1
  • (z1z2)z3=z1(z2z3)(z_1z_2)z_3=z_1(z_2z_3)
  • z1(z2+z3)=z1z2+z1z3z_1(z_2+z_3)=z_1z_2+z_1z_3

Since the laws of operation hold, we can see that the multiplication formulas from the real number field also apply in the complex number field.

Division is the inverse operation of multiplication. We can derive its rule as follows:

a+bic+di=(a+bi)(c−di)(c+di)(c−di)=ac+bdc2+d2+bc−adc2+d2i(c+di≠0)\begin{aligned} \frac{a+b\mathrm{i}}{c+d\mathrm{i}}&=\frac{(a+b\mathrm{i})(c-d\mathrm{i})}{(c+d\mathrm{i})(c-d\mathrm{i})}\\ &=\frac{ac+bd}{c^2+d^2}+\frac{bc-ad}{c^2+d^2}\mathrm{i} &(c+d\mathrm{i}\not =0) \end{aligned}

Since vectors do not have division, we will not discuss the relationship with vectors here.

To rationalize the denominator, we multiplied by c−dic-d\mathrm{i}; this expression has an important meaning.

For the complex number z=a+biz=a+b\mathrm{i}, call a−bia-b\mathrm{i} the complex conjugate of zz, usually denoted by zˉ\bar z. We can see that if two complex numbers are conjugates of each other, they are symmetric about the real axis.

For complex numbers z,wz,w, complex conjugation has the following properties

  • z⋅zˉ=∣z∣2z\cdot\bar{z}=|z|^2
  • z‾‾=z\overline{\overline{z}}=z
  • Re⁡(z)=z+zˉ2\operatorname{Re}(z)=\dfrac{z+\bar{z}}{2},Im⁡(z)=z−zˉ2\operatorname{Im}(z)=\dfrac{z-\bar{z}}{2}
  • z±w‾=zˉ±wˉ\overline{z\pm w}=\bar{z}\pm\bar{w}
  • zw‾=zˉwˉ\overline{zw}=\bar{z}\bar{w}
  • z/w‾=zˉ/wˉ\overline{z/w}=\bar{z}/\bar{w}

Argument and Principal Argument

If we set the real unit 11 as the positive horizontal direction and the imaginary unit i\mathrm{i} as the positive vertical direction, we obtain the complex plane from the Cartesian-coordinate perspective.

The position of a complex number zz can also be determined using polar coordinates (r,θ)(r, \theta). As mentioned earlier, rr is the modulus of the complex number zz.

For the nonzero complex number z=x+iyz=x+\mathrm{i}y, the angle θ\theta between the positive direction of the real axis and its corresponding vector satisfies:

tan⁡θ=yx\tan \theta=\frac{y}{x}

This is called the argument of the complex number zz, denoted by:

θ=arg⁡z\theta= \arg z

Any nonzero complex number zz has infinitely many arguments, so arg⁡z\arg z is in fact a set. We use the capitalized Arg⁡z\operatorname{Arg} z to denote one particular value satisfying:

−π<Arg⁡z≤π-\pi<\operatorname{Arg} z \le \pi

Arg⁡z\operatorname{Arg} z is called the principal value of the argument or the principal argument. The arguments are obtained by adding an arbitrary integer multiple of (which may be zero or negative) 2kπ2k\pi to the principal argument; that is, arg⁡z={Arg⁡z+2kπ∣k∈Z}\arg z = \{\operatorname{Arg} z + 2k\pi \mid k\in \mathbf Z\}.

Note that the sum of two principal arguments is not necessarily a principal argument, whereas the sum of two arguments is always a valid argument.

The set of complex numbers with modulus less than 11 forms the unit disk in the complex plane. A complex number with modulus equal to 11 is called a unit complex number, and all unit complex numbers form the unit circle in the complex plane. When there is no risk of confusion, the unit circle is sometimes also called the unit disk.

From the polar-coordinate perspective, multiplication and division of complex numbers become very simple: for multiplication, multiply the moduli and add the arguments; for division, divide the moduli and subtract the arguments.

Euler's Formula

Euler's formula(Euler's formula)1

For any real number xx, we have

eix=cos⁡x+isin⁡x\mathrm{e}^{\mathrm{i}x}=\cos x+\mathrm{i}\sin x

After defining the complex exponential and complex trigonometric functions, this formula can be extended to all complex numbers.

Exponential and Trigonometric Functions

For the complex number z=x+iyz=x+\mathrm{i}y, the function f(z)=ex(cos⁡y+isin⁡y)f(z)=\mathrm{e}^x(\cos y+\mathrm{i}\sin y) satisfies f(z1+z2)=f(z1)f(z2)f(z_1+z_2)=f(z_1)f(z_2). This gives the definition of the complex exponential function:

exp⁡z=ex(cos⁡y+isin⁡y)\exp z=\mathrm{e}^x(\cos y+\mathrm{i}\sin y)

On the real numbers, the definition of the complex exponential function is exactly the same as that of the real exponential function. In the complex plane it has the following properties:

  • Always positive modulus: ∣exp⁡z∣=exp⁡x>0|\exp z|=\exp x>0.
  • Argument: arg⁡(exp⁡z)={y+2kπ∣k∈Z}\arg(\exp z)=\{y + 2k\pi \mid k\in\mathbf Z\}.
  • Addition theorem: exp⁡(z1+z2)=exp⁡(z1)exp⁡(z2)\exp (z_1+z_2)=\exp (z_1)\exp (z_2).
  • Periodicity: exp⁡z\exp z is a periodic function with fundamental period 2πi2\pi \mathrm{i}. If a function f(z)f(z) has a period that is an integer multiple of another period, that period is called a fundamental period.

The definitions of complex trigonometric functions (also simply called trigonometric functions) are as follows:

cos⁡z=exp⁡(iz)+exp⁡(−iz)2\cos z=\frac{\exp (\mathrm{i}z)+\exp (-\mathrm{i}z)}{2} sin⁡z=exp⁡(iz)−exp⁡(−iz)2i\sin z=\frac{\exp (\mathrm{i}z)-\exp (-\mathrm{i}z)}{2\mathrm{i}}

For z∈Rz\in\mathbf{R}, Euler's formula gives:

cos⁡z=Re⁡(eiz)\cos z=\operatorname{Re}\left(\mathrm{e}^{\mathrm{i}z}\right) sin⁡z=Im⁡(eiz)\sin z=\operatorname{Im}\left(\mathrm{e}^{\mathrm{i}z}\right)

On the real numbers, the definitions of the complex trigonometric functions are exactly the same as those of the real trigonometric functions. In the complex plane they have the following properties:

  • Parity: the sine function is odd, and the cosine function is even.
  • Trigonometric identities: the usual trigonometric identities all hold, such as the sum of squares being 11, or the sum-and-difference formulas for angles.
  • Periodicity: the sine and cosine functions have fundamental period 2π2\pi.
  • Zeros: all zeros of the real sine and real cosine functions together form all zeros of the complex sine and complex cosine functions. This extension introduces no new zeros.
  • Unbounded modulus: the modulus of the complex sine and cosine functions can exceed any given positive number; unlike their real counterparts, they are no longer restricted to the range 11.

Three Forms of Complex Numbers

Using the Cartesian-coordinate and polar-coordinate perspectives, we can write a complex number in three forms.

The algebraic form of a complex number is used to represent any complex number.

z=x+yiz=x+y\mathrm{i}

The algebraic form is convenient for computing the four operations of addition, subtraction, multiplication, and division of complex numbers.

The trigonometric form and exponential form of a complex number are used to represent nonzero complex numbers.

z=r(cos⁡θ+isin⁡θ)=rexp⁡(iθ)z=r(\cos \theta +\mathrm{i}\sin \theta)=r \exp (\mathrm{i}\theta)

These two forms are more convenient for computing multiplication and division, as well as the operations that follow. If we use only functions familiar from high school, we can use the trigonometric form. If we introduce the complex exponential function, it is more convenient to write the equivalent exponential form.

Roots of Unity

Consider the solutions of xn=1x^n=1 over the complex numbers. Clearly, there are nn such solutions, and all nn solutions are called nn-th (complex) roots of unity(nn-th root of unity). From the geometry of the complex plane, the nn-th roots of unity divide the unit circle into nn equal parts.

Let ωn=exp⁡2πin\omega_n=\exp\dfrac{2\pi \mathrm{i}}{n} (the unit complex number whose argument is 2π/n2\pi/n). Then the solution set of xn=1x^n=1 is {ωnk∣k=0,1⋯ ,n−1}\{\omega_n^k\mid k=0,1\cdots,n-1\}, where

wnk=exp⁡2πkin=cos⁡2πkn+isin⁡2πkn.w_n^k = \exp\dfrac{2\pi k \mathrm{i}}{n} = \cos\dfrac{2\pi k}{n} + \mathrm{i}\sin\dfrac{2\pi k}{n}.

Unless otherwise specified, an nn-th root of unity in general discussion means the first solution encountered counterclockwise from 11, namely the ωn\omega_n above; all other solutions can be represented by powers of ωn\omega_n.

Why, when mentioning the nn-th roots of unity, do we usually mean specifically the first one?

Mainly for convenience in applications. All nn-th roots of unity can be expressed as powers of the first nn-th root of unity ωn\omega_n; moreover, for any k<nk < n, the complex number ωn\omega_n is not a kk-th root of unity.

Primitive Roots of Unity

In fact, among the nn-th roots of unity, more than just ωn\omega_n have similar properties. The elements of the set

{ωnk∣0≤k<n, gcd⁡(n,k)=1}\{\omega_n^k\mid 0\le k<n,~\gcd(n,k)=1\}

are called nn-th primitive roots of unity(nn-th primitive root of unity). From the expression above, all nn-th primitive roots of unity number φ(n)\varphi(n) in total, where φ(n)\varphi(n) is the Euler totient function.

Every primitive root of unity ω\omega has the same properties as the ωn\omega_n above: for every 0<k<n0<k<n, the power of ω\omega with exponent kk is not 11; in other words, ω\omega is not a kk-th root of unity. Therefore, any primitive root of unity can be used to generate all roots of unity.

To understand the structure of the nn-th primitive roots of unity, we need the following property of roots of unity:

Property

For integers nn and kk, let d=gcd⁡(n,k)d=\gcd(n,k). Then ωnk=ωn/dk/d\omega_n^k = \omega_{n/d}^{k/d}.

Proof

Direct calculation gives

wnk=exp⁡2πkin=exp⁡2π(k/d)in/d=ωn/dk/d.w_n^k = \exp\dfrac{2\pi k\mathrm{i}}{n} = \exp\dfrac{2\pi (k/d)\mathrm{i}}{n/d} = \omega_{n/d}^{k/d}.

This shows that whenever gcd⁡(n,k)≠1\gcd(n,k)\neq 1, ωnk\omega_n^k is necessarily an ngcd⁡(n,k)\dfrac{n}{\gcd(n,k)}-th (primitive) root of unity. Therefore, a root of unity ωnk\omega_n^k with the property described above must satisfy gcd⁡(n,k)=1\gcd(n,k)=1. This is precisely why primitive roots of unity have the definition given above.

As a simple consequence of this analysis, we also have:

Theorem

As kk ranges over the divisors of nn, all kk-th primitive roots of unity form exactly a partition of the nn-th roots of unity. Moreover, for ℓ⊥n\ell\perp n, the map x↦xℓx\mapsto x^\ell is a bijection among the nn-th roots of unity and preserves the partition above: it still maps the k∣nk\mid n-th primitive roots of unity to the kk-th primitive roots of unity.

Although there are many choices of primitive roots of unity, because the first root ωn\omega_n has the simplest form, ωn\omega_n is still the most commonly used one in algorithm competitions. In some settings, to improve computational efficiency, one may also use a primitive root of unity modulo a given modulus in place of ωn\omega_n in the complex field.

Complex Numbers in Programming Languages

Complex Numbers in C

The C99 standard provides the <complex.h> header.

The <complex.h> header provides three types: double complex, float complex, and long double complex.

The arithmetic operators '+', '-', '*', and '/', can be used in any mixture of floating-point and complex numbers. If one end of an expression is a complex number, the result is a complex number.

The <complex.h> header provides the imaginary unit I; when this header is included, the uppercase letter I cannot be used as a variable name.

For an individual complex number, <complex.h> provides several operations: the creal function extracts the real part, cimag extracts the imaginary part, cabs computes the modulus, and carg computes the principal argument.

There are three versions of each function depending on the type. For example, the creal function has three versions, creal, crealf, and creall, for handling double, float, and long double, respectively. The version with no suffix handles double by default. All functions below follow this rule, so it will not be stated separately.

These functions all return ordinary floating-point numbers. An ordinary floating-point number can be assigned directly to a complex number, but a complex number cannot be assigned directly to a floating-point number; one of the extraction operations above must be used.

The conj function computes the complex conjugate and returns a complex number.

The cexp function computes the complex exponential, clog computes the principal value of the logarithm, csin computes the sine, ccos computes the cosine, and ctan computes the tangent.

The cpow function computes powers, csqrt computes square roots, casin computes the inverse sine, cacos computes the inverse cosine, and catan computes the inverse tangent. All of these functions compute the principal values of multivalued functions.

Complex Numbers in C++

In C, <ctype.h> becomes <cctype> in C++; almost all header files follow this naming convention.

However, <complex.h> is an exception: C++ has no <ccomplex> header. In C++, complex numbers are provided directly by <complex>, whose contents are completely different from those of C.

This is interesting. The reason is that <complex> already existed in the first version of C++, C++98, whereas the C language did not add it until C99.

In C++, complex types are defined using complex<float>, complex<double>, and complex<long double>. Because of object-oriented polymorphism, the functions below have unique names and do not need f or l suffixes.

A complex-number object has member functions real and imag, which can access the real and imaginary parts.

A complex-number object has the non-member functions real, imag, abs, and arg, which return the real part, imaginary part, modulus, and argument.

A complex-number object also has the non-member functions: norm for the square of the modulus, and conj for the complex conjugate.

A complex-number object also has the non-member functions exp, log (the principal value of the logarithm with base e\mathrm{e}), log10 (the principal value of the logarithm with base 10, which C does not have), pow, sqrt, sin, cos, and tan; their meanings are the same as in C.

In C++14 and later, the literal operators std::literals::complex_literals::""if, ""i, ""il are defined. For example, entering 100if, 100i, and 100il returns std::complex<float>{0.0f, 100.0f}, std::complex<double>{0.0, 100.0}, and std::complex<long double>{0.0l, 100.0l}, respectively. This makes it convenient to write complex declarations such as auto z = 4.0 + 3i.

Footnotes

  1. For more information about Euler's formula, see the two videos Euler's Formula and Elementary Group Theory and An Introduction to Differential Equations - Chapter 5: Understanding eiπ\mathrm{e}^{\mathrm{i}\pi} in 3.14 Minutes. ↩

This content comes from OI Wiki: Complex Numbers. See the original for authors and revision history. AIOJ has adapted the formatting, in-site links, and resource paths.

Content is shared under CC BY-SA 4.0 and SATA license; additional terms are governed by the original notice. Thanks to the OI Wiki authors and contributors; per the SATA terms, please visit the OI Wiki repository and star it to show your support.