Complex Inner Product Spaces
In the plain dot product fails as a measure of length: . The fix is to conjugate one of the two vectors. The resulting Hermitian inner product powers the discrete Fourier transform, quantum computing and every complex-valued signal library.
Why we need a conjugate
For a complex number , the squared modulus is , where is the conjugate (see The Complex Numbers). So the natural length in is
and the matching inner product is
where is the conjugate transpose (also written , " Hermitian").
The axioms
A complex inner product on a complex vector space satisfies, for all and complex :
| Axiom | Statement |
|---|---|
| Conjugate symmetry | |
| Linearity in the first slot | , |
| Positivity | is real and for |
Combining the first two gives conjugate linearity in the second slot: . A real inner product is the special case where conjugation does nothing.
Note: Physics, quantum computing and NumPy use the opposite convention, conjugating the first argument:
np.vdot(a, b), which is in our notation. Both are fine; check which one a formula uses before moving a scalar out of a bracket.
Norms, distance, orthogonality (), orthonormal bases, projections and Gram-Schmidt all carry over word for word, and so does the Cauchy–Schwarz inequality . What does not carry over is the angle formula: is complex, so no longer makes sense. People use as a measure of alignment instead.
import numpy as np
u = np.array([1 + 1j, 2j, 3])
v = np.array([2, 1 - 1j, 1j])
print("plain u.u (wrong as a length):", u @ u)
print("<u, u> = sum |u_i|^2:", np.vdot(u, u).real, "=", float(np.sum(np.abs(u) ** 2)))
uv = np.sum(u * np.conj(v)) # our convention: conjugate the second argument
print("<u, v> =", uv, " <v, u> =", np.sum(v * np.conj(u)))
print("np.vdot(v, u) =", np.vdot(v, u), " (conjugates its first argument)")
print("Cauchy-Schwarz:", round(abs(uv), 4), "<=", round(float(np.linalg.norm(u) * np.linalg.norm(v)), 4))plain u.u (wrong as a length): (5+2j)
<u, u> = sum |u_i|^2: 15.0 = 15.0
<u, v> = 1j <v, u> = -1j
np.vdot(v, u) = 1j (conjugates its first argument)
Cauchy-Schwarz: 1.0 <= 10.247
Gram-Schmidt in
The projection coefficient becomes , and the order of the arguments now matters.
from sympy import Matrix, I, simplify
def ip(a, b): # <a, b> = b^* a
return (b.H * a)[0]
v1 = Matrix([1, I, 0])
v2 = Matrix([1, 0, I])
u1 = v1
u2 = v2 - ip(v2, u1) / ip(u1, u1) * u1
print("u2 =", list(simplify(u2)))
print("<u2, u1> =", simplify(ip(u2, u1)), " <u2, u2> =", simplify(ip(u2, u2)))
print("plain dot u2.u1 =", simplify(u2.dot(u1)), "(not zero: the conjugate matters)")u2 = [1/2, -I/2, I]
<u2, u1> = 0 <u2, u2> = 3/2
plain dot u2.u1 = 1 (not zero: the conjugate matters)
Complex exponentials and the DFT
On functions on with , the functions , , are orthogonal: for , because the integrand goes round the unit circle a whole number of times. This packs the sines and cosines of Fourier series into one family.
Sampling at points gives the discrete Fourier basis: the vectors with entries , . They are orthogonal in with . The DFT of a signal is the list of inner products , which is what np.fft.fft computes:
import numpy as np
N = 8
j = np.arange(N)
F = np.exp(2j * np.pi * np.outer(j, j) / N) # column k is f_k
print("F^* F = N I:", np.allclose(F.conj().T @ F, N * np.eye(N)))
x = np.cos(2 * np.pi * 2 * j / N) + 0.5 * np.sin(2 * np.pi * 3 * j / N)
coeffs = F.conj().T @ x # <x, f_k> for every k
print("matches np.fft.fft:", np.allclose(coeffs, np.fft.fft(x)))
print("|<x, f_k>|:", np.round(np.abs(coeffs), 4))F^* F = N I: True
matches np.fft.fft: True
|<x, f_k>|: [0. 0. 4. 2. 0. 2. 4. 0.]
The cosine at frequency 2 shows up at and , the sine at frequency 3 at and 5. A real signal always gives these mirrored pairs.
In software
- Signal processing. Audio spectra, image filters and convolution via FFT are complex inner products (SciPy FFT).
- Quantum computing. A qubit state is a unit vector in ; the probability of measuring state given state is .
- Communications. Wi-Fi and 4G/5G (OFDM) put data on orthogonal complex exponentials so that channels do not interfere.
- Numerics. In NumPy,
a.conj().Tora.conj().T @ bis the Hermitian transpose and inner product; forgetting.conj()is a common silent bug.
Exercises
Exercise 1: A complex length
Find .
Answer
.
Solution
and , so .
Exercise 2: Moving scalars
With , simplify in terms of .
Answer
.
Solution
Exercise 3: Orthogonal or not?
Let , and . Which pairs are orthogonal under ? Compare with the plain dot product .
Answer
and . The plain dot products are and , which would wrongly say "not orthogonal".
Solution
Conjugate the second vector term by term (, ):
import numpy as np
u, v, w = np.array([1, 1j]), np.array([1j, 1]), np.array([1, -1j])
ip = lambda a, b: np.sum(a * np.conj(b))
print("hermitian:", ip(u, v), ip(u, w), " plain:", u @ v, u @ w)hermitian: 0j 0j plain: 2j (2+0j)
Exercise 4: DFT basis vectors (code)
For , write and explicitly and check that they are orthogonal.
Answer
, , and .
Solution
and . .
import numpy as np
j = np.arange(4)
f1, f2 = np.exp(2j * np.pi * j / 4), np.exp(2j * np.pi * 2 * j / 4)
print(np.round(f1, 10) + 0, np.round(f2, 10) + 0, np.round(np.sum(f1 * np.conj(f2)), 10) + 0)[ 1.+0.j 0.+1.j -1.+0.j 0.-1.j] [ 1.+0.j -1.+0.j 1.+0.j -1.+0.j] 0j
Test yourself
Why does need instead of ?
- To make the product faster
- So that is real and positive
- Because complex numbers do not commute
- It does not; both work
With our convention (linear in the first slot), equals…
What does np.vdot(a, b) compute?