Inner Products
The previous page measured one vector at a time. Everything else in this chapter needs a function of two vectors — a way of asking how much they have in common — and once you have one, length, distance, angle and orthogonality all follow without further assumptions.
You already know one such function: the dot product . This page shows what the dot product is an instance of, and why the general version is not an abstraction for its own sake — a covariance matrix, a kernel, and a Mahalanobis distance are all inner products that are not the dot product.
What you’ll learn
Section titled “What you’ll learn”- What a bilinear mapping is, and why bilinearity is the condition that makes matrix notation possible.
- The two extra conditions — symmetry and positive definiteness — and what each one buys.
- Why every inner product on can be written for a symmetric positive definite matrix , and vice versa.
- How to test a candidate matrix, and why Cholesky is the test to reach for rather than eigenvalues.
- The book’s Example 3.4, where changing one entry from 5 to 3 destroys the whole structure — and the exact value of that entry at which it breaks.
Intuition: a scoring rule for agreement
Section titled “Intuition: a scoring rule for agreement”Think of an inner product as a scoring rule that takes two vectors and returns how much they agree. The dot product’s version of “agree” is a specific one: multiply matching coordinates, add up. That treats every coordinate as equally important and as entirely independent of the others.
Often neither is true. If your two coordinates are height in metres and height in centimetres, the dot product double-counts what is really one measurement. If one coordinate is measured carefully and the other is noise, the dot product weighs them the same. The general inner product is what lets you say which coordinates matter and how they interact — and it does so with one matrix:
The diagonal of sets how much each coordinate counts; the off-diagonal entries say how much a unit of one coordinate is worth in the direction of another.
flowchart TD F["Ω : V × V → ℝ
a function of two vectors"] F --> BI["bilinear
linear in each argument separately"] BI --> MAT["so it is x-transpose A y
for exactly one matrix A"] MAT --> SYM["symmetric
Ω(x,y) = Ω(y,x)
⟺ A = A-transpose"] MAT --> PD["positive definite
Ω(x,x) > 0 for x ≠ 0
⟺ A has positive eigenvalues"] SYM --> IP["INNER PRODUCT
⟨x,y⟩"] PD --> IP IP --> NORM["a norm falls out:
‖x‖ = √⟨x,x⟩"] PD --> WHY["positive definiteness is what
makes that square root real"]
The rightmost node is the reason positive definiteness is not optional decoration. Length is going to be defined as ; if the inner product of a vector with itself could be negative, that square root would be imaginary and there would be no geometry to do.
The math
Section titled “The math”Bilinearity
Section titled “Bilinearity”“Linear in each argument separately” is worth reading carefully. The map is not linear in the pair — doubling both arguments quadruples the output, not doubles it. It is linear if you freeze one argument and vary the other.
Bilinearity is what makes the matrix form possible. Fix an ordered basis and expand , . Bilinearity lets you pull both sums out:
with and the coordinate vectors with respect to . The inner product is determined entirely by its values on pairs of basis vectors — numbers, and nothing else is needed.
Symmetry and definiteness
Section titled “Symmetry and definiteness”The correspondence with SPD matrices
Section titled “The correspondence with SPD matrices”That “if and only if” is the practical content of the section. It means:
- Every inner product you will ever meet on is a matrix. There is no exotic case hiding.
- Testing whether a candidate is an inner product reduces to testing whether one matrix is SPD.
- The dot product is the case , which is why it treats coordinates as independent and equally weighted.
Two further properties of an SPD matrix, both stated in the book:
- Its null space is trivial — only for , since otherwise for a nonzero .
- Its diagonal entries are positive, because .
Neither is sufficient. A matrix can have a positive diagonal and a trivial null space and still fail — which is exactly what the next section demonstrates.
Worked example by hand
Section titled “Worked example by hand”The book’s Example 3.4. Two matrices, identical except for a single entry:
Both are symmetric. Both have positive diagonals. One is an inner product and one is not.
Completing the square is the honest way to see it. For :
Check the expansion: , and adding gives in the last term. Both summands are squares, so the total is , and it is only when and — that is, only at the origin. Positive definite.
For :
Now the second term is subtracted, and there is nothing stopping it from winning. The book’s witness is :
Not positive definite, and therefore not an inner product. Under the vector would have squared length , so its “length” would be .
Where exactly does it break?
Section titled “Where exactly does it break?”Vary the lower-right entry and keep the rest: . Completing the square gives , so positive definiteness needs — and the determinant agrees, changing sign at exactly .
| smallest eigenvalue | verdict | ||
|---|---|---|---|
| 5.0 | SPD — the book’s | ||
| 4.5 | SPD | ||
| 4.0 | the boundary — positive semidefinite, not definite | ||
| 3.5 | indefinite | ||
| 3.0 | indefinite — the book’s |
At the matrix is only semidefinite: for without being zero. That fails Definition 3.2, and it fails in a way that matters downstream — a nonzero vector of length zero breaks the positive-definiteness of the induced norm too.
The book’s other inner product
Section titled “The book’s other inner product”Example 3.3 defines, on ,
which in matrix form is , with eigenvalues and — both positive, so this really is an inner product. And it disagrees with the dot product about more than magnitude. Take and :
Different sign. Under the dot product these two vectors are (weakly) pointing the same way; under Example 3.3’s inner product they are pointing away from each other. Whatever “similar” means, it means something relative to a choice.
import numpy as np
A1 = np.array([[9.0, 6.0], [6.0, 5.0]])
A2 = np.array([[9.0, 6.0], [6.0, 3.0]])
A3 = np.array([[1.0, -1.0], [-1.0, 2.0]]) # Example 3.3
for name, A in (("A1", A1), ("A2", A2), ("Ex3.3", A3)):
ev = np.linalg.eigvalsh(A)
try:
np.linalg.cholesky(A)
chol = "succeeds"
except np.linalg.LinAlgError:
chol = "fails"
print(f"{name:6} eig {np.round(ev, 6)} det {np.linalg.det(A):+.4f} "
f"cholesky {chol} spd {bool(np.all(ev > 0))}")
w = np.array([2.0, -3.0])
print("witness (2,-3): A1 gives", float(w @ A1 @ w), " A2 gives", float(w @ A2 @ w))
x, y = np.array([1.0, 2.0]), np.array([3.0, -1.0])
print("dot product:", float(x @ y), " Example 3.3:", float(x @ A3 @ y))A1 eig [ 0.675445 13.324555] det +9.0000 cholesky succeeds spd True
A2 eig [-0.708204 12.708204] det -9.0000 cholesky fails spd False
Ex3.3 eig [0.381966 2.618034] det +1.0000 cholesky succeeds spd True
witness (2,-3): A1 gives 9.0 A2 gives -9.0
dot product: 1.0 Example 3.3: -6.0See it move
Section titled “See it move”The first sketch is Example 3.4 with the broken entry on a knob. The background is the quadratic form — green where it is positive, red where it is negative — and the white curve is where it equals zero. Slide down through and watch the red wedge open.
The second sketch is the payoff: the same two vectors, and an inner product you control. Drag the matrix entries and watch the inner product’s sign flip while the arrows do not move at all.
An inner product is a linear map’s worth of information, so the matrix stepper from Chapter 2 applies directly. Here it is on Example 3.3’s matrix — note the eigenvalues it reports, which are the definiteness test:
Both eigenvalues are positive, so no direction gets flipped or flattened — which is exactly what positive definiteness means geometrically.
From scratch
Section titled “From scratch”Testing a candidate has three parts, and the third one has a good implementation and a bad one:
import numpy as np
def is_inner_product(A, tol=1e-12):
"""Test the conditions of Definition 3.2 on a candidate matrix A."""
A = np.asarray(A, dtype=float)
checks = {}
# 1. Bilinearity is automatic for x^T A y. Any matrix gives a bilinear form;
# that is what the matrix form of Equation 3.10 means. Nothing to test.
checks["bilinear"] = True
# 2. Symmetry.
checks["symmetric"] = bool(np.allclose(A, A.T, atol=tol))
# 3. Positive definiteness. Cholesky is the right test: it succeeds exactly
# when the matrix is positive definite, so there is no tolerance to pick.
# Comparing eigenvalues to zero needs one, and the choice is where the
# semidefinite boundary case slips through.
if not checks["symmetric"]:
checks["positive definite"] = False
else:
try:
np.linalg.cholesky(A)
checks["positive definite"] = True
except np.linalg.LinAlgError:
checks["positive definite"] = False
return all(checks.values()), checks
candidates = {
"identity (the dot product)": np.eye(3),
"A1 from Example 3.4": [[9, 6], [6, 5]],
"A2 from Example 3.4": [[9, 6], [6, 3]],
"the a = 4 boundary": [[9, 6], [6, 4]],
"non-symmetric": [[2, 0], [1, 2]],
"Example 3.3": [[1, -1], [-1, 2]],
}
for name, A in candidates.items():
ok, detail = is_inner_product(A)
print(f"{'YES' if ok else 'no':4} {name:28} "
f"symmetric={detail['symmetric']} definite={detail['positive definite']}")YES identity (the dot product) symmetric=True definite=True
YES A1 from Example 3.4 symmetric=True definite=True
no A2 from Example 3.4 symmetric=True definite=False
no the a = 4 boundary symmetric=True definite=False
no non-symmetric symmetric=False definite=False
YES Example 3.3 symmetric=True definite=TrueSix candidates, three accepted. The instructive rejection is the fourth, and it is worth checking why the naive test disagrees:
import numpy as np
boundary = np.array([[9.0, 6.0], [6.0, 4.0]])
print("eigenvalues:", np.round(np.linalg.eigvalsh(boundary), 12))
print("a >= 0 test would accept it:", bool(np.all(np.linalg.eigvalsh(boundary) >= 0)))
print("cholesky accepts it:", end=" ")
try:
np.linalg.cholesky(boundary)
print(True)
except np.linalg.LinAlgError:
print(False)
w = np.array([2.0, -3.0])
print("but (2,-3) has squared length", float(w @ boundary @ w), "while being nonzero")eigenvalues: [ 0. 13.]
a >= 0 test would accept it: True
cholesky accepts it: False
but (2,-3) has squared length 0.0 while being nonzeroThe eigenvalues at the boundary are exactly and , so np.all(eigvalsh(A) >= 0) returns True
and a nonzero vector nevertheless has length zero. That is positive semidefiniteness, and Definition
3.2 asks for the strict version. Cholesky tests the strict version by construction — it is the test to
reach for, and it happens to be about twice as fast as an eigendecomposition as well.
One more thing the run shows: the shear is rejected on symmetry, before definiteness is ever examined. It is worth knowing that its symmetric part is positive definite, so the shear gives a perfectly positive quadratic form while still failing to be an inner product. Definiteness of the form is not enough; the matrix itself has to be symmetric, or the two arguments are not interchangeable.
On real data
Section titled “On real data”Reading the plot
Section titled “Reading the plot”From the surface plot. The interesting feature of ‘s panel is not that a negative region exists but that it is a wedge through the origin, not a bounded blob. Positive definiteness is a statement about directions rather than about magnitudes: the form is homogeneous of degree two, so if it is negative at it is negative along the whole line through , scaled by . The negative eigenvalue is the value of the form at its own eigenvector, and that is the most negative value any unit vector can produce. The book’s witness is a different direction in the same wedge — normalised, it scores , which is close to the extreme without being it.
Note also that ‘s largest eigenvalue is — comfortably positive. A single negative eigenvalue among positives is enough. There is no “mostly positive definite”.
From the unit sets. The three curves have the same centre and enclose the point to different depths, which is the visual form of the statement that the same vector has three lengths. More usefully: the shape tells you what the inner product cares about. The axis-aligned ellipse of is narrow in , meaning is expensive — a small step in counts as much length as a bigger step in . The tilted ellipse of Equation 3.19 is stretched along the diagonal , meaning that agreement between the coordinates is cheap: moving both together costs less length than moving one alone. That is what a negative off-diagonal entry does, and it is exactly the structure a covariance matrix has when two features are positively correlated.
Pitfalls
Section titled “Pitfalls”Compare
Section titled “Compare”| candidate | matrix | inner product? | why |
|---|---|---|---|
| dot product | yes | symmetric, all eigenvalues | |
| weighted dot | , | yes | symmetric, eigenvalues are the weights |
| Example 3.3 | yes | eigenvalues , | |
| Mahalanobis | for invertible | yes | a covariance matrix of full rank is SPD, and so is its inverse |
| yes | completing the square gives a sum of two squares | ||
| the boundary | no | semidefinite: has squared length | |
| no | has squared length | ||
| a shear | no | not symmetric |
-
Theorem 3.5 says something stronger than 'matrices give inner products'. What is the extra content?
The 'if and only if' is what makes the test practical: checking a candidate reduces to checking whether one matrix is SPD, with no exotic cases to worry about. Note that plain symmetry is not enough — A2 of Example 3.4 is symmetric and fails.
pch.quizShowAnswer
B — That the correspondence runs both ways: every inner product on a finite-dimensional real vector space with a fixed basis IS x-transpose A y for some symmetric positive definite A, so there are no other kinds — The 'if and only if' is what makes the test practical: checking a candidate reduces to checking whether one matrix is SPD, with no exotic cases to worry about. Note that plain symmetry is not enough — A2 of Example 3.4 is symmetric and fails.
-
A2 = [[9, 6], [6, 3]] has positive diagonal entries and a trivial-looking structure. Why is it not an inner product?
The determinant is -9 and the eigenvalues are -0.708 and 12.708. One negative eigenvalue among positive ones is enough; there is no partial credit for definiteness.
pch.quizShowAnswer
B — Because completing the square gives (3x1 + 2x2)^2 minus x2^2, and the witness (2, -3) makes that minus 9 — a nonzero vector with negative squared length — The determinant is -9 and the eigenvalues are -0.708 and 12.708. One negative eigenvalue among positive ones is enough; there is no partial credit for definiteness.
-
Why does the from-scratch code use Cholesky rather than comparing eigenvalues to zero?
It is also about twice as fast, but the correctness argument is the one that matters. Semidefinite is not definite, and the a = 4 case is exactly where the two tests disagree.
pch.quizShowAnswer
B — Because Cholesky tests definiteness exactly, whereas an eigenvalue comparison needs a tolerance — and at the a = 4 boundary the eigenvalues are 0 and 13, so a >= 0 test wrongly accepts a matrix that Definition 3.2 rejects — It is also about twice as fast, but the correctness argument is the one that matters. Semidefinite is not definite, and the a = 4 case is exactly where the two tests disagree.
-
Under the dot product, x = (1, 2) and y = (3, -1) have inner product +1. Under Example 3.3's inner product the value is -6. What should you conclude?
Example 3.3's matrix has eigenvalues 0.382 and 2.618, so it is a perfectly valid inner product. The sign flip is the point: cosine similarity, orthogonality and angle all inherit this relativity, which is what the next two pages develop.
pch.quizShowAnswer
B — Nothing follows — the two numbers measure different things, and whether two vectors 'agree' is a statement relative to a chosen inner product, including its sign — Example 3.3's matrix has eigenvalues 0.382 and 2.618, so it is a perfectly valid inner product. The sign flip is the point: cosine similarity, orthogonality and angle all inherit this relativity, which is what the next two pages develop.
🧪 Try It Yourself
Section titled “🧪 Try It Yourself”Exercise 1 – Test the three conditions
Section titled “Exercise 1 – Test the three conditions”Exercise 2 – The worst direction, and the book’s witness
Section titled “Exercise 2 – The worst direction, and the book’s witness”Exercise 3 – Bilinearity, symmetry, definiteness, all measured
Section titled “Exercise 3 – Bilinearity, symmetry, definiteness, all measured”Exercise 4 – The Gram matrix of a basis
Section titled “Exercise 4 – The Gram matrix of a basis”Exercise 5 – Where does it break?
Section titled “Exercise 5 – Where does it break?”Recall card
Section titled “Recall card”- An inner product is a bilinear, symmetric, positive definite function of two vectors, and those three words are the entire definition.
- Bilinear means linear in each argument separately — scaling both arguments scales the result by the square, so an inner product is not a linear map.
- Theorem 3.5 is an if and only if: every inner product on a finite-dimensional real space is x-transpose A y for a symmetric positive definite A, and every such A gives one.
- Positive definiteness is what makes the induced norm real, since length is the square root of the inner product of a vector with itself.
- A positive diagonal is necessary but not sufficient — the book’s second matrix of Example 3.4 has both diagonal entries positive and a witness of squared length minus nine.
- Semidefinite is not definite: at the boundary value the eigenvalues are zero and thirteen, and a nonzero vector has length zero. Test with Cholesky, not with eigenvalues compared to zero.
- The dot product is the case where the matrix is the identity, which is why it treats coordinates as independent and equally weighted.
Next: Lengths and Distances — the first two things the inner product hands you for free.
pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading