Introduction to Mathematical Software

21-126, Spring 2000
Dr. David Handron

Lesson 5

An Introduction to Complex Numbers

Introduction

All of you are well aware of the fact that there is no real number x satisfying x^2 = -1. An alternative statement of this obvious fact would be that the polynomial p(x) = x^2 + 1 has no real roots. If we are to work with such polynomials, and insist that they have roots, we need to extend our number system, and it turns out that the complex number system we study below has the remarkable property that all polynomials p(x) (having real or complex coefficients) can be completely factored with complex numbers.

Below we show how do define Mathematica rules that will implement complex arithmetic. The simplicity of the rules we define below illustrates that power of the programing environment.

Definition

We begin by abstractly defining the set of complex numbers to be the set of all ordered pairs of real numbers.

		C = { (x,y) | x and y Real }

Since Mathematica doesn't have a convenient way to represent such pairs, we will simply write CC[x,y] for the complex number (x,y) (The command C[] already exists in Mathematica). Typically we write z = (x,y) or w = (u,v) for generic complex numbers.

z = CC[x,y]

w = CC[u,v]

Addition and Subtraction

Given z = (x,y) and w = (u,v) we define their sum z + w by

	z + w = (x + u,  y + v)
	
Or using the jargon of Mathematica:

Clear[CC]
CC/: CC[x_, y_] + CC[u_, v_] := CC[x + u, y + v]
?CC

CC[x,y] + CC[u,v]

Of course all reasonable addition operations should satisfy the following axioms:

	1) Commutative: (x,y) + (u,v) = (u,v) + (x,y)
	2) Associative: ((s,t) + (u,v)) + (x,y) = (s,t) + ((u,v) + (x,y))
	3) There exists a zero z0 such that (u,v) + z0 = (u,v)
	4) For each complex number w = (u,v) there must be a complex number -w 
	     such that w + (-w) = z0 (the complex zero)
	     
You don't have to be a genius to guess that the complex zero is (0,0) and if w = (u,v) then -w = (-u, -v). Let's check out these properties.

CC[x,y] + CC[u,v] == CC[u,v] + CC[x,y]

(CC[s,t] + CC[x,y]) + CC[u,v] == 
						CC[s,t] + (CC[u,v] + CC[x,y])

CC[u,v] + CC[0,0] == CC[u,v]

CC[u,v] + CC[-u,-v] == CC[0,0]

Notice that subtraction w - z means w + (-z), and Mathematica doesn't know about negation of expressions having heads CC

CC[u,v] - CC[x,y]

So we must teach it:

Clear[CC]
CC/:  CC[x_, y_] + CC[u_, v_] := CC[x + u, y + v]
CC/: -CC[x_,y_] := CC[-x, -y]
?CC

CC[u,v] - CC[x,y]

Multiplication and The Distributive Law

Given that we plan to define a complex number as an ordered pair, the addition operation seems natural  -- we simply add the terms component by component to get another ordered pair. Not so with multiplication, which is defined as follows:

			(x,y) (u,v) = (x u - y v,  x v + y v)

Clear[CC]
CC/: CC[x_, y_] CC[u_, v_] := CC[x u - y v, x v + y u]
?CC

Notice that I have not included the definition of complex addition just to highlight the fact that none of the properties of multiplication depend upon addition.

CC[u,v] CC[x,y] == CC[x,y] CC[u,v]

(CC[s,t] CC[u,v]) CC[x,y] == CC[s,t] (CC[u,v] CC[x,y])
Simplify[%]

CC[u,v] CC[1,0] == CC[u,v]

Notice that each complex multiplication requires four real multiplications, and for this reason alone, complex arithmetic is rarely done manually. Lets look at the product of the three complex numbers Mathematica had to compute to check associativity.

CC[s,t] CC[u,v] CC[x,y]

Simplify[%]

This clearly involves the product of many real numbers.

Finally we check that multiplication and addition fit together correctly to satisfy the distributive law.

		(s,t) ((u,v) + (x,y)) = (s,t) (u,v) + (s,t) (x,y)

Clear[CC]
CC/: CC[x_, y_] + CC[u_, v_] := 
				Map[Simplify, CC[x + u, y + v]]
CC/: CC[x_, y_] CC[u_, v_] := 
				Map[Simplify, CC[x u - y v, x v + y u]]
?CC

Notice that I've told Mathematica to simplify a sum and product so that we don't have to manually map Expand[] etc. onto an expression like I did above. This also makes verification of the distributive law a one liner:

CC[s,t] (CC[u,v] + CC[x,y]) == 
						CC[s,t] CC[u,v] + CC[s,t] CC[x,y]

Division

Recall that the zero complex number is (0,0) and the identity complex number is (1,0). In order to define division, we need to be able to find multiplicative inverses. That is, given z = (x,y), can we find w = (u,v) such that z w = (1,0) ?

Mathematica represents division x / y as a product x * y^(-1):

FullForm[x / y]

so we must define CC[]^(-1) in order to do division. The inverse of a complex number is given by the formula

		1 / (x, y) = (x/d, -y/d) 	where 	d = x^2 + y^2

CC/: CC[x_, y_]^(-1) := 
       Map[Simplify, CC[x/(x^2 + y^2), -y/(x^2 + y^2)]] 
?CC

CC[u,v] / CC[x,y]
CC[x,y] / CC[x,y]

Complex division is a very tedious chore. It requires six real multiplies, three real adds and two real divides. A human will almost never get the correct answer the first time!

Note that the denominator x^2 + y^2 appearing in the inverse of (x, y) can be computed as.

CC[x, y] CC[x, -y]

The complex number (x, -y) is called the complex conjugate of z, and is "almost" the inverse in the sense that multiplication by (x, -y) produces a complex number with zero second component. To get the actual inverse, we divide each component of the conjugate by (x^2 + y^2).

Summary and Examples

Let's collect the rules we've made up for complex arithmetic

Clear[CC]
CC/: CC[x_, y_] + CC[u_, v_] := CC[x + u, y + v]						
CC/: CC[x_, y_] CC[u_, v_] := CC[x u - y v, x v + y u]
CC/: -CC[x_, y_] := CC[-x, -y]
CC/: CC[x_, y_]^(-1) := CC[x/(x^2 + y^2), -y/(x^2 + y^2)]
?CC

A few examples:

z1 = CC[4,-1]
z2 = CC[-2,5]

w1 = CC[7, 7]
w2 = CC[7,-7]

z1 - z2
w1 + w2

z1 z2
w1 w2

z1 / z2
w1 / w2

(z1 - w1) (z2 + w2)
(z1 - w1) / (z2 + w2)

When using symbolic quantities it is often convenient include simplification in the definition of the arithmetic operations.