TL;DR
The Cauchy–Schwarz inequality says that the dot product of two vectors is never larger than the product of their lengths. It gives a hard upper limit on how much two vectors can line up, and it is the reason the cosine of the angle between two vectors always lies between minus one and one. Equality holds only when one vector is a multiple of the other.
Builds on: Vector Norm, Dot Product · Leads to: Large Sieve Inequality (an analysis result that uses the same bound), Hilbert Space (where the same inequality holds for functions)
Where it's used
Correlation in statistics. Treat two lists of measurements, after centring each around its mean, as two vectors. Their dot product divided by the product of their lengths is the correlation coefficient. Cauchy–Schwarz is exactly the reason that this number cannot be bigger than 1 or smaller than minus 1.
Search and text similarity. A search engine turns each document into a vector of word counts, then ranks documents by how closely their vectors point in the same direction, measured by cosine similarity. The cosine is always between minus one and one, because the inequality bounds the dot product by the lengths.
Machine learning proofs. Many convergence proofs for gradient methods bound a dot product between a gradient and a step by the product of their sizes. The bound is the first line of the argument, and the rest of the proof works with the resulting number. The same bound also yields the triangle inequality for lengths, which is what lets us say that the length of a sum is at most the sum of lengths.
How it works
Take two small vectors in the plane, and , and check the inequality by hand.
-
Pick the two vectors. and . Each is a point, or an arrow from the origin.
-
Compute the dot product. Multiply matching entries and add: . Check: the answer is a single number, not a vector.
-
Compute the two lengths. The length of is . The length of is . Check: each length is a square root of a sum of squares.
-
Multiply the lengths. , to two decimals. Check: this is the largest value the dot product is allowed to take.
-
Compare. The dot product is less than , so the inequality holds. A cleaner way to see the same fact is to square both sides: and , and . Check: the gap is small, so these two vectors point fairly close to the same direction.
-
See equality. Now take , which is . Its dot product with is , and the product of lengths is . The two sides are equal. Check: points along the same line as , and that is the only way to reach equality.
The plot below shows the ratio in step 5 as an angle. The dot product divided by the product of lengths is the cosine of the angle between the vectors, so it can never leave the band between minus one and one.
- cos of the angle between two vectors
- upper limit 1
- lower limit -1
The math
For any two vectors and in ,
Equality holds if and only if one of the vectors is a scalar multiple of the other, that is, or for some number .
In words: the absolute value of the dot product is at most the product of the lengths. The absolute value on the left covers vectors that point in opposite directions, where the dot product is negative.
Step 2 in symbols: the ratio form
When and are both nonzero, divide both sides by :
The middle quantity is, by definition, the cosine of the angle between and , so this says exactly , which is true for every angle. The plot in the walkthrough draws this ratio.
Step 3 in symbols: the proof
The idea is to look at the length of , a vector that is with the part along removed for a suitable . Its squared length is never negative:
This holds for every number . Assume and choose . This is the value that makes perpendicular to , since , so the leftover piece is exactly the part of that is not along . Substituting gives
Multiply by and rearrange to get . Taking square roots gives the inequality.
Step 4 in symbols: equality
Equality in the proof forces , which means , so . The converse is a direct check: if , both sides equal . This is why equality needs the vectors to lie on one line.
Worked examples
Take and .
- Dot product: .
- Lengths: and .
- Product of lengths: .
- Compare: , so the inequality holds with room to spare.
- The cosine is , which is the cosine of .
Interpretation: the vectors are at a 45 degree angle, so they are not parallel and the inequality is strict.
Take and .
- Dot product: .
- Lengths: and .
- Product of lengths: .
- Squared comparison: and , and .
- Cosine: .
Interpretation: the cosine is close to one, so the vectors point in nearly the same direction, but they are not parallel.
Two short documents are described by counts of the words cat, dog and fish. Document has counts and document has counts .
- Dot product: .
- Lengths: and .
- Product of lengths: .
- Compare: , so the inequality holds.
- Cosine similarity: .
Interpretation: a cosine of about 0.42 says the documents share some vocabulary, but they differ a lot. The bound from the inequality is what keeps this score on a fixed scale, so documents of very different length can still be compared.
Try it: documents and . What are the dot product, the product of lengths, and the cosine? Answer: the dot product is . The lengths are and , whose product is . So the two sides are equal and the cosine is 1. This is correct because , so the documents point the same way.
Common mistakes and tradeoffs
It is tempting to think the bound is the sum of the two lengths. In fact it is their product. Take : the dot product is , while the sum of the lengths is , so the sum would be a false bound. The product is exactly right.
It is tempting to think equality means the two vectors are the same. In fact equality means they are parallel, so or also reach it. The absolute value on the left is what lets opposite directions count.
It is tempting to think the inequality needs unit vectors. In fact it holds for any vectors. The lengths on the right side do the scaling, which is why the cosine form divides by them.
It is tempting to think Cauchy–Schwarz is only about arrows in the plane. In fact it holds in any space with an inner product, including spaces of functions, which is the setting of Hilbert spaces.
When to use it: whenever you need an upper bound on a dot product or an inner product, or need to show that a cosine or correlation stays in its range.
When not to use it: when you measure size with a different norm, such as the sum of absolute values. Then the matching bound is Hölder's inequality, which pairs the two norms differently.
| Question | Use | Why |
|---|---|---|
| Is the dot product at most the product of lengths? | Cauchy–Schwarz | It is the exact statement |
| Is the length of a sum at most the sum of lengths? | Triangle inequality | Follows from Cauchy–Schwarz |
| Are the two vectors parallel? | Check for equality | Equality holds only then |
History
Augustin-Louis Cauchy stated the inequality for finite sums in the 1820s, in his lectures on analysis. Viktor Bunyakovsky proved the integral form around 1859, and Hermann Amandus Schwarz gave a version for integrals in 1888. The inequality is named for the three of them because each contributed a form of it.
It caught on because it is short to prove and reaches far. The same bound gives the triangle inequality, shows that correlations stay between minus one and one, and gives the basic estimates in analysis. Modern textbooks prove it from the squared-length argument above, which works without any calculus.
Recap
- The dot product of two vectors is at most the product of their lengths, in absolute value.
- The proof looks at the squared length of for a well-chosen , which is never negative.
- Dividing by the lengths gives the cosine, which therefore lies between minus one and one.
- Equality holds exactly when one vector is a multiple of the other.
- The inequality holds in any inner product space, which is where Hilbert Space comes in.
Next, read Large Sieve Inequality to see the same bound used in analysis.
Check yourself
QuestionRecall: state the Cauchy–Schwarz inequality, and say when equality holds.Show answer
For any vectors and , the absolute value of the dot product is at most the product of the lengths: . Equality holds exactly when one vector is a scalar multiple of the other, so they lie on the same line.
QuestionComputation: for and , compute the dot product, the product of the lengths, and the cosine.Show answer
The dot product is . The lengths are and , and their product is . The inequality holds, since . The cosine is , so the vectors are nearly perpendicular.
QuestionWhy: why does equality in Cauchy–Schwarz force the two vectors to be parallel?Show answer
In the proof, equality makes the squared length of zero for the chosen . A vector with zero squared length is the zero vector, so , which means . Two vectors that are multiples of one another are parallel.
QuestionApplied: a colleague reports two sensor readings, treated as vectors, with a dot product of 50 and lengths 4 and 5. Is this possible?Show answer
No. The product of the lengths is , and the inequality says the dot product cannot exceed 20 in absolute value. The value 50 breaks the bound, so the readings, the lengths, or the dot product calculation must be wrong, and the colleague should recheck the data before using it.