Complex Numbers#

Many high school programs omit complex numbers, and some treatments even in university are bad (bad pedagogically and sometimes even bad logically). So it’s quite possible that a student in this course or a reader of this book will need an upgrade of their skills and understanding. Luckily, looked at the right way, the basics are very simple, and there is some amazing new pedagogy made possible by use of computer graphics.

We should point out that most of the hate directed at complex numbers is because arithmetic by hand is a bit more involved than that for real arithmetic, especially division. But, really, nobody has to do complex arithmetic by hand more than a few times to get the hang of it, anymore. The drudgery is quite usefully relegated to a computer.

Let’s begin by clearing out some logical `underbrush’ in order to clarify the issues. Plot y=x2+1 on, say, 2x2.

import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-2, 2, 50)
plt.grid()
plt.axhline(y=0, color='k')
plt.axvline(x=0, color='k')
plt.plot(x, x*x + 1)
plt.plot(x, x*0)
plt.xlim(-1.5,1.5)
plt.ylim(-1,4)
plt.show()
../_images/complex-numbers_2_0.png

Very clearly there is no real x where x2+1=0. Said another way, there is no real number which, when multiplied by itself, gives 1.

Because mathematicians use the words “real number” to mean numbers that are the limits of converging sequences of rational numbers (which gives a solid definition to them), and in the meantime the word “real” has an entirely different meaning in the “real world”, we have an unfortunate opportunity for miscommunication. The phrase “there is no real number which when squared gives 1” sounds almost exactly like “There is no such thing as the square root of 1” and this misconception lies at the heart of most people’s difficulty with i. This is compounded by calling i an “imaginary” number, because it’s “not real” ( “not a real number”). Funny joke! Gah! Mathematicians.

Even the word “number” has different meanings in math than in real life. If your partner says “I have a number of things to talk to you about” it certainly doesn’t mean they have nothing to say! Whereas to a mathematician, zero is a perfectly good number. The collision between math language and ordinary language really does cause problems sometimes.

This is quite unfortunate, because as we will now show concretely, i actually does exist; there’s nothing imaginary about it. It’s a real thing, but for sure it isn’t a “real number”.

What is it? The complex number i is defined to be the pair of real numbers (0,1):

i:=(0,1).

The rules for adding and subtracting complex numbers (pairs of real numbers) are easy:

(a,b)±(c,d)=(a±c,b±d)

(just add or subtract component-wise, like vectors). Multiplication has a funny rule:

(a,b)(c,d)=(acbd,ad+bc).

We will see shortly that this rule makes more sense in polar coordinates. For now, note that (a,0)(c,0)=(ac,0) so that if the second component is zero, these complex numbers act just like real numbers. Mathematicians say that the set of complex numbers contain an isomorphic copy of the real numbers. The complex number (1,0) is the copy of the real number 1. Notice now (0,1)(0,1)=(0011,01+01)=(1,0) or i2=(1,0), the copy of 1.

At this point most people’s brains go, Click! “Why didn’t teachers just say this?” Well, two reasons. First, most people will just want to “get on with it” and go, and it all works, so why fuss? Second, it actually took a long time for this simple idea to be thought of. People were just saying things like “Well, let i be the square root of 1 even if there’s no such thing, and then the following computation is easy.” The French mathematician Argand was apparently the first to think of i=(0,1), over nearly two hundred years after i had been used to find (real!) roots of cubic equations. The great C. F. Gauss, revered as one of the best mathematicians and physicists ever, took the idea further and gave the first proof of the “Fundamental Theorem of Algebra,” namely that a polynomial of degree n has exactly n roots, counting multiplicities.

Polar Coordinates for Complex Numbers#

When the famous physicist Richard Feynman talked about multiplication of complex numbers, he didn’t use the Cartesian rule (a,b)(c,d)=(acbd,ad+bc) but rather said, in words, “multiply the magnitudes and add the angles.” This is much simpler to understand geometrically and much more believable that such a rule could be useful in real (physical) life. So, how does it work?

../_images/polar_coordinates.png

To get to the point P=(a,b) from the origin, one needn’t walk a units in the Re direction, turn left 90° and walk b units. Instead, one can head off at angle θ and walk r units. By trigonometry,

b=rsinθa=rcosθ

and by Pythagoras’ Theorem

r2=a2+b2sor=a2+b2.

Computing θ from a and b is a little more awkward than the usual high school treatment, and for many purposes all we need are (if r0)

sinθ=br=ba2+b2

and

cosθ=ar=aa2+b2.

Taking the ratio loses one important bit of information, namely the quadrant:

sinθcosθ=tanθ=ba.
../_images/polar_coordinates1.png

Since ba=ba, once we’ve computed the ratio, there’s no way to detect the quadrant: is it I or III? If ba is negative, is it II or IV? To get around this, most computer languages define a two-argument arctan function:

θ=arctan(b,a).

Moreover, we take conventionally π<θπ, so if (a,b)=(1,0) then θ=π. Since sinπ=0 and cosπ=1, this agrees with experience.

Theorem 2 (The multiplication rule in polar coordinates)

If z1=(a1,b1)=r1θ1 is one number and z2=(a2,b2)=r2θ2 is another, then their product is

z3=(r1r2)θ1+θ2.

That is,

r3=r1r2multiply the magnitudes

and

θ3=θ1+θ2add the angles.
../_images/polar_coordinates2.png

If θ1+θ2 lies outside π<θ3π, add or subtract 2π until it is; that doesn’t change sinθ3 or cosθ3, which is all we care about.

Proof. Use

cos(θ1+θ2)=cosθ1cosθ2sinθ1sinθ2sin(θ1+θ2)=sinθ1cosθ2+sinθ2cosθ1

and prove it yourself.

Example 1

Multiply a+ib by aib.

../_images/polar_coordinates3.png

Pretty clearly the angle for (a,b) is the negative of that for (a,b). Also the magnitudes are the same:

r=a2+b2=a2+(b)2.

Therefore

(a+ib)(aib)=rrθθ=r20=a2+b20

which is a real nonnegative number!

Check in Cartesian:

(a,b)(a,b)=(aab(b),a(b)+ba)=(a2+b2,0)

just the same. The number z¯=aib=(a,b) is called the conjugate of z=a+ib=(a,b).

Note

If r=0, θ is not defined. If you have to walk zero steps does it matter which direction you have to walk them in?

Theorem 3 (Euler’s Theorem: eiθ=cosθ+isinθ)

The notation rθ is rarely seen, not because it’s so ugly but because there’s something better: z=rθ=reiθ where e=2.7182818284 is the base of the natural logarithm. This is because of Euler’s theorem, which states eiθ=cosθ+isinθ. Then

z=a+ib=rcosθ+irsinθ=r(cosθ+isinθ)=reiθ.

Then the multiplication rule fits the addition law of multiplying exponentials:

r1eiθ1r2eiθ2=r1r2ei(θ1+θ2).

Why is eiθ=cosθ+isinθ? Sometimes this is just taken as a definition of eiθ. That may not satisfy. Another proof uses Taylor series, which is convincing in this case if one is comfortable with the Taylor series

eiθ=1+(iθ)+(iθ)22!+(iθ)33!+(iθ)44!+cosθ=1θ22!+θ44!sinθ=θθ33!+

Another way is by differential equation: eat solves

dydt=ay

and so one expects eiθ to solve dydθ=iy. But if Y=cosθ+isinθ then

dYdθ=sinθ+icosθ=i(cosθ+isinθ)because i2=1

so Y also solves this; since cos0=1, sin0=0, ei0=1, by uniqueness of solutions of this DE, we must have eiθ=y=Y=cosθ+isinθ. There are other proofs: people are keen to prove it in different ways because it’s such a strange result. One can use trig identities to show that

(cosθ1+isinθ1)(cosθ2+isinθ2)=(cosθ1cosθ2sinθ1sinθ2)+i(cosθ1sinθ2+sinθ1cosθ2)=cos(θ1+θ2)+isin(θ1+θ2)

which satisfies the same functional equation as eiθ1eiθ2=ei(θ1+θ2), and maybe this proof scratches the deepest itch.

One can run this backwards, like so

eiθ=cosθ+isinθeiθ=cos(θ)+isin(θ)=cosθisinθ

because cosine is even and sine is odd.

 adding giveseiθ+eiθ=2cosθsubtracting giveseiθeiθ=2isinθ

so

cosθ=eiθ+eiθ2sinθ=eiθeiθ2i.

These lovely formulae make trig identities simpler, like so:

cos3θ=(eiθ+eiθ2)3=ei3θ+3ei2θeiθ+3eiθe2iθ+ei3θ8=ei3θ+ei3θ8+34(eiθ+eiθ2)=14cos3θ+34cosθ.

Complex Weirdness#

Now that we have eiθ we can define ez: if z=x+iy, we define it as ex+iy=exeiy=ex(cosy+isiny).

So what?

…so for instance defining zb as eblnz,

ii=eilni=ei(ln1+iπ2)=ei(iπ2)=eπ2R.

Say what?

Well, if w=ez=ex+iy then |w| is the magnitude of

w=|(excosy,exsiny)|=e2xcos2y+e2xsin2y=excos2y+sin2y=ex,

and

argw=arctan(exsiny,excosy)=y

if π<yπ so we can define lnw=x+iy if π<yy so ln(i)=ln(eiπ2)=iπ2 so ii=eπ2 is real.

… If you say so

But there’s more to this

ln(1)=2πik

for any integer k because

e2πik=cos(2πk)+isin(2πk)=1+i0=1.

So, actually, i has an infinite number of logarithms:

lni?=iπ2+2iπk

for any integer k’:

eiπ2+2πik=cos(π2+2πk)+isin(π2+2πk)=cosπ2+isinπ2=0+i1=i

because cos and sin are periodic with period 2π.

Let’s use David Jeffrey’s notation and say

lnkz=lnz+2πk.

Therefore, we could have (but didn’t) define

ii?=eilnki=ei(iπ2+2πik)=eπ22πk

an infinite number of possible real values. This isn’t the weirdest thing about complex numbers; but following the rules, it will all make sense, and some of it will be very useful indeed.

We just have to share an interesting new fact from Twitter. Christopher D. Long (@octonion) asked about the infinite tower of powers

c=iii

and was surprised to learn that this thing has a known value (well, for a certain value of “known”). Actually, we were surprised, too, at how simple it turned out to be. The answer involves the Lambert W function: see The Lambert W Function Poster for a picture. The answer is that

c=2iπW(π2i)

To prove that, we have to carefully define that tower. We do so this way: put c0=0, and cn+1=icn for n0. This can be implemented in Python, and we do so now. The approach to the limit is a bit slow, but 1000 terms are enough.

from scipy import special as spc
import numpy as np
import math
c = 2.0j*spc.lambertw(math.pi/(2.0j))/math.pi
print(c)
N = 1000
xi = np.zeros(N,dtype=complex)
xi[0] = 0.0  # we already knew this
for k in range(N):
    xi[k] = 1.0j**xi[k-1]
print(xi[-1])
print(abs(c - xi[-1])/abs(c))
(0.4382829367270321+0.3605924718713855j)
(0.4382829367270322+0.3605924718713855j)
1.9561499857674642e-16