Zalgorithm

Multiplying complex numbers

This is not a math tutorial. See Why am I writing about math?

The fast way:

a = complex(2, 3)
b = complex(4, 5)
z = a * b

print(z)
# (-7+22j)

Considering multiplication in terms of the rectangular form #

A complex number is any number that can be written as a+bia + bi, where ii is the imaginary unit and aa and bb are real numbers.1

Remember that i=(1)i = \sqrt(-1). Think about the process as though ii is a regular variable, for example xx, but that the result of the multiplication needs to be in the form a+bia + bi, not something like ai2+biai^2 + bi.

Multiplying a complex number by a scalar #

a=6+4ia = 6+4i:

b=3b = 3

ba=3(6+4i)=18+12ib\cdot a = 3(6 + 4i) = 18 + 12i

Multiplying a complex number by a complex number #

a=2+3ia = 2+3i

b=4+2ib = 4+2i

ab=(2+3i)(4+2i)=8+4i+12i+6i2=8+16i6=2+16ia\cdot b = (2 + 3i)(4 + 2i) = 8 + 4i + 12i + 6i^2 = 8 + 16i - 6 = 2+16i

Considering multiplication in terms of the polar form #

The polar coordinate system is outlined here: notes / The polar coordinate system

The polar coordinate system defines points on the complex plane in terms of a magnitude rr and an angle θ\theta. The angle θ\theta determines how much the polar coordinate rotates away from the polar axis (the line starting from the center of the circle in the image below):

Polar form power of i
Polar form power of i

The polar form is essentially:

complex number = magnitude * (unit circle point at its angle)

See notes/ The polar coordinate system (where do the angles of for the powers of ii come from?)

Skipping the proof , the formula for multiplying complex numbers in polar form is:

r1r2[cos(θ1+θ2)+isin(θ1+θ2)] r_1r_2[cos(\theta_1 + \theta_2) + i \sin(\theta_1 + \theta_2)]

The magnitudes of the numbers are multiplied and the angles are summed.

Polar form notation versus computation #

I’m not sure how better to phrase the issue. Polar form notation often represents complex numbers in the form:

r(cosθ+isinθ) r(cos \theta + i sin \theta)

This shows how the polar form related to the Cartesian (rectangular) form a+bia + bi, but when working with complex numbers computationally, you don’t actually carry out the trig functions.

An example from Processing code:

class ComplexPolar {
  float r, theta, re, im;
  int hue;

  ComplexPolar(float r, float theta) {
    this.r = r;
    this.theta = theta;
    this.re = r * cos(theta);  // used in the sketch's code
    this.im = r * sin(theta);  // used in the sketch's code
    this.hue = (int)(theta * 180.0/PI) % 360;
  }

  ComplexPolar mult(ComplexPolar other) {
    return new ComplexPolar(
      r * other.r, theta + other.theta
      );
  }

  float magnitude() {
    return r;
  }
}

Multiplication of complex numbers on the unit circle #

When two complex numbers that are on the unit circle are multiplied, only the sine/cosine parts of the numbers are affected (because the magnitudes of the numbers are 1). This means that multiplication only has a rotation effect:

i0i1=1(cos 0+i sin 0)×1(cos π/2+i sin π/2)i^0 \cdot i^1 = 1(cos\text{ }0 + i\text{ }sin\text{ }0)\times 1(cos\text{ }\pi/2 + i\text{ }sin\text{ }\pi/2)

i0i1=1(cos π/2+i sin π/2) i^0\cdot i^1 = 1(cos\text{ }\pi/2 + i\text{ }sin\text{ }\pi/2)

Multiplying a complex number by ii rotates the number 90 degrees counter-clockwise from the polar axis.

Multiplying a complex number 4 times by ii results in a 360 degree rotation (it’s back to the starting point).

Using complex numbers to parameterize the equation for a circle #

The way that multiplying complex numbers applies a rotation effect helps to explain how the formula for creating a circle can be parameterized.

The parameterized formula for a circle with radius rr centered at the origin is (in “cis” form):

z(t)=rcis(t) z(t) = r\cdot cis(t)

The “cis” (cosine, imaginary, sine) notation expands to:

z(t)=r(cos(t)+isin(t)) z(t) = r(cos(t) + i\cdot\sin(t))

As tt varies from 00 to 2π2\pi, this traces a complete circle.

This is the way I’ve always drawn circles with Processing (ignoring the ii component):

float x = r*cos(t);
float y = r*sin(t);
t += PI/32 // or some other increment

Tracing what’s happening to points on the complex plane during the Mandelbrot iterations #

Related to Mandelbrot set (Processing)

I tried a small experiment with this here: notes / Tracing how numbers change during the Mandelbrot iterations

References #

Khan Academy. “Multiplying complex numbers.” Accessed on: January 26, 2026. https://www.khanacademy.org/math/algebra2/x2ec2f6f830c9fb89:complex/x2ec2f6f830c9fb89:complex-mul/a/multiplying-complex-numbers .