Inner products, orthogonality, Cauchy–Schwarz
Define the inner product, prove the Cauchy–Schwarz inequality step by step from positivity of a quadratic, and use it to give precise meaning to angle and orthogonality.
A norm tells you how long a vector is. An inner product tells you how two vectors relate: the angle between them, whether they are perpendicular, how much one points along another. Almost every geometric statement later in the course (projections, least squares, orthogonal attention directions) is an inner-product statement, and they all rest on one inequality we will prove carefully here.
Definition
An inner product on a real vector space is a rule assigning a real number to each pair of vectors, with three properties[1]:
- Symmetry: .
- Linearity in the first slot: .
- Positive definiteness: , with equality only when .
On the standard choice is the dot product . Property 3 lets us define a length from the inner product, the induced norm:
For the dot product this is exactly the Euclidean norm from the previous lesson.
The inequality everything depends on
Cauchy–Schwarz inequality. For all [2],
with equality if and only if and are scalar multiples of each other.
The proof is short once you see the trick: build a quantity that must be nonnegative (a squared length), expand it, and read off the inequality.
Proof. If both sides are and the statement holds. So assume , and consider the vector for a real number we will choose later. By positive definiteness its squared length is nonnegative:
Step 1: start from a square that cannot be negative.
Step 2: expand using symmetry and linearity.
So for every real ,
Step 3: a nonnegative quadratic has nonpositive discriminant. The left side is a quadratic in with . A parabola that opens upward and never goes below zero can touch zero at most once, which means its discriminant is . Here
Step 4: solve for the inequality. Divide by and rearrange:
Taking square roots (both sides nonnegative) gives , the claim.
Equality. The discriminant is zero exactly when the quadratic has a real root , i.e. , which by positive definiteness forces . So equality holds precisely when and are parallel.
Angle and orthogonality
Cauchy–Schwarz says the ratio always lies in . That is exactly the range of cosine, so we may define the angle between two nonzero vectors by
The definition is only legitimate because the inequality guarantees the right-hand side is a valid cosine. The normalized inner product is then an alignment score on a fixed scale from to , and the familiar angles sit at recognizable values:
- (): the vectors point the same way, the equality case of Cauchy–Schwarz. and .
- (): and give , , , ratio .
- (): perpendicular, and .
- (): antiparallel, and , the other equality case.
Two vectors are orthogonal when , i.e. . This single condition is the seed of projections, the normal equations of least squares, and the orthogonality of principal components later in the course.
A companion fact, proved in one line from the expansion above with , is the triangle inequality for the induced norm: . So the induced norm is genuinely a norm in the sense of the previous lesson.
Check it on arrays
Cauchy–Schwarz is a claim you can stress-test: for many random pairs the ratio should never exceed , and it should hit exactly when the two vectors are parallel.
import numpy as np
rng = np.random.default_rng(0)
# 100000 random pairs in R^5: the ratio must stay <= 1.
U = rng.normal(size=(100_000, 5))
V = rng.normal(size=(100_000, 5))
dots = np.einsum("ij,ij->i", U, V)
ratio = np.abs(dots) / (np.linalg.norm(U, axis=1) * np.linalg.norm(V, axis=1))
print("max ratio over 100k random pairs:", ratio.max()) # < 1
# Parallel vectors saturate the bound (ratio == 1):
u = np.array([1.0, 2.0, 3.0])
v = -4.0 * u
print("parallel ratio:", abs(u @ v) / (np.linalg.norm(u) * np.linalg.norm(v))) # 1.0
# Orthogonal vectors: inner product is 0, angle 90 degrees.
a = np.array([1.0, 0.0]); b = np.array([0.0, 1.0])
print("orthogonal dot:", a @ b, "-> angle", np.degrees(np.arccos(a @ b)))The random ratios crowd under but never cross it; the parallel pair sits exactly at (the equality case of the proof); the orthogonal pair gives .
Exercises
Exercise 1. For and under the standard dot product, compute , the two norms, and the cosine of the angle between them. Confirm the Cauchy–Schwarz inequality holds.
Solution
Step 1. Inner product: .
Step 2. Norms: and .
Step 3. Cosine: . Cauchy–Schwarz requires , which holds, and the ratio lies in as it must.
Exercise 2. Prove the parallelogram law for any inner-product norm.
Solution
Step 1. Expand each squared norm with the inner product, using symmetry and linearity:
Step 2. Likewise, replacing with :
Step 3. Add the two. The cross terms cancel, leaving , which is the claim.
Exercise 3 (code). A valid inner product can weight coordinates differently: for a diagonal with positive entries. Pick , draw many random pairs in , and verify Cauchy–Schwarz holds in this weighted inner product (using its induced norm).
Solution
import numpy as np
rng = np.random.default_rng(0)
W = np.diag([1.0, 2.0, 3.0]) # positive diagonal -> valid inner product
def ip(u, v): # weighted inner product u^T W v
return u @ W @ v
U = rng.normal(size=(100_000, 3))
V = rng.normal(size=(100_000, 3))
dots = np.einsum("ij,jk,ik->i", U, W, V) # <u, v>_W per row
nu = np.sqrt(np.einsum("ij,jk,ik->i", U, W, U)) # induced norms
nv = np.sqrt(np.einsum("ij,jk,ik->i", V, W, V))
ratio = np.abs(dots) / (nu * nv)
assert ratio.max() <= 1.0 + 1e-12 # Cauchy-Schwarz, weighted
print("max weighted ratio:", round(ratio.max(), 6))Every weighted ratio stays at or below , so Cauchy–Schwarz holds in the weighted inner product just as in the standard one; the proof never used anything beyond the three defining properties, which satisfies.
The next lesson turns orthogonality into a construction, Gram–Schmidt, that manufactures an orthonormal basis from any basis.
References
- [1]Axler, S. (2015). Linear Algebra Done Right (3rd ed.), ch. 6. Springer. Inner-product spaces, orthogonality, and the induced norm (doi:10.1007/978-3-319-11080-6).↩
- [2]Horn, R. A., & Johnson, C. R. (2012). Matrix Analysis (2nd ed.). Cambridge University Press. The Cauchy-Schwarz inequality and its equality conditions.↩