TExcelTAD
Home › Linear Algebra & Matrix Theory › Complex Inner Product Spaces

Complex Inner Product Spaces

In Cn\mathbb{C}^n the plain dot product fails as a measure of length: (1,i)⋅(1,i)=1+i2=0(1, i) \cdot (1, i) = 1 + i^2 = 0. 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 z=a+biz = a + bi, the squared modulus is ∣z∣2=zzˉ=a2+b2\lvert z \rvert^2 = z\bar{z} = a^2 + b^2, where zˉ=a−bi\bar{z} = a - bi is the conjugate (see The Complex Numbers). So the natural length in Cn\mathbb{C}^n is

∥v∥2=∣v1∣2+⋯+∣vn∣2=v1vˉ1+⋯+vnvˉn\lVert \mathbf{v} \rVert^2 = \lvert v_1 \rvert^2 + \cdots + \lvert v_n \rvert^2 = v_1\bar{v}_1 + \cdots + v_n\bar{v}_n

and the matching inner product is

⟨u,v⟩=u1vˉ1+u2vˉ2+⋯+unvˉn=v∗u\langle \mathbf{u}, \mathbf{v} \rangle = u_1\bar{v}_1 + u_2\bar{v}_2 + \cdots + u_n\bar{v}_n = \mathbf{v}^*\mathbf{u}

where v∗=vˉT\mathbf{v}^* = \bar{\mathbf{v}}^T is the conjugate transpose (also written vH\mathbf{v}^H, "v\mathbf{v} Hermitian").

The axioms

A complex inner product on a complex vector space VV satisfies, for all u,v,w\mathbf{u}, \mathbf{v}, \mathbf{w} and complex cc:

Axiom Statement
Conjugate symmetry ⟨u,v⟩=⟨v,u⟩‾\langle \mathbf{u}, \mathbf{v} \rangle = \overline{\langle \mathbf{v}, \mathbf{u} \rangle}
Linearity in the first slot ⟨u+w,v⟩=⟨u,v⟩+⟨w,v⟩\langle \mathbf{u} + \mathbf{w}, \mathbf{v} \rangle = \langle \mathbf{u}, \mathbf{v} \rangle + \langle \mathbf{w}, \mathbf{v} \rangle, ⟨cu,v⟩=c⟨u,v⟩\langle c\mathbf{u}, \mathbf{v} \rangle = c\langle \mathbf{u}, \mathbf{v} \rangle
Positivity ⟨v,v⟩\langle \mathbf{v}, \mathbf{v} \rangle is real and >0> 0 for v≠0\mathbf{v} \ne \mathbf{0}

Combining the first two gives conjugate linearity in the second slot: ⟨u,cv⟩=cˉ⟨u,v⟩\langle \mathbf{u}, c\mathbf{v} \rangle = \bar{c}\langle \mathbf{u}, \mathbf{v} \rangle. 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) =∑ai‾bi= \sum \overline{a_i} b_i, which is ⟨b,a⟩\langle \mathbf{b}, \mathbf{a} \rangle in our notation. Both are fine; check which one a formula uses before moving a scalar out of a bracket.

Norms, distance, orthogonality (⟨u,v⟩=0\langle \mathbf{u}, \mathbf{v} \rangle = 0), orthonormal bases, projections and Gram-Schmidt all carry over word for word, and so does the Cauchy–Schwarz inequality ∣⟨u,v⟩∣≤∥u∥∥v∥\lvert \langle \mathbf{u}, \mathbf{v} \rangle \rvert \le \lVert \mathbf{u} \rVert\lVert \mathbf{v} \rVert. What does not carry over is the angle formula: ⟨u,v⟩\langle \mathbf{u}, \mathbf{v} \rangle is complex, so cos⁡θ=⟨u,v⟩∥u∥∥v∥\cos\theta = \frac{\langle \mathbf{u}, \mathbf{v} \rangle}{\lVert \mathbf{u} \rVert\lVert \mathbf{v} \rVert} no longer makes sense. People use ∣⟨u,v⟩∣∥u∥∥v∥∈[0,1]\frac{\lvert \langle \mathbf{u}, \mathbf{v} \rangle \rvert}{\lVert \mathbf{u} \rVert\lVert \mathbf{v} \rVert} \in [0, 1] as a measure of alignment instead.

python · try it yourself
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 Cn\mathbb{C}^n

The projection coefficient becomes ⟨v,u⟩/⟨u,u⟩\langle \mathbf{v}, \mathbf{u} \rangle/\langle \mathbf{u}, \mathbf{u} \rangle, and the order of the arguments now matters.

python · try it yourself
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 [−π,π][-\pi, \pi] with ⟨f,g⟩=∫f(x)g(x)‾ dx\langle f, g \rangle = \int f(x) \overline{g(x)} \, dx, the functions en(x)=einxe_n(x) = e^{inx}, n∈Zn \in \mathbb{Z}, are orthogonal: for m≠nm \ne n, ∫ei(m−n)x dx=0\int e^{i(m-n)x} \, dx = 0 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 NN points gives the discrete Fourier basis: the vectors fk\mathbf{f}_k with entries e2πi⋅jk/Ne^{2\pi i \cdot jk/N}, j=0,…,N−1j = 0, \ldots, N - 1. They are orthogonal in CN\mathbb{C}^N with ∥fk∥2=N\lVert \mathbf{f}_k \rVert^2 = N. The DFT of a signal x\mathbf{x} is the list of inner products ⟨x,fk⟩\langle \mathbf{x}, \mathbf{f}_k \rangle, which is what np.fft.fft computes:

python · try it yourself
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 k=2k = 2 and k=6=N−2k = 6 = N - 2, the sine at frequency 3 at k=3k = 3 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 C2\mathbb{C}^2; the probability of measuring state φ\varphi given state ψ\psi is ∣⟨ψ,φ⟩∣2\lvert \langle \psi, \varphi \rangle \rvert^2.
  • Communications. Wi-Fi and 4G/5G (OFDM) put data on orthogonal complex exponentials so that channels do not interfere.
  • Numerics. In NumPy, a.conj().T or a.conj().T @ b is the Hermitian transpose and inner product; forgetting .conj() is a common silent bug.

Exercises

Exercise 1: A complex length

Find ∥(3−4i,1+i)∥\lVert (3 - 4i, 1 + i) \rVert.

Answer

27=33≈5.1962\sqrt{27} = 3\sqrt{3} \approx 5.1962.

Solution

∣3−4i∣2=9+16=25\lvert 3 - 4i \rvert^2 = 9 + 16 = 25 and ∣1+i∣2=2\lvert 1 + i \rvert^2 = 2, so ∥v∥2=27\lVert \mathbf{v} \rVert^2 = 27.

Exercise 2: Moving scalars

With ⟨u,v⟩=∑uivˉi\langle \mathbf{u}, \mathbf{v} \rangle = \sum u_i\bar{v}_i, simplify ⟨2iu,3iv⟩\langle 2i\mathbf{u}, 3i\mathbf{v} \rangle in terms of ⟨u,v⟩\langle \mathbf{u}, \mathbf{v} \rangle.

Answer

6⟨u,v⟩6\langle \mathbf{u}, \mathbf{v} \rangle.

Solution
⟨2iu,3iv⟩=(2i)⋅3i‾⋅⟨u,v⟩=2i⋅(−3i)⋅⟨u,v⟩=−6i2⟨u,v⟩=6⟨u,v⟩\langle 2i\mathbf{u}, 3i\mathbf{v} \rangle = (2i) \cdot \overline{3i} \cdot \langle \mathbf{u}, \mathbf{v} \rangle = 2i \cdot (-3i) \cdot \langle \mathbf{u}, \mathbf{v} \rangle = -6i^2 \langle \mathbf{u}, \mathbf{v} \rangle = 6\langle \mathbf{u}, \mathbf{v} \rangle

Exercise 3: Orthogonal or not?

Let u=(1,i)\mathbf{u} = (1, i), v=(i,1)\mathbf{v} = (i, 1) and w=(1,−i)\mathbf{w} = (1, -i). Which pairs are orthogonal under ⟨a,b⟩=∑aibˉi\langle \mathbf{a}, \mathbf{b} \rangle = \sum a_i\bar{b}_i? Compare with the plain dot product ∑aibi\sum a_ib_i.

Answer

u⊥v\mathbf{u} \perp \mathbf{v} and u⊥w\mathbf{u} \perp \mathbf{w}. The plain dot products are u⋅v=2i\mathbf{u} \cdot \mathbf{v} = 2i and u⋅w=2\mathbf{u} \cdot \mathbf{w} = 2, which would wrongly say "not orthogonal".

Solution

Conjugate the second vector term by term (i‾=−i\overline{i} = -i, −i‾=i\overline{-i} = i):

⟨u,v⟩=1⋅i‾+i⋅1‾=−i+i=0⟨u,w⟩=1⋅1‾+i⋅−i‾=1+i⋅i=1−1=0u⋅v=1⋅i+i⋅1=2iu⋅w=1⋅1+i⋅(−i)=1−i2=2\begin{aligned} \langle \mathbf{u}, \mathbf{v} \rangle &= 1 \cdot \overline{i} + i \cdot \overline{1} = -i + i = 0 \\ \langle \mathbf{u}, \mathbf{w} \rangle &= 1 \cdot \overline{1} + i \cdot \overline{-i} = 1 + i \cdot i = 1 - 1 = 0 \\ \mathbf{u} \cdot \mathbf{v} &= 1 \cdot i + i \cdot 1 = 2i \\ \mathbf{u} \cdot \mathbf{w} &= 1 \cdot 1 + i \cdot (-i) = 1 - i^2 = 2 \end{aligned}
python · try it yourself
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 N=4N = 4, write f1\mathbf{f}_1 and f2\mathbf{f}_2 explicitly and check that they are orthogonal.

Answer

f1=(1,i,−1,−i)\mathbf{f}_1 = (1, i, -1, -i), f2=(1,−1,1,−1)\mathbf{f}_2 = (1, -1, 1, -1), and ⟨f1,f2⟩=0\langle \mathbf{f}_1, \mathbf{f}_2 \rangle = 0.

Solution

e2πi⋅j/4=ije^{2\pi i \cdot j/4} = i^j and e2πi⋅2j/4=(−1)je^{2\pi i \cdot 2j/4} = (-1)^j. ⟨f1,f2⟩=1⋅1+i⋅(−1)+(−1)⋅1+(−i)⋅(−1)=1−i−1+i=0\langle \mathbf{f}_1, \mathbf{f}_2 \rangle = 1 \cdot 1 + i \cdot (-1) + (-1) \cdot 1 + (-i) \cdot (-1) = 1 - i - 1 + i = 0.

python · try it yourself
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 Cn\mathbb{C}^n need ⟨u,v⟩=∑uivˉi\langle \mathbf{u}, \mathbf{v} \rangle = \sum u_i\bar{v}_i instead of ∑uivi\sum u_iv_i?

  1. To make the product faster
  2. So that ⟨v,v⟩=∑∣vi∣2\langle \mathbf{v}, \mathbf{v} \rangle = \sum \lvert v_i \rvert^2 is real and positive
  3. Because complex numbers do not commute
  4. It does not; both work

With our convention (linear in the first slot), ⟨u,cv⟩\langle \mathbf{u}, c\mathbf{v} \rangle equals…

  1. c⟨u,v⟩c\langle \mathbf{u}, \mathbf{v} \rangle
  2. cˉ⟨u,v⟩\bar{c}\langle \mathbf{u}, \mathbf{v} \rangle
  3. ∣c∣⟨u,v⟩\lvert c \rvert\langle \mathbf{u}, \mathbf{v} \rangle
  4. ⟨u,v⟩\langle \mathbf{u}, \mathbf{v} \rangle

What does np.vdot(a, b) compute?

  1. ∑aibi\sum a_ib_i
  2. ∑aibi‾\sum a_i \overline{b_i}
  3. ∑ai‾bi\sum \overline{a_i} b_i
  4. ∣a∣⋅∣b∣\lvert \mathbf{a} \rvert \cdot \lvert \mathbf{b} \rvert