Trig and Exponential Functions
Sine and cosine describe rotation; the exponential function describes growth. They look unrelated, but with complex numbers they turn out to be the same function. Euler's formula ties them together and makes trigonometry much easier to compute with.
A quick reminder about complex numbers
A complex number has a real part and an imaginary part , where . Plot it as the point in the plane. Python has them built in, written with j: 3 + 4j. Its length is and its angle with the positive real axis is . More on this in Complex Numbers in Polar Form.
Euler's formula
As varies, runs around the unit circle: its real part is and its imaginary part is , exactly the point from the unit circle.
Why it is true (series sketch). The exponential, sine and cosine all have power series (see Expanding Functions into Series and Taylor series):
Put into the first series. The powers of cycle , so
Let us check it numerically, including by summing the series ourselves:
import cmath
import math
theta = 2.0
z = cmath.exp(1j * theta)
print("e^(iθ) =", z)
print("cos θ + i sinθ =", complex(math.cos(theta), math.sin(theta)))
print("|e^(iθ)| =", abs(z))
partial, term = 0, 1 + 0j
for n in range(25): # sum (iθ)^n / n!
partial += term
term *= 1j * theta / (n + 1)
print("series sum =", partial)e^(iθ) = (-0.4161468365471424+0.9092974268256817j)
cos θ + i sinθ = (-0.4161468365471424+0.9092974268256817j)
|e^(iθ)| = 1.0
series sum = (-0.41614683654714246+0.9092974268256817j)
The last digit of the series differs only by rounding.
At the formula gives the famous Euler's identity, , linking five fundamental constants.
Trig from exponentials
Write Euler's formula for and , and add or subtract:
So sine and cosine are combinations of exponentials. Replacing by a real in these formulas gives the hyperbolic functions.
Identities for free
The exponent rule contains every sum formula. Multiply:
Matching real and imaginary parts gives the sum formulas from the angle-formulas lesson in two lines. Raising to the -th power gives De Moivre's formula:
Expanding the left side with the binomial theorem gives and as polynomials in and . SymPy can do the rewriting:
import sympy as sp
t = sp.Symbol("theta", real=True)
print("cos as exp :", sp.cos(t).rewrite(sp.exp))
print("sin as exp :", sp.sin(t).rewrite(sp.exp))
lhs = sp.expand((sp.cos(t) + sp.I * sp.sin(t))**3)
print("real part of (cos+i sin)^3:", sp.re(lhs))
print("equals cos 3θ?", sp.simplify(sp.re(lhs) - sp.cos(3 * t)) == 0)
print("e^(iπ) + 1 =", sp.exp(sp.I * sp.pi) + 1)cos as exp : exp(I*theta)/2 + exp(-I*theta)/2
sin as exp : -I*(exp(I*theta) - exp(-I*theta))/2
real part of (cos+i sin)^3: -3*sin(theta)**2*cos(theta) + cos(theta)**3
equals cos 3θ? True
e^(iπ) + 1 = 0
Multiplying means rotating
Every complex number can be written in polar form , with and . Then
Multiplication multiplies lengths and adds angles. In particular, multiplying by rotates a point by about the origin without changing its length. This is the complex-number version of the rotation matrix.
In software
- 2D rotation with complex numbers. Store a point as
complex(x, y)and rotate it withp * cmath.exp(1j * angle). Some 2D engines and many quick scripts do exactly this; it is the 2D cousin of quaternions (quaternions). - Signals and the FFT. The discrete Fourier transform measures how much of each frequency is in a signal by multiplying with . Every audio equaliser, MP3/JPEG compressor and spectrum analyser uses it (/signals-fourier/).
- Phasors in electronics and rotary positional embeddings (RoPE) in large language models both treat pairs of numbers as complex numbers rotated by : RoPE rotates query and key vectors by an angle proportional to the token position, so attention depends on relative position.
import cmath
import math
p = complex(3, 1)
r = cmath.exp(1j * math.pi / 2) # rotate by 90°
print("rotated 90°:", complex(round((p * r).real, 12), round((p * r).imag, 12)))
# 12 points of a clock face by repeated rotation
step = cmath.exp(1j * 2 * math.pi / 12)
z, pts = 1 + 0j, []
for _ in range(12):
pts.append(z)
z *= step
print("after 12 steps back at start:", round(abs(z - 1), 12))
print("polar form of 1+1j: r =", round(abs(1 + 1j), 6), " angle =", round(math.degrees(cmath.phase(1 + 1j)), 6), "°")rotated 90°: (-1+3j)
after 12 steps back at start: 0.0
polar form of 1+1j: r = 1.414214 angle = 45.0 °
Exercises
Exercise 1: Evaluate
Write and in the form , exactly.
Answer
, .
Solution
Exercise 2: Polar form
Write as with in .
Answer
.
Solution
import cmath, math
r, phi = cmath.polar(-2 + 2j)
print(round(r, 6), round(2 * math.sqrt(2), 6), round(phi / math.pi, 6))2.828427 2.828427 0.75
Exercise 3: De Moivre
Use De Moivre's formula to express and in terms of and .
Answer
, .
Solution
Exercise 4: Powers of a complex number
Compute using polar form, then check in Python.
Answer
Solution
print((1 + 1j) ** 8)(16+0j)
Exercise 5: Rotate a polygon
Rotate the square with corners 1+1j, -1+1j, -1-1j, 1-1j by 30° about the origin using complex multiplication, and print the new corners rounded to 4 decimals.
Answer
(0.366+1.366j), (-1.366+0.366j), (-0.366-1.366j), (1.366-0.366j).
Solution
import cmath, math
rot = cmath.exp(1j * math.radians(30))
for c in [1+1j, -1+1j, -1-1j, 1-1j]:
z = c * rot
print(complex(round(z.real, 4), round(z.imag, 4)))(0.366+1.366j)
(-1.366+0.366j)
(-0.366-1.366j)
(1.366-0.366j)
Test yourself
What is for a real angle ?
- 1
- It depends on
Which expression equals ?
What does multiplying a complex number by do geometrically?
- Doubles its length
- Reflects it in the real axis
- Rotates it 90° counter-clockwise about the origin
- Moves it right by